Subversion Repositories shark

Rev

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/util.h>
23
#include <fs/maccess.h>
24
#include <fs/fcntl.h>
25
 
26
#include "file.h"
27
#include "dentry.h"
28
#include "fs.h"
29
 
30
/*
31
  this are from bits/fcntl.h
32
  if they are changed then this code must be rewritten!  
33
  #define F_DUPFD               0
34
  #define F_GETFD               1
35
  #define F_SETFD               2
36
  #define F_GETFL               3
37
  #define F_SETFL               4
38
  #define F_GETLK               5
39
  #define F_SETLK               6
40
  #define F_SETLKW              7
41
 */
42
 
43
int dupfd(__pid_t pid, int fildes, void *ptr)
44
{
45
  int res;
46
  res=__duplicate_fd(pid,fildes,(int)ptr);
47
  unlock_desctable(pid);
48
  if (res) return -EMFILE;
49
  return EOK;
50
}
51
 
52
int getfd(__pid_t pid, int fildes, void *ptr)
53
{
54
  int res;
55
  res=*fildesflags_ptr(pid,fildes);
56
  unlock_desctable(pid);  
57
  return res;
58
}
59
 
60
int setfd(__pid_t pid, int fildes, void *ptr)
61
{
62
  *fildesflags_ptr(pid,fildes)=((int)ptr)&FD_CLOEXEC;
63
  unlock_desctable(pid);  
64
  return EOK;
65
}
66
 
67
int getfl(__pid_t pid, int fildes, void *ptr)
68
{
69
  int res;
70
  res=*fildesfflags_ptr(pid,fildes);
71
  unlock_desctable(pid);  
72
  return res;
73
}
74
 
75
int setfl(__pid_t pid, int fildes, void *ptr)
76
{
77
  *fildesfflags_ptr(pid,fildes)=((int)ptr)&
78
    (O_APPEND|O_DSYNC|O_NONBLOCK|O_RSYNC|O_SYNC);
79
  unlock_desctable(pid);  
80
  return EOK;
81
}
82
 
83
int dummy(__pid_t pid, int fildes, void *ptr)
84
{
85
  unlock_desctable(pid);  
86
  return -EINVAL;
87
}
88
 
89
static struct {
90
  int (*f)(__pid_t pid, int fildes, void *ptr);
91
} func[]={
92
  {dupfd},
93
  {getfd},
94
  {setfd},
95
  {getfl},
96
  {setfl},
97
  {dummy},
98
  {dummy},
99
  {dummy}
100
};
101
 
102
int k_fcntl(int fildes,int cmd,void *ptr)
103
{
104
  __pid_t pid;
105
 
106
  call_to_fs();
107
 
108
  pid=__get_pid();  
109
  lock_desctable(pid);
110
  if (!__isvalid_fd(pid,fildes)) {
111
    lock_desctable(pid);
112
    return_from_fs(-EBADF);
113
  }
114
 
115
  if (cmd<F_DUPFD||cmd>=F_SETLKW)
116
    return_from_fs(-ENOSYS);
117
 
118
  return_from_fs(func[cmd].f(pid,fildes,ptr));  
119
}