OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [fs/] [stat.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/fs/stat.c
3
 *
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
5
 */
6
 
7
#include <linux/errno.h>
8
#include <linux/string.h>
9
#include <linux/stat.h>
10
#include <linux/fs.h>
11
#include <linux/sched.h>
12
#include <linux/kernel.h>
13
#include <linux/mm.h>
14
 
15
#include <asm/segment.h>
16
 
17
#ifndef __alpha__
18
 
19
/*
20
 * For backward compatibility?  Maybe this should be moved
21
 * into arch/i386 instead?
22
 */
23
static void cp_old_stat(struct inode * inode, struct old_stat * statbuf)
24
{
25
        struct old_stat tmp;
26
        static int nagcount = 0;
27
 
28
        if (++nagcount < 5)
29
                printk("VFS: Warning: %s using old stat() call. "
30
                        "Recompile your binary.\n",
31
                        current->comm);
32
 
33
        tmp.st_dev = kdev_t_to_nr(inode->i_dev);
34
        tmp.st_ino = inode->i_ino;
35
        tmp.st_mode = inode->i_mode;
36
        tmp.st_nlink = inode->i_nlink;
37
        tmp.st_uid = inode->i_uid;
38
        tmp.st_gid = inode->i_gid;
39
        tmp.st_rdev = kdev_t_to_nr(inode->i_rdev);
40
        tmp.st_size = inode->i_size;
41
        if (inode->i_pipe)
42
                tmp.st_size = PIPE_SIZE(*inode);
43
        tmp.st_atime = inode->i_atime;
44
        tmp.st_mtime = inode->i_mtime;
45
        tmp.st_ctime = inode->i_ctime;
46
        memcpy_tofs(statbuf,&tmp,sizeof(tmp));
47
}
48
 
49
#endif
50
 
51
static void cp_new_stat(struct inode * inode, struct new_stat * statbuf)
52
{
53
        struct new_stat tmp;
54
        unsigned int blocks, indirect;
55
 
56
        memset(&tmp, 0, sizeof(tmp));
57
        tmp.st_dev = kdev_t_to_nr(inode->i_dev);
58
        tmp.st_ino = inode->i_ino;
59
        tmp.st_mode = inode->i_mode;
60
        tmp.st_nlink = inode->i_nlink;
61
        tmp.st_uid = inode->i_uid;
62
        tmp.st_gid = inode->i_gid;
63
        tmp.st_rdev = kdev_t_to_nr(inode->i_rdev);
64
        tmp.st_size = inode->i_size;
65
        if (inode->i_pipe)
66
                tmp.st_size = PIPE_SIZE(*inode);
67
        tmp.st_atime = inode->i_atime;
68
        tmp.st_mtime = inode->i_mtime;
69
        tmp.st_ctime = inode->i_ctime;
70
/*
71
 * st_blocks and st_blksize are approximated with a simple algorithm if
72
 * they aren't supported directly by the filesystem. The minix and msdos
73
 * filesystems don't keep track of blocks, so they would either have to
74
 * be counted explicitly (by delving into the file itself), or by using
75
 * this simple algorithm to get a reasonable (although not 100% accurate)
76
 * value.
77
 */
78
 
79
/*
80
 * Use minix fs values for the number of direct and indirect blocks.  The
81
 * count is now exact for the minix fs except that it counts zero blocks.
82
 * Everything is in BLOCK_SIZE'd units until the assignment to
83
 * tmp.st_blksize.
84
 */
85
#define D_B   7
86
#define I_B   (BLOCK_SIZE / sizeof(unsigned short))
87
 
88
        if (!inode->i_blksize) {
89
                blocks = (tmp.st_size + BLOCK_SIZE - 1) / BLOCK_SIZE;
90
                if (blocks > D_B) {
91
                        indirect = (blocks - D_B + I_B - 1) / I_B;
92
                        blocks += indirect;
93
                        if (indirect > 1) {
94
                                indirect = (indirect - 1 + I_B - 1) / I_B;
95
                                blocks += indirect;
96
                                if (indirect > 1)
97
                                        blocks++;
98
                        }
99
                }
100
                tmp.st_blocks = (BLOCK_SIZE / 512) * blocks;
101
                tmp.st_blksize = BLOCK_SIZE;
102
        } else {
103
                tmp.st_blocks = inode->i_blocks;
104
                tmp.st_blksize = inode->i_blksize;
105
        }
106
        memcpy_tofs(statbuf,&tmp,sizeof(tmp));
107
}
108
 
109
#ifndef __alpha__
110
/*
111
 * For backward compatibility?  Maybe this should be moved
112
 * into arch/i386 instead?
113
 */
114
asmlinkage int sys_stat(char * filename, struct old_stat * statbuf)
115
{
116
        struct inode * inode;
117
        int error;
118
 
119
        error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
120
        if (error)
121
                return error;
122
        error = namei(filename,&inode);
123
        if (error)
124
                return error;
125
        cp_old_stat(inode,statbuf);
126
        iput(inode);
127
        return 0;
128
}
129
#endif
130
 
131
asmlinkage int sys_newstat(char * filename, struct new_stat * statbuf)
132
{
133
        struct inode * inode;
134
        int error;
135
 
136
        error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
137
        if (error)
138
                return error;
139
        error = namei(filename,&inode);
140
        if (error)
141
                return error;
142
        cp_new_stat(inode,statbuf);
143
        iput(inode);
144
        return 0;
145
}
146
 
147
#ifndef __alpha__
148
 
149
/*
150
 * For backward compatibility?  Maybe this should be moved
151
 * into arch/i386 instead?
152
 */
153
asmlinkage int sys_lstat(char * filename, struct old_stat * statbuf)
154
{
155
        struct inode * inode;
156
        int error;
157
 
158
        error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
159
        if (error)
160
                return error;
161
        error = lnamei(filename,&inode);
162
        if (error)
163
                return error;
164
        cp_old_stat(inode,statbuf);
165
        iput(inode);
166
        return 0;
167
}
168
 
169
#endif
170
 
171
asmlinkage int sys_newlstat(char * filename, struct new_stat * statbuf)
172
{
173
        struct inode * inode;
174
        int error;
175
 
176
        error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
177
        if (error)
178
                return error;
179
        error = lnamei(filename,&inode);
180
        if (error)
181
                return error;
182
        cp_new_stat(inode,statbuf);
183
        iput(inode);
184
        return 0;
185
}
186
 
187
#ifndef __alpha__
188
 
189
/*
190
 * For backward compatibility?  Maybe this should be moved
191
 * into arch/i386 instead?
192
 */
193
asmlinkage int sys_fstat(unsigned int fd, struct old_stat * statbuf)
194
{
195
        struct file * f;
196
        struct inode * inode;
197
        int error;
198
 
199
        error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
200
        if (error)
201
                return error;
202
        if (fd >= NR_OPEN || !(f=current->files->fd[fd]) || !(inode=f->f_inode))
203
                return -EBADF;
204
        cp_old_stat(inode,statbuf);
205
        return 0;
206
}
207
 
208
#endif
209
 
210
asmlinkage int sys_newfstat(unsigned int fd, struct new_stat * statbuf)
211
{
212
        struct file * f;
213
        struct inode * inode;
214
        int error;
215
 
216
        error = verify_area(VERIFY_WRITE,statbuf,sizeof (*statbuf));
217
        if (error)
218
                return error;
219
        if (fd >= NR_OPEN || !(f=current->files->fd[fd]) || !(inode=f->f_inode))
220
                return -EBADF;
221
        cp_new_stat(inode,statbuf);
222
        return 0;
223
}
224
 
225
asmlinkage int sys_readlink(const char * path, char * buf, int bufsiz)
226
{
227
        struct inode * inode;
228
        int error;
229
 
230
        if (bufsiz <= 0)
231
                return -EINVAL;
232
        error = verify_area(VERIFY_WRITE,buf,bufsiz);
233
        if (error)
234
                return error;
235
        error = lnamei(path,&inode);
236
        if (error)
237
                return error;
238
        if (!inode->i_op || !inode->i_op->readlink) {
239
                iput(inode);
240
                return -EINVAL;
241
        }
242
        UPDATE_ATIME(inode);
243
        return inode->i_op->readlink(inode,buf,bufsiz);
244
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.