diff --git a/libmaxsi/decl/blkcnt_t.h b/libmaxsi/decl/blkcnt_t.h new file mode 100644 index 00000000..c9174ac0 --- /dev/null +++ b/libmaxsi/decl/blkcnt_t.h @@ -0,0 +1,4 @@ +#ifndef _BLKCNT_T_DECL +#define _BLKCNT_T_DECL +typedef __blkcnt_t blkcnt_t; +#endif diff --git a/libmaxsi/decl/blksize_t.h b/libmaxsi/decl/blksize_t.h new file mode 100644 index 00000000..5ae42412 --- /dev/null +++ b/libmaxsi/decl/blksize_t.h @@ -0,0 +1,4 @@ +#ifndef _BLKSIZE_T_DECL +#define _BLKSIZE_T_DECL +typedef __blksize_t blksize_t; +#endif diff --git a/libmaxsi/decl/ino_t.h b/libmaxsi/decl/ino_t.h new file mode 100644 index 00000000..38c89605 --- /dev/null +++ b/libmaxsi/decl/ino_t.h @@ -0,0 +1,4 @@ +#ifndef _INO_T_DECL +#define _INO_T_DECL +typedef __ino_t ino_t; +#endif diff --git a/libmaxsi/decl/mode_t_values.h b/libmaxsi/decl/mode_t_values.h deleted file mode 100644 index c060d951..00000000 --- a/libmaxsi/decl/mode_t_values.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _MODE_T_VALUES_DECL -#define _MODE_T_VALUES_DECL -#define S_IRUSR __S_IREAD /* Read by owner. */ -#define S_IWUSR __S_IWRITE /* Write by owner. */ -#define S_IXUSR __S_IEXEC /* Execute by owner. */ -/* Read, write, and execute by owner. */ -#define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC) - -#define S_IRGRP (S_IRUSR >> 3) /* Read by group. */ -#define S_IWGRP (S_IWUSR >> 3) /* Write by group. */ -#define S_IXGRP (S_IXUSR >> 3) /* Execute by group. */ -/* Read, write, and execute by group. */ -#define S_IRWXG (S_IRWXU >> 3) - -#define S_IROTH (S_IRGRP >> 3) /* Read by others. */ -#define S_IWOTH (S_IWGRP >> 3) /* Write by others. */ -#define S_IXOTH (S_IXGRP >> 3) /* Execute by others. */ -/* Read, write, and execute by others. */ -#define S_IRWXO (S_IRWXG >> 3) - -#define __S_ISUID 04000 /* Set user ID on execution. */ -#define __S_ISGID 02000 /* Set group ID on execution. */ -#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */ -#define __S_IREAD 0400 /* Read by owner. */ -#define __S_IWRITE 0200 /* Write by owner. */ -#define __S_IEXEC 0100 /* Execute by owner. */ -#endif diff --git a/libmaxsi/decl/nlink_t.h b/libmaxsi/decl/nlink_t.h new file mode 100644 index 00000000..3a7b2f83 --- /dev/null +++ b/libmaxsi/decl/nlink_t.h @@ -0,0 +1,4 @@ +#ifndef _NLINK_T_DECL +#define _NLINK_T_DECL +typedef __nlink_t nlink_t; +#endif diff --git a/libmaxsi/include/fcntl.h b/libmaxsi/include/fcntl.h index 418cd145..7b05caf0 100644 --- a/libmaxsi/include/fcntl.h +++ b/libmaxsi/include/fcntl.h @@ -60,8 +60,7 @@ __BEGIN_DECLS #define O_TRUNC (1<<13) #define O_TTY_INIT (1<<13) -@include(mode_t.h) -@include(mode_t_values.h) +#include /* TODO: AT_FDCWD missing here */ /* TODO: AT_EACCESS missing here */ diff --git a/libmaxsi/include/libmaxsi/types.h b/libmaxsi/include/libmaxsi/types.h index 03434b90..fd632377 100644 --- a/libmaxsi/include/libmaxsi/types.h +++ b/libmaxsi/include/libmaxsi/types.h @@ -40,6 +40,10 @@ @include(mode_t.h) @include(off_t.h) @include(gid_t.h) +@include(ino_t.h) +@include(nlink_t.h) +@include(blksize_t.h) +@include(blkcnt_t.h) @include(va_list.h) diff --git a/libmaxsi/include/sys/stat.h b/libmaxsi/include/sys/stat.h index c09fb126..515aabf7 100644 --- a/libmaxsi/include/sys/stat.h +++ b/libmaxsi/include/sys/stat.h @@ -22,20 +22,30 @@ ******************************************************************************/ -// TODO: Make this header comply with POSIX-1.2008 +/* TODO: Make this header comply with POSIX-1.2008, if it makes sense. */ -#ifndef _STAT_H -#define _STAT_H 1 +#ifndef _SYS_STAT_H +#define _SYS_STAT_H 1 #include __BEGIN_DECLS - +@include(blkcnt_t.h) +@include(blksize_t.h) +@include(ino_t.h) @include(mode_t.h) -@include(mode_t_values.h) +@include(nlink_t.h) +@include(uid_t.h) +@include(gid_t.h) +@include(off_t.h) +__END_DECLS +#include + +__BEGIN_DECLS +int fstat(int fd, struct stat* st); int mkdir(const char *path, mode_t mode); - +int stat(const char* restrict path, struct stat* restrict st); __END_DECLS #endif diff --git a/libmaxsi/io.cpp b/libmaxsi/io.cpp index 8965da7a..2c803c8b 100644 --- a/libmaxsi/io.cpp +++ b/libmaxsi/io.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,8 @@ namespace Maxsi DEFN_SYSCALL1(int, SysRmDir, SYSCALL_RMDIR, const char*); DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t); DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t); + DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*); + DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*); size_t Print(const char* string) { @@ -278,6 +281,16 @@ namespace Maxsi { return SysFTruncate(fd, length); } + + extern "C" int stat(const char* path, struct stat* st) + { + return SysStat(path, st); + } + + extern "C" int fstat(int fd, struct stat* st) + { + return SysFStat(fd, st); + } #endif } diff --git a/sortix/filesystem.cpp b/sortix/filesystem.cpp index c150cf3d..6a35f764 100644 --- a/sortix/filesystem.cpp +++ b/sortix/filesystem.cpp @@ -111,6 +111,20 @@ namespace Sortix return -1; } + int SysStat(const char* pathname, struct stat* st) + { + // TODO: Add the proper filesystem support! + Error::Set(ENOSYS); + return -1; + } + + int SysFStat(int fd, struct stat* st) + { + // TODO: Add the proper filesystem support! + Error::Set(ENOSYS); + return -1; + } + void Init() { Syscall::Register(SYSCALL_OPEN, (void*) SysOpen); @@ -119,6 +133,8 @@ namespace Sortix Syscall::Register(SYSCALL_RMDIR, (void*) SysRmDir); Syscall::Register(SYSCALL_TRUNCATE, (void*) SysTruncate); Syscall::Register(SYSCALL_FTRUNCATE, (void*) SysFTruncate); + Syscall::Register(SYSCALL_STAT, (void*) SysStat); + Syscall::Register(SYSCALL_FSTAT, (void*) SysFStat); } } diff --git a/sortix/stat.h b/sortix/stat.h new file mode 100644 index 00000000..7775fb4e --- /dev/null +++ b/sortix/stat.h @@ -0,0 +1,73 @@ +/******************************************************************************* + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + stat.h + Defines the struct stat used for file meta-information and other useful + macros and values relating to values stored in it. + +*******************************************************************************/ + +#ifndef SORTIX_STAT_H +#define SORTIX_STAT_H + +#include + +__BEGIN_DECLS + +struct stat +{ + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + off_t st_size; + /* TODO: st_atim, st_mtim, st_st_ctim */ + blksize_t st_blksize; + blkcnt_t st_blocks; +}; + +#define S_IXOTH 01 +#define S_IWOTH 02 +#define S_IROTH 03 +#define S_IRWXO 07 +#define S_IXGRP 010 +#define S_IWGRP 020 +#define S_IRGRP 040 +#define S_IRWXG 070 +#define S_IXUSR 0100 +#define S_IWUSR 0200 +#define S_IRUSR 0400 +#define S_IRWXU 0700 +#define S_IFDIR 0040000 +#define S_IFBLK 0060000 +#define S_IFREG 0100000 +#define S_IFLNK 0200000 /* not the same as in Linux */ +/* TODO: Define the other useful values and implement their features. */ + +#define S_ISBLK(m) ((m) & S_IFBLK) +#define S_ISDIR(m) ((m) & S_IFDIR) +#define S_ISREG(m) ((m) & S_IFREG) +#define S_ISLNK(m) ((m) & S_IFLNK) +/* TODO: Define the other useful macros and implement their features. */ + +__END_DECLS + +#endif + diff --git a/sortix/syscallnum.h b/sortix/syscallnum.h index 5be6f2a6..382d2dc5 100644 --- a/sortix/syscallnum.h +++ b/sortix/syscallnum.h @@ -68,7 +68,9 @@ #define SYSCALL_FTRUNCATE 41 #define SYSCALL_SETTERMMODE 42 #define SYSCALL_GETTERMMODE 43 -#define SYSCALL_MAX_NUM 44 /* index of highest constant + 1 */ +#define SYSCALL_STAT 44 +#define SYSCALL_FSTAT 45 +#define SYSCALL_MAX_NUM 46 /* index of highest constant + 1 */ #endif diff --git a/sortix/x64/bits.h b/sortix/x64/bits.h index eb916e57..b161df4a 100644 --- a/sortix/x64/bits.h +++ b/sortix/x64/bits.h @@ -125,6 +125,10 @@ typedef __intmax_t __off_t; typedef unsigned int __wctrans_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */ typedef unsigned int __wctype_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */ typedef unsigned int __useconds_t; +typedef __off_t __blksize_t; +typedef __off_t __blkcnt_t; +typedef unsigned int __nlink_t; +typedef __uintmax_t __ino_t; #endif diff --git a/sortix/x86/bits.h b/sortix/x86/bits.h index 619b1c97..d5b3b0cd 100644 --- a/sortix/x86/bits.h +++ b/sortix/x86/bits.h @@ -125,6 +125,10 @@ typedef __intmax_t __off_t; typedef unsigned int __wctrans_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */ typedef unsigned int __wctype_t; /* TODO: figure out what this does and typedef it properly. This is just a temporary assignment. */ typedef unsigned int __useconds_t; +typedef __off_t __blksize_t; +typedef __off_t __blkcnt_t; +typedef unsigned int __nlink_t; +typedef __uintmax_t __ino_t; #endif