1 /* Copyright 2001, 2002, 2003, 2004 by Hans Reiser, licensing governed by
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
*);
17 ssize_t
read_unix_file(struct file
*, char __user
*buf
, size_t read_amount
,
19 ssize_t
write_unix_file(struct file
*, const char __user
*buf
, size_t write_amount
,
21 int ioctl_unix_file(struct inode
*, struct file
*, unsigned int cmd
,
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
,
34 int commit_write_unix_file(struct file
*, struct page
*, unsigned from
,
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
*,
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
57 /* unix file may be in one the following states */
59 UF_CONTAINER_UNKNOWN
= 0,
60 UF_CONTAINER_TAILS
= 1,
61 UF_CONTAINER_EXTENTS
= 2,
62 UF_CONTAINER_EMPTY
= 3
65 struct formatting_plugin
;
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)
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
85 struct formatting_plugin
*tplug
;
86 /* if this is set, file is in exclusive use */
89 /* pointer to task struct of thread owning exclusive access to file */
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
,
104 int find_file_item_nohint(coord_t
*, lock_handle
*,
105 const reiser4_key
*, znode_lock_mode
,
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"
120 struct extent_coord_extension extent
;
121 struct tail_coord_extension tail
;
122 struct ctail_coord_extension ctail
;
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.
138 seal_t seal
; /* a seal over last file item accessed */
139 uf_coord_t ext_coord
;
141 znode_lock_mode mode
;
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));
173 /* return 1 is exclusive access is obtained, 0 - otherwise */
174 static inline int ea_obtained(struct unix_file_info
* uf_info
)
178 ret
= down_read_trylock(&uf_info
->latch
);
180 up_read(&uf_info
->latch
);
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
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
,
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
,
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
*,
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
,
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__ */
259 * c-indentation-style: "K&R"