11#include <kernel/atomic.h>
13#include <kernel/spinlock.h>
34 FD_RW = FD_READ | FD_WRITE,
36 FD_NOINHERIT = _FNOINHERIT,
107 error_t (*
bind)(
struct file *,
struct sockaddr *addr,
size_t len);
109 error_t (*
connect)(
struct file *,
struct sockaddr *addr,
size_t len);
111 ssize_t (*
sendmsg)(
struct file *,
const struct msghdr *,
int flags);
148#define __file_ops(_default, _file, _ops, ...) \
149 (_file->ops->_ops ? _file->ops->_ops(_file __VA_OPT__(, ) __VA_ARGS__) \
152#define file_ops(_file, _ops, ...) \
153 __file_ops(E_NOT_SUPPORTED, _file, _ops, __VA_ARGS__)
155#define file_size(file) file_ops(file, size)
157#define file_write(file, buf, len) file_ops(file, write, buf, len)
158#define file_read(file, buf, len) file_ops(file, read, buf, len)
159#define file_seek(file, off, whence) file_ops(file, seek, off, whence)
161#define file_bind(file, addr, len) file_ops(file, bind, addr, len)
162#define file_connect(file, addr, len) file_ops(file, connect, addr, len)
164#define file_sendmsg(file, msg, flags) file_ops(file, sendmsg, msg, flags)
165ssize_t file_send(
struct file *
file,
const char *data,
size_t len,
int flags);
166ssize_t file_sendto(
struct file *
file,
const char *data,
size_t len,
int flags,
167 struct sockaddr *addr,
size_t addrlen);
169#define file_recvmsg(file, msg, flags) file_ops(file, recvmsg, msg, flags)
170ssize_t file_recv(
struct file *
file,
const char *data,
size_t len,
int flags);
171ssize_t file_recvfrom(
struct file *
file,
const char *data,
size_t len,
172 int flags,
struct sockaddr *addr,
size_t *addrlen);
static struct file * file_get(struct file *file)
Increment an open file description's reference count.
Definition: file.h:60
static void file_close(struct file *file)
Free a file struct and release its content.
Definition: file.h:138
static void file_put(struct file *file)
Decrement an open file description's reference count.
Definition: file.h:71
off_t default_file_seek(struct file *file, off_t off, int whence)
Reposition the open file description offset.
Definition: file.c:68
void file_modified(struct file *file)
Update the file's vnode's last modification time.
Definition: file.c:63
void file_accessed(struct file *file)
Update the file's vnode's last access time.
Definition: file.c:58
struct file * file_open(struct vnode *, const struct file_operations *)
Create a new file structure.
Definition: file.c:10
An atomic value.
Definition: atomic.h:22
Operations that can be performed on an opened file.
Definition: file.h:85
off_t(* seek)(struct file *, off_t, int whence)
Reposition the open file description offset.
Definition: file.h:124
ssize_t(* sendmsg)(struct file *, const struct msghdr *, int flags)
Send a message through an endpoint (socket)
Definition: file.h:111
error_t(* bind)(struct file *, struct sockaddr *addr, size_t len)
Associate a socket with a local address.
Definition: file.h:107
error_t(* open)(struct file *)
Filesystem-specific open function (optional).
Definition: file.h:92
size_t(* size)(struct file *)
Compute the file's total size in memory.
Definition: file.h:105
ssize_t(* read)(struct file *, char *, size_t)
Read the content at the current position in the file.
Definition: file.h:103
void(* close)(struct file *)
Called when closing a file (optional).
Definition: file.h:99
ssize_t(* recvmsg)(struct file *, struct msghdr *, int flags)
Send a message through an endpoint (socket)
Definition: file.h:113
ssize_t(* write)(struct file *, const char *, size_t)
Write a buffer to the file at the current position.
Definition: file.h:101
error_t(* connect)(struct file *, struct sockaddr *addr, size_t len)
Connect to a remote host.
Definition: file.h:109
Opened file description.
Definition: file.h:45
void * priv
Private data used by the driver.
Definition: file.h:47
const struct file_operations * ops
Definition: file.h:49
off_t pos
Current offset into the file.
Definition: file.h:46
atomic_t refcount
Number of references to this file.
Definition: file.h:50
spinlock_t lock
Synchronization lock.
Definition: file.h:51
struct vnode * vnode
The file's vnode in the VFS.
Definition: file.h:48
int flags
Parameter flags (.
Definition: file.h:52
Spinlock.
Definition: spinlock.h:29
represents a single virtual node
Definition: vfs.h:206