vfs/file.h header reference
[Virtual File System module]

The source code of this header can be browsed online.

Description  

The node_open operation  

When opening a node, enum vfs_open_flags_e are passed to tell the VFS and the filesystem driver what type of operation is required.

When opening directories, the only valid operation is to open read-only. Thus the correct flags are: VFS_OPEN_READ | VFS_OPEN_DIR.

When opening files, one may open with VFS_OPEN_READ and/or VFS_OPEN_WRITE. If VFS_OPEN_APPEND is passed-in, write operations will always write at the end of file.

VFS_OPEN_CREATE is only valid for creating files (so it is invalid with VFS_OPEN_DIR), and is not supported at all layers of the VFS. It is valid when using vfs_open, but invalid when using node_open action of struct vfs_fs_ops_s (because node already exists).

VFS_OPEN_TRUNCATE is to erase contents of a file at opening, filesystem is responsible for implementing this flag.

Members  

Types  

Functions  

Macros  

Members detail  

#define VFS_FILE_CLEANUP(x)  

This macro is declared in vfs/file.h source file, line 169.

This macro defines the VFS file cleanup prototype

#define VFS_FILE_READ(x)  

This macro is declared in vfs/file.h source file, line 95.

this macro defines the file read operation prototype. Compatible with #FILEOPS_READ

#define VFS_FILE_SEEK(x)  

This macro is declared in vfs/file.h source file, line 132.

this macro defines the file seek operation prototype. Compatible with #FILEOPS_LSEEK

#define VFS_FILE_TRUNCATE(x)  

This macro is declared in vfs/file.h source file, line 151.

this macro defines the file truncate operation prototype

#define VFS_FILE_WRITE(x)  

This macro is declared in vfs/file.h source file, line 113.

this macro defines the file write operation prototype. Compatible with #FILEOPS_WRITE

#define _VFS_FILE_H_  

This macro is declared in vfs/file.h source file, line 53.

void vfs_file_cleanup(struct vfs_file_s *file)  

This function frees resources allocated by vfs_file_init.

typedef void (vfs_file_cleanup_t)(struct vfs_file_s *file)   

This typedef is declared in vfs/file.h source file, line 173.

This typedef free resources associated with a fs file.

This declaration involves expansion of the VFS_FILE_CLEANUP macro.

void vfs_file_close(struct vfs_file_s *file)  

this function closes an opened file.

  • file: File descriptor to close

void vfs_file_destroy(struct vfs_file_s *file)  

This function calls the vfs_file_s::close and the vfs_file_cleanup functions then free the file object. This is called when the file refcount reaches 0.

error_t vfs_file_init(struct vfs_file_s *file, const struct vfs_file_ops_s *ops, enum vfs_open_flags_e flags, struct vfs_node_s *node)  

This function initializes common fields of a file object.

struct vfs_file_ops_s  

This struct is declared in vfs/file.h source file, line 176.

FieldDescription
vfs_file_read_t * read;Read operation for this file
vfs_file_write_t * write;Write operation for this file
vfs_file_seek_t * seek;Seek operation for this file
vfs_file_truncate_t * truncate;Truncate operation for this file
vfs_file_cleanup_t * cleanup;Cleanup operation for this file, optional

ssize_t vfs_file_read(struct vfs_file_s *file, void *buffer, size_t size)  

this function reads from an opened file

Parameter list:

  • file: File descriptor
  • buffer: Buffer to read into
  • size: Size of the transfer

The return value is the size of buffer actually read

typedef ssize_t (vfs_file_read_t)(struct vfs_file_s *file, void *buffer, size_t size)   

This typedef is declared in vfs/file.h source file, line 109.

this typedef reads from a file.

Parameter list:

  • file: File descriptor to read from
  • buffer: User buffer to fill
  • size: Size of transfer in bytes

The return value is size or less for valid transfers, 0 on end-of-file condition, a negative number on error conditions

