Kernel, libc: Add st_uid and st_gid to stat, and handle st_mode differently

This commit is contained in:
apio 2022-10-28 17:13:20 +02:00
parent 26b20938de
commit c312d81de4
4 changed files with 48 additions and 6 deletions

View File

@ -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;
}

View File

@ -5,4 +5,6 @@
#define __VFS_DIRECTORY 0x1
#define __VFS_DEVICE 0x2
#define __VFS_TO_IFMT(type) ((1 << type) * 010000)
#endif

View File

@ -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. */

View File

@ -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