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 DPRINTK("smb_file_read: exit %s\n", SMB_FINFO(inode)->path);
123
124 return already_read;
125 }
126
127 static int
128 smb_file_write(struct inode *inode, struct file *file, char *buf, int count)
129 {
130 int result, bufsize, to_write, already_written;
131 off_t pos;
132 int errno;
133
134 if (!inode) {
135 DPRINTK("smb_file_write: inode = NULL\n");
136 return -EINVAL;
137 }
138
139 if (!S_ISREG(inode->i_mode)) {
140 DPRINTK("smb_file_write: write to non-file, mode %07o\n",
141 inode->i_mode);
142 return -EINVAL;
143 }
144
145 DPRINTK("smb_file_write: enter %s\n", SMB_FINFO(inode)->path);
146
147 if (count <= 0)
148 return 0;
149
150 if ((errno = smb_make_open(inode, O_RDWR)) != 0)
151 return errno;
152
153 pos = file->f_pos;
154
155 if (file->f_flags & O_APPEND)
156 pos = inode->i_size;
157
158 bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
159
160 already_written = 0;
161
162 while (already_written < count) {
163
164 to_write = min(bufsize, count - already_written);
165
166 result = smb_proc_write(SMB_SERVER(inode), SMB_FINFO(inode),
167 pos, to_write, buf);
168
169 if (result < 0)
170 return result;
171
172 pos += result;
173 buf += result;
174 already_written += result;
175
176 if (result < to_write) {
177 break;
178 }
179 }
180
181 file->f_pos = pos;
182
183 if (pos > inode->i_size) {
184 inode->i_size = pos;
185 }
186
187 DPRINTK("smb_file_write: exit %s\n", SMB_FINFO(inode)->path);
188
189 return already_written;
190 }
191
192 static struct file_operations smb_file_operations = {
193 NULL,
194 smb_file_read,
195 smb_file_write,
196 NULL,
197 NULL,
198 smb_ioctl,
199 smb_mmap,
200 NULL,
201 NULL,
202 smb_fsync,
203 };
204
205 struct inode_operations smb_file_inode_operations = {
206 &smb_file_operations,
207 NULL,
208 NULL,
209 NULL,
210 NULL,
211 NULL,
212 NULL,
213 NULL,
214 NULL,
215 NULL,
216 NULL,
217 NULL,
218 NULL,
219 NULL
220 };
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237