revert-mm-fix-blkdev-size-calculation-in-generic_write_checks
[linux-2.6/linux-trees-mm.git] / fs / reiser4 / plugin / file_ops.c
blobef8ba9de85abd4150aa5562e75077a677b68db80
1 /* Copyright 2005 by Hans Reiser, licensing governed by
2 reiser4/README */
4 /* this file contains typical implementations for some of methods of
5 struct file_operations and of struct address_space_operations
6 */
8 #include "../inode.h"
9 #include "object.h"
11 /* file 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);
23 /**
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)
33 reiser4_context *ctx;
35 ctx = reiser4_init_context(inode->i_sb);
36 if (IS_ERR(ctx))
37 return PTR_ERR(ctx);
38 reiser4_free_file_fsdata(file);
39 reiser4_exit_context(ctx);
40 return 0;
43 /* this is common implementation of vfs's fsync method of struct
44 file_operations
46 int reiser4_sync_common(struct file *file, struct dentry *dentry, int datasync)
48 reiser4_context *ctx;
49 int result;
51 ctx = reiser4_init_context(dentry->d_inode->i_sb);
52 if (IS_ERR(ctx))
53 return PTR_ERR(ctx);
54 result = txnmgr_force_commit_all(dentry->d_inode->i_sb, 0);
56 context_set_commit_async(ctx);
57 reiser4_exit_context(ctx);
58 return result;
61 /* this is common implementation of vfs's sendfile method of struct
62 file_operations
64 Reads @count bytes from @file and calls @actor for every page read. This is
65 needed for loop back devices support.
67 #if 0
68 ssize_t
69 sendfile_common(struct file *file, loff_t *ppos, size_t count,
70 read_actor_t actor, void *target)
72 reiser4_context *ctx;
73 ssize_t result;
75 ctx = reiser4_init_context(file->f_dentry->d_inode->i_sb);
76 if (IS_ERR(ctx))
77 return PTR_ERR(ctx);
78 result = generic_file_sendfile(file, ppos, count, actor, target);
79 reiser4_exit_context(ctx);
80 return result;
82 #endif /* 0 */
84 /* address space operations */
86 /* this is common implementation of vfs's prepare_write method of struct
87 address_space_operations
89 int
90 prepare_write_common(struct file *file, struct page *page, unsigned from,
91 unsigned to)
93 reiser4_context *ctx;
94 int result;
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);
103 return result;
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,
110 unsigned to)
112 int result;
113 file_plugin *fplug;
114 struct inode *inode;
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))
121 return 0;
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);
130 if (result != 0) {
131 SetPageError(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));
136 } else {
138 * ->readpage() either:
140 * 1. starts IO against @page. @page is locked for IO in
141 * this case.
143 * 2. doesn't start IO. @page is unlocked.
145 * In either case, page should be locked.
147 lock_page(page);
149 * IO (if any) is completed at this point. Check for IO
150 * errors.
152 if (!PageUptodate(page))
153 result = RETERR(-EIO);
155 assert("umka-3098", PageLocked(page));
156 return result;
160 * Local variables:
161 * c-indentation-style: "K&R"
162 * mode-name: "LC"
163 * c-basic-offset: 8
164 * tab-width: 8
165 * fill-column: 79
166 * scroll-step: 1
167 * End: