. service tells you which device it couldn't stat
[minix3.git] / servers / mfs / stadir.c
blob720ee04608b20b2b8607d5b4e8e145c3ffeb245f
3 #include "fs.h"
4 #include <sys/stat.h>
5 #include <sys/statfs.h>
6 #include <minix/com.h>
7 #include <string.h>
8 #include "buf.h"
9 #include "inode.h"
10 #include "super.h"
12 #include <minix/vfsif.h>
15 FORWARD _PROTOTYPE( int stat_inode, (struct inode *rip, int pipe_pos,
16 int who_e, cp_grant_id_t gid) );
19 /*===========================================================================*
20 * stat_inode *
21 *===========================================================================*/
22 PRIVATE int stat_inode(rip, pipe_pos, who_e, gid)
23 register struct inode *rip; /* pointer to inode to stat */
24 int pipe_pos; /* position in a pipe, supplied by fstat() */
25 int who_e; /* Caller endpoint */
26 cp_grant_id_t gid; /* grant for the stat buf */
28 /* Common code for stat and fstat system calls. */
30 struct stat statbuf;
31 mode_t mo;
32 int r, s;
34 /* Update the atime, ctime, and mtime fields in the inode, if need be. */
35 if (rip->i_update) update_times(rip);
37 /* Fill in the statbuf struct. */
38 mo = rip->i_mode & I_TYPE;
40 /* true iff special */
41 s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
43 statbuf.st_dev = rip->i_dev;
44 statbuf.st_ino = rip->i_num;
45 statbuf.st_mode = rip->i_mode;
46 statbuf.st_nlink = rip->i_nlinks;
47 statbuf.st_uid = rip->i_uid;
48 statbuf.st_gid = rip->i_gid;
49 statbuf.st_rdev = (dev_t) (s ? rip->i_zone[0] : NO_DEV);
50 statbuf.st_size = rip->i_size;
52 if (rip->i_pipe == I_PIPE) {
53 statbuf.st_mode &= ~I_REGULAR; /* wipe out I_REGULAR bit for pipes */
54 statbuf.st_size -= pipe_pos;
57 statbuf.st_atime = rip->i_atime;
58 statbuf.st_mtime = rip->i_mtime;
59 statbuf.st_ctime = rip->i_ctime;
61 /* Copy the struct to user space. */
62 r = sys_safecopyto(who_e, gid, 0, (vir_bytes) &statbuf,
63 (phys_bytes) sizeof(statbuf), D);
65 return(r);
69 /*===========================================================================*
70 * fs_fstatfs *
71 *===========================================================================*/
72 PUBLIC int fs_fstatfs()
74 struct statfs st;
75 struct inode *rip;
76 int r;
78 if ((rip = find_inode(fs_dev, fs_m_in.REQ_FD_INODE_NR))
79 == NIL_INODE) {
80 printf("FSfstatfs: couldn't find inode %d\n", fs_m_in.REQ_FD_INODE_NR);
81 return EINVAL;
84 st.f_bsize = rip->i_sp->s_block_size;
86 /* Copy the struct to user space. */
87 r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0,
88 (vir_bytes) &st, (phys_bytes) sizeof(st), D);
90 return(r);
93 /*===========================================================================*
94 * fs_stat *
95 *===========================================================================*/
96 PUBLIC int fs_stat()
98 register int r; /* return value */
99 register struct inode *rip; /* target inode */
101 if ( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE) {
102 printf("MFS(%d) get_inode by fs_stat() failed\n", SELF_E);
103 return(EINVAL);
106 r = stat_inode(rip, 0, fs_m_in.m_source, fs_m_in.REQ_GRANT);
107 put_inode(rip); /* release the inode */
108 return(r);