9 ufstat(int fd
, Ustat
*ps
)
15 if((f
= fdgetfile(fd
)) == nil
)
18 if(devtab
[f
->dev
]->fstat
== nil
)
20 memset(ps
, 0, sizeof(Ustat
));
21 err
= devtab
[f
->dev
]->fstat(f
, ps
);
51 ustat2linuxstat(Ustat
*x
, struct linux_stat
*s
)
53 memset(s
, 0, sizeof(*s
));
63 s
->st_blocks
= (x
->size
+s
->st_blksize
-1) / s
->st_blksize
;
64 s
->st_atime
= x
->atime
;
65 s
->st_mtime
= x
->mtime
;
66 s
->st_ctime
= x
->ctime
;
93 ustat2linuxstat64(Ustat
*x
, struct linux_stat64
*s
)
95 memset(s
, 0, sizeof(*s
));
98 s
->__lst_ino
= x
->ino
& 0xFFFFFFFF;
99 s
->lst_mode
= x
->mode
;
103 s
->lst_size
= x
->size
;
104 s
->lst_rdev
= x
->rdev
;
105 s
->lst_blksize
= 4096; // good as any
106 s
->lst_blocks
= (x
->size
+s
->lst_blksize
-1) / s
->lst_blksize
;
107 s
->lst_atime
= x
->atime
;
108 s
->lst_mtime
= x
->mtime
;
109 s
->lst_ctime
= x
->ctime
;
112 int sys_linux_stat(char *path
, void *st
)
117 trace("sys_linux_stat(%s, %p)", path
, st
);
118 err
= fsstat(path
, 0, &x
);
121 ustat2linuxstat(&x
, (struct linux_stat
*)st
);
125 int sys_linux_lstat(char *path
, void *st
)
130 trace("sys_linux_lstat(%s, %p)", path
, st
);
132 if((path
= fsfullpath(path
)) == nil
)
134 err
= fsstat(path
, 1, &x
);
139 ustat2linuxstat(&x
, (struct linux_stat
*)st
);
143 int sys_linux_stat64(char *path
, void *st
)
148 trace("sys_linux_stat64(%s, %p)", path
, st
);
150 if((path
= fsfullpath(path
)) == nil
)
152 err
= fsstat(path
, 0, &x
);
157 ustat2linuxstat64(&x
, (struct linux_stat64
*)st
);
161 int sys_linux_lstat64(char *path
, void *st
)
166 trace("sys_linux_lstat64(%s, %p)", path
, st
);
168 if((path
= fsfullpath(path
)) == nil
)
170 err
= fsstat(path
, 1, &x
);
175 ustat2linuxstat64(&x
, (struct linux_stat64
*)st
);
179 int sys_linux_fstat(int fd
, void *st
)
184 trace("sys_linux_fstat(%d, %p)", fd
, st
);
186 err
= ufstat(fd
, &x
);
189 ustat2linuxstat(&x
, (struct linux_stat
*)st
);
193 int sys_linux_fstat64(int fd
, void *st
)
198 trace("sys_linux_fstat64(%d, %p)", fd
, st
);
200 err
= ufstat(fd
, &x
);
203 ustat2linuxstat64(&x
, (struct linux_stat64
*)st
);
208 getdents(int fd
, void *buf
, int len
, int (*fconv
)(Udirent
*, void *, int, int))
215 if((f
= fdgetfile(fd
)) == nil
)
221 if(t
== nil
|| f
->off
== 0){
227 if((err
= devtab
[f
->dev
]->readdir(f
, &t
)) <= 0){
234 /* just calculate size */
235 r
= fconv(t
, nil
, 0, e
- p
);
241 r
= fconv(t
, p
, t
->next
? f
->off
: 0, e
- p
);
247 return p
- (uchar
*)buf
;
251 newdirent(char *path
, char *name
, int mode
)
258 d
= kmallocz(sizeof(*d
) + nlen
+ 1, 1);
260 strcpy(d
->name
, name
);
261 s
= allocpath(path
, nil
, d
->name
);
262 d
->ino
= hashpath(s
);
268 struct linux_dirent
{
276 udirent2linux(Udirent
*u
, void *d
, int off
, int left
)
279 struct linux_dirent
*e
= d
;
281 n
= sizeof(*e
) + strlen(u
->name
) + 1;
285 e
->d_ino
= u
->ino
& 0xFFFFFFFF;
288 strcpy(e
->d_name
, u
->name
);
293 struct linux_dirent64
{
302 udirent2linux64(Udirent
*u
, void *d
, int off
, int left
)
305 struct linux_dirent64
*e
= d
;
307 n
= sizeof(*e
) + strlen(u
->name
) + 1;
314 e
->d_type
= (u
->mode
>>12)&15;
315 strcpy(e
->d_name
, u
->name
);
320 int sys_linux_getdents(int fd
, void *buf
, int nbuf
)
322 trace("sys_linux_getdents(%d, %p, %x)", fd
, buf
, nbuf
);
324 return getdents(fd
, buf
, nbuf
, udirent2linux
);
327 int sys_linux_getdents64(int fd
, void *buf
, int nbuf
)
329 trace("sys_linux_getdents64(%d, %p, %x)", fd
, buf
, nbuf
);
331 return getdents(fd
, buf
, nbuf
, udirent2linux64
);
334 struct linux_statfs
{
348 int sys_statfs(char *name
, void *pstatfs
)
350 struct linux_statfs
*s
= pstatfs
;
352 trace("sys_statfs(%s, %p)", name
, s
);
354 if((s
== nil
) || (name
== nil
))
357 memset(s
, 0, sizeof(*s
));
361 s
->f_blocks
= 0x80000000;
362 s
->f_bavail
= s
->f_bfree
= 0x80000000;
363 s
->f_files
= s
->f_ffree
= 0x40000000;
365 if(strncmp(name
, "/dev/pts", 8) == 0){
370 memmove(&s
->f_type
, "PLN9", 4);
371 memmove(s
->f_fsid
, "PLAN9_FS", 8);
377 sys_getxattr(char *path
, char *name
, void *value
, int size
)
379 trace("sys_getxattr(%s, %s, %p, %x)", path
, name
, value
, size
);
385 sys_lgetxattr(char *path
, char *name
, void *value
, int size
)
387 trace("sys_lgetxattr(%s, %s, %p, %x)", path
, name
, value
, size
);
393 sys_fgetxattr(int fd
, char *name
, void *value
, int size
)
398 trace("sys_fgetxattr(%d, %s, %p, %x)", fd
, name
, value
, size
);
400 if((f
= fdgetfile(fd
)) == nil
)
409 sys_setxattr(char *path
, char *name
, void *value
, int flags
, int size
)
411 trace("sys_setxattr(%s, %s, %p, %x, %x)", path
, name
, value
, flags
, size
);
417 sys_lsetxattr(char *path
, char *name
, void *value
, int flags
, int size
)
419 trace("sys_lsetxattr(%s, %s, %p, %x, %x)", path
, name
, value
, flags
, size
);
425 sys_fsetxattr(int fd
, char *name
, void *value
, int size
, int flags
)
430 trace("sys_fsetxattr(%d, %s, %p, %x, %x)", fd
, name
, value
, flags
, size
);
432 if((f
= fdgetfile(fd
)) == nil
)