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

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