1 /* Copyright 2005 by Hans Reiser, licensing governed by
4 /* this file contains typical implementations for some of methods of
5 struct file_operations and of struct address_space_operations
13 /* implementation of vfs's llseek method of struct file_operations for
14 typical directory can be found in readdir_common.c
16 loff_t
reiser4_llseek_dir_common(struct file
*, loff_t
, int origin
);
18 /* implementation of vfs's readdir method of struct file_operations for
19 typical directory can be found in readdir_common.c
21 int reiser4_readdir_common(struct file
*, void *dirent
, filldir_t
);
24 * reiser4_release_dir_common - release of struct file_operations
25 * @inode: inode of released file
26 * @file: file to release
28 * Implementation of release method of struct file_operations for typical
29 * directory. All it does is freeing of reiser4 specific file data.
31 int reiser4_release_dir_common(struct inode
*inode
, struct file
*file
)
35 ctx
= reiser4_init_context(inode
->i_sb
);
38 reiser4_free_file_fsdata(file
);
39 reiser4_exit_context(ctx
);
43 /* this is common implementation of vfs's fsync method of struct
46 int reiser4_sync_common(struct file
*file
, struct dentry
*dentry
, int datasync
)
51 ctx
= reiser4_init_context(dentry
->d_inode
->i_sb
);
54 result
= txnmgr_force_commit_all(dentry
->d_inode
->i_sb
, 0);
56 context_set_commit_async(ctx
);
57 reiser4_exit_context(ctx
);
61 /* this is common implementation of vfs's sendfile method of struct
64 Reads @count bytes from @file and calls @actor for every page read. This is
65 needed for loop back devices support.
69 sendfile_common(struct file
*file
, loff_t
*ppos
, size_t count
,
70 read_actor_t actor
, void *target
)
75 ctx
= reiser4_init_context(file
->f_dentry
->d_inode
->i_sb
);
78 result
= generic_file_sendfile(file
, ppos
, count
, actor
, target
);
79 reiser4_exit_context(ctx
);
84 /* address space operations */
86 /* this is common implementation of vfs's prepare_write method of struct
87 address_space_operations
90 prepare_write_common(struct file
*file
, struct page
*page
, unsigned from
,
96 ctx
= reiser4_init_context(page
->mapping
->host
->i_sb
);
97 result
= do_prepare_write(file
, page
, from
, to
);
99 /* don't commit transaction under inode semaphore */
100 context_set_commit_async(ctx
);
101 reiser4_exit_context(ctx
);
106 /* this is helper for prepare_write_common and prepare_write_unix_file
109 do_prepare_write(struct file
*file
, struct page
*page
, unsigned from
,
116 assert("umka-3099", file
!= NULL
);
117 assert("umka-3100", page
!= NULL
);
118 assert("umka-3095", PageLocked(page
));
120 if (to
- from
== PAGE_CACHE_SIZE
|| PageUptodate(page
))
123 inode
= page
->mapping
->host
;
124 fplug
= inode_file_plugin(inode
);
126 if (page
->mapping
->a_ops
->readpage
== NULL
)
127 return RETERR(-EINVAL
);
129 result
= page
->mapping
->a_ops
->readpage(file
, page
);
132 ClearPageUptodate(page
);
133 /* All reiser4 readpage() implementations should return the
134 * page locked in case of error. */
135 assert("nikita-3472", PageLocked(page
));
138 * ->readpage() either:
140 * 1. starts IO against @page. @page is locked for IO in
143 * 2. doesn't start IO. @page is unlocked.
145 * In either case, page should be locked.
149 * IO (if any) is completed at this point. Check for IO
152 if (!PageUptodate(page
))
153 result
= RETERR(-EIO
);
155 assert("umka-3098", PageLocked(page
));
161 * c-indentation-style: "K&R"