Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

file_object.h File Reference

#include "common.h"

Go to the source code of this file.

Functions

void file_object_init (void)
 Initializes this module and must be called before using any other function of this module.
void file_object_close (void)
 Releases all used resources and should be called on shutdown.
file_objectfile_object_new (int fd, const char *pathname, int accmode)
 Acquires a new file object for a given pathname.
file_objectfile_object_open (const char *pathname, int accmode)
 Acquires a file object for a given pathname and access mode.
ssize_t file_object_pwrite (const struct file_object *fo, const void *data, size_t buf, filesize_t offset)
 Write the given data to a file object at the given offset.
ssize_t file_object_pwritev (const struct file_object *fo, const struct iovec *iov, int iov_cnt, filesize_t offset)
 Write the given data to a file object at the given offset.
ssize_t file_object_pread (const struct file_object *fo, void *data, size_t size, filesize_t pos)
 Read data from the file object from the given offset.
ssize_t file_object_preadv (const struct file_object *fo, struct iovec *iov, int iov_cnt, filesize_t offset)
 Read data from a file object from the given offset.
int file_object_get_fd (const struct file_object *fo)
 Get the file descriptor associated with a file object.
const char * file_object_get_pathname (const struct file_object *fo)
 Get the pathname associated with a file object.
void file_object_release (struct file_object **fo_ptr)
 Releases a file object and frees its memory.
void file_object_revoke (const char *pathname)
 Revokes all file objects associated with the pathname.


Function Documentation

void file_object_close void   ) 
 

Releases all used resources and should be called on shutdown.

Note:
Still existing file objects are not destroyed.

int file_object_get_fd const struct file_object *const   fo  ) 
 

Get the file descriptor associated with a file object.

This should not be used lightly and the returned file descriptor should not be cached. Future versions might open/close the file descriptor on demand or dynamically.

Parameters:
An initialized file object.
Returns:
The file descriptor of the file object.

const char* file_object_get_pathname const struct file_object *const   fo  ) 
 

Get the pathname associated with a file object.

Parameters:
An initialized file object.
Returns:
The pathname of the file object.

void file_object_init void   ) 
 

Initializes this module and must be called before using any other function of this module.

struct file_object* file_object_new const int  fd,
const char *const   pathname,
int  accmode
 

Acquires a new file object for a given pathname.

There must not be any file object registered for this pathname already.

Parameters:
pathname An absolute pathname.
Returns:
On failure NULL is returned. On success a file object is returned.

struct file_object* file_object_open const char *const   pathname,
int  accmode
 

Acquires a file object for a given pathname and access mode.

If no matching file object exists, NULL is returned.

Parameters:
pathname An absolute pathname.
Returns:
On failure NULL is returned. On success a file object is returned.

ssize_t file_object_pread const struct file_object *const   fo,
void *const   data,
const size_t  size,
const filesize_t  pos
 

Read data from the file object from the given offset.

Parameters:
fo An initialized file object.
data A buffer for holding the data to be read.
size The amount of bytes to read (i.e., the size of data).
offset The file offset from which to start reading data.
Returns:
On failure -1 is returned and errno is set. On success the amount of bytes read is returned.

ssize_t file_object_preadv const struct file_object *const   fo,
struct iovec *const   iov,
const int  iov_cnt,
const filesize_t  pos
 

Read data from a file object from the given offset.

Parameters:
fo An initialized file object.
iov An initialized I/O vector buffer.
iov_cnt The number of initialized buffer in iov (i.e., its size).
offset The file offset at which to start reading data.
Returns:
On failure -1 is returned and errno is set. On success the amount of data bytes read is returned.

ssize_t file_object_pwrite const struct file_object *const   fo,
const void *const   data,
const size_t  size,
const filesize_t  pos
 

Write the given data to a file object at the given offset.

Parameters:
fo An initialized file object.
data An initialized buffer holding the data to write.
size The amount of bytes to write (i.e., the size of data).
offset The file offset at which to start writing the data.
Returns:
On failure -1 is returned and errno is set. On success the amount of bytes written is returned.

ssize_t file_object_pwritev const struct file_object *const   fo,
const struct iovec *const   iov,
const int  iov_cnt,
const filesize_t  pos
 

Write the given data to a file object at the given offset.

Parameters:
fo An initialized file object.
iov An initialized I/O vector buffer.
iov_cnt The number of initialized buffer in iov (i.e., its size).
offset The file offset at which to start writing the data.
Returns:
On failure -1 is returned and errno is set. On success the amount of data bytes written is returned.

void file_object_release struct file_object **  fo_ptr  ) 
 

Releases a file object and frees its memory.

The underlying file descriptor however is not closed unless no other file object references it. The pointer is nullified.

Parameters:
fo_ptr If pointing to NULL, nothing happens. Otherwise, it must point to an initialized file_object.

void file_object_revoke const char *const   pathname  ) 
 

Revokes all file objects associated with the pathname.

This is useful after moving a file to prevent that file_object_open() returns a file object associated with the now removed file.

Parameters:
pathname An absolute pathname.


Generated on Sat Jun 30 17:53:26 2007 for gtk-gnutella by  doxygen 1.3.9.1