Annotation of linux/fs/stat.c, revision 1.1.1.7

1.1.1.2   root        1: /*
                      2:  *  linux/fs/stat.c
                      3:  *
1.1.1.7 ! root        4:  *  Copyright (C) 1991, 1992  Linus Torvalds
1.1.1.2   root        5:  */
                      6: 
1.1.1.7 ! root        7: #include <linux/errno.h>
1.1.1.5   root        8: #include <linux/stat.h>
1.1       root        9: #include <linux/fs.h>
                     10: #include <linux/sched.h>
                     11: #include <linux/kernel.h>
                     12: #include <asm/segment.h>
                     13: 
1.1.1.5   root       14: static void cp_old_stat(struct inode * inode, struct old_stat * statbuf)
1.1       root       15: {
1.1.1.5   root       16:        struct old_stat tmp;
1.1       root       17: 
1.1.1.5   root       18:        if (inode->i_ino & 0xffff0000)
                     19:                printk("Warning: using old stat() call on bigfs\n");
                     20:        verify_area(statbuf,sizeof (*statbuf));
1.1       root       21:        tmp.st_dev = inode->i_dev;
1.1.1.4   root       22:        tmp.st_ino = inode->i_ino;
1.1       root       23:        tmp.st_mode = inode->i_mode;
1.1.1.4   root       24:        tmp.st_nlink = inode->i_nlink;
1.1       root       25:        tmp.st_uid = inode->i_uid;
                     26:        tmp.st_gid = inode->i_gid;
1.1.1.4   root       27:        tmp.st_rdev = inode->i_rdev;
1.1.1.6   root       28:        if( S_ISFIFO(inode->i_mode) )
                     29:                tmp.st_size = 0;
                     30:        else
                     31:                tmp.st_size = inode->i_size;
1.1       root       32:        tmp.st_atime = inode->i_atime;
                     33:        tmp.st_mtime = inode->i_mtime;
                     34:        tmp.st_ctime = inode->i_ctime;
1.1.1.5   root       35:        memcpy_tofs(statbuf,&tmp,sizeof(tmp));
1.1       root       36: }
                     37: 
1.1.1.5   root       38: static void cp_new_stat(struct inode * inode, struct new_stat * statbuf)
                     39: {
                     40:        struct new_stat tmp = {0, };
1.1.1.6   root       41:        unsigned int blocks, indirect;
1.1.1.5   root       42: 
                     43:        verify_area(statbuf,sizeof (*statbuf));
                     44:        tmp.st_dev = inode->i_dev;
                     45:        tmp.st_ino = inode->i_ino;
                     46:        tmp.st_mode = inode->i_mode;
                     47:        tmp.st_nlink = inode->i_nlink;
                     48:        tmp.st_uid = inode->i_uid;
                     49:        tmp.st_gid = inode->i_gid;
                     50:        tmp.st_rdev = inode->i_rdev;
1.1.1.6   root       51:        if( S_ISFIFO(inode->i_mode) )
                     52:                tmp.st_size = 0;
                     53:        else
                     54:                tmp.st_size = inode->i_size;
1.1.1.5   root       55:        tmp.st_atime = inode->i_atime;
                     56:        tmp.st_mtime = inode->i_mtime;
                     57:        tmp.st_ctime = inode->i_ctime;
1.1.1.6   root       58: /*
                     59:  * Right now we fake the st_blocks numbers: we'll eventually have to
                     60:  * add st_blocks to the inode, and let the vfs routines keep track of
                     61:  * it all. This algorithm doesn't guarantee correct block numbers, but
                     62:  * at least it tries to come up with a plausible answer...
                     63:  *
                     64:  * In fact, the minix fs doesn't use these numbers (it uses 7 and 512
                     65:  * instead of 10 and 256), but who cares... It's not that exact anyway.
                     66:  */
                     67:        blocks = (tmp.st_size + 1023) / 1024;
                     68:        if (blocks > 10) {
                     69:                indirect = (blocks - 11)/256+1;
                     70:                if (blocks > 10+256) {
                     71:                        indirect += (blocks - 267)/(256*256)+1;
                     72:                        if (blocks > 10+256+256*256)
                     73:                                indirect++;
                     74:                }
                     75:                blocks += indirect;
                     76:        }
                     77:        tmp.st_blksize = 1024;
                     78:        tmp.st_blocks = blocks;
1.1.1.5   root       79:        memcpy_tofs(statbuf,&tmp,sizeof(tmp));
                     80: }
                     81: 
                     82: int sys_stat(char * filename, struct old_stat * statbuf)
                     83: {
                     84:        struct inode * inode;
                     85: 
                     86:        if (!(inode=namei(filename)))
                     87:                return -ENOENT;
                     88:        cp_old_stat(inode,statbuf);
                     89:        iput(inode);
                     90:        return 0;
                     91: }
                     92: 
                     93: int sys_newstat(char * filename, struct new_stat * statbuf)
