#include <u.h>
#include <libc.h>
#include <ureg.h>
#include "linuxsys.h"
#include "fns.h"
struct __old_kernel_stat {
ushort st_dev;
ushort st_ino;
ushort st_mode;
ushort st_nlink;
ushort st_uid;
ushort st_gid;
ushort st_rdev;
ulong st_size;
ulong st_atime;
ulong st_mtime;
ulong st_ctime;
};
struct stat {
ushort st_dev;
ushort __pad1;
ulong st_ino;
ushort st_mode;
ushort st_nlink;
ushort st_uid;
ushort st_gid;
ushort st_rdev;
ushort __pad2;
ulong st_size;
ulong st_blksize;
ulong st_blocks;
ulong st_atime;
ulong __unused1;
ulong st_mtime;
ulong __unused2;
ulong st_ctime;
ulong __unused3;
ulong __unused4;
ulong __unused5;
};
static void
dir2nstat(struct stat *st, Dir *d)
{
st->st_dev = 0;
st->st_ino = d->qid.path;
st->st_mode = d->mode & 777;
if(d->mode & CHDIR)
st->st_mode |= 0040000;
st->st_nlink = 1;
st->st_uid = 1; // BUG get uid
st->st_gid = 1; // BUG get gid
st->st_size = d->length;
st->st_rdev = 0;
st->st_blksize = 512; // good as any
st->st_blocks = (d->length+st->st_blksize-1) / st->st_blksize;
st->st_atime = d->atime;
st->st_mtime = d->mtime;
st->st_ctime = d->mtime;
}
void
sys_newfstat(struct Ureg *ureg)
{
ulong fd = ARG1;
struct stat *sbuf = (struct stat *) ARG2;
Dir d;
DPRINT("newfstat(%d, %x)...", fd, sbuf);
if(dirfstat(fd, &d) < 0)
RETURN(-EBADF);
dir2nstat(sbuf, &d);
RETURN(0);
}
|