minix/lib/libc/posix/_fstat.c
Evgeniy Ivanov ef0a265086 New stat structure.
* VFS and installed MFSes must be in sync before and after this change *

Use struct stat from NetBSD. It requires adding new STAT, FSTAT and LSTAT
syscalls. Libc modification is both backward and forward compatible.

Also new struct stat uses modern field sizes to avoid ABI
incompatibility, when we update uid_t, gid_t and company.
Exceptions are ino_t and off_t in old libc (though paddings added).
2011-07-12 16:39:55 +02:00

36 lines
685 B
C

#include <lib.h>
#define fstat _fstat
#include <sys/stat.h>
#include <string.h>
PUBLIC int fstat(fd, buffer)
int fd;
struct stat *buffer;
{
message m;
int r;
struct minix_prev_stat old_sb;
m.m1_i1 = fd;
m.m1_p1 = (char *) buffer;
if((r = _syscall(VFS_PROC_NR, FSTAT, &m)) >= 0 || errno != ENOSYS)
return r;
errno = 0;
/* ENOSYS: new binary and old VFS, fallback to PREV_STAT.
* User has struct stat (buffer), VFS still fills minix_prev_stat.
*/
m.m1_i1 = fd;
m.m1_p1 = (char *) &old_sb;
if((r = _syscall(VFS_PROC_NR, PREV_FSTAT, &m)) < 0)
return r;
memset(buffer, 0, sizeof(struct stat));
COPY_PREV_STAT_TO_NEW(buffer, &old_sb);
return r;
}