2006-10-25 15:40:36 +02:00
|
|
|
#include "fs.h"
|
2011-07-01 21:35:54 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/statfs.h>
|
2010-06-24 01:58:16 +02:00
|
|
|
#include <sys/statvfs.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#include "inode.h"
|
|
|
|
#include "super.h"
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
|
2011-07-12 18:09:52 +02:00
|
|
|
PRIVATE int copy_new_to_old_stat(endpoint_t who_e,
|
|
|
|
cp_grant_id_t gid, struct stat *st)
|
|
|
|
{
|
|
|
|
struct minix_prev_stat prevst;
|
|
|
|
|
|
|
|
memset(&prevst, 0, sizeof(prevst));
|
|
|
|
|
|
|
|
prevst.st_dev = st->st_dev;
|
|
|
|
prevst.st_ino = st->st_ino;
|
|
|
|
prevst.st_mode = st->st_mode;
|
|
|
|
prevst.st_uid = st->st_uid;
|
|
|
|
prevst.st_gid = st->st_gid;
|
|
|
|
prevst.st_size = st->st_size;
|
|
|
|
prevst.st_rdev = st->st_rdev;
|
|
|
|
|
|
|
|
return sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &prevst,
|
|
|
|
(size_t) sizeof(prevst), D);
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* stat_inode *
|
|
|
|
*===========================================================================*/
|
2010-03-30 16:07:15 +02:00
|
|
|
PRIVATE int stat_inode(
|
|
|
|
register struct inode *rip, /* pointer to inode to stat */
|
|
|
|
endpoint_t who_e, /* Caller endpoint */
|
|
|
|
cp_grant_id_t gid /* grant for the stat buf */
|
|
|
|
)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
/* Common code for stat and fstat system calls. */
|
|
|
|
|
|
|
|
struct stat statbuf;
|
|
|
|
mode_t mo;
|
|
|
|
int r, s;
|
2011-07-01 21:35:54 +02:00
|
|
|
u32_t blocks; /* The unit of this is 512 */
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
/* Update the atime, ctime, and mtime fields in the inode, if need be. */
|
|
|
|
if (rip->i_update) update_times(rip);
|
|
|
|
|
|
|
|
/* Fill in the statbuf struct. */
|
|
|
|
mo = rip->i_mode & I_TYPE;
|
|
|
|
|
|
|
|
/* true iff special */
|
|
|
|
s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL);
|
|
|
|
|
2011-07-01 21:35:54 +02:00
|
|
|
blocks = rip->i_size / 512;
|
|
|
|
if (rip->i_size % 512 != 0)
|
|
|
|
blocks += 1;
|
|
|
|
|
|
|
|
memset(&statbuf, 0, sizeof(struct stat));
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
statbuf.st_dev = rip->i_dev;
|
|
|
|
statbuf.st_ino = rip->i_num;
|
|
|
|
statbuf.st_mode = rip->i_mode;
|
|
|
|
statbuf.st_nlink = rip->i_nlinks;
|
|
|
|
statbuf.st_uid = rip->i_uid;
|
2010-06-01 14:35:33 +02:00
|
|
|
statbuf.st_gid = (short) rip->i_gid; /* FIXME: should become gid_t */
|
|
|
|
statbuf.st_rdev = (s ? (dev_t) rip->i_zone[0] : NO_DEV);
|
2006-10-25 15:40:36 +02:00
|
|
|
statbuf.st_size = rip->i_size;
|
|
|
|
statbuf.st_atime = rip->i_atime;
|
|
|
|
statbuf.st_mtime = rip->i_mtime;
|
|
|
|
statbuf.st_ctime = rip->i_ctime;
|
2011-07-01 21:35:54 +02:00
|
|
|
statbuf.st_blksize = fs_block_size;
|
|
|
|
statbuf.st_blocks = blocks;
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
2010-06-01 14:35:33 +02:00
|
|
|
r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
|
|
|
|
(size_t) sizeof(statbuf), D);
|
2011-07-12 18:09:52 +02:00
|
|
|
|
|
|
|
/* Fallback for older VFS (old stat) */
|
|
|
|
if(r != OK) {
|
|
|
|
r = copy_new_to_old_stat(who_e, gid, &statbuf);
|
|
|
|
if(r == OK) printf("MFS: old vfs stat fallback ok\n");
|
|
|
|
else printf("MFS: old vfs stat fallback failed\n");
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_fstatfs *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int fs_fstatfs()
|
|
|
|
{
|
|
|
|
struct statfs st;
|
|
|
|
struct inode *rip;
|
|
|
|
int r;
|
2007-01-05 17:36:55 +01:00
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
if((rip = find_inode(fs_dev, ROOT_INODE)) == NULL)
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(EINVAL);
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
st.f_bsize = rip->i_sp->s_block_size;
|
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
2010-06-01 14:35:33 +02:00
|
|
|
r = sys_safecopyto(fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT,
|
|
|
|
(vir_bytes) 0, (vir_bytes) &st, (size_t) sizeof(st), D);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2010-06-24 01:58:16 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* fs_statvfs *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int fs_statvfs()
|
|
|
|
{
|
|
|
|
struct statvfs st;
|
|
|
|
struct super_block *sp;
|
|
|
|
int r, scale;
|
2011-02-28 15:19:19 +01:00
|
|
|
u32_t used;
|
2010-06-24 01:58:16 +02:00
|
|
|
|
|
|
|
sp = get_super(fs_dev);
|
|
|
|
|
|
|
|
scale = sp->s_log_zone_size;
|
|
|
|
|
2011-02-28 15:19:19 +01:00
|
|
|
blockstats(&st.f_blocks, &st.f_bfree, &used);
|
|
|
|
st.f_bavail = st.f_bfree;
|
|
|
|
|
2010-06-24 01:58:16 +02:00
|
|
|
st.f_bsize = sp->s_block_size << scale;
|
|
|
|
st.f_frsize = sp->s_block_size;
|
|
|
|
st.f_files = sp->s_ninodes;
|
|
|
|
st.f_ffree = count_free_bits(sp, IMAP);
|
|
|
|
st.f_favail = st.f_ffree;
|
|
|
|
st.f_fsid = fs_dev;
|
|
|
|
st.f_flag = (sp->s_rd_only == 1 ? ST_RDONLY : 0);
|
|
|
|
st.f_namemax = NAME_MAX;
|
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
|
|
|
r = sys_safecopyto(fs_m_in.m_source, fs_m_in.REQ_GRANT, 0, (vir_bytes) &st,
|
|
|
|
(phys_bytes) sizeof(st), D);
|
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/*===========================================================================*
|
2007-01-05 17:36:55 +01:00
|
|
|
* fs_stat *
|
2006-10-25 15:40:36 +02:00
|
|
|
*===========================================================================*/
|
2007-01-05 17:36:55 +01:00
|
|
|
PUBLIC int fs_stat()
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
register int r; /* return value */
|
|
|
|
register struct inode *rip; /* target inode */
|
|
|
|
|
2010-06-01 14:35:33 +02:00
|
|
|
if ((rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(EINVAL);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2010-06-01 14:35:33 +02:00
|
|
|
r = stat_inode(rip, fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT);
|
2006-10-25 15:40:36 +02:00
|
|
|
put_inode(rip); /* release the inode */
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|