This source file includes following definitions.
- cp_old_stat
- cp_new_stat
- sys_stat
- sys_newstat
- sys_lstat
- sys_newlstat
- sys_fstat
- sys_newfstat
- sys_readlink
1
2
3
4
5
6
7 #include <linux/errno.h>
8 #include <linux/stat.h>
9 #include <linux/fs.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12 #include <asm/segment.h>
13
14 static void cp_old_stat(struct inode * inode, struct old_stat * statbuf)
15 {
16 struct old_stat tmp;
17
18 if (inode->i_ino & 0xffff0000)
19 printk("Warning: using old stat() call on bigfs\n");
20 verify_area(statbuf,sizeof (*statbuf));
21 tmp.st_dev = inode->i_dev;
22 tmp.st_ino = inode->i_ino;
23 tmp.st_mode = inode->i_mode;
24 tmp.st_nlink = inode->i_nlink;
25 tmp.st_uid = inode->i_uid;
26 tmp.st_gid = inode->i_gid;
27 tmp.st_rdev = inode->i_rdev;
28 if( S_ISFIFO(inode->i_mode) )
29 tmp.st_size = 0;
30 else
31 tmp.st_size = inode->i_size;
32 tmp.st_atime = inode->i_atime;
33 tmp.st_mtime = inode->i_mtime;
34 tmp.st_ctime = inode->i_ctime;
35 memcpy_tofs(statbuf,&tmp,sizeof(tmp));
36 }
37
38 static void cp_new_stat(struct inode * inode, struct new_stat * statbuf)
39 {
40 struct new_stat tmp = {0, };
41 unsigned int blocks, indirect;
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;
51 if( S_ISFIFO(inode->i_mode) )
52 tmp.st_size = 0;
53 else
54 tmp.st_size = inode->i_size;
55 tmp.st_atime = inode->i_atime;
56 tmp.st_mtime = inode->i_mtime;
57 tmp.st_ctime = inode->i_ctime;
58
59
60
61
62
63
64
65
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;
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)
94 {
95 struct inode * inode;
96
97 if (!(inode=namei(filename)))
98 return -ENOENT;
99 cp_new_stat(inode,statbuf);
100 iput(inode);
101 return 0;
102 }
103
104 int sys_lstat(char * filename, struct old_stat * statbuf)
105 {
106 struct inode * inode;
107
108 if (!(inode = lnamei(filename)))
109 return -ENOENT;
110 cp_old_stat(inode,statbuf);
111 iput(inode);
112 return 0;
113 }
114
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)
138 {
139 struct file * f;
140 struct inode * inode;
141
142 if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))
143 return -EBADF;
144 cp_new_stat(inode,statbuf);
145 return 0;
146 }
147
148 int sys_readlink(const char * path, char * buf, int bufsiz)
149 {
150 struct inode * inode;
151
152 if (bufsiz <= 0)
153 return -EINVAL;
154 verify_area(buf,bufsiz);
155 if (!(inode = lnamei(path)))
156 return -ENOENT;
157 if (!inode->i_op || !inode->i_op->readlink) {
158 iput(inode);
159 return -EINVAL;
160 }
161 return inode->i_op->readlink(inode,buf,bufsiz);
162 }