4 #include <sys/statfs.h>
5 #include <sys/statvfs.h>
10 #include <minix/vfsif.h>
13 /*===========================================================================*
15 *===========================================================================*/
16 static int stat_dir_record(
17 register struct dir_record
*dir
, /* pointer to dir record to stat */
18 int pipe_pos
, /* position in a pipe, supplied by fstat() */
19 endpoint_t who_e
, /* Caller endpoint */
20 cp_grant_id_t gid
/* grant for the stat buf */
23 /* This function returns all the info about a particular inode. It's missing
24 * the recording date because of a bug in the standard functions stdtime.
25 * Once the bug is fixed the function can be called inside this function to
28 /* Common code for stat and fstat system calls. */
35 blocks
= v_pri
.volume_space_size_l
;
36 /* The unit of blocks should be 512 */
37 assert(v_pri
.logical_block_size_l
>= 512);
38 blocks
= blocks
* (v_pri
.logical_block_size_l
>> 9);
40 memset(&statbuf
, 0, sizeof(struct stat
));
42 statbuf
.st_dev
= fs_dev
; /* the device of the file */
43 statbuf
.st_ino
= ID_DIR_RECORD(dir
); /* the id of the dir record */
44 statbuf
.st_mode
= dir
->d_mode
; /* flags of the file */
45 statbuf
.st_nlink
= dir
->d_count
; /* times this file is used */
46 statbuf
.st_uid
= 0; /* user root */
47 statbuf
.st_gid
= 0; /* group operator */
48 statbuf
.st_rdev
= NO_DEV
;
49 statbuf
.st_size
= dir
->d_file_size
; /* size of the file */
50 statbuf
.st_blksize
= v_pri
.logical_block_size_l
;
51 statbuf
.st_blocks
= blocks
;
53 ltime
.tm_year
= dir
->rec_date
[0];
54 ltime
.tm_mon
= dir
->rec_date
[1] - 1;
55 ltime
.tm_mday
= dir
->rec_date
[2];
56 ltime
.tm_hour
= dir
->rec_date
[3];
57 ltime
.tm_min
= dir
->rec_date
[4];
58 ltime
.tm_sec
= dir
->rec_date
[5];
61 if (dir
->rec_date
[6] != 0)
62 ltime
.tm_hour
+= dir
->rec_date
[6] / 4;
64 time1
= mktime(<ime
);
66 statbuf
.st_atime
= time1
;
67 statbuf
.st_mtime
= time1
;
68 statbuf
.st_ctime
= time1
;
70 /* Copy the struct to user space. */
71 r
= sys_safecopyto(who_e
, gid
, 0, (vir_bytes
) &statbuf
,
72 (phys_bytes
) sizeof(statbuf
));
78 /*===========================================================================*
80 *===========================================================================*/
83 register int r
; /* return value */
84 struct dir_record
*dir
;
87 if ((dir
= get_dir_record(fs_m_in
.REQ_INODE_NR
)) != NULL
) {
88 r
= stat_dir_record(dir
, 0, fs_m_in
.m_source
, fs_m_in
.REQ_GRANT
);
89 release_dir_record(dir
);
96 /*===========================================================================*
98 *===========================================================================*/
104 st
.f_bsize
= v_pri
.logical_block_size_l
;
106 /* Copy the struct to user space. */
107 r
= sys_safecopyto(fs_m_in
.m_source
, fs_m_in
.REQ_GRANT
, 0,
108 (vir_bytes
) &st
, (phys_bytes
) sizeof(st
));
114 /*===========================================================================*
116 *===========================================================================*/
123 st
.f_bsize
= v_pri
.logical_block_size_l
;
124 st
.f_frsize
= st
.f_bsize
;
125 st
.f_blocks
= v_pri
.volume_space_size_l
;
132 st
.f_flag
= ST_RDONLY
;
133 st
.f_namemax
= NAME_MAX
;
135 /* Copy the struct to user space. */
136 r
= sys_safecopyto(fs_m_in
.m_source
, fs_m_in
.REQ_GRANT
, 0, (vir_bytes
) &st
,
137 (phys_bytes
) sizeof(st
));
142 /*===========================================================================*
144 *===========================================================================*/
145 void fs_blockstats(u32_t
*blocks
, u32_t
*free
, u32_t
*used
)
147 *used
= *blocks
= v_pri
.volume_space_size_l
;