Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | |
2 | #include <fs/types.h> |
||
3 | #include <fs/errno.h> |
||
4 | #include <fs/task.h> |
||
5 | #include <fs/util.h> |
||
6 | #include <fs/maccess.h> |
||
7 | #include <fs/fcntl.h> |
||
8 | |||
9 | #include "file.h" |
||
10 | #include "dentry.h" |
||
11 | #include "fs.h" |
||
12 | |||
13 | /* |
||
14 | this are from bits/fcntl.h |
||
15 | if they are changed then this code must be rewritten! |
||
16 | #define F_DUPFD 0 |
||
17 | #define F_GETFD 1 |
||
18 | #define F_SETFD 2 |
||
19 | #define F_GETFL 3 |
||
20 | #define F_SETFL 4 |
||
21 | #define F_GETLK 5 |
||
22 | #define F_SETLK 6 |
||
23 | #define F_SETLKW 7 |
||
24 | */ |
||
25 | |||
26 | int dupfd(__pid_t pid, int fildes, void *ptr) |
||
27 | { |
||
28 | int res; |
||
29 | res=__duplicate_fd(pid,fildes,(int)ptr); |
||
30 | unlock_desctable(pid); |
||
31 | if (res) return -EMFILE; |
||
32 | return EOK; |
||
33 | } |
||
34 | |||
35 | int getfd(__pid_t pid, int fildes, void *ptr) |
||
36 | { |
||
37 | int res; |
||
38 | res=*fildesflags_ptr(pid,fildes); |
||
39 | unlock_desctable(pid); |
||
40 | return res; |
||
41 | } |
||
42 | |||
43 | int setfd(__pid_t pid, int fildes, void *ptr) |
||
44 | { |
||
45 | *fildesflags_ptr(pid,fildes)=((int)ptr)&FD_CLOEXEC; |
||
46 | unlock_desctable(pid); |
||
47 | return EOK; |
||
48 | } |
||
49 | |||
50 | int getfl(__pid_t pid, int fildes, void *ptr) |
||
51 | { |
||
52 | int res; |
||
53 | res=*fildesfflags_ptr(pid,fildes); |
||
54 | unlock_desctable(pid); |
||
55 | return res; |
||
56 | } |
||
57 | |||
58 | int setfl(__pid_t pid, int fildes, void *ptr) |
||
59 | { |
||
60 | *fildesfflags_ptr(pid,fildes)=((int)ptr)& |
||
61 | (O_APPEND|O_DSYNC|O_NONBLOCK|O_RSYNC|O_SYNC); |
||
62 | unlock_desctable(pid); |
||
63 | return EOK; |
||
64 | } |
||
65 | |||
66 | int dummy(__pid_t pid, int fildes, void *ptr) |
||
67 | { |
||
68 | unlock_desctable(pid); |
||
69 | return -EINVAL; |
||
70 | } |
||
71 | |||
72 | static struct { |
||
73 | int (*f)(__pid_t pid, int fildes, void *ptr); |
||
74 | } func[]={ |
||
75 | {dupfd}, |
||
76 | {getfd}, |
||
77 | {setfd}, |
||
78 | {getfl}, |
||
79 | {setfl}, |
||
80 | {dummy}, |
||
81 | {dummy}, |
||
82 | {dummy} |
||
83 | }; |
||
84 | |||
85 | int k_fcntl(int fildes,int cmd,void *ptr) |
||
86 | { |
||
87 | __pid_t pid; |
||
88 | |||
89 | call_to_fs(); |
||
90 | |||
91 | pid=__get_pid(); |
||
92 | lock_desctable(pid); |
||
93 | if (!__isvalid_fd(pid,fildes)) { |
||
94 | lock_desctable(pid); |
||
95 | return_from_fs(-EBADF); |
||
96 | } |
||
97 | |||
98 | if (cmd<F_DUPFD||cmd>=F_SETLKW) |
||
99 | return_from_fs(-ENOSYS); |
||
100 | |||
101 | return_from_fs(func[cmd].f(pid,fildes,ptr)); |
||
102 | } |