New stat structure.

* VFS and installed MFSes must be in sync before and after this change *

Use struct stat from NetBSD. It requires adding new STAT, FSTAT and LSTAT
syscalls. Libc modification is both backward and forward compatible.

Also new struct stat uses modern field sizes to avoid ABI
incompatibility, when we update uid_t, gid_t and company.
Exceptions are ino_t and off_t in old libc (though paddings added).
This commit is contained in:
Evgeniy Ivanov
2011-07-12 16:39:55 +02:00
committed by Ben Gras
parent 48331843ea
commit ef0a265086
34 changed files with 533 additions and 417 deletions
+5
View File
@@ -3,6 +3,7 @@
*/
#include "fs.h"
#include <string.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
@@ -35,6 +36,8 @@ PRIVATE int stat_inode(
/* true iff special */
s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
memset(&statbuf, 0, sizeof(struct stat));
statbuf.st_dev = rip->i_dev;
statbuf.st_ino = rip->i_num;
statbuf.st_mode = rip->i_mode;
@@ -46,6 +49,8 @@ PRIVATE int stat_inode(
statbuf.st_atime = rip->i_atime;
statbuf.st_mtime = rip->i_mtime;
statbuf.st_ctime = rip->i_ctime;
statbuf.st_blksize = rip->i_sp->s_block_size;
statbuf.st_blocks = rip->i_blocks;
/* Copy the struct to user space. */
r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
+8
View File
@@ -62,6 +62,8 @@ PUBLIC int do_stat()
if ((r = verify_inode(ino, path, &attr)) != OK)
return r;
memset(&stat, 0, sizeof(struct stat));
stat.st_dev = state.dev;
stat.st_ino = ino_nr;
stat.st_mode = get_mode(ino, attr.a_mode);
@@ -76,6 +78,12 @@ PUBLIC int do_stat()
stat.st_mtime = attr.a_mtime;
stat.st_ctime = attr.a_ctime;
stat.st_blocks = stat.st_size / S_BLKSIZE;
if (stat.st_size % S_BLKSIZE != 0)
stat.st_blocks += 1;
stat.st_blksize = BLOCK_SIZE;
/* We could make this more accurate by iterating over directory inodes'
* children, counting how many of those are directories as well.
* It's just not worth it.
+11
View File
@@ -1,4 +1,5 @@
#include "inc.h"
#include <assert.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
@@ -29,6 +30,14 @@ PRIVATE int stat_dir_record(
int r;
struct tm ltime;
time_t time1;
u32_t blocks;
blocks = v_pri.volume_space_size_l;
/* The unit of blocks should be 512 */
assert(v_pri.logical_block_size_l >= 512);
blocks = blocks * (v_pri.logical_block_size_l >> 9);
memset(&statbuf, 0, sizeof(struct stat));
statbuf.st_dev = fs_dev; /* the device of the file */
statbuf.st_ino = ID_DIR_RECORD(dir); /* the id of the dir record */
@@ -38,6 +47,8 @@ PRIVATE int stat_dir_record(
statbuf.st_gid = 0; /* group operator */
statbuf.st_rdev = NO_DEV;
statbuf.st_size = dir->d_file_size; /* size of the file */
statbuf.st_blksize = v_pri.logical_block_size_l;
statbuf.st_blocks = blocks;
ltime.tm_year = dir->rec_date[0];
ltime.tm_mon = dir->rec_date[1] - 1;
+11
View File
@@ -1,4 +1,6 @@
#include "fs.h"
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
@@ -21,6 +23,7 @@ PRIVATE int stat_inode(
struct stat statbuf;
mode_t mo;
int r, s;
u32_t blocks; /* The unit of this is 512 */
/* Update the atime, ctime, and mtime fields in the inode, if need be. */
if (rip->i_update) update_times(rip);
@@ -31,6 +34,12 @@ PRIVATE int stat_inode(
/* true iff special */
s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
blocks = rip->i_size / 512;
if (rip->i_size % 512 != 0)
blocks += 1;
memset(&statbuf, 0, sizeof(struct stat));
statbuf.st_dev = rip->i_dev;
statbuf.st_ino = rip->i_num;
statbuf.st_mode = rip->i_mode;
@@ -42,6 +51,8 @@ PRIVATE int stat_inode(
statbuf.st_atime = rip->i_atime;
statbuf.st_mtime = rip->i_mtime;
statbuf.st_ctime = rip->i_ctime;
statbuf.st_blksize = fs_block_size;
statbuf.st_blocks = blocks;
/* Copy the struct to user space. */
r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
+10
View File
@@ -1,5 +1,6 @@
#include "fs.h"
#include "inode.h"
#include <string.h>
#include <sys/stat.h>
@@ -15,6 +16,7 @@ PRIVATE int stat_inode(
/* Common code for stat and fstat system calls. */
mode_t type;
struct stat statbuf;
u32_t blocks; /* The unit of this is 512 */
int r, s;
type = rip->i_mode & I_TYPE;
@@ -23,6 +25,12 @@ PRIVATE int stat_inode(
/* Update the atime, ctime, and mtime fields in the inode, if need be. */
if (rip->i_update) update_times(rip);
blocks = rip->i_size / S_BLKSIZE;
if (rip->i_size % S_BLKSIZE != 0)
blocks += 1;
memset(&statbuf, 0, sizeof(struct stat));
statbuf.st_dev = rip->i_dev;
statbuf.st_ino = rip->i_num;
statbuf.st_mode = rip->i_mode;
@@ -35,6 +43,8 @@ PRIVATE int stat_inode(
statbuf.st_atime = rip->i_atime;
statbuf.st_mtime = rip->i_mtime;
statbuf.st_ctime = rip->i_ctime;
statbuf.st_blksize = PIPE_BUF;
statbuf.st_blocks = blocks;
/* Copy the struct to user space. */
r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
+1 -1
View File
@@ -61,7 +61,7 @@ _PROTOTYPE (int (*call_vec[]), (void) ) = {
do_get, /* 47 = getgid */
no_sys, /* 48 = (signal)*/
no_sys, /* 49 = unused */
no_sys, /* 50 = unused */
no_sys, /* 50 = lstat */
no_sys, /* 51 = (acct) */
no_sys, /* 52 = (phys) */
no_sys, /* 53 = (lock) */
+3 -3
View File
@@ -12,7 +12,7 @@ static int exec_newmem(int proc_e, vir_bytes text_addr,
vir_bytes text_bytes, vir_bytes data_addr,
vir_bytes data_bytes, vir_bytes tot_bytes,
vir_bytes frame_len, int sep_id, int is_elf,
dev_t st_dev, ino_t st_ino, time_t st_ctime, char *progname,
dev_t st_dev, ino_t st_ino, time_t ctime, char *progname,
int new_uid, int new_gid, vir_bytes *stack_topp,
int *load_textp, int *allow_setuidp);
static void patch_ptr(char stack[ARG_MAX], vir_bytes base);
@@ -321,7 +321,7 @@ static int exec_newmem(
int is_elf,
dev_t st_dev,
ino_t st_ino,
time_t st_ctime,
time_t ctime,
char *progname,
int new_uid,
int new_gid,
@@ -344,7 +344,7 @@ static int exec_newmem(
e.is_elf= is_elf;
e.st_dev= st_dev;
e.st_ino= st_ino;
e.st_ctime= st_ctime;
e.enst_ctime= ctime;
e.new_uid= new_uid;
e.new_gid= new_gid;
strncpy(e.progname, progname, sizeof(e.progname)-1);
+4 -4
View File
@@ -38,7 +38,7 @@
static int exec_newmem(int proc_e, vir_bytes text_addr, vir_bytes text_bytes,
vir_bytes data_addr, vir_bytes data_bytes,
vir_bytes tot_bytes, vir_bytes frame_len, int sep_id,
int is_elf, dev_t st_dev, ino_t st_ino, time_t st_ctime,
int is_elf, dev_t st_dev, ino_t st_ino, time_t ctime,
char *progname, int new_uid, int new_gid,
vir_bytes *stack_topp, int *load_textp,
int *allow_setuidp);
@@ -129,7 +129,7 @@ PUBLIC int pm_exec(int proc_e, char *path, vir_bytes path_len, char *frame,
r = r1;
else
r = req_stat(vp->v_fs_e, vp->v_inode_nr, VFS_PROC_NR,
(char *) &(execi.sb), 0);
(char *) &(execi.sb), 0, 0);
if (r != OK) {
put_vnode(vp);
return(r);
@@ -314,7 +314,7 @@ static int exec_newmem(
int is_elf,
dev_t st_dev,
ino_t st_ino,
time_t st_ctime,
time_t ctime,
char *progname,
int new_uid,
int new_gid,
@@ -337,7 +337,7 @@ static int exec_newmem(
e.is_elf = is_elf;
e.st_dev = st_dev;
e.st_ino = st_ino;
e.st_ctime = st_ctime;
e.enst_ctime = ctime;
e.new_uid = new_uid;
e.new_gid = new_gid;
strncpy(e.progname, progname, sizeof(e.progname)-1);
+1 -1
View File
@@ -226,7 +226,7 @@ _PROTOTYPE(int req_slink, (endpoint_t fs_e, ino_t inode_nr, char *lastc,
endpoint_t who_e, char *path_addr,
unsigned short path_length, uid_t uid, gid_t gid) );
_PROTOTYPE( int req_stat, (int fs_e, ino_t inode_nr, int who_e,
char *buf, int pos) );
char *buf, int pos, int stat_version) );
_PROTOTYPE( int req_sync, (endpoint_t fs_e) );
_PROTOTYPE( int req_unlink, (endpoint_t fs_e, ino_t inode_nr,
char *lastc) );
+49 -6
View File
@@ -9,6 +9,7 @@
#include "fs.h"
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
@@ -925,19 +926,21 @@ PUBLIC int req_slink(
/*===========================================================================*
* req_stat *
*===========================================================================*/
PUBLIC int req_stat(fs_e, inode_nr, who_e, buf, pos)
PUBLIC int req_stat(fs_e, inode_nr, who_e, buf, pos, stat_version)
int fs_e;
ino_t inode_nr;
int who_e;
char *buf;
int pos;
int stat_version;
{
cp_grant_id_t grant_id;
int r;
message m;
struct stat sb;
struct minix_prev_stat old_sb; /* for backward compatibility */
if (pos != 0)
if (pos != 0 || stat_version != 0)
grant_id = cpf_grant_direct(fs_e, (vir_bytes) &sb,
sizeof(struct stat), CPF_WRITE);
else
@@ -956,11 +959,51 @@ int pos;
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r == OK && pos != 0) {
sb.st_size -= pos;
r = sys_vircopy(SELF, D, (vir_bytes) &sb, who_e, D, (vir_bytes) buf,
sizeof(struct stat));
if (r != OK || (pos == 0 && stat_version == 0))
return(r);
if (pos != 0)
sb.st_size -= pos;
if (stat_version == 0) {
r = sys_vircopy(SELF, D, (vir_bytes) &sb, who_e, D, (vir_bytes) buf,
sizeof(struct stat));
return(r);
}
/* User needs old struct stat.
* Just 1 prev version at this moment */
assert(stat_version == 1);
/* XXX until that st_Xtime macroses used, we have to undefine them,
* because of minix_prev_stat
*/
#undef st_atime
#undef st_ctime
#undef st_mtime
/* Copy field by field because of st_gid type mismath and
* difference in order after atime.
*/
old_sb.st_dev = sb.st_dev;
old_sb.st_ino = sb.st_ino;
old_sb.st_mode = sb.st_mode;
old_sb.st_nlink = sb.st_nlink;
old_sb.st_uid = sb.st_uid;
old_sb.st_gid = sb.st_gid;
old_sb.st_rdev = sb.st_rdev;
old_sb.st_size = sb.st_size;
#if defined(_NETBSD_SOURCE)
old_sb.st_atime = sb.st_atimespec.tv_sec;
old_sb.st_mtime = sb.st_mtimespec.tv_sec;
old_sb.st_ctime = sb.st_ctimespec.tv_sec;
#else
old_sb.st_atime = sb.st_atime;
old_sb.st_mtime = sb.st_mtime;
old_sb.st_ctime = sb.st_ctime;
#endif
r = sys_vircopy(SELF, D, (vir_bytes) &old_sb, who_e, D, (vir_bytes) buf,
sizeof(struct minix_prev_stat));
return(r);
}
+16 -3
View File
@@ -22,6 +22,7 @@
#include "fproc.h"
#include "param.h"
#include <minix/vfsif.h>
#include <minix/callnr.h>
#include "vnode.h"
#include "vmnt.h"
@@ -121,10 +122,14 @@ PUBLIC int do_stat()
/* Perform the stat(name, buf) system call. */
int r;
struct vnode *vp;
int old_stat = 0;
if (call_nr == PREV_STAT)
old_stat = 1;
if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
if ((vp = eat_path(PATH_NOFLAGS, fp)) == NULL) return(err_code);
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, m_in.name2, 0);
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, m_in.name2, 0, old_stat);
put_vnode(vp);
return r;
@@ -139,6 +144,10 @@ PUBLIC int do_fstat()
/* Perform the fstat(fd, buf) system call. */
register struct filp *rfilp;
int pipe_pos = 0;
int old_stat = 0;
if (call_nr == PREV_FSTAT)
old_stat = 1;
/* Is the file descriptor valid? */
if ((rfilp = get_filp(m_in.fd)) == NULL) return(err_code);
@@ -153,7 +162,7 @@ PUBLIC int do_fstat()
}
return req_stat(rfilp->filp_vno->v_fs_e, rfilp->filp_vno->v_inode_nr,
who_e, m_in.buffer, pipe_pos);
who_e, m_in.buffer, pipe_pos, old_stat);
}
@@ -212,10 +221,14 @@ PUBLIC int do_lstat()
/* Perform the lstat(name, buf) system call. */
struct vnode *vp;
int r;
int old_stat = 0;
if (call_nr == PREV_LSTAT)
old_stat = 1;
if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
if ((vp = eat_path(PATH_RET_SYMLINK, fp)) == NULL) return(err_code);
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, m_in.name2, 0);
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, m_in.name2, 0, old_stat);
put_vnode(vp);
return(r);
+6 -6
View File
@@ -33,7 +33,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = {
do_chmod, /* 15 = chmod */
do_chown, /* 16 = chown */
no_sys, /* 17 = break */
do_stat, /* 18 = stat */
do_stat, /* 18 = stat (prev)*/
do_lseek, /* 19 = lseek */
no_sys, /* 20 = getpid */
do_mount, /* 21 = mount */
@@ -43,7 +43,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = {
no_sys, /* 25 = (stime) */
no_sys, /* 26 = ptrace */
no_sys, /* 27 = alarm */
do_fstat, /* 28 = fstat */
do_fstat, /* 28 = fstat (prev)*/
no_sys, /* 29 = pause */
do_utime, /* 30 = utime */
no_sys, /* 31 = (stty) */
@@ -65,7 +65,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = {
no_sys, /* 47 = getgid */
no_sys, /* 48 = (signal)*/
do_rdlink, /* 49 = readlink*/
do_lstat, /* 50 = lstat */
do_lstat, /* 50 = lstat (prev)*/
no_sys, /* 51 = (acct) */
no_sys, /* 52 = (phys) */
no_sys, /* 53 = (lock) */
@@ -80,9 +80,9 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = {
no_sys, /* 62 = (setsid)*/
no_sys, /* 63 = (getpgrp)*/
no_sys, /* 64 = (itimer)*/
no_sys, /* 65 = unused */
no_sys, /* 66 = unused */
no_sys, /* 67 = unused */
do_stat, /* 65 = stat */
do_fstat, /* 66 = fstat */
do_lstat, /* 67 = lstat */
no_sys, /* 68 = unused */
no_sys, /* 69 = unused */
no_sys, /* 70 = unused */
+1 -1
View File
@@ -113,7 +113,7 @@ SANITYCHECK(SCL_DETAIL);
/* Save file identification to allow it to be shared. */
vmp->vm_ino = args.st_ino;
vmp->vm_dev = args.st_dev;
vmp->vm_ctime = args.st_ctime;
vmp->vm_ctime = args.enst_ctime;
/* set/clear separate I&D flag */
if (args.sep_id)