9 #include <asm/uaccess.h>
11 #include <linux/time.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/fcntl.h>
15 #include <linux/stat.h>
18 #include <linux/sched.h>
22 static int ncp_fsync(
struct file *
file, loff_t
start, loff_t
end,
int datasync)
41 DPRINTK(
"ncp_make_open: opened=%d, volume # %u, dir entry # %u\n",
74 PPRINTK(
"ncp_make_open: failed, result=%d\n", result);
85 access = NCP_FINFO(inode)->access;
86 PPRINTK(
"ncp_make_open: file open, access=%x\n", access);
87 if (access == right || access ==
O_RDWR) {
99 ncp_file_read(
struct file *
file,
char __user *
buf,
size_t count, loff_t *ppos)
103 size_t already_read = 0;
110 DPRINTK(
"ncp_file_read: enter %s/%s\n",
120 if (pos > inode->
i_sb->s_maxbytes)
122 if (pos + count > inode->
i_sb->s_maxbytes) {
123 count = inode->
i_sb->s_maxbytes -
pos;
135 freelen = ncp_read_bounce_size(bufsize);
141 while (already_read < count) {
143 size_t to_read =
min_t(
unsigned int,
144 bufsize - (pos % bufsize),
145 count - already_read);
149 pos, to_read, buf, &read_this_time,
155 pos += read_this_time;
156 buf += read_this_time;
157 already_read += read_this_time;
159 if (read_this_time != to_read) {
169 DPRINTK(
"ncp_file_read: exit %s/%s\n",
172 ncp_inode_close(inode);
173 return already_read ? already_read :
error;
177 ncp_file_write(
struct file *file,
const char __user *buf,
size_t count, loff_t *ppos)
179 struct dentry *dentry = file->
f_path.dentry;
180 struct inode *inode = dentry->
d_inode;
181 size_t already_written = 0;
187 DPRINTK(
"ncp_file_write: enter %s/%s\n",
193 pos = i_size_read(inode);
204 if (pos >= inode->
i_sb->s_maxbytes) {
205 if (count || pos > inode->
i_sb->s_maxbytes) {
209 if (pos + count > inode->
i_sb->s_maxbytes) {
210 count = inode->
i_sb->s_maxbytes -
pos;
228 bouncebuffer =
vmalloc(bufsize);
233 while (already_written < count) {
234 int written_this_time;
235 size_t to_write =
min_t(
unsigned int,
236 bufsize - (pos % bufsize),
237 count - already_written);
245 pos, to_write, bouncebuffer, &written_this_time) != 0) {
249 pos += written_this_time;
250 buf += written_this_time;
251 already_written += written_this_time;
253 if (written_this_time != to_write) {
261 if (pos > i_size_read(inode)) {
263 if (pos > i_size_read(inode))
264 i_size_write(inode, pos);
267 DPRINTK(
"ncp_file_write: exit %s/%s\n",
270 ncp_inode_close(inode);
271 return already_written ? already_written : errno;
274 static int ncp_release(
struct inode *inode,
struct file *file) {
276 DPRINTK(
"ncp_release: failed to close\n");
284 .read = ncp_file_read,
285 .write = ncp_file_write,
291 .release = ncp_release,