root/fs/stat.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cp_stat
  2. sys_stat
  3. sys_lstat
  4. sys_fstat
  5. sys_readlink

   1 /*
   2  *  linux/fs/stat.c
   3  *
   4  *  (C) 1991  Linus Torvalds
   5  */
   6 
   7 #include <errno.h>
   8 #include <sys/stat.h>
   9 
  10 #include <linux/fs.h>
  11 #include <linux/sched.h>
  12 #include <linux/kernel.h>
  13 #include <asm/segment.h>
  14 
  15 static void cp_stat(struct inode * inode, struct stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17         struct stat tmp;
  18         int i;
  19 
  20         verify_area(statbuf,sizeof (struct stat));
  21         tmp.st_dev = inode->i_dev;
  22         tmp.st_ino = inode->i_ino;
  23         tmp.st_mode = inode->i_mode;
  24         tmp.st_nlink = inode->i_nlink;
  25         tmp.st_uid = inode->i_uid;
  26         tmp.st_gid = inode->i_gid;
  27         tmp.st_rdev = inode->i_rdev;
  28         tmp.st_size = inode->i_size;
  29         tmp.st_atime = inode->i_atime;
  30         tmp.st_mtime = inode->i_mtime;
  31         tmp.st_ctime = inode->i_ctime;
  32         for (i=0 ; i<sizeof (tmp) ; i++)
  33                 put_fs_byte(((char *) &tmp)[i],i + (char *) statbuf);
  34 }
  35 
  36 int sys_stat(char * filename, struct stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38         struct inode * inode;
  39 
  40         if (!(inode=namei(filename)))
  41                 return -ENOENT;
  42         cp_stat(inode,statbuf);
  43         iput(inode);
  44         return 0;
  45 }
  46 
  47 int sys_lstat(char * filename, struct stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49         struct inode * inode;
  50 
  51         if (!(inode = lnamei(filename)))
  52                 return -ENOENT;
  53         cp_stat(inode,statbuf);
  54         iput(inode);
  55         return 0;
  56 }
  57 
  58 int sys_fstat(unsigned int fd, struct stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         struct file * f;
  61         struct inode * inode;
  62 
  63         if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
  64                 return -EBADF;
  65         cp_stat(inode,statbuf);
  66         return 0;
  67 }
  68 
  69 int sys_readlink(const char * path, char * buf, int bufsiz)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71         struct inode * inode;
  72 
  73         if (bufsiz <= 0)
  74                 return -EINVAL;
  75         verify_area(buf,bufsiz);
  76         if (!(inode = lnamei(path)))
  77                 return -ENOENT;
  78         if (!inode->i_op || !inode->i_op->readlink) {
  79                 iput(inode);
  80                 return -EINVAL;
  81         }
  82         return inode->i_op->readlink(inode,buf,bufsiz);
  83 }

/* [previous][next][first][last][top][bottom][index][help] */