My Kernel v0.1.0
file_operations Struct Reference

Operations that can be performed on an opened file.

#include <file.h>

Data Fields

error_t(* open )(struct file *)
 Filesystem-specific open function (optional). More...
 
void(* close )(struct file *)
 Called when closing a file (optional). More...
 
ssize_t(* write )(struct file *, const char *, size_t)
 Write a buffer to the file at the current position.
 
ssize_t(* read )(struct file *, char *, size_t)
 Read the content at the current position in the file.
 
size_t(* size )(struct file *)
 Compute the file's total size in memory.
 
error_t(* bind )(struct file *, struct sockaddr *addr, size_t len)
 Associate a socket with a local address.
 
error_t(* connect )(struct file *, struct sockaddr *addr, size_t len)
 Connect to a remote host.
 
ssize_t(* sendmsg )(struct file *, const struct msghdr *, int flags)
 Send a message through an endpoint (socket)
 
ssize_t(* recvmsg )(struct file *, struct msghdr *, int flags)
 Send a message through an endpoint (socket)
 
off_t(* seek )(struct file *, off_t, int whence)
 Reposition the open file description offset. More...
 

Field Documentation

◆ close

void(* file_operations::close) (struct file *)

If present, it should release any memory allocated by the driver to keep trace of the file's internal state.

◆ open

error_t(* file_operations::open) (struct file *)

If present it is called when opening a new file, and can be used to initialize the file's priv field.

◆ seek

off_t(* file_operations::seek) (struct file *, off_t, int whence)
Note
It is possible for a description's offset to go beyond the backing file's size. In this case subsequent reads will return empty bytes until data is actually written into the gap.
Returns
The updated offset
See also
man 2 lseek

The documentation for this struct was generated from the following file: