Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: implement fstatvfs #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/sys/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ extern "C" {
#endif


/* clang-format off */
enum { otDir = 0, otFile, otDev, otSymlink, otUnknown };


enum { mtMount = 0xf50, mtUmount, mtSync, mtStat, mtMountPoint };

enum { mtMount = 0xf50, mtUmount, mtSync, /* Moved to kernel: mtStat ,*/ mtMountPoint = 0xf54 };
badochov marked this conversation as resolved.
Show resolved Hide resolved
/* clang-format on */

typedef struct {
oid_t mnt;
Expand Down
18 changes: 2 additions & 16 deletions include/sys/statvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define _LIBPHOENIX_SYS_STATVFS_H_

#include <sys/types.h>
#include <phoenix/posix-statvfs.h>

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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

Check failure on line 20 in include/sys/statvfs.h

View workflow job for this annotation

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

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


#ifdef __cplusplus
Expand All @@ -29,23 +30,8 @@
#define ST_NOSUID (1 << 1) /* Ignore S_ISUID and S_ISGID file mode bits */


struct statvfs
{
unsigned long f_bsize; /* Filesystem block size */
unsigned long f_frsize; /* Fundamental filesystem block size */
fsblkcnt_t f_blocks; /* Number of blocks on filesystem (in f_frsize units) */
fsblkcnt_t f_bfree; /* Number of free blocks */
fsblkcnt_t f_bavail; /* Number of free blocks available to non-privileged process */
fsfilcnt_t f_files; /* Number of inodes */
fsfilcnt_t f_ffree; /* Number of free inodes */
fsfilcnt_t f_favail; /* Number of free inodes available to non-privileged process */
unsigned long f_fsid; /* Filesystem ID */
unsigned long f_flag; /* Filesystem flags */
unsigned long f_namemax; /* Maximum filename length */
};


extern int statvfs(const char *path, struct statvfs *buf);
extern int fstatvfs(int fildes, struct statvfs *buf);


#ifdef __cplusplus
Expand Down
3 changes: 0 additions & 3 deletions include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include <phoenix/types.h>


typedef unsigned long long fsblkcnt_t;
typedef unsigned long long fsfilcnt_t;

typedef int clock_t;
typedef int clockid_t;

Expand Down
46 changes: 12 additions & 34 deletions sys/statvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* statvfs
*
* Copyright 2022 Phoenix Systems
* Author: Lukasz Kosinski
* Copyright 2022, 2025 Phoenix Systems
* Author: Lukasz Kosinski, Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
Expand All @@ -23,49 +23,27 @@
#include <sys/statvfs.h>


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


int statvfs(const char *path, struct statvfs *buf)
{
char *canonical = resolve_path(path, NULL, 1, 0);
if (canonical == NULL) {
/* errno set by resolve_path() */
return -1;
}
int res = sys_statvfs(canonical, -1, buf);

oid_t oid, dev;
if (lookup(canonical, &oid, &dev) < 0) {
free(canonical);
return SET_ERRNO(-ENOENT);
}
free(canonical);

/* Detect mountpoint */
if (oid.port != dev.port) {
msg_t msg = {
.type = mtGetAttr,
.oid = oid,
.i.attr.type = atMode
};

if ((msgSend(oid.port, &msg) < 0) || (msg.o.err < 0)) {
return SET_ERRNO(-EIO);
}

if (S_ISDIR(msg.o.attr.val)) {
oid = dev;
}
}

memset(buf, 0, sizeof(struct statvfs));
return set_errno(res);
}

msg_t msg = {
.type = mtStat,
.o.data = buf,
.o.size = sizeof(struct statvfs)
};

if (msgSend(oid.port, &msg) < 0) {
return SET_ERRNO(-EIO);
}
int fstatvfs(int fildes, struct statvfs *buf)
{
int res = sys_statvfs(NULL, fildes, buf);

return SET_ERRNO(msg.o.err);
return set_errno(res);
}
Loading