make vfs & filesystems use failable copying
[minix3.git] / lib / libpuffs / stadir.c
blob7b41174b667cfdd3acaeba6d9671502687c8e7d4
1 /* Created (MFS based):
2 * February 2010 (Evgeniy Ivanov)
3 */
5 #include "fs.h"
6 #include <sys/stat.h>
7 #include <sys/statvfs.h>
8 #include <minix/vfsif.h>
10 #include "puffs.h"
11 #include "puffs_priv.h"
14 /*===========================================================================*
15 * fs_stat *
16 *===========================================================================*/
17 int fs_stat(void)
19 register int r; /* return value */
20 register struct puffs_node *pn; /* target pnode */
21 struct vattr va;
22 struct stat statbuf;
23 pmode_t mo;
24 int s;
25 PUFFS_MAKECRED(pcr, &global_kcred);
27 if (global_pu->pu_ops.puffs_node_getattr == NULL) {
28 lpuffs_debug("fs_stat: puffs_node_getattr is missing\n");
29 return(EINVAL);
32 if ((pn = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_INODE_NR)) == NULL) {
33 lpuffs_debug("walk failed...\n");
34 return(EINVAL);
37 if (global_pu->pu_ops.puffs_node_getattr(global_pu, pn, &va, pcr) != 0) {
38 if (errno) {
39 if (errno > 0) errno = -errno;
40 return(errno);
42 return(EINVAL);
45 /* Fill in the statbuf struct. */
46 mo = va.va_mode & I_TYPE;
48 /* true iff special */
49 s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
51 statbuf.st_dev = fs_dev;
52 statbuf.st_ino = va.va_fileid;
53 statbuf.st_mode = va.va_mode;
54 statbuf.st_nlink = va.va_nlink;
55 statbuf.st_uid = va.va_uid;
56 statbuf.st_gid = va.va_gid;
57 statbuf.st_rdev = (s ? va.va_rdev : NO_DEV);
58 statbuf.st_size = va.va_size;
59 statbuf.st_atimespec = va.va_atime;
60 statbuf.st_mtimespec = va.va_mtime;
61 statbuf.st_ctimespec = va.va_ctime;
63 statbuf.st_birthtimespec = va.va_birthtime;
64 statbuf.st_blksize = va.va_blocksize;
65 statbuf.st_blocks = va.va_bytes / va.va_blocksize;
66 statbuf.st_flags = va.va_flags;
67 statbuf.st_gen = va.va_gen;
69 /* Copy the struct to user space. */
70 r = sys_safecopyto(fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT,
71 (vir_bytes) 0, (vir_bytes) &statbuf,
72 (size_t) sizeof(statbuf));
74 return(r);
78 /*===========================================================================*
79 * fs_statvfs *
80 *===========================================================================*/
81 int fs_statvfs(void)
83 int r;
84 struct statvfs st;
86 memset(&st, 0, sizeof(st));
88 if (global_pu->pu_ops.puffs_fs_statvfs(global_pu, &st) != 0) {
89 lpuffs_debug("statvfs failed\n");
90 return(EINVAL);
93 /* XXX libpuffs doesn't truncate filenames and returns ENAMETOOLONG,
94 * though some servers would like to behave differently.
95 * See subtest 2.18-19 of test23 and test/common.c:does_fs_truncate().
97 st.f_flag |= ST_NOTRUNC;
99 /* Copy the struct to user space. */
100 r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0, (vir_bytes) &st,
101 (phys_bytes) sizeof(st));
103 return(r);