root/fs/stat.c

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

DEFINITIONS

This source file includes following definitions.
  1. cp_old_stat
  2. cp_new_stat
  3. sys_stat
  4. sys_newstat
  5. sys_lstat
  6. sys_newlstat
  7. sys_fstat
  8. sys_newfstat
  9. sys_readlink

   1 /*
   2  *  linux/fs/stat.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/errno.h>
   8 #include <linux/stat.h>
   9 #include <linux/fs.h>
  10 #include <linux/sched.h>
  11 #include <linux/kernel.h>
  12 #include <asm/segment.h>
  13 
  14 static void cp_old_stat(struct inode * inode, struct old_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  15 {
  16         struct old_stat tmp;
  17 
  18         printk("VFS: Warning: %s using old stat() call. Recompile your binary.\n",
  19                 current->comm);
  20         tmp.st_dev = inode->i_dev;
  21         tmp.st_ino = inode->i_ino;
  22         tmp.st_mode = inode->i_mode;
  23         tmp.st_nlink = inode->i_nlink;
  24         tmp.st_uid = inode->i_uid;
  25         tmp.st_gid = inode->i_gid;
  26         tmp.st_rdev = inode->i_rdev;
  27         tmp.st_size = inode->i_size;
  28         tmp.st_atime = inode->i_atime;
  29         tmp.st_mtime = inode->i_mtime;
  30         tmp.st_ctime = inode->i_ctime;
  31         memcpy_tofs(statbuf,&tmp,sizeof(tmp));
  32 }
  33 
  34 static void cp_new_stat(struct inode * inode, struct new_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36         struct new_stat tmp = {0, };
  37         unsigned int blocks, indirect;
  38 
  39         tmp.st_dev = inode->i_dev;
  40         tmp.st_ino = inode->i_ino;
  41         tmp.st_mode = inode->i_mode;
  42         tmp.st_nlink = inode->i_nlink;
  43         tmp.st_uid = inode->i_uid;
  44         tmp.st_gid = inode->i_gid;
  45         tmp.st_rdev = inode->i_rdev;
  46         tmp.st_size = inode->i_size;
  47         tmp.st_atime = inode->i_atime;
  48         tmp.st_mtime = inode->i_mtime;
  49         tmp.st_ctime = inode->i_ctime;
  50 /*
  51  * st_blocks and st_blksize are approximated with a simple algorithm if
  52  * they aren't supported directly by the filesystem. The minix and msdos
  53  * filesystems don't keep track of blocks, so they would either have to
  54  * be counted explicitly (by delving into the file itself), or by using
  55  * this simple algorithm to get a reasonable (although not 100% accurate)
  56  * value.
  57  */
  58         if (!inode->i_blksize) {
  59                 blocks = (tmp.st_size + 511) / 512;
  60                 if (blocks > 10) {
  61                         indirect = (blocks - 11)/256+1;
  62                         if (blocks > 10+256) {
  63                                 indirect += (blocks - 267)/(256*256)+1;
  64                                 if (blocks > 10+256+256*256)
  65                                         indirect++;
  66                         }
  67                         blocks += indirect;
  68                 }
  69                 tmp.st_blocks = blocks;
  70                 tmp.st_blksize = BLOCK_SIZE;
  71         } else {
  72                 tmp.st_blocks = inode->i_blocks;
  73                 tmp.st_blksize = inode->i_blksize;
  74         }
  75         memcpy_tofs(statbuf,&tmp,sizeof(tmp));
  76 }
  77 
  78 int sys_stat(char * filename, struct old_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         struct inode * inode;
  81         int error;
  82 
  83         error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
  84         if (error)
  85                 return error;
  86         error = namei(filename,&inode);
  87         if (error)
  88                 return error;
  89         cp_old_stat(inode,statbuf);
  90         iput(inode);
  91         return 0;
  92 }
  93 
  94 int sys_newstat(char * filename, struct new_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         struct inode * inode;
  97         int error;
  98 
  99         error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
 100         if (error)
 101                 return error;
 102         error = namei(filename,&inode);
 103         if (error)
 104                 return error;
 105         cp_new_stat(inode,statbuf);
 106         iput(inode);
 107         return 0;
 108 }
 109 
 110 int sys_lstat(char * filename, struct old_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 111 {
 112         struct inode * inode;
 113         int error;
 114 
 115         error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
 116         if (error)
 117                 return error;
 118         error = lnamei(filename,&inode);
 119         if (error)
 120                 return error;
 121         cp_old_stat(inode,statbuf);
 122         iput(inode);
 123         return 0;
 124 }
 125 
 126 int sys_newlstat(char * filename, struct new_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128         struct inode * inode;
 129         int error;
 130 
 131         error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
 132         if (error)
 133                 return error;
 134         error = lnamei(filename,&inode);
 135         if (error)
 136                 return error;
 137         cp_new_stat(inode,statbuf);
 138         iput(inode);
 139         return 0;
 140 }
 141 
 142 int sys_fstat(unsigned int fd, struct old_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144         struct file * f;
 145         struct inode * inode;
 146         int error;
 147 
 148         error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
 149         if (error)
 150                 return error;
 151         if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
 152                 return -EBADF;
 153         cp_old_stat(inode,statbuf);
 154         return 0;
 155 }
 156 
 157 int sys_newfstat(unsigned int fd, struct new_stat * statbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159         struct file * f;
 160         struct inode * inode;
 161         int error;
 162 
 163         error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
 164         if (error)
 165                 return error;
 166         if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
 167                 return -EBADF;
 168         cp_new_stat(inode,statbuf);
 169         return 0;
 170 }
 171 
 172 int sys_readlink(const char * path, char * buf, int bufsiz)
     /* [previous][next][first][last][top][bottom][index][help] */
 173 {
 174         struct inode * inode;
 175         int error;
 176 
 177         if (bufsiz <= 0)
 178                 return -EINVAL;
 179         error = verify_area(VERIFY_WRITE,buf,bufsiz);
 180         if (error)
 181                 return error;
 182         error = lnamei(path,&inode);
 183         if (error)
 184                 return error;
 185         if (!inode->i_op || !inode->i_op->readlink) {
 186                 iput(inode);
 187                 return -EINVAL;
 188         }
 189         return inode->i_op->readlink(inode,buf,bufsiz);
 190 }

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