11#include <kernel/atomic.h>
13#include <kernel/spinlock.h>
85 ssize_t (*
write)(
struct file *,
const char *, size_t);
87 ssize_t (*
read)(
struct file *,
char *, size_t);
91 error_t (*
bind)(
struct file *,
struct sockaddr *addr,
size_t len);
93 error_t (*
connect)(
struct file *,
struct sockaddr *addr,
size_t len);
95 ssize_t (*
sendmsg)(
struct file *,
const struct msghdr *,
int flags);
97 ssize_t (*
recvmsg)(
struct file *,
struct msghdr *,
int flags);
132#define __file_ops(_default, _file, _ops, ...) \
133 (_file->ops->_ops ? _file->ops->_ops(_file __VA_OPT__(, ) __VA_ARGS__) \
136#define file_ops(_file, _ops, ...) \
137 __file_ops(E_NOT_SUPPORTED, _file, _ops, __VA_ARGS__)
139#define file_size(file) file_ops(file, size)
141#define file_write(file, buf, len) file_ops(file, write, buf, len)
142#define file_read(file, buf, len) file_ops(file, read, buf, len)
143#define file_seek(file, off, whence) file_ops(file, seek, off, whence)
145#define file_bind(file, addr, len) file_ops(file, bind, addr, len)
146#define file_connect(file, addr, len) file_ops(file, connect, addr, len)
148#define file_sendmsg(file, msg, flags) file_ops(file, sendmsg, msg, flags)
149ssize_t file_send(
struct file *
file,
const char *data,
size_t len,
int flags);
150ssize_t file_sendto(
struct file *
file,
const char *data,
size_t len,
int flags,
151 struct sockaddr *addr,
size_t addrlen);
153#define file_recvmsg(file, msg, flags) file_ops(file, recvmsg, msg, flags)
154ssize_t file_recv(
struct file *
file,
const char *data,
size_t len,
int flags);
155ssize_t file_recvfrom(
struct file *
file,
const char *data,
size_t len,
156 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:44
static void file_close(struct file *file)
Free a file struct and release its content.
Definition: file.h:122
static void file_put(struct file *file)
Decrement an open file description's reference count.
Definition: file.h:55
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:69
off_t(* seek)(struct file *, off_t, int whence)
Reposition the open file description offset.
Definition: file.h:108
ssize_t(* sendmsg)(struct file *, const struct msghdr *, int flags)
Send a message through an endpoint (socket)
Definition: file.h:95
error_t(* bind)(struct file *, struct sockaddr *addr, size_t len)
Associate a socket with a local address.
Definition: file.h:91
error_t(* open)(struct file *)
Filesystem-specific open function (optional).
Definition: file.h:76
size_t(* size)(struct file *)
Compute the file's total size in memory.
Definition: file.h:89
ssize_t(* read)(struct file *, char *, size_t)
Read the content at the current position in the file.
Definition: file.h:87
void(* close)(struct file *)
Called when closing a file (optional).
Definition: file.h:83
ssize_t(* recvmsg)(struct file *, struct msghdr *, int flags)
Send a message through an endpoint (socket)
Definition: file.h:97
ssize_t(* write)(struct file *, const char *, size_t)
Write a buffer to the file at the current position.
Definition: file.h:85
error_t(* connect)(struct file *, struct sockaddr *addr, size_t len)
Connect to a remote host.
Definition: file.h:93
Opened file description.
Definition: file.h:29
void * priv
Private data used by the driver.
Definition: file.h:31
const struct file_operations * ops
Definition: file.h:33
off_t pos
Current offset into the file.
Definition: file.h:30
atomic_t refcount
Number of references to this file.
Definition: file.h:34
spinlock_t lock
Synchronization lock.
Definition: file.h:35
struct vnode * vnode
The file's vnode in the VFS.
Definition: file.h:32
int flags
Parameter flags (.
Definition: file.h:36
Spinlock.
Definition: spinlock.h:29
represents a single virtual node
Definition: vfs.h:205