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