Skip to content

Commit

Permalink
syscalls: create sys_statvfs syscalls
Browse files Browse the repository at this point in the history
JIRA: RTOS-965
  • Loading branch information
badochov committed Jan 17, 2025
1 parent 479e752 commit 4f18d62
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ enum {
/* Directory operations */
mtLookup, mtLink, mtUnlink, mtReaddir,

mtCount
mtCount,

mtStat = 0xf53
};

/* clang-format on */
Expand Down
2 changes: 2 additions & 0 deletions include/posix-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ typedef int ino_t; /* FIXME: should be unsigned long long to encode id_t? */
typedef int nlink_t;
typedef int blksize_t;
typedef long long blkcnt_t;
typedef unsigned long long fsblkcnt_t;
typedef unsigned long long fsfilcnt_t;


#endif
4 changes: 3 additions & 1 deletion include/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,7 @@
ID(sbi_getchar) \
ID(sigreturn) \
\
ID(mprotect)
ID(mprotect) \
\
ID(sys_statvfs)
/* clang-format on */
66 changes: 66 additions & 0 deletions posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,72 @@ static int posix_create(const char *filename, int type, mode_t mode, oid_t dev,
return err;
}

int posix_statvfs(const char *path, int fildes, struct statvfs *stat)
{
oid_t oid, dev;
oid_t *oidp, *devp;
open_file_t *f;
msg_t msg;
int err = EOK;

if (((path == NULL) && (fildes < 0)) ||
((path != NULL) && (fildes != -1))) {
return -EINVAL;
}

if (path == NULL) {
err = posix_getOpenFile(fildes, &f);
if (err < 0) {
return err;
}
oidp = &f->oid;
} else {
if (proc_lookup(path, &oid, &dev) < 0) {
return -ENOENT;
}
oidp = &oid;
devp = &dev;
}

/* Detect mountpoint */
if ((devp != NULL) && (oidp->port != devp->port)) {
msg.type = mtGetAttr;
hal_memcpy(&msg.oid, oidp, sizeof(*oidp));
msg.i.attr.type = atMode;

if ((proc_send(oidp->port, &msg) < 0) || (msg.o.err < 0)) {
(void)posix_fileDeref(f);
return -EIO;
}

if (S_ISDIR(msg.o.attr.val)) {
oidp = devp;
}
}

hal_memset(stat, 0, sizeof(*stat));

msg.type = mtStat;
msg.o.data = stat;
msg.o.size = sizeof(*stat);

if (proc_send(oid.port, &msg) < 0) {
err = -EIO;
} else {
err = msg.o.err;
}

if (path == NULL) {
if (err == EOK) {
err = posix_fileDeref(f);
} else {
(void)posix_fileDeref(f);
}
}

return err;
}


/* TODO: handle O_CREAT and O_EXCL */
int posix_open(const char *filename, int oflag, char *ustack)
Expand Down
4 changes: 4 additions & 0 deletions posix/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "include/posix-poll.h"
#include "include/posix-socket.h"
#include "include/posix-stat.h"
#include "include/posix-statvfs.h"

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zedboard)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zedboard)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zturn)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zturn)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt105x-evk)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt105x-evk)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-spike)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (riscv64-generic-spike)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-generic-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-generic-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (sparcv8leon-gr712rc-board)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8m33-mcxn94x-frdm)

include/posix-statvfs.h: No such file or directory

Check failure on line 26 in posix/posix.h

View workflow job for this annotation

GitHub Actions / call-ci / build (armv8m33-mcxn94x-frdm)

include/posix-statvfs.h: No such file or directory
#include "include/posix-stdio.h"
#include "include/posix-timespec.h"
#include "include/posix-uio.h"
Expand Down Expand Up @@ -77,6 +78,9 @@ extern int posix_chmod(const char *path, mode_t mode);
extern int posix_fstat(int fd, struct stat *buf);


extern int posix_statvfs(const char *path, int fd, struct statvfs *buf);


extern int posix_fsync(int fd);


Expand Down
19 changes: 19 additions & 0 deletions syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,25 @@ int syscalls_sys_fstat(char *ustack)
}


int syscalls_sys_statvfs(char *ustack)
{
process_t *proc = proc_current()->process;
int fd;
const char *path;
struct statvfs *stat;

GETFROMSTACK(ustack, const char *, path, 0);
GETFROMSTACK(ustack, int, fd, 1);
GETFROMSTACK(ustack, struct statvfs *, stat, 2);

if (vm_mapBelongs(proc, stat, sizeof(*stat)) < 0) {
return -EFAULT;
}

return posix_statvfs(path, fd, stat);
}


int syscalls_sys_fsync(char *ustack)
{
int fd;
Expand Down

0 comments on commit 4f18d62

Please sign in to comment.