Skip to content

Commit

Permalink
Implement FIONREAD for real files and sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Jan 20, 2020
1 parent 804e387 commit 0a01c66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fs/real.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/statvfs.h>
#include <poll.h>

#include "debug.h"
#include "kernel/errno.h"
#include "kernel/calls.h"
#include "kernel/fs.h"
Expand Down Expand Up @@ -442,6 +443,26 @@ int realfs_setflags(struct fd *fd, dword_t flags) {
return 0;
}

ssize_t realfs_ioctl_size(int cmd) {
if (cmd == FIONREAD_)
return sizeof(dword_t);
return -1;
}

int realfs_ioctl(struct fd *fd, int cmd, void *arg) {
int err;
size_t nread;
switch (cmd) {
case FIONREAD_:
err = ioctl(fd->real_fd, FIONREAD, &nread);
if (err < 0)
return errno_map();
*(dword_t *) arg = nread;
return 0;
}
return _ENOTTY;
}

const struct fs_ops realfs = {
.name = "real", .magic = 0x7265616c,
.mount = realfs_mount,
Expand Down Expand Up @@ -477,6 +498,8 @@ const struct fd_ops realfs_fdops = {
.lseek = realfs_lseek,
.mmap = realfs_mmap,
.poll = realfs_poll,
.ioctl_size = realfs_ioctl_size,
.ioctl = realfs_ioctl,
.fsync = realfs_fsync,
.close = realfs_close,
.getflags = realfs_getflags,
Expand Down
2 changes: 2 additions & 0 deletions fs/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,8 @@ const struct fd_ops socket_fdops = {
.poll = realfs_poll,
.getflags = realfs_getflags,
.setflags = realfs_setflags,
.ioctl_size = realfs_ioctl_size,
.ioctl = realfs_ioctl,
};

#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
Expand Down
2 changes: 2 additions & 0 deletions kernel/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ ssize_t realfs_write(struct fd *fd, const void *buf, size_t bufsize);
int realfs_poll(struct fd *fd);
int realfs_getflags(struct fd *fd);
int realfs_setflags(struct fd *fd, dword_t arg);
ssize_t realfs_ioctl_size(int cmd);
int realfs_ioctl(struct fd *fd, int cmd, void *arg);
int realfs_close(struct fd *fd);

// adhoc fs
Expand Down

0 comments on commit 0a01c66

Please sign in to comment.