5 #include <sys/statfs.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 /*===========================================================================*
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. */
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
);
69 /*===========================================================================*
71 *===========================================================================*/
72 PUBLIC
int fs_fstatfs()
78 if ((rip
= find_inode(fs_dev
, fs_m_in
.REQ_FD_INODE_NR
))
80 printf("FSfstatfs: couldn't find inode %d\n", fs_m_in
.REQ_FD_INODE_NR
);
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
);
93 /*===========================================================================*
95 *===========================================================================*/
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
);
106 r
= stat_inode(rip
, 0, fs_m_in
.m_source
, fs_m_in
.REQ_GRANT
);
107 put_inode(rip
); /* release the inode */