Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | |
1063 | tullio | 2 | /* |
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
16 | * |
||
17 | */ |
||
18 | |||
2 | pj | 19 | #include <fs/types.h> |
20 | #include <fs/errno.h> |
||
21 | #include <fs/task.h> |
||
22 | #include <fs/maccess.h> |
||
23 | #include <fs/major.h> |
||
24 | |||
25 | #include "file.h" |
||
26 | #include "inode.h" |
||
27 | #include "dentry.h" |
||
28 | #include "fs.h" |
||
29 | |||
30 | #include "debug.h" |
||
31 | |||
32 | int k_fstat(int fd, struct stat *buf) |
||
33 | { |
||
34 | struct inode *in=NULL; |
||
35 | __pid_t pid; |
||
36 | |||
37 | call_to_fs(); |
||
38 | |||
39 | /* to do better: for console i/o */ |
||
40 | if (fd>=0&&fd<=2) { |
||
41 | struct stat st; |
||
42 | |||
43 | /* !!! */ |
||
44 | return_from_fs(-EBADF); |
||
45 | |||
46 | st.st_dev=NULLDEV; |
||
47 | st.st_ino=0; |
||
48 | st.st_mode=((fd==0)? |
||
49 | __S_IRUSR|__S_IRGRP|__S_IROTH: |
||
50 | __S_IWUSR|__S_IWGRP|__S_IWOTH); |
||
51 | st.st_nlink=1; |
||
52 | st.st_uid=0; |
||
53 | st.st_gid=0; |
||
54 | st.st_size=0; |
||
55 | st.st_atime=0; |
||
56 | st.st_mtime=0; |
||
57 | st.st_ctime=0; |
||
58 | |||
59 | if (!__verify_write(buf,sizeof(struct stat))) return_from_fs(-EVERIFY); |
||
60 | __copy_to_user(buf,&(in->i_st),sizeof(struct stat)); |
||
61 | return_from_fs(EOK); |
||
62 | } |
||
63 | |||
64 | /* don't try to use bad file descriptor */ |
||
65 | pid=__get_pid(); |
||
66 | if (check_fd(pid,fd)) { |
||
67 | printk(KERN_INFO "k_fstat: using a bad file descriptor"); |
||
68 | return_from_fs(-EBADF); |
||
69 | } |
||
70 | |||
71 | if (!__verify_write(buf,sizeof(struct stat))) return_from_fs(-EVERIFY); |
||
72 | |||
73 | in=file_ptr(pid,fd)->f_dentry->d_inode; |
||
74 | __copy_to_user(buf,&(in->i_st),sizeof(struct stat)); |
||
75 | |||
76 | return_from_fs(EOK); |
||
77 | } |