vm, kernel, top: report memory usage of vm, kernel
[minix.git] / lib / libvtreefs / stadir.c
blobc2f9a1e50b4ce5f30e5adf5ebfa624e9f5b3e607
1 /* VTreeFS - stadir.c - by Alen Stojanov and David van Moolenbroek */
3 #include "inc.h"
5 #include <time.h>
6 #include <sys/statfs.h>
7 #include <sys/statvfs.h>
8 #include <string.h>
10 /*===========================================================================*
11 * fs_stat *
12 *===========================================================================*/
13 int fs_stat(void)
15 /* Retrieve file status.
17 char path[PATH_MAX];
18 struct stat statbuf;
19 time_t cur_time;
20 struct inode *node;
21 int r;
23 if ((node = find_inode(fs_m_in.REQ_INODE_NR)) == NULL)
24 return EINVAL;
26 memset(&statbuf, 0, sizeof(struct stat));
28 /* Fill in the basic info. */
29 statbuf.st_dev = fs_dev;
30 statbuf.st_ino = get_inode_number(node);
31 statbuf.st_mode = node->i_stat.mode;
32 statbuf.st_nlink = !is_inode_deleted(node);
33 statbuf.st_uid = node->i_stat.uid;
34 statbuf.st_gid = node->i_stat.gid;
35 statbuf.st_rdev = (dev_t) node->i_stat.dev;
36 statbuf.st_size = node->i_stat.size;
38 /* If it is a symbolic link, return the size of the link target. */
39 if (S_ISLNK(node->i_stat.mode) && vtreefs_hooks->rdlink_hook != NULL) {
40 r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path),
41 get_inode_cbdata(node));
43 if (r == OK)
44 statbuf.st_size = strlen(path);
47 /* Take the current time as file time for all files. */
48 cur_time = time(NULL);
49 statbuf.st_atime = cur_time;
50 statbuf.st_mtime = cur_time;
51 statbuf.st_ctime = cur_time;
53 /* Copy the struct to user space. */
54 return sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0,
55 (vir_bytes) &statbuf, (phys_bytes) sizeof(statbuf));
58 /*===========================================================================*
59 * fs_fstatfs *
60 *===========================================================================*/
61 int fs_fstatfs(void)
63 /* Retrieve file system statistics.
65 struct statfs statfs;
67 memset(&statfs, 0, sizeof(statfs));
69 /* Copy the struct to user space. */
70 return sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0,
71 (vir_bytes) &statfs, (phys_bytes) sizeof(statfs));
74 /*===========================================================================*
75 * fs_fstatfs *
76 *===========================================================================*/
77 int fs_statvfs(void)
79 /* Retrieve file system statistics.
81 struct statvfs statvfs;
83 memset(&statvfs, 0, sizeof(statvfs));
85 statvfs.f_fsid = fs_dev;
86 statvfs.f_flag = ST_RDONLY | ST_NOTRUNC;
87 statvfs.f_namemax = PNAME_MAX;
89 return sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0,
90 (vir_bytes) &statvfs, sizeof(statvfs));