This declaration involves expansion of the VFS_FILE_READ macro.

See also VFS_FILE_READ.

bool_t vfs_file_refdec(struct vfs_file_s *file)  

this function decreases the file reference count and may delete the file if no more reference exist.

struct vfs_file_s * vfs_file_refinc(struct vfs_file_s *file)  

this function increases the file reference count and return the file itself.

struct vfs_file_s  

This struct is declared in vfs/file.h source file, line 185.

FieldDescription
struct vfs_node_s * node;Corresponding node in the FS
off_t offset;Current access position in file
enum vfs_open_flags_e flags;
const struct vfs_file_ops_s * ops;

off_t vfs_file_seek(struct vfs_file_s *file, off_t offset, enum vfs_whence_e whence)  

this function seeks to the given position into an opened file

Parameter list:

  • file: File descriptor to seek into
  • offset: To seek from given point
  • whence: Reference point to seek from

The return value is new absolute position from the beginning of file

typedef off_t (vfs_file_seek_t)(struct vfs_file_s *file, off_t offset, enum vfs_whence_e whence)   

This typedef is declared in vfs/file.h source file, line 148.

this typedef changes current point into a file.

Parameter list:

  • file: File descriptor to seek in
  • offset: Offset to move the point by
  • whence: Reference point to calculate the offset from

The return value is the new absolute point from start of file

this typedef function may be used to seek beyond end of file. This is not an error.

This declaration involves expansion of the VFS_FILE_SEEK macro.

See also VFS_FILE_SEEK.

off_t vfs_file_truncate(struct vfs_file_s *file, off_t new_size)  

this function truncates the file to the exact size new_size

Parameter list:

  • file: File to truncate
  • new_size: New file size

The return value is 0 if done

typedef off_t (vfs_file_truncate_t)(struct vfs_file_s *file, off_t new_size)   

This typedef is declared in vfs/file.h source file, line 166.

this typedef changes size of a file to exactly new_size

Parameter list:

  • file: File to truncate
  • new_size: Offset to cut at

The return value is 0 if done

this typedef function may be used to truncate beyond end of file. This will extent the file with zeros.

This declaration involves expansion of the VFS_FILE_TRUNCATE macro.

See also VFS_FILE_TRUNCATE.

ssize_t vfs_file_write(struct vfs_file_s *file, const void *buffer, size_t size)  

this function writes from an opened file

Parameter list:

  • file: File descriptor
  • buffer: Buffer to write into
  • size: Size of the transfer

The return value is the size of buffer actually written

typedef ssize_t (vfs_file_write_t)(struct vfs_file_s *file, const void *buffer, size_t size)   

This typedef is declared in vfs/file.h source file, line 127.

this typedef writes to a file.

Parameter list:

  • file: File descriptor to write to
  • buffer: User buffer to read data from
  • size: Size of transfer in bytes

The return value is size or less for valid transfers, 0 on end-of-file condition, a negative number on error conditions

This declaration involves expansion of the VFS_FILE_WRITE macro.

See also VFS_FILE_WRITE.

enum vfs_open_flags_e  

This enum is declared in vfs/file.h source file, line 65.

IdentifierDescription
VFS_OPEN_READAllow read operation
VFS_OPEN_WRITEAllow write operation
VFS_OPEN_CREATECreate the file if nonexistant
VFS_OPEN_APPENDAlways write at end
VFS_OPEN_TRUNCATEErase contents of file on open, this is filesystem-implemented
VFS_OPEN_DIROpen a directory (only valid with VFS_OPEN_READ)

enum vfs_whence_e  

This enum is declared in vfs/file.h source file, line 82.

Compatible with enum seek_whence_e

IdentifierDescription
VFS_SEEK_SETSeek from start of file
VFS_SEEK_ENDSeek from end of file
VFS_SEEK_CURSeek from current point in file

Valid XHTML 1.0 StrictGenerated by diaxen on Wed Oct 17 21:18:39 2018 using MkDoc