7 /*===========================================================================*
9 *===========================================================================*/
10 static int stat_inode(
11 register struct inode
*rip
, /* pointer to inode to stat */
12 endpoint_t who_e
, /* Caller endpoint */
13 cp_grant_id_t gid
/* grant for the stat buf */
16 /* Common code for stat and fstat system calls. */
19 u32_t blocks
; /* The unit of this is 512 */
22 type
= rip
->i_mode
& I_TYPE
;
23 s
= (type
== I_CHAR_SPECIAL
|| type
== I_BLOCK_SPECIAL
);
25 /* Update the atime, ctime, and mtime fields in the inode, if need be. */
26 if (rip
->i_update
) update_times(rip
);
28 blocks
= rip
->i_size
/ S_BLKSIZE
;
29 if (rip
->i_size
% S_BLKSIZE
!= 0)
32 memset(&statbuf
, 0, sizeof(struct stat
));
34 statbuf
.st_dev
= rip
->i_dev
;
35 statbuf
.st_ino
= rip
->i_num
;
36 statbuf
.st_mode
= rip
->i_mode
;
37 statbuf
.st_nlink
= rip
->i_nlinks
;
38 statbuf
.st_uid
= rip
->i_uid
;
39 statbuf
.st_gid
= (short int) rip
->i_gid
;
40 statbuf
.st_rdev
= (dev_t
) (s
? rip
->i_rdev
: NO_DEV
);
41 statbuf
.st_size
= rip
->i_size
;
42 if (!s
) statbuf
.st_mode
&= ~I_REGULAR
;/* wipe out I_REGULAR bit for pipes */
43 statbuf
.st_atime
= rip
->i_atime
;
44 statbuf
.st_mtime
= rip
->i_mtime
;
45 statbuf
.st_ctime
= rip
->i_ctime
;
46 statbuf
.st_blksize
= PIPE_BUF
;
47 statbuf
.st_blocks
= blocks
;
49 /* Copy the struct to user space. */
50 r
= sys_safecopyto(who_e
, gid
, (vir_bytes
) 0, (vir_bytes
) &statbuf
,
51 (size_t) sizeof(statbuf
));
57 /*===========================================================================*
59 *===========================================================================*/
60 int fs_stat(message
*fs_m_in
, message
*fs_m_out
)
62 register int r
; /* return value */
63 register struct inode
*rip
; /* target inode */
65 if( (rip
= find_inode(fs_m_in
->REQ_INODE_NR
)) == NULL
) return(EINVAL
);
66 get_inode(rip
->i_dev
, rip
->i_num
); /* mark inode in use */
67 r
= stat_inode(rip
, fs_m_in
->m_source
, (cp_grant_id_t
) fs_m_in
->REQ_GRANT
);
68 put_inode(rip
); /* release the inode */