This source file includes following definitions.
- smb_fsync
- smb_make_open
- smb_file_read
- smb_file_write
1
2
3
4
5
6
7
8 #include <asm/segment.h>
9 #include <asm/system.h>
10
11 #include <linux/sched.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/fcntl.h>
15 #include <linux/stat.h>
16 #include <linux/mm.h>
17 #include <linux/smb_fs.h>
18 #include <linux/malloc.h>
19
20 static int
21 smb_fsync(struct inode *inode, struct file *file)
22 {
23 return 0;
24 }
25
26 int
27 smb_make_open(struct inode *i, int right)
28 {
29 struct smb_dirent *dirent;
30 int open_result;
31
32 if (i == NULL) {
33 printk("smb_make_open: got NULL inode\n");
34 return -EINVAL;
35 }
36
37 dirent = &(SMB_INOP(i)->finfo);
38
39 DDPRINTK("smb_make_open: dirent->opened = %d\n", dirent->opened);
40
41 if ((dirent->opened) == 0) {
42
43 open_result = smb_proc_open(SMB_SERVER(i),
44 dirent->path, dirent->len,
45 dirent);
46 if (open_result)
47 return open_result;
48
49 dirent->opened = 1;
50 }
51
52 if ( ((right == O_RDONLY) && ( (dirent->access == O_RDONLY)
53 || (dirent->access == O_RDWR)))
54 || ((right == O_WRONLY) && ( (dirent->access == O_WRONLY)
55 || (dirent->access == O_RDWR)))
56 || ((right == O_RDWR) && (dirent->access == O_RDWR)))
57 return 0;
58
59 return -EACCES;
60 }
61
62 static int
63 smb_file_read(struct inode *inode, struct file *file, char *buf, int count)
64 {
65 int result, bufsize, to_read, already_read;
66 off_t pos;
67 int errno;
68
69 DPRINTK("smb_file_read: enter %s\n", SMB_FINFO(inode)->path);
70
71 if (!inode) {
72 DPRINTK("smb_file_read: inode = NULL\n");
73 return -EINVAL;
74 }
75
76 if (!S_ISREG(inode->i_mode)) {
77 DPRINTK("smb_file_read: read from non-file, mode %07o\n",
78 inode->i_mode);
79 return -EINVAL;
80 }
81
82 if ((errno = smb_make_open(inode, O_RDONLY)) != 0)
83 return errno;
84
85 pos = file->f_pos;
86
87 if (pos + count > inode->i_size)
88 count = inode->i_size - pos;
89
90 if (count <= 0)
91 return 0;
92 bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
93
94 already_read = 0;
95
96
97 while (already_read < count) {
98
99 result = 0;
100 to_read = 0;
101
102 if ((SMB_SERVER(inode)->blkmode & 1) != 0) {
103 to_read = min(65535, count - already_read);
104 DPRINTK("smb_file_read: Raw %d bytes\n", to_read);
105 result = smb_proc_read_raw(SMB_SERVER(inode),
106 SMB_FINFO(inode),
107 pos, to_read, buf);
108 DPRINTK("smb_file_read: returned %d\n", result);
109 }
110
111 if (result <= 0) {
112 to_read = min(bufsize, count - already_read);
113 result = smb_proc_read(SMB_SERVER(inode),
114 SMB_FINFO(inode),
115 pos, to_read, buf, 1);
116 }
117
118 if (result < 0)
119 return result;
120 pos += result;
121 buf += result;
122 already_read += result;
123
124 if (result < to_read) {
125 break;
126 }
127 }
128
129 file->f_pos = pos;
130
131 if (!IS_RDONLY(inode)) inode->i_atime = CURRENT_TIME;
132 inode->i_dirt = 1;
133
134 DPRINTK("smb_file_read: exit %s\n", SMB_FINFO(inode)->path);
135
136 return already_read;
137 }
138
139 static int
140 smb_file_write(struct inode *inode, struct file *file, const char *buf, int count)
141 {
142 int result, bufsize, to_write, already_written;
143 off_t pos;
144 int errno;
145
146 if (!inode) {
147 DPRINTK("smb_file_write: inode = NULL\n");
148 return -EINVAL;
149 }
150
151 if (!S_ISREG(inode->i_mode)) {
152 DPRINTK("smb_file_write: write to non-file, mode %07o\n",
153 inode->i_mode);
154 return -EINVAL;
155 }
156
157 DPRINTK("smb_file_write: enter %s\n", SMB_FINFO(inode)->path);
158
159 if (count <= 0)
160 return 0;
161
162 if ((errno = smb_make_open(inode, O_RDWR)) != 0)
163 return errno;
164
165 pos = file->f_pos;
166
167 if (file->f_flags & O_APPEND)
168 pos = inode->i_size;
169
170 bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
171
172 already_written = 0;
173
174 DPRINTK("smb_write_file: blkmode = %d, blkmode & 2 = %d\n",
175 SMB_SERVER(inode)->blkmode,
176 SMB_SERVER(inode)->blkmode & 2);
177
178 while (already_written < count) {
179
180 result = 0;
181 to_write = 0;
182
183 if ((SMB_SERVER(inode)->blkmode & 2) != 0) {
184 to_write = min(65535, count - already_written);
185 DPRINTK("smb_file_write: Raw %d bytes\n", to_write);
186 result = smb_proc_write_raw(SMB_SERVER(inode),
187 SMB_FINFO(inode),
188 pos, to_write, buf);
189 DPRINTK("smb_file_write: returned %d\n", result);
190 }
191
192 if (result <= 0) {
193 to_write = min(bufsize, count - already_written);
194 result = smb_proc_write(SMB_SERVER(inode),
195 SMB_FINFO(inode),
196 pos, to_write, buf);
197 }
198
199 if (result < 0)
200 return result;
201
202 pos += result;
203 buf += result;
204 already_written += result;
205
206 if (result < to_write) {
207 break;
208 }
209 }
210
211 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
212 inode->i_dirt = 1;
213
214 file->f_pos = pos;
215
216 if (pos > inode->i_size) {
217 inode->i_size = pos;
218 }
219
220 DPRINTK("smb_file_write: exit %s\n", SMB_FINFO(inode)->path);
221
222 return already_written;
223 }
224
225 static struct file_operations smb_file_operations = {
226 NULL,
227 smb_file_read,
228 smb_file_write,
229 NULL,
230 NULL,
231 smb_ioctl,
232 smb_mmap,
233 NULL,
234 NULL,
235 smb_fsync,
236 };
237
238 struct inode_operations smb_file_inode_operations = {
239 &smb_file_operations,
240 NULL,
241 NULL,
242 NULL,
243 NULL,
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 NULL,
249 NULL,
250 NULL,
251 NULL,
252 NULL
253 };
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270