Esempio n. 1
0
/*===========================================================================*
 *                             fs_stat					     *
 *===========================================================================*/
int fs_stat(ino_t ino_nr, struct stat *statbuf)
{
    struct inode *rip;
    mode_t mo;
    int s;

    if ((rip = get_inode(fs_dev, ino_nr)) == NULL)
        return(EINVAL);

    /* 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);

    statbuf->st_mode = (mode_t) rip->i_mode;
    statbuf->st_nlink = (nlink_t) rip->i_nlinks;
    statbuf->st_uid = rip->i_uid;
    statbuf->st_gid = rip->i_gid;
    statbuf->st_rdev = (s ? (dev_t)rip->i_zone[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;
    statbuf->st_blksize = lmfs_fs_block_size();
    statbuf->st_blocks = estimate_blocks(rip);

    put_inode(rip);		/* release the inode */

    return(OK);
}
Esempio n. 2
0
/*===========================================================================*
 *				stat_inode				     *
 *===========================================================================*/
static 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 */
)
{
/* Common code for stat and fstat system calls. */

  struct stat statbuf;
  mode_t mo;
  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);

  memset(&statbuf, 0, sizeof(struct stat));

  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;
  statbuf.st_gid = rip->i_gid;
  statbuf.st_rdev = (s ? (dev_t) rip->i_zone[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;
  statbuf.st_blksize = fs_block_size;
  statbuf.st_blocks = estimate_blocks(rip);

  /* Copy the struct to user space. */
  r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
  		(size_t) sizeof(statbuf));

  return(r);
}