diff options
Diffstat (limited to 'src/fs/stat.c')
-rw-r--r-- | src/fs/stat.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/fs/stat.c b/src/fs/stat.c new file mode 100644 index 0000000..61a4ceb --- /dev/null +++ b/src/fs/stat.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * linux/fs/stat.c | ||
3 | * | ||
4 | * (C) 1991 Linus Torvalds | ||
5 | */ | ||
6 | |||
7 | #include <errno.h> | ||
8 | #include <sys/stat.h> | ||
9 | |||
10 | #include <linux/fs.h> | ||
11 | #include <linux/sched.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <asm/segment.h> | ||
14 | |||
15 | static void cp_stat(struct m_inode * inode, struct stat * statbuf) | ||
16 | { | ||
17 | struct stat tmp; | ||
18 | int i; | ||
19 | |||
20 | verify_area(statbuf,sizeof (* statbuf)); | ||
21 | tmp.st_dev = inode->i_dev; | ||
22 | tmp.st_ino = inode->i_num; | ||
23 | tmp.st_mode = inode->i_mode; | ||
24 | tmp.st_nlink = inode->i_nlinks; | ||
25 | tmp.st_uid = inode->i_uid; | ||
26 | tmp.st_gid = inode->i_gid; | ||
27 | tmp.st_rdev = inode->i_zone[0]; | ||
28 | tmp.st_size = inode->i_size; | ||
29 | tmp.st_atime = inode->i_atime; | ||
30 | tmp.st_mtime = inode->i_mtime; | ||
31 | tmp.st_ctime = inode->i_ctime; | ||
32 | for (i=0 ; i<sizeof (tmp) ; i++) | ||
33 | put_fs_byte(((char *) &tmp)[i],&((char *) statbuf)[i]); | ||
34 | } | ||
35 | |||
36 | int sys_stat(char * filename, struct stat * statbuf) | ||
37 | { | ||
38 | struct m_inode * inode; | ||
39 | |||
40 | if (!(inode=namei(filename))) | ||
41 | return -ENOENT; | ||
42 | cp_stat(inode,statbuf); | ||
43 | iput(inode); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | int sys_fstat(unsigned int fd, struct stat * statbuf) | ||
48 | { | ||
49 | struct file * f; | ||
50 | struct m_inode * inode; | ||
51 | |||
52 | if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode)) | ||
53 | return -EBADF; | ||
54 | cp_stat(inode,statbuf); | ||
55 | return 0; | ||
56 | } | ||