|
|
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 root 29: tmp.st_size = inode->i_size;
30: tmp.st_atime = inode->i_atime;
31: tmp.st_mtime = inode->i_mtime;
32: tmp.st_ctime = inode->i_ctime;
1.1.1.5 ! root 33: memcpy_tofs(statbuf,&tmp,sizeof(tmp));
1.1 root 34: }
35:
1.1.1.5 ! root 36: static void cp_new_stat(struct inode * inode, struct new_stat * statbuf)
! 37: {
! 38: struct new_stat tmp = {0, };
! 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: memcpy_tofs(statbuf,&tmp,sizeof(tmp));
! 53: }
! 54:
! 55: int sys_stat(char * filename, struct old_stat * statbuf)
! 56: {
! 57: struct inode * inode;
! 58:
! 59: if (!(inode=namei(filename)))
! 60: return -ENOENT;
! 61: cp_old_stat(inode,statbuf);
! 62: iput(inode);
! 63: return 0;
! 64: }
! 65:
! 66: int sys_newstat(char * filename, struct new_stat * statbuf)
1.1 root 67: {
1.1.1.4 root 68: struct inode * inode;
1.1 root 69:
70: if (!(inode=namei(filename)))
71: return -ENOENT;
1.1.1.5 ! root 72: cp_new_stat(inode,statbuf);
1.1 root 73: iput(inode);
1.1.1.2 root 74: return 0;
1.1 root 75: }
76:
1.1.1.5 ! root 77: int sys_lstat(char * filename, struct old_stat * statbuf)
1.1.1.3 root 78: {
1.1.1.4 root 79: struct inode * inode;
1.1.1.3 root 80:
81: if (!(inode = lnamei(filename)))
82: return -ENOENT;
1.1.1.5 ! root 83: cp_old_stat(inode,statbuf);
1.1.1.3 root 84: iput(inode);
85: return 0;
86: }
87:
1.1.1.5 ! root 88: int sys_newlstat(char * filename, struct new_stat * statbuf)
! 89: {
! 90: struct inode * inode;
! 91:
! 92: if (!(inode = lnamei(filename)))
! 93: return -ENOENT;
! 94: cp_new_stat(inode,statbuf);
! 95: iput(inode);
! 96: return 0;
! 97: }
! 98:
! 99: int sys_fstat(unsigned int fd, struct old_stat * statbuf)
! 100: {
! 101: struct file * f;
! 102: struct inode * inode;
! 103:
! 104: if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
! 105: return -EBADF;
! 106: cp_old_stat(inode,statbuf);
! 107: return 0;
! 108: }
! 109:
! 110: int sys_newfstat(unsigned int fd, struct new_stat * statbuf)
1.1 root 111: {
112: struct file * f;
1.1.1.4 root 113: struct inode * inode;
1.1 root 114:
115: if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
1.1.1.2 root 116: return -EBADF;
1.1.1.5 ! root 117: cp_new_stat(inode,statbuf);
1.1.1.2 root 118: return 0;
1.1 root 119: }
1.1.1.3 root 120:
121: int sys_readlink(const char * path, char * buf, int bufsiz)
122: {
1.1.1.4 root 123: struct inode * inode;
1.1.1.3 root 124:
125: if (bufsiz <= 0)
1.1.1.4 root 126: return -EINVAL;
1.1.1.3 root 127: verify_area(buf,bufsiz);
128: if (!(inode = lnamei(path)))
129: return -ENOENT;
1.1.1.4 root 130: if (!inode->i_op || !inode->i_op->readlink) {
131: iput(inode);
132: return -EINVAL;
1.1.1.3 root 133: }
1.1.1.4 root 134: return inode->i_op->readlink(inode,buf,bufsiz);
1.1.1.3 root 135: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.