panic() cleanup.
[minix.git] / servers / mfs / stadir.c
blob00968084d73d83235435c2df7bf70cf5b64bb18e
1 #include "fs.h"
2 #include <sys/stat.h>
3 #include <sys/statfs.h>
4 #include <minix/com.h>
5 #include <string.h>
6 #include "buf.h"
7 #include "inode.h"
8 #include "super.h"
9 #include <minix/vfsif.h>
11 FORWARD _PROTOTYPE( int stat_inode, (struct inode *rip, int who_e,
12 cp_grant_id_t gid) );
15 /*===========================================================================*
16 * stat_inode *
17 *===========================================================================*/
18 PRIVATE int stat_inode(rip, who_e, gid)
19 register struct inode *rip; /* pointer to inode to stat */
20 int who_e; /* Caller endpoint */
21 cp_grant_id_t gid; /* grant for the stat buf */
23 /* Common code for stat and fstat system calls. */
25 struct stat statbuf;
26 mode_t mo;
27 int r, s;
29 /* Update the atime, ctime, and mtime fields in the inode, if need be. */
30 if (rip->i_update) update_times(rip);
32 /* Fill in the statbuf struct. */
33 mo = rip->i_mode & I_TYPE;
35 /* true iff special */
36 s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
38 statbuf.st_dev = rip->i_dev;
39 statbuf.st_ino = rip->i_num;
40 statbuf.st_mode = rip->i_mode;
41 statbuf.st_nlink = rip->i_nlinks;
42 statbuf.st_uid = rip->i_uid;
43 statbuf.st_gid = rip->i_gid;
44 statbuf.st_rdev = (dev_t) (s ? rip->i_zone[0] : NO_DEV);
45 statbuf.st_size = rip->i_size;
46 statbuf.st_atime = rip->i_atime;
47 statbuf.st_mtime = rip->i_mtime;
48 statbuf.st_ctime = rip->i_ctime;
50 /* Copy the struct to user space. */
51 r = sys_safecopyto(who_e, gid, 0, (vir_bytes) &statbuf,
52 (phys_bytes) sizeof(statbuf), D);
54 return(r);
58 /*===========================================================================*
59 * fs_fstatfs *
60 *===========================================================================*/
61 PUBLIC int fs_fstatfs()
63 struct statfs st;
64 struct inode *rip;
65 int r;
67 if((rip = find_inode(fs_dev, ROOT_INODE)) == NIL_INODE)
68 return(EINVAL);
70 st.f_bsize = rip->i_sp->s_block_size;
72 /* Copy the struct to user space. */
73 r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0, (vir_bytes) &st,
74 (phys_bytes) sizeof(st), D);
76 return(r);
80 /*===========================================================================*
81 * fs_stat *
82 *===========================================================================*/
83 PUBLIC int fs_stat()
85 register int r; /* return value */
86 register struct inode *rip; /* target inode */
88 if ((rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
89 return(EINVAL);
91 r = stat_inode(rip, fs_m_in.m_source, fs_m_in.REQ_GRANT);
92 put_inode(rip); /* release the inode */
93 return(r);