kernel: kill proc with bogus ipc address
[minix.git] / servers / iso9660fs / stadir.c
blob9e41e3659047b5d7b8796faced6b99070e90ba0d
1 #include "inc.h"
2 #include <assert.h>
3 #include <sys/stat.h>
4 #include <sys/statfs.h>
5 #include <sys/statvfs.h>
6 #include <minix/com.h>
7 #include <string.h>
8 #include <time.h>
10 #include <minix/vfsif.h>
13 /*===========================================================================*
14 * stat_dir_record *
15 *===========================================================================*/
16 static int stat_dir_record(
17 register struct dir_record *dir, /* pointer to dir record to stat */
18 int pipe_pos, /* position in a pipe, supplied by fstat() */
19 endpoint_t who_e, /* Caller endpoint */
20 cp_grant_id_t gid /* grant for the stat buf */
23 /* This function returns all the info about a particular inode. It's missing
24 * the recording date because of a bug in the standard functions stdtime.
25 * Once the bug is fixed the function can be called inside this function to
26 * return the date. */
28 /* Common code for stat and fstat system calls. */
29 struct stat statbuf;
30 int r;
31 struct tm ltime;
32 time_t time1;
33 u32_t blocks;
35 blocks = v_pri.volume_space_size_l;
36 /* The unit of blocks should be 512 */
37 assert(v_pri.logical_block_size_l >= 512);
38 blocks = blocks * (v_pri.logical_block_size_l >> 9);
40 memset(&statbuf, 0, sizeof(struct stat));
42 statbuf.st_dev = fs_dev; /* the device of the file */
43 statbuf.st_ino = ID_DIR_RECORD(dir); /* the id of the dir record */
44 statbuf.st_mode = dir->d_mode; /* flags of the file */
45 statbuf.st_nlink = dir->d_count; /* times this file is used */
46 statbuf.st_uid = 0; /* user root */
47 statbuf.st_gid = 0; /* group operator */
48 statbuf.st_rdev = NO_DEV;
49 statbuf.st_size = dir->d_file_size; /* size of the file */
50 statbuf.st_blksize = v_pri.logical_block_size_l;
51 statbuf.st_blocks = blocks;
53 ltime.tm_year = dir->rec_date[0];
54 ltime.tm_mon = dir->rec_date[1] - 1;
55 ltime.tm_mday = dir->rec_date[2];
56 ltime.tm_hour = dir->rec_date[3];
57 ltime.tm_min = dir->rec_date[4];
58 ltime.tm_sec = dir->rec_date[5];
59 ltime.tm_isdst = 0;
61 if (dir->rec_date[6] != 0)
62 ltime.tm_hour += dir->rec_date[6] / 4;
64 time1 = mktime(&ltime);
66 statbuf.st_atime = time1;
67 statbuf.st_mtime = time1;
68 statbuf.st_ctime = time1;
70 /* Copy the struct to user space. */
71 r = sys_safecopyto(who_e, gid, 0, (vir_bytes) &statbuf,
72 (phys_bytes) sizeof(statbuf));
74 return(r);
78 /*===========================================================================*
79 * fs_stat *
80 *===========================================================================*/
81 int fs_stat()
83 register int r; /* return value */
84 struct dir_record *dir;
85 r = EINVAL;
87 if ((dir = get_dir_record(fs_m_in.REQ_INODE_NR)) != NULL) {
88 r = stat_dir_record(dir, 0, fs_m_in.m_source, fs_m_in.REQ_GRANT);
89 release_dir_record(dir);
92 return(r);
96 /*===========================================================================*
97 * fs_fstatfs *
98 *===========================================================================*/
99 int fs_fstatfs()
101 struct statfs st;
102 int r;
104 st.f_bsize = v_pri.logical_block_size_l;
106 /* Copy the struct to user space. */
107 r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0,
108 (vir_bytes) &st, (phys_bytes) sizeof(st));
110 return(r);
114 /*===========================================================================*
115 * fs_statvfs *
116 *===========================================================================*/
117 int fs_statvfs()
119 struct statvfs st;
120 int r;
123 st.f_bsize = v_pri.logical_block_size_l;
124 st.f_frsize = st.f_bsize;
125 st.f_blocks = v_pri.volume_space_size_l;
126 st.f_bfree = 0;
127 st.f_bavail = 0;
128 st.f_files = 0;
129 st.f_ffree = 0;
130 st.f_favail = 0;
131 st.f_fsid = fs_dev;
132 st.f_flag = ST_RDONLY;
133 st.f_namemax = NAME_MAX;
135 /* Copy the struct to user space. */
136 r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0, (vir_bytes) &st,
137 (phys_bytes) sizeof(st));
139 return(r);
142 /*===========================================================================*
143 * blockstats *
144 *===========================================================================*/
145 void fs_blockstats(u32_t *blocks, u32_t *free, u32_t *used)
147 *used = *blocks = v_pri.volume_space_size_l;
148 *free = 0;