VM: restore >4k secondary cache functionality
[minix.git] / lib / libpuffs / stadir.c
blobddf9acf9b0bf3171b786d27ac8d2a33f1d6c9cb8
1 /* Created (MFS based):
2 * February 2010 (Evgeniy Ivanov)
3 */
5 #include "fs.h"
6 #include <sys/stat.h>
7 #include <sys/statfs.h>
8 #include <sys/statvfs.h>
9 #include <minix/vfsif.h>
11 #include "puffs.h"
12 #include "puffs_priv.h"
15 /*===========================================================================*
16 * fs_fstatfs *
17 *===========================================================================*/
18 int fs_fstatfs()
20 int r;
21 struct statvfs st_vfs;
22 struct statfs st;
24 if (global_pu->pu_ops.puffs_fs_statvfs(global_pu, &st_vfs) != 0) {
25 lpuffs_debug("statfs failed\n");
26 return(EINVAL);
29 st.f_bsize = st_vfs.f_bsize;
31 /* Copy the struct to user space. */
32 r = sys_safecopyto(fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT,
33 (vir_bytes) 0, (vir_bytes) &st, (size_t) sizeof(st));
35 return(r);
39 /*===========================================================================*
40 * fs_stat *
41 *===========================================================================*/
42 int fs_stat()
44 register int r; /* return value */
45 register struct puffs_node *pn; /* target pnode */
46 struct vattr va;
47 struct stat statbuf;
48 mode_t mo;
49 int s;
50 PUFFS_MAKECRED(pcr, &global_kcred);
52 if (global_pu->pu_ops.puffs_node_getattr == NULL) {
53 lpuffs_debug("fs_stat: puffs_node_getattr is missing\n");
54 return(EINVAL);
57 if ((pn = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_INODE_NR)) == NULL) {
58 lpuffs_debug("walk failed...\n");
59 return(EINVAL);
62 if (global_pu->pu_ops.puffs_node_getattr(global_pu, pn, &va, pcr) != 0) {
63 if (errno) {
64 if (errno > 0) errno = -errno;
65 return(errno);
67 return(EINVAL);
70 /* Fill in the statbuf struct. */
71 mo = va.va_mode & I_TYPE;
73 /* true iff special */
74 s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
76 statbuf.st_dev = fs_dev;
77 statbuf.st_ino = va.va_fileid;
78 statbuf.st_mode = va.va_mode;
79 statbuf.st_nlink = va.va_nlink;
80 statbuf.st_uid = va.va_uid;
81 statbuf.st_gid = va.va_gid;
82 statbuf.st_rdev = (s ? va.va_rdev : NO_DEV);
83 statbuf.st_size = va.va_size;
84 statbuf.st_atime = va.va_atime.tv_sec;
85 statbuf.st_mtime = va.va_mtime.tv_sec;
86 statbuf.st_ctime = va.va_ctime.tv_sec;
88 /* Copy the struct to user space. */
89 r = sys_safecopyto(fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT,
90 (vir_bytes) 0, (vir_bytes) &statbuf,
91 (size_t) sizeof(statbuf));
93 return(r);
97 /*===========================================================================*
98 * fs_statvfs *
99 *===========================================================================*/
100 int fs_statvfs()
102 int r;
103 struct statvfs st;
105 if (global_pu->pu_ops.puffs_fs_statvfs(global_pu, &st) != 0) {
106 lpuffs_debug("statvfs failed\n");
107 return(EINVAL);
110 /* XXX libpuffs doesn't truncate filenames and returns ENAMETOOLONG,
111 * though some servers would like to behave differently.
112 * See subtest 2.18-19 of test23 and test/common.c:does_fs_truncate().
114 st.f_flag |= ST_NOTRUNC;
116 /* Copy the struct to user space. */
117 r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0, (vir_bytes) &st,
118 (phys_bytes) sizeof(st));
120 return(r);