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>
|
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>
|
|
|
|
|
2012-03-04 12:14:06 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* estimate_blocks *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static blkcnt_t estimate_blocks(struct inode *rip)
|
2012-03-04 12:14:06 +01:00
|
|
|
{
|
|
|
|
/* Return the number of 512-byte blocks used by this file. This includes space
|
|
|
|
* used by data zones and indirect blocks (actually also zones). Reading in all
|
|
|
|
* indirect blocks is too costly for a stat call, so we disregard holes and
|
|
|
|
* return a conservative estimation.
|
|
|
|
*/
|
2012-08-02 15:03:23 +02:00
|
|
|
blkcnt_t zones, sindirs, dindirs, nr_indirs, sq_indirs;
|
|
|
|
unsigned int zone_size;
|
2012-03-04 12:14:06 +01:00
|
|
|
|
|
|
|
/* Compute the number of zones used by the file. */
|
|
|
|
zone_size = rip->i_sp->s_block_size << rip->i_sp->s_log_zone_size;
|
|
|
|
|
2012-08-02 15:03:23 +02:00
|
|
|
zones = (blkcnt_t) ((rip->i_size + zone_size - 1) / zone_size);
|
2012-03-04 12:14:06 +01:00
|
|
|
|
|
|
|
/* Compute the number of indirect blocks needed for that zone count. */
|
2012-07-26 17:16:11 +02:00
|
|
|
nr_indirs = (blkcnt_t) rip->i_nindirs;
|
2012-03-04 12:14:06 +01:00
|
|
|
sq_indirs = nr_indirs * nr_indirs;
|
|
|
|
|
2012-08-02 15:03:23 +02:00
|
|
|
sindirs = (zones - (blkcnt_t) rip->i_ndzones + nr_indirs - 1) / nr_indirs;
|
|
|
|
dindirs = (sindirs - 1 + sq_indirs - 1) / sq_indirs;
|
2012-03-04 12:14:06 +01:00
|
|
|
|
|
|
|
/* Return the number of 512-byte blocks corresponding to the number of data
|
|
|
|
* zones and indirect blocks.
|
|
|
|
*/
|
2012-08-02 15:03:23 +02:00
|
|
|
return (zones + sindirs + dindirs) * (blkcnt_t) (zone_size / 512);
|
2012-03-04 12:14:06 +01:00
|
|
|
}
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* stat_inode *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int stat_inode(
|
2010-03-30 16:07:15 +02:00
|
|
|
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;
|
2014-05-01 16:19:28 +02:00
|
|
|
mode_t mo;
|
2006-10-25 15:40:36 +02:00
|
|
|
int r, s;
|
|
|
|
|
|
|
|
/* 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
|
|
|
memset(&statbuf, 0, sizeof(struct stat));
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
statbuf.st_dev = rip->i_dev;
|
2013-03-07 16:55:22 +01:00
|
|
|
statbuf.st_ino = (ino_t) rip->i_num;
|
|
|
|
statbuf.st_mode = (mode_t) rip->i_mode;
|
|
|
|
statbuf.st_nlink = (nlink_t) rip->i_nlinks;
|
2006-10-25 15:40:36 +02:00
|
|
|
statbuf.st_uid = rip->i_uid;
|
2011-09-05 15:56:14 +02:00
|
|
|
statbuf.st_gid = rip->i_gid;
|
2013-11-15 19:01:25 +01:00
|
|
|
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;
|
2012-10-16 17:40:39 +02:00
|
|
|
statbuf.st_blksize = lmfs_fs_block_size();
|
2012-03-04 12:14:06 +01:00
|
|
|
statbuf.st_blocks = estimate_blocks(rip);
|
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,
|
2012-06-16 03:46:15 +02:00
|
|
|
(size_t) sizeof(statbuf));
|
2011-07-12 18:09:52 +02:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2010-06-24 01:58:16 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* fs_statvfs *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_statvfs()
|
2010-06-24 01:58:16 +02:00
|
|
|
{
|
|
|
|
struct statvfs st;
|
|
|
|
struct super_block *sp;
|
|
|
|
int r, scale;
|
2013-08-31 22:59:44 +02:00
|
|
|
u64_t used;
|
2010-06-24 01:58:16 +02:00
|
|
|
|
|
|
|
sp = get_super(fs_dev);
|
|
|
|
|
|
|
|
scale = sp->s_log_zone_size;
|
|
|
|
|
2013-08-20 01:35:35 +02:00
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
|
2013-04-18 14:42:15 +02:00
|
|
|
fs_blockstats(&st.f_blocks, &st.f_bfree, &used);
|
2011-02-28 15:19:19 +01:00
|
|
|
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;
|
2013-08-20 01:35:35 +02:00
|
|
|
st.f_iosize = st.f_frsize;
|
2010-06-24 01:58:16 +02:00
|
|
|
st.f_files = sp->s_ninodes;
|
|
|
|
st.f_ffree = count_free_bits(sp, IMAP);
|
|
|
|
st.f_favail = st.f_ffree;
|
2011-08-05 01:15:16 +02:00
|
|
|
st.f_namemax = MFS_DIRSIZ;
|
2010-06-24 01:58:16 +02:00
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
2014-05-01 11:19:18 +02:00
|
|
|
r = sys_safecopyto(fs_m_in.m_source, fs_m_in.m_vfs_fs_statvfs.grant, 0,
|
|
|
|
(vir_bytes) &st, (phys_bytes) sizeof(st));
|
2010-06-24 01:58:16 +02:00
|
|
|
|
|
|
|
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
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_stat()
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
register int r; /* return value */
|
|
|
|
register struct inode *rip; /* target inode */
|
|
|
|
|
2014-05-01 10:05:07 +02:00
|
|
|
if ((rip = get_inode(fs_dev, fs_m_in.m_vfs_fs_stat.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
|
|
|
|
2014-05-01 10:05:07 +02:00
|
|
|
r = stat_inode(rip, fs_m_in.m_source, fs_m_in.m_vfs_fs_stat.grant);
|
2006-10-25 15:40:36 +02:00
|
|
|
put_inode(rip); /* release the inode */
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|