2009-12-20 21:41:50 +01:00
|
|
|
#include "fs.h"
|
|
|
|
#include "inode.h"
|
2011-07-01 21:35:54 +02:00
|
|
|
#include <string.h>
|
2009-12-20 21:41:50 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* 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 */
|
|
|
|
)
|
2009-12-20 21:41:50 +01:00
|
|
|
{
|
|
|
|
/* Common code for stat and fstat system calls. */
|
2013-03-07 15:46:21 +01:00
|
|
|
pmode_t type;
|
2009-12-20 21:41:50 +01:00
|
|
|
struct stat statbuf;
|
2011-07-01 21:35:54 +02:00
|
|
|
u32_t blocks; /* The unit of this is 512 */
|
2009-12-20 21:41:50 +01:00
|
|
|
int r, s;
|
|
|
|
|
2010-03-30 17:00:09 +02:00
|
|
|
type = rip->i_mode & I_TYPE;
|
|
|
|
s = (type == I_CHAR_SPECIAL || type == I_BLOCK_SPECIAL);
|
|
|
|
|
2009-12-20 21:41:50 +01:00
|
|
|
/* Update the atime, ctime, and mtime fields in the inode, if need be. */
|
|
|
|
if (rip->i_update) update_times(rip);
|
|
|
|
|
2011-07-01 21:35:54 +02:00
|
|
|
blocks = rip->i_size / S_BLKSIZE;
|
|
|
|
if (rip->i_size % S_BLKSIZE != 0)
|
|
|
|
blocks += 1;
|
|
|
|
|
|
|
|
memset(&statbuf, 0, sizeof(struct stat));
|
|
|
|
|
2009-12-20 21:41:50 +01: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-05-28 11:39:18 +02:00
|
|
|
statbuf.st_gid = (short int) rip->i_gid;
|
2010-03-30 17:00:09 +02:00
|
|
|
statbuf.st_rdev = (dev_t) (s ? rip->i_rdev : NO_DEV);
|
2009-12-20 21:41:50 +01:00
|
|
|
statbuf.st_size = rip->i_size;
|
2010-03-30 17:00:09 +02:00
|
|
|
if (!s) statbuf.st_mode &= ~I_REGULAR;/* wipe out I_REGULAR bit for pipes */
|
2009-12-20 21:41:50 +01:00
|
|
|
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 = PIPE_BUF;
|
|
|
|
statbuf.st_blocks = blocks;
|
2009-12-20 21:41:50 +01:00
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
2010-05-28 11:39:18 +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));
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2009-12-20 21:41:50 +01:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_stat *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_stat(message *fs_m_in, message *fs_m_out)
|
2009-12-20 21:41:50 +01:00
|
|
|
{
|
|
|
|
register int r; /* return value */
|
|
|
|
register struct inode *rip; /* target inode */
|
|
|
|
|
2010-07-15 15:39:57 +02:00
|
|
|
if( (rip = find_inode(fs_m_in->REQ_INODE_NR)) == NULL) return(EINVAL);
|
2012-02-13 16:28:04 +01:00
|
|
|
get_inode(rip->i_dev, rip->i_num); /* mark inode in use */
|
2010-07-15 15:39:57 +02:00
|
|
|
r = stat_inode(rip, fs_m_in->m_source, (cp_grant_id_t) fs_m_in->REQ_GRANT);
|
2009-12-20 21:41:50 +01:00
|
|
|
put_inode(rip); /* release the inode */
|
|
|
|
return(r);
|
|
|
|
}
|