Annotation of linux/fs/ext/dir.c, revision 1.1.1.3

1.1       root        1: /*
                      2:  *  linux/fs/ext/dir.c
                      3:  *
1.1.1.2   root        4:  *  Copyright (C) 1992 Remy Card ([email protected])
1.1       root        5:  *
                      6:  *  from
                      7:  *
                      8:  *  linux/fs/minix/dir.c
                      9:  *
1.1.1.2   root       10:  *  Copyright (C) 1991, 1992 Linus Torvalds
1.1       root       11:  *
                     12:  *  ext directory handling functions
                     13:  */
                     14: 
                     15: #include <asm/segment.h>
                     16: 
1.1.1.2   root       17: #include <linux/errno.h>
1.1.1.3 ! root       18: #include <linux/kernel.h>
1.1       root       19: #include <linux/fs.h>
                     20: #include <linux/ext_fs.h>
                     21: #include <linux/stat.h>
                     22: 
                     23: static int ext_readdir(struct inode *, struct file *, struct dirent *, int);
                     24: 
                     25: static struct file_operations ext_dir_operations = {
                     26:        NULL,                   /* lseek - default */
                     27:        NULL,                   /* read */
                     28:        NULL,                   /* write - bad */
                     29:        ext_readdir,            /* readdir */
                     30:        NULL,                   /* select - default */
                     31:        NULL,                   /* ioctl - default */
                     32:        NULL,                   /* no special open code */
                     33:        NULL                    /* no special release code */
                     34: };
                     35: 
                     36: /*
                     37:  * directories can handle most operations...
                     38:  */
                     39: struct inode_operations ext_dir_inode_operations = {
                     40:        &ext_dir_operations,    /* default directory file-ops */
                     41:        ext_create,             /* create */
                     42:        ext_lookup,             /* lookup */
                     43:        ext_link,               /* link */
                     44:        ext_unlink,             /* unlink */
                     45:        ext_symlink,            /* symlink */
                     46:        ext_mkdir,              /* mkdir */
                     47:        ext_rmdir,              /* rmdir */
                     48:        ext_mknod,              /* mknod */
                     49:        ext_rename,             /* rename */
                     50:        NULL,                   /* readlink */
                     51:        NULL,                   /* follow_link */
1.1.1.3 ! root       52:        NULL,                   /* bmap */
1.1       root       53:        ext_truncate            /* truncate */
                     54: };
                     55: 
                     56: static int ext_readdir(struct inode * inode, struct file * filp,
                     57:        struct dirent * dirent, int count)
                     58: {
1.1.1.3 ! root       59:        unsigned int offset,i;
1.1       root       60:        char c;
                     61:        struct buffer_head * bh;
                     62:        struct ext_dir_entry * de;
                     63: 
                     64:        if (!inode || !S_ISDIR(inode->i_mode))
                     65:                return -EBADF;
                     66:        while (filp->f_pos < inode->i_size) {
                     67:                offset = filp->f_pos & 1023;
1.1.1.3 ! root       68:                bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
        !            69:                if (!bh) {
1.1       root       70:                        filp->f_pos += 1024-offset;
                     71:                        continue;
                     72:                }
                     73:                de = (struct ext_dir_entry *) (offset + bh->b_data);
                     74:                while (offset < 1024 && filp->f_pos < inode->i_size) {
                     75:                        offset += de->rec_len;
                     76:                        filp->f_pos += de->rec_len;
1.1.1.3 ! root       77:                        if (de->rec_len < 8 || de->rec_len % 4 != 0 ||
        !            78:                            de->rec_len < de->name_len + 8) {
        !            79:                                printk ("ext_readdir: bad directory entry\n");
        !            80:                                printk ("dev=%d, dir=%d, offset=%d, rec_len=%d, name_len=%d\n",
        !            81:                                        inode->i_dev, inode->i_ino, offset, de->rec_len, de->name_len);
        !            82:                                return 0;
        !            83:                        }
1.1       root       84:                        if (de->inode) {
                     85:                                for (i = 0; i < de->name_len; i++)
                     86:                                        if (c = de->name[i])
                     87:                                                put_fs_byte(c,i+dirent->d_name);
                     88:                                        else
                     89:                                                break;
                     90:                                if (i) {
                     91:                                        put_fs_long(de->inode,&dirent->d_ino);
                     92:                                        put_fs_byte(0,i+dirent->d_name);
                     93:                                        put_fs_word(i,&dirent->d_reclen);
                     94:                                        brelse(bh);
                     95:                                        return i;
                     96:                                }
                     97:                        }
1.1.1.3 ! root       98:                        de = (struct ext_dir_entry *) ((char *) de 
        !            99:                                + de->rec_len);
1.1       root      100:                }
                    101:                brelse(bh);
                    102:        }
                    103:        return 0;
                    104: }

unix.superglobalmegacorp.com

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