diff --git a/kernel/src/sys/stat.cpp b/kernel/src/sys/stat.cpp index abe517bf..49a5ad10 100644 --- a/kernel/src/sys/stat.cpp +++ b/kernel/src/sys/stat.cpp @@ -5,7 +5,6 @@ #include "sys/UserMemory.h" #include "thread/Scheduler.h" -typedef unsigned long off_t; typedef unsigned short mode_t; typedef unsigned long ino_t; @@ -15,6 +14,8 @@ struct stat // FIXME: This struct is quite stubbed out. mode_t st_mode; off_t st_size; int st_dev; // FIXME: Implement this. + uid_t st_uid; + gid_t st_gid; }; void do_stat(Context* context, VFS::Node* node, struct stat* buf) @@ -26,8 +27,10 @@ void do_stat(Context* context, VFS::Node* node, struct stat* buf) return; } kstat->st_ino = node->inode; - kstat->st_mode = (mode_t)node->type; + kstat->st_mode = node->mode | ((1 << (node->type)) * 010000); kstat->st_size = node->length; + kstat->st_uid = node->uid; + kstat->st_gid = node->gid; release_user_ref(kstat); context->rax = 0; } diff --git a/libs/libc/include/luna/vfs.h b/libs/libc/include/luna/vfs.h index 3cc260a9..e34c83eb 100644 --- a/libs/libc/include/luna/vfs.h +++ b/libs/libc/include/luna/vfs.h @@ -5,4 +5,6 @@ #define __VFS_DIRECTORY 0x1 #define __VFS_DEVICE 0x2 +#define __VFS_TO_IFMT(type) ((1 << type) * 010000) + #endif \ No newline at end of file diff --git a/libs/libc/include/sys/stat.h b/libs/libc/include/sys/stat.h index f66d42ef..e96c766f 100644 --- a/libs/libc/include/sys/stat.h +++ b/libs/libc/include/sys/stat.h @@ -10,18 +10,49 @@ struct stat // FIXME: This struct is quite stubbed out. mode_t st_mode; off_t st_size; int st_dev; // Not implemented. + uid_t st_uid; + gid_t st_gid; }; -#define S_ISDIR(mode) (((mode)&0xf) == __VFS_DIRECTORY) -#define S_ISREG(mode) (((mode)&0xf) == __VFS_FILE) -#define S_ISCHR(mode) (((mode)&0xf) == __VFS_DEVICE) +/* Type of file. */ +#define S_IFMT 070000 +/* Directory. */ +#define S_IFDIR __VFS_TO_IFMT(__VFS_DIRECTORY) +/* Regular file. */ +#define S_IFREG __VFS_TO_IFMT(__VFS_FILE) +/* Character device. */ +#define S_IFCHR __VFS_TO_IFMT(__VFS_DEVICE) + +#define __S_IFCMP(mode, value) (mode & S_IFMT) == value + +/* Is it a directory? */ +#define S_ISDIR(mode) (__S_IFCMP((mode), S_IFDIR)) +/* Is it a regular file? */ +#define S_ISREG(mode) (__S_IFCMP((mode), S_IFREG)) +/* Is it a character device? */ +#define S_ISCHR(mode) (__S_IFCMP((mode), S_IFCHR)) + +#define S_IRWXU 0700 +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#define S_IRWXG 070 +#define S_IRGRP 040 +#define S_IWGRP 020 +#define S_IXGRP 010 +#define S_IRWXO 07 +#define S_IROTH 04 +#define S_IWOTH 02 +#define S_IXOTH 01 +#define S_ISUID 04000 +#define S_ISGID 02000 #ifdef __cplusplus extern "C" { #endif - /* Creates a new directory at the path pathname. FIXME: For now, mode is ignored. */ + /* Creates a new directory at the path pathname with the specified mode. */ int mkdir(const char* pathname, mode_t mode); /* Returns information about the file pointed to by fd in buf. */ diff --git a/libs/libc/include/sys/types.h b/libs/libc/include/sys/types.h index 843a8974..e8d0135e 100644 --- a/libs/libc/include/sys/types.h +++ b/libs/libc/include/sys/types.h @@ -28,4 +28,10 @@ typedef long int time_t; /* Type representing signed time in microseconds. */ typedef long int suseconds_t; +/* Type representing a user ID. */ +typedef int uid_t; + +/* Type representing a group ID. */ +typedef int gid_t; + #endif \ No newline at end of file