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
);
62 * common sync method for regular files.
64 * We are trying to be smart here. Instead of committing all atoms (original
65 * solution), we scan dirty pages of this file and commit all atoms they are
68 * Situation is complicated by anonymous pages: i.e., extent-less pages
69 * dirtied through mmap. Fortunately sys_fsync() first calls
70 * filemap_fdatawrite() that will ultimately call reiser4_writepages(), insert
71 * all missing extents and capture anonymous pages.
73 int reiser4_sync_file_common(struct file
*file
,
74 struct dentry
*dentry
, int datasync
)
78 reiser4_block_nr reserve
;
80 ctx
= reiser4_init_context(dentry
->d_inode
->i_sb
);
84 reserve
= estimate_update_common(dentry
->d_inode
);
85 if (reiser4_grab_space(reserve
, BA_CAN_COMMIT
)) {
86 reiser4_exit_context(ctx
);
87 return RETERR(-ENOSPC
);
89 write_sd_by_inode_common(dentry
->d_inode
);
91 atom
= get_current_atom_locked();
92 spin_lock_txnh(ctx
->trans
);
93 force_commit_atom(ctx
->trans
);
94 reiser4_exit_context(ctx
);
99 /* address space operations */
102 /* this is helper for plugin->write_begin() */
103 int do_prepare_write(struct file
*file
, struct page
*page
, unsigned from
,
110 assert("umka-3099", file
!= NULL
);
111 assert("umka-3100", page
!= NULL
);
112 assert("umka-3095", PageLocked(page
));
114 if (to
- from
== PAGE_CACHE_SIZE
|| PageUptodate(page
))
117 inode
= page
->mapping
->host
;
118 fplug
= inode_file_plugin(inode
);
120 if (page
->mapping
->a_ops
->readpage
== NULL
)
121 return RETERR(-EINVAL
);
123 result
= page
->mapping
->a_ops
->readpage(file
, page
);
126 ClearPageUptodate(page
);
127 /* All reiser4 readpage() implementations should return the
128 * page locked in case of error. */
129 assert("nikita-3472", PageLocked(page
));
132 * ->readpage() either:
134 * 1. starts IO against @page. @page is locked for IO in
137 * 2. doesn't start IO. @page is unlocked.
139 * In either case, page should be locked.
143 * IO (if any) is completed at this point. Check for IO
146 if (!PageUptodate(page
))
147 result
= RETERR(-EIO
);
149 assert("umka-3098", PageLocked(page
));
155 * c-indentation-style: "K&R"