revert-mm-fix-blkdev-size-calculation-in-generic_write_checks
[linux-2.6/linux-trees-mm.git] / fs / reiser4 / plugin / file / file.h
blob3142b959243ee0f2df65e17d773f967e1167a668
1 /* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
2 * reiser4/README */
4 /* this file contains declarations of methods implementing
5 file plugins (UNIX_FILE_PLUGIN_ID, CRYPTCOMPRESS_FILE_PLUGIN_ID
6 and SYMLINK_FILE_PLUGIN_ID) */
8 #if !defined( __REISER4_FILE_H__ )
9 #define __REISER4_FILE_H__
11 /* declarations of functions implementing UNIX_FILE_PLUGIN_ID file plugin */
13 /* inode operations */
14 int setattr_unix_file(struct dentry *, struct iattr *);
16 /* file operations */
17 ssize_t read_unix_file(struct file *, char __user *buf, size_t read_amount,
18 loff_t *off);
19 ssize_t write_unix_file(struct file *, const char __user *buf, size_t write_amount,
20 loff_t * off);
21 int ioctl_unix_file(struct inode *, struct file *, unsigned int cmd,
22 unsigned long arg);
23 int mmap_unix_file(struct file *, struct vm_area_struct *);
24 int open_unix_file(struct inode *, struct file *);
25 int release_unix_file(struct inode *, struct file *);
26 int sync_unix_file(struct file *, struct dentry *, int datasync);
28 /* address space operations */
29 int readpage_unix_file(struct file *, struct page *);
30 int readpages_unix_file(struct file*, struct address_space*, struct list_head*, unsigned);
31 int writepages_unix_file(struct address_space *, struct writeback_control *);
32 int prepare_write_unix_file(struct file *, struct page *, unsigned from,
33 unsigned to);
34 int commit_write_unix_file(struct file *, struct page *, unsigned from,
35 unsigned to);
36 sector_t bmap_unix_file(struct address_space *, sector_t lblock);
38 /* file plugin operations */
39 int flow_by_inode_unix_file(struct inode *, const char __user *buf,
40 int user, loff_t, loff_t, rw_op, flow_t *);
41 int owns_item_unix_file(const struct inode *, const coord_t *);
42 void init_inode_data_unix_file(struct inode *, reiser4_object_create_data *,
43 int create);
44 int delete_object_unix_file(struct inode *);
47 * all the write into unix file is performed by item write method. Write method
48 * of unix file plugin only decides which item plugin (extent or tail) and in
49 * which mode (one from the enum below) to call
51 typedef enum {
52 FIRST_ITEM = 1,
53 APPEND_ITEM = 2,
54 OVERWRITE_ITEM = 3
55 } write_mode_t;
57 /* unix file may be in one the following states */
58 typedef enum {
59 UF_CONTAINER_UNKNOWN = 0,
60 UF_CONTAINER_TAILS = 1,
61 UF_CONTAINER_EXTENTS = 2,
62 UF_CONTAINER_EMPTY = 3
63 } file_container_t;
65 struct formatting_plugin;
66 struct inode;
68 /* unix file plugin specific part of reiser4 inode */
69 struct unix_file_info {
71 * this read-write lock protects file containerization change. Accesses
72 * which do not change file containerization (see file_container_t)
73 * (read, readpage, writepage, write (until tail conversion is
74 * involved)) take read-lock. Accesses which modify file
75 * containerization (truncate, conversion from tail to extent and back)
76 * take write-lock.
78 struct rw_semaphore latch;
79 /* this enum specifies which items are used to build the file */
80 file_container_t container;
82 * plugin which controls when file is to be converted to extents and
83 * back to tail
85 struct formatting_plugin *tplug;
86 /* if this is set, file is in exclusive use */
87 int exclusive_use;
88 #if REISER4_DEBUG
89 /* pointer to task struct of thread owning exclusive access to file */
90 void *ea_owner;
91 atomic_t nr_neas;
92 void *last_reader;
93 #endif
96 struct unix_file_info *unix_file_inode_data(const struct inode *inode);
97 void get_exclusive_access(struct unix_file_info *);
98 void drop_exclusive_access(struct unix_file_info *);
99 void get_nonexclusive_access(struct unix_file_info *);
100 void drop_nonexclusive_access(struct unix_file_info *);
101 int try_to_get_nonexclusive_access(struct unix_file_info *);
102 int find_file_item(hint_t *, const reiser4_key *, znode_lock_mode,
103 struct inode *);
104 int find_file_item_nohint(coord_t *, lock_handle *,
105 const reiser4_key *, znode_lock_mode,
106 struct inode *);
108 int load_file_hint(struct file *, hint_t *);
109 void save_file_hint(struct file *, const hint_t *);
111 #include "../item/extent.h"
112 #include "../item/tail.h"
113 #include "../item/ctail.h"
115 struct uf_coord {
116 coord_t coord;
117 lock_handle *lh;
118 int valid;
119 union {
120 struct extent_coord_extension extent;
121 struct tail_coord_extension tail;
122 struct ctail_coord_extension ctail;
123 } extension;
126 #include "../../forward.h"
127 #include "../../seal.h"
128 #include "../../lock.h"
131 * This structure is used to speed up file operations (reads and writes). A
132 * hint is a suggestion about where a key resolved to last time. A seal
133 * indicates whether a node has been modified since a hint was last recorded.
134 * You check the seal, and if the seal is still valid, you can use the hint
135 * without traversing the tree again.
137 struct hint {
138 seal_t seal; /* a seal over last file item accessed */
139 uf_coord_t ext_coord;
140 loff_t offset;
141 znode_lock_mode mode;
142 lock_handle lh;
145 static inline int hint_is_valid(hint_t * hint)
147 return hint->ext_coord.valid;
150 static inline void hint_set_valid(hint_t * hint)
152 hint->ext_coord.valid = 1;
155 static inline void hint_clr_valid(hint_t * hint)
157 hint->ext_coord.valid = 0;
160 int load_file_hint(struct file *, hint_t *);
161 void save_file_hint(struct file *, const hint_t *);
162 void hint_init_zero(hint_t *);
163 void reiser4_set_hint(hint_t *, const reiser4_key *, znode_lock_mode);
164 int hint_is_set(const hint_t *);
165 void reiser4_unset_hint(hint_t *);
167 int reiser4_update_file_size(struct inode *, reiser4_key *, int update_sd);
168 int cut_file_items(struct inode *, loff_t new_size, int update_sd,
169 loff_t cur_size, int (*update_actor) (struct inode *,
170 reiser4_key *, int));
171 #if REISER4_DEBUG
173 /* return 1 is exclusive access is obtained, 0 - otherwise */
174 static inline int ea_obtained(struct unix_file_info * uf_info)
176 int ret;
178 ret = down_read_trylock(&uf_info->latch);
179 if (ret)
180 up_read(&uf_info->latch);
181 return !ret;
184 #endif
186 /* declarations of functions implementing SYMLINK_FILE_PLUGIN_ID file plugin */
187 int reiser4_create_symlink(struct inode *symlink, struct inode *dir,
188 reiser4_object_create_data *);
189 void destroy_inode_symlink(struct inode *);
191 /* declarations of functions implementing CRYPTCOMPRESS_FILE_PLUGIN_ID
192 file plugin */
194 /* inode operations */
195 int setattr_cryptcompress(struct dentry *, struct iattr *);
196 int prot_setattr_cryptcompress(struct dentry *, struct iattr *);
198 /* file operations */
199 ssize_t read_cryptcompress(struct file *, char __user *buf, size_t read_amount,
200 loff_t * off);
201 ssize_t prot_read_cryptcompress(struct file *, char __user *buf,
202 size_t read_amount, loff_t * off);
204 ssize_t write_cryptcompress(struct file *, const char __user *buf, size_t write_amount,
205 loff_t * off, int * conv);
206 ssize_t prot_write_cryptcompress(struct file *, const char __user *buf, size_t write_amount,
207 loff_t * off);
208 int mmap_cryptcompress(struct file *, struct vm_area_struct *);
209 int prot_mmap_cryptcompress(struct file *, struct vm_area_struct *);
211 int release_cryptcompress(struct inode *, struct file *);
212 int prot_release_cryptcompress(struct inode *, struct file *);
214 /* address space operations */
215 extern int readpage_cryptcompress(struct file *, struct page *);
216 extern int writepages_cryptcompress(struct address_space *,
217 struct writeback_control *);
218 /* file plugin operations */
219 int flow_by_inode_cryptcompress(struct inode *, const char __user *buf,
220 int user, loff_t, loff_t, rw_op, flow_t *);
221 int key_by_inode_cryptcompress(struct inode *, loff_t off, reiser4_key *);
222 int create_cryptcompress(struct inode *, struct inode *,
223 reiser4_object_create_data *);
224 int delete_object_cryptcompress(struct inode *);
225 void init_inode_data_cryptcompress(struct inode *, reiser4_object_create_data *,
226 int create);
227 int cut_tree_worker_cryptcompress(tap_t *, const reiser4_key * from_key,
228 const reiser4_key * to_key,
229 reiser4_key * smallest_removed,
230 struct inode *object, int truncate,
231 int *progress);
232 void destroy_inode_cryptcompress(struct inode *);
233 int open_object_cryptcompress(struct inode * inode, struct file * file);
235 extern reiser4_plugin_ops cryptcompress_plugin_ops;
237 #define WRITE_GRANULARITY 32
239 int tail2extent(struct unix_file_info *);
240 int extent2tail(struct file *, struct unix_file_info *);
242 int goto_right_neighbor(coord_t *, lock_handle *);
243 int find_or_create_extent(struct page *);
244 int equal_to_ldk(znode *, const reiser4_key *);
246 void init_uf_coord(uf_coord_t *uf_coord, lock_handle *lh);
248 static inline int cbk_errored(int cbk_result)
250 return (cbk_result != CBK_COORD_NOTFOUND
251 && cbk_result != CBK_COORD_FOUND);
254 /* __REISER4_FILE_H__ */
255 #endif
258 * Local variables:
259 * c-indentation-style: "K&R"
260 * mode-name: "LC"
261 * c-basic-offset: 8
262 * tab-width: 8
263 * fill-column: 79
264 * scroll-step: 1
265 * End: