at_wini: more general system to allow devices that behave like ata controllers.
[minix.git] / servers / pfs / stadir.c
blob2eaec09db38e930e74637cafab13782170981682
1 #include "fs.h"
2 #include "inode.h"
3 #include <sys/stat.h>
6 /*===========================================================================*
7 * stat_inode *
8 *===========================================================================*/
9 PRIVATE int stat_inode(
10 register struct inode *rip, /* pointer to inode to stat */
11 endpoint_t who_e, /* Caller endpoint */
12 cp_grant_id_t gid /* grant for the stat buf */
15 /* Common code for stat and fstat system calls. */
16 mode_t type;
17 struct stat statbuf;
18 int r, s;
20 type = rip->i_mode & I_TYPE;
21 s = (type == I_CHAR_SPECIAL || type == I_BLOCK_SPECIAL);
23 /* Update the atime, ctime, and mtime fields in the inode, if need be. */
24 if (rip->i_update) update_times(rip);
26 statbuf.st_dev = rip->i_dev;
27 statbuf.st_ino = rip->i_num;
28 statbuf.st_mode = rip->i_mode;
29 statbuf.st_nlink = rip->i_nlinks;
30 statbuf.st_uid = rip->i_uid;
31 statbuf.st_gid = rip->i_gid;
32 statbuf.st_rdev = (dev_t) (s ? rip->i_rdev : NO_DEV);
33 statbuf.st_size = rip->i_size;
34 if (!s) statbuf.st_mode &= ~I_REGULAR;/* wipe out I_REGULAR bit for pipes */
35 statbuf.st_atime = rip->i_atime;
36 statbuf.st_mtime = rip->i_mtime;
37 statbuf.st_ctime = rip->i_ctime;
39 /* Copy the struct to user space. */
40 r = sys_safecopyto(who_e, gid, 0, (vir_bytes) &statbuf,
41 (phys_bytes) sizeof(statbuf), D);
43 return(r);
47 /*===========================================================================*
48 * fs_stat *
49 *===========================================================================*/
50 PUBLIC int fs_stat()
52 register int r; /* return value */
53 register struct inode *rip; /* target inode */
55 if( (rip = find_inode(fs_m_in.REQ_INODE_NR)) == NIL_INODE) return(EINVAL);
56 get_inode(rip->i_dev, rip->i_num); /* mark inode in use */
57 r = stat_inode(rip, fs_m_in.m_source, fs_m_in.REQ_GRANT);
58 put_inode(rip); /* release the inode */
59 return(r);