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

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

unix.superglobalmegacorp.com

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