Annotation of linux/fs/proc/root.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *  linux/fs/proc/root.c
        !             3:  *
        !             4:  *  Copyright (C) 1991, 1992 Linus Torvalds
        !             5:  *
        !             6:  *  proc root directory handling functions
        !             7:  */
        !             8: 
        !             9: #include <asm/segment.h>
        !            10: 
        !            11: #include <linux/errno.h>
        !            12: #include <linux/sched.h>
        !            13: #include <linux/proc_fs.h>
        !            14: #include <linux/stat.h>
        !            15: 
        !            16: static int proc_readroot(struct inode *, struct file *, struct dirent *, int);
        !            17: static int proc_lookuproot(struct inode *,const char *,int,struct inode **);
        !            18: 
        !            19: static struct file_operations proc_root_operations = {
        !            20:        NULL,                   /* lseek - default */
        !            21:        NULL,                   /* read - bad */
        !            22:        NULL,                   /* write - bad */
        !            23:        proc_readroot,          /* readdir */
        !            24:        NULL,                   /* select - default */
        !            25:        NULL,                   /* ioctl - default */
        !            26:        NULL,                   /* no special open code */
        !            27:        NULL                    /* no special release code */
        !            28: };
        !            29: 
        !            30: /*
        !            31:  * proc directories can do almost nothing..
        !            32:  */
        !            33: struct inode_operations proc_root_inode_operations = {
        !            34:        &proc_root_operations,  /* default base directory file-ops */
        !            35:        NULL,                   /* create */
        !            36:        proc_lookuproot,        /* lookup */
        !            37:        NULL,                   /* link */
        !            38:        NULL,                   /* unlink */
        !            39:        NULL,                   /* symlink */
        !            40:        NULL,                   /* mkdir */
        !            41:        NULL,                   /* rmdir */
        !            42:        NULL,                   /* mknod */
        !            43:        NULL,                   /* rename */
        !            44:        NULL,                   /* readlink */
        !            45:        NULL,                   /* follow_link */
        !            46:        NULL,                   /* bmap */
        !            47:        NULL                    /* truncate */
        !            48: };
        !            49: 
        !            50: static int proc_lookuproot(struct inode * dir,const char * name, int len,
        !            51:        struct inode ** result)
        !            52: {
        !            53:        unsigned int pid, c;
        !            54:        int i, ino;
        !            55: 
        !            56:        *result = NULL;
        !            57:        if (!dir)
        !            58:                return -ENOENT;
        !            59:        if (!S_ISDIR(dir->i_mode)) {
        !            60:                iput(dir);
        !            61:                return -ENOENT;
        !            62:        }
        !            63:        pid = 0;
        !            64:        if (!len || (get_fs_byte(name) == '.' && (len == 1 ||
        !            65:            (get_fs_byte(name+1) == '.' && len == 2)))) {
        !            66:                *result = dir;
        !            67:                return 0;
        !            68:        }
        !            69:        while (len-- > 0) {
        !            70:                c = get_fs_byte(name) - '0';
        !            71:                name++;
        !            72:                if (c > 9) {
        !            73:                        pid = 0;
        !            74:                        break;
        !            75:                }
        !            76:                pid *= 10;
        !            77:                pid += c;
        !            78:                if (pid & 0xffff0000) {
        !            79:                        pid = 0;
        !            80:                        break;
        !            81:                }
        !            82:        }
        !            83:        for (i = 0 ; i < NR_TASKS ; i++)
        !            84:                if (task[i] && task[i]->pid == pid)
        !            85:                        break;
        !            86:        if (!pid || i >= NR_TASKS) {
        !            87:                iput(dir);
        !            88:                return -ENOENT;
        !            89:        }
        !            90:        ino = (pid << 16) + 2;
        !            91:        if (!(*result = iget(dir->i_dev,ino))) {
        !            92:                iput(dir);
        !            93:                return -ENOENT;
        !            94:        }
        !            95:        iput(dir);
        !            96:        return 0;
        !            97: }
        !            98: 
        !            99: static int proc_readroot(struct inode * inode, struct file * filp,
        !           100:        struct dirent * dirent, int count)
        !           101: {
        !           102:        struct task_struct * p;
        !           103:        unsigned int pid;
        !           104:        int i,j;
        !           105: 
        !           106:        if (!inode || !S_ISDIR(inode->i_mode))
        !           107:                return -EBADF;
        !           108:        while ((pid = filp->f_pos) < NR_TASKS+2) {
        !           109:                filp->f_pos++;
        !           110:                if (pid < 2) {
        !           111:                        i = j = pid+1;
        !           112:                        put_fs_long(1, &dirent->d_ino);
        !           113:                        put_fs_word(i, &dirent->d_reclen);
        !           114:                        put_fs_byte(0, i+dirent->d_name);
        !           115:                        while (i--)
        !           116:                                put_fs_byte('.', i+dirent->d_name);
        !           117:                        return j;
        !           118:                }                       
        !           119:                p = task[pid-2];
        !           120:                if (!p || !(pid = p->pid))
        !           121:                        continue;
        !           122:                if (pid & 0xffff0000)
        !           123:                        continue;
        !           124:                j = 10;
        !           125:                i = 1;
        !           126:                while (pid >= j) {
        !           127:                        j *= 10;
        !           128:                        i++;
        !           129:                }
        !           130:                j = i;
        !           131:                put_fs_long((pid << 16)+2, &dirent->d_ino);
        !           132:                put_fs_word(i, &dirent->d_reclen);
        !           133:                put_fs_byte(0, i+dirent->d_name);
        !           134:                while (i--) {
        !           135:                        put_fs_byte('0'+(pid % 10), i+dirent->d_name);
        !           136:                        pid /= 10;
        !           137:                }
        !           138:                return j;
        !           139:        }
        !           140:        return 0;
        !           141: }

unix.superglobalmegacorp.com

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