2010-08-02 13:44:45 +02:00
|
|
|
/* Created (MFS based):
|
|
|
|
* February 2010 (Evgeniy Ivanov)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
2011-07-01 21:35:54 +02:00
|
|
|
#include <string.h>
|
2010-08-02 13:44:45 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#include "inode.h"
|
|
|
|
#include "super.h"
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* stat_inode *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int stat_inode(
|
2010-08-02 13:44:45 +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 */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
/* Common code for stat and fstat system calls. */
|
|
|
|
|
|
|
|
struct stat statbuf;
|
2013-03-07 15:46:21 +01:00
|
|
|
pmode_t mo;
|
2010-08-02 13:44:45 +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));
|
|
|
|
|
2010-08-02 13:44:45 +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_links_count;
|
|
|
|
statbuf.st_uid = rip->i_uid;
|
|
|
|
statbuf.st_gid = rip->i_gid;
|
|
|
|
statbuf.st_rdev = (s ? rip->i_block[0] : NO_DEV);
|
|
|
|
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 = rip->i_sp->s_block_size;
|
|
|
|
statbuf.st_blocks = rip->i_blocks;
|
2010-08-02 13:44:45 +02:00
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
|
|
|
r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
|
2012-06-16 03:46:15 +02:00
|
|
|
(size_t) sizeof(statbuf));
|
2010-08-02 13:44:45 +02:00
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_stat *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_stat()
|
2010-08-02 13:44:45 +02:00
|
|
|
{
|
|
|
|
register int r; /* return value */
|
|
|
|
register struct inode *rip; /* target inode */
|
|
|
|
|
2013-03-07 15:46:21 +01:00
|
|
|
if ((rip = get_inode(fs_dev, (pino_t) fs_m_in.REQ_INODE_NR)) == NULL)
|
2010-08-02 13:44:45 +02:00
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
r = stat_inode(rip, fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT);
|
|
|
|
put_inode(rip); /* release the inode */
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_statvfs *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_statvfs()
|
2010-08-02 13:44:45 +02:00
|
|
|
{
|
|
|
|
struct statvfs st;
|
|
|
|
struct super_block *sp;
|
|
|
|
int r;
|
|
|
|
|
2013-08-20 01:35:35 +02:00
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
|
2010-08-02 13:44:45 +02:00
|
|
|
sp = get_super(fs_dev);
|
|
|
|
|
2013-08-20 01:35:35 +02:00
|
|
|
st.f_flag = ST_NOTRUNC;
|
2010-08-02 13:44:45 +02:00
|
|
|
st.f_bsize = sp->s_block_size;
|
|
|
|
st.f_frsize = sp->s_block_size;
|
2013-08-20 01:35:35 +02:00
|
|
|
st.f_iosize = sp->s_block_size;
|
2010-08-02 13:44:45 +02:00
|
|
|
st.f_blocks = sp->s_blocks_count;
|
|
|
|
st.f_bfree = sp->s_free_blocks_count;
|
|
|
|
st.f_bavail = sp->s_free_blocks_count - sp->s_r_blocks_count;
|
|
|
|
st.f_files = sp->s_inodes_count;
|
|
|
|
st.f_ffree = sp->s_free_inodes_count;
|
|
|
|
st.f_favail = sp->s_free_inodes_count;
|
|
|
|
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,
|
2012-06-16 03:46:15 +02:00
|
|
|
(phys_bytes) sizeof(st));
|
2010-08-02 13:44:45 +02:00
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
2012-10-16 17:40:39 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* blockstats *
|
|
|
|
*===========================================================================*/
|
2013-04-18 14:42:15 +02:00
|
|
|
void fs_blockstats(u64_t *blocks, u64_t *free, u64_t *used)
|
2012-10-16 17:40:39 +02:00
|
|
|
{
|
|
|
|
struct super_block *sp = get_super(fs_dev);
|
|
|
|
|
|
|
|
*blocks = sp->s_blocks_count;
|
|
|
|
*free = sp->s_free_blocks_count;
|
|
|
|
*used = *blocks - *free;
|
|
|
|
}
|
|
|
|
|