1.1       root       94: {
1.1.1.4   root       95:        struct inode * inode;
1.1       root       96: 
                     97:        if (!(inode=namei(filename)))
                     98:                return -ENOENT;
1.1.1.5   root       99:        cp_new_stat(inode,statbuf);
1.1       root      100:        iput(inode);
1.1.1.2   root      101:        return 0;
1.1       root      102: }
                    103: 
1.1.1.5   root      104: int sys_lstat(char * filename, struct old_stat * statbuf)
1.1.1.3   root      105: {
1.1.1.4   root      106:        struct inode * inode;
1.1.1.3   root      107: 
                    108:        if (!(inode = lnamei(filename)))
                    109:                return -ENOENT;
1.1.1.5   root      110:        cp_old_stat(inode,statbuf);
1.1.1.3   root      111:        iput(inode);
                    112:        return 0;
                    113: }
                    114: 
1.1.1.5   root      115: int sys_newlstat(char * filename, struct new_stat * statbuf)
                    116: {
                    117:        struct inode * inode;
                    118: 
                    119:        if (!(inode = lnamei(filename)))
                    120:                return -ENOENT;
                    121:        cp_new_stat(inode,statbuf);
                    122:        iput(inode);
                    123:        return 0;
                    124: }
                    125: 
                    126: int sys_fstat(unsigned int fd, struct old_stat * statbuf)
                    127: {
                    128:        struct file * f;
                    129:        struct inode * inode;
                    130: 
                    131:        if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
                    132:                return -EBADF;
                    133:        cp_old_stat(inode,statbuf);
                    134:        return 0;
                    135: }
                    136: 
                    137: int sys_newfstat(unsigned int fd, struct new_stat * statbuf)
1.1       root      138: {
                    139:        struct file * f;
1.1.1.4   root      140:        struct inode * inode;
1.1       root      141: 
                    142:        if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
1.1.1.2   root      143:                return -EBADF;
1.1.1.5   root      144:        cp_new_stat(inode,statbuf);
1.1.1.2   root      145:        return 0;
1.1       root      146: }
1.1.1.3   root      147: 
                    148: int sys_readlink(const char * path, char * buf, int bufsiz)
                    149: {
1.1.1.4   root      150:        struct inode * inode;
1.1.1.3   root      151: 
                    152:        if (bufsiz <= 0)
1.1.1.4   root      153:                return -EINVAL;
1.1.1.3   root      154:        verify_area(buf,bufsiz);
                    155:        if (!(inode = lnamei(path)))
                    156:                return -ENOENT;
1.1.1.4   root      157:        if (!inode->i_op || !inode->i_op->readlink) {
                    158:                iput(inode);
                    159:                return -EINVAL;
1.1.1.3   root      160:        }
1.1.1.4   root      161:        return inode->i_op->readlink(inode,buf,bufsiz);
1.1.1.3   root      162: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.