Added stubs for stat(2), and fstat(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2012-02-22 00:30:34 +01:00
parent 75b3b9c858
commit 03273d0076
14 changed files with 150 additions and 36 deletions

4
libmaxsi/decl/blkcnt_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _BLKCNT_T_DECL
#define _BLKCNT_T_DECL
typedef __blkcnt_t blkcnt_t;
#endif

View File

@ -0,0 +1,4 @@
#ifndef _BLKSIZE_T_DECL
#define _BLKSIZE_T_DECL
typedef __blksize_t blksize_t;
#endif

4
libmaxsi/decl/ino_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _INO_T_DECL
#define _INO_T_DECL
typedef __ino_t ino_t;
#endif

View File

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

4
libmaxsi/decl/nlink_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _NLINK_T_DECL
#define _NLINK_T_DECL
typedef __nlink_t nlink_t;
#endif

View File

@ -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 <sys/stat.h>
/* TODO: AT_FDCWD missing here */
/* TODO: AT_EACCESS missing here */

View File

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

View File

@ -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 <features.h>
__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 <sortix/stat.h>
__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

View File

@ -29,6 +29,7 @@
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <sys/readdirents.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
@ -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
}

View File

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

73
sortix/stat.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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 <features.h>
__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

View File

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

View File

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

View File

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