26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/sched.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
34 #include <linux/list.h>
36 #include <linux/utsname.h>
37 #include <asm/uaccess.h>
47 static const struct vm_operations_struct v9fs_file_vm_ops;
65 v9inode = V9FS_I(inode);
66 v9ses = v9fs_inode2v9ses(inode);
67 if (v9fs_proto_dotl(v9ses))
71 v9fs_proto_dotu(v9ses));
84 i_size_write(inode, 0);
88 (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
112 #ifdef CONFIG_9P_FSCACHE
152 static int v9fs_file_do_lock(
struct file *filp,
int cmd,
struct file_lock *fl)
158 unsigned char fl_type;
190 flock.client_id = utsname()->nodename;
231 if (res < 0 && fl->fl_type !=
F_UNLCK) {
241 static int v9fs_file_getlock(
struct file *filp,
struct file_lock *fl)
259 memset(&glock, 0,
sizeof(glock));
266 glock.proc_id = fl->
fl_pid;
267 glock.client_id = utsname()->nodename;
273 switch (glock.type) {
286 if (glock.length == 0)
289 fl->
fl_end = glock.start + glock.length - 1;
290 fl->
fl_pid = glock.proc_id;
303 static int v9fs_file_lock_dotl(
struct file *filp,
int cmd,
struct file_lock *fl)
305 struct inode *inode = filp->
f_path.dentry->d_inode;
309 filp, cmd, fl, filp->
f_path.dentry->d_name.name);
321 ret = v9fs_file_do_lock(filp, cmd, fl);
323 ret = v9fs_file_getlock(filp, fl);
338 static int v9fs_file_flock_dotl(
struct file *filp,
int cmd,
341 struct inode *inode = filp->
f_path.dentry->d_inode;
345 filp, cmd, fl, filp->
f_path.dentry->d_name.name);
366 ret = v9fs_file_do_lock(filp, cmd, fl);
389 fid->
fid, (
long long unsigned)offset, count);
406 }
while (count > 0 && n == size);
440 v9fs_file_read(
struct file *filp,
char __user *udata,
size_t count,
464 const char __user *
data,
size_t count,
465 loff_t *offset,
int invalidate)
472 unsigned long pg_start, pg_end;
475 data, (
int)count, (
int)*offset);
486 if (invalidate && (total > 0)) {
488 pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
493 i_size = i_size_read(inode);
494 if (*offset > i_size) {
496 i_size_write(inode, *offset);
514 v9fs_file_write(
struct file *filp,
const char __user *
data,
515 size_t count, loff_t *offset)
534 data, count, &origin, 1);
543 static int v9fs_file_fsync(
struct file *filp, loff_t
start, loff_t
end,
547 struct inode *inode = filp->
f_mapping->host;
571 struct inode *inode = filp->
f_mapping->host;
596 vma->
vm_ops = &v9fs_file_vm_ops;
602 v9fs_vm_page_mkwrite(
struct vm_area_struct *vma,
struct vm_fault *vmf)
606 struct file *filp = vma->
vm_file;
607 struct inode *inode = filp->
f_path.dentry->d_inode;
616 v9inode = V9FS_I(inode);
618 v9fs_fscache_wait_on_page_write(inode, page);
624 return VM_FAULT_LOCKED;
627 return VM_FAULT_NOPAGE;
631 v9fs_direct_read(
struct file *filp,
char __user *udata,
size_t count,
640 inode = mapping->
host;
643 size = i_size_read(inode);
648 return v9fs_file_read(filp, udata, count, offsetp);
660 v9fs_cached_file_read(
struct file *filp,
char __user *data,
size_t count,
664 return v9fs_direct_read(filp, data, count, offset);
669 v9fs_direct_write(
struct file *filp,
const char __user * data,
670 size_t count, loff_t *offsetp)
679 inode = mapping->
host;
696 pgoff_t pg_end = (offset + count - 1) >> PAGE_CACHE_SHIFT;
705 if (retval == -
EBUSY)
710 retval = v9fs_file_write(filp, data, count, offsetp);
729 v9fs_cached_file_write(
struct file *filp,
const char __user * data,
730 size_t count, loff_t *offset)
734 return v9fs_direct_write(filp, data, count, offset);
738 static const struct vm_operations_struct v9fs_file_vm_ops = {
740 .page_mkwrite = v9fs_vm_page_mkwrite,
747 .read = v9fs_cached_file_read,
748 .write = v9fs_cached_file_write,
753 .lock = v9fs_file_lock,
754 .mmap = v9fs_file_mmap,
755 .fsync = v9fs_file_fsync,
760 .read = v9fs_cached_file_read,
761 .write = v9fs_cached_file_write,
766 .lock = v9fs_file_lock_dotl,
767 .flock = v9fs_file_flock_dotl,
768 .mmap = v9fs_file_mmap,
774 .read = v9fs_file_read,
775 .write = v9fs_file_write,
778 .lock = v9fs_file_lock,
780 .fsync = v9fs_file_fsync,
785 .read = v9fs_file_read,
786 .write = v9fs_file_write,
789 .lock = v9fs_file_lock_dotl,
790 .flock = v9fs_file_flock_dotl,