revert-mm-fix-blkdev-size-calculation-in-generic_write_checks
[linux-2.6/linux-trees-mm.git] / fs / reiser4 / plugin / item / extent.h
blob4f4116e848d05f3a1f85d027b8c200baa6f207d2
1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
3 #ifndef __REISER4_EXTENT_H__
4 #define __REISER4_EXTENT_H__
6 /* on disk extent */
7 typedef struct {
8 reiser4_dblock_nr start;
9 reiser4_dblock_nr width;
10 } reiser4_extent;
12 struct extent_stat {
13 int unallocated_units;
14 int unallocated_blocks;
15 int allocated_units;
16 int allocated_blocks;
17 int hole_units;
18 int hole_blocks;
21 /* extents in an extent item can be either holes, or unallocated or allocated
22 extents */
23 typedef enum {
24 HOLE_EXTENT,
25 UNALLOCATED_EXTENT,
26 ALLOCATED_EXTENT
27 } extent_state;
29 #define HOLE_EXTENT_START 0
30 #define UNALLOCATED_EXTENT_START 1
31 #define UNALLOCATED_EXTENT_START2 2
33 struct extent_coord_extension {
34 reiser4_block_nr pos_in_unit;
35 reiser4_block_nr width; /* width of current unit */
36 pos_in_node_t nr_units; /* number of units */
37 int ext_offset; /* offset from the beginning of zdata() */
38 unsigned long expected_page;
39 #if REISER4_DEBUG
40 reiser4_extent extent;
41 #endif
44 /* macros to set/get fields of on-disk extent */
45 static inline reiser4_block_nr extent_get_start(const reiser4_extent * ext)
47 return le64_to_cpu(ext->start);
50 static inline reiser4_block_nr extent_get_width(const reiser4_extent * ext)
52 return le64_to_cpu(ext->width);
55 extern __u64 reiser4_current_block_count(void);
57 static inline void
58 extent_set_start(reiser4_extent * ext, reiser4_block_nr start)
60 cassert(sizeof(ext->start) == 8);
61 assert("nikita-2510",
62 ergo(start > 1, start < reiser4_current_block_count()));
63 put_unaligned(cpu_to_le64(start), &ext->start);
66 static inline void
67 extent_set_width(reiser4_extent * ext, reiser4_block_nr width)
69 cassert(sizeof(ext->width) == 8);
70 assert("", width > 0);
71 put_unaligned(cpu_to_le64(width), &ext->width);
72 assert("nikita-2511",
73 ergo(extent_get_start(ext) > 1,
74 extent_get_start(ext) + width <=
75 reiser4_current_block_count()));
78 #define extent_item(coord) \
79 ({ \
80 assert("nikita-3143", item_is_extent(coord)); \
81 ((reiser4_extent *)item_body_by_coord (coord)); \
84 #define extent_by_coord(coord) \
85 ({ \
86 assert("nikita-3144", item_is_extent(coord)); \
87 (extent_item (coord) + (coord)->unit_pos); \
90 #define width_by_coord(coord) \
91 ({ \
92 assert("nikita-3145", item_is_extent(coord)); \
93 extent_get_width (extent_by_coord(coord)); \
96 struct carry_cut_data;
97 struct carry_kill_data;
99 /* plugin->u.item.b.* */
100 reiser4_key *max_key_inside_extent(const coord_t *, reiser4_key *);
101 int can_contain_key_extent(const coord_t * coord, const reiser4_key * key,
102 const reiser4_item_data *);
103 int mergeable_extent(const coord_t * p1, const coord_t * p2);
104 pos_in_node_t nr_units_extent(const coord_t *);
105 lookup_result lookup_extent(const reiser4_key *, lookup_bias, coord_t *);
106 void init_coord_extent(coord_t *);
107 int init_extent(coord_t *, reiser4_item_data *);
108 int paste_extent(coord_t *, reiser4_item_data *, carry_plugin_info *);
109 int can_shift_extent(unsigned free_space,
110 coord_t * source, znode * target, shift_direction,
111 unsigned *size, unsigned want);
112 void copy_units_extent(coord_t * target, coord_t * source, unsigned from,
113 unsigned count, shift_direction where_is_free_space,
114 unsigned free_space);
115 int kill_hook_extent(const coord_t *, pos_in_node_t from, pos_in_node_t count,
116 struct carry_kill_data *);
117 int create_hook_extent(const coord_t * coord, void *arg);
118 int cut_units_extent(coord_t * coord, pos_in_node_t from, pos_in_node_t to,
119 struct carry_cut_data *, reiser4_key * smallest_removed,
120 reiser4_key * new_first);
121 int kill_units_extent(coord_t * coord, pos_in_node_t from, pos_in_node_t to,
122 struct carry_kill_data *, reiser4_key * smallest_removed,
123 reiser4_key * new_first);
124 reiser4_key *unit_key_extent(const coord_t *, reiser4_key *);
125 reiser4_key *max_unit_key_extent(const coord_t *, reiser4_key *);
126 void print_extent(const char *, coord_t *);
127 int utmost_child_extent(const coord_t * coord, sideof side, jnode ** child);
128 int utmost_child_real_block_extent(const coord_t * coord, sideof side,
129 reiser4_block_nr * block);
130 void item_stat_extent(const coord_t * coord, void *vp);
131 int reiser4_check_extent(const coord_t * coord, const char **error);
133 /* plugin->u.item.s.file.* */
134 ssize_t reiser4_write_extent(struct file *, const char __user *,
135 size_t, loff_t *);
136 int reiser4_read_extent(struct file *, flow_t *, hint_t *);
137 int reiser4_readpage_extent(void *, struct page *);
138 int reiser4_do_readpage_extent(reiser4_extent*, reiser4_block_nr, struct page*);
139 reiser4_key *append_key_extent(const coord_t *, reiser4_key *);
140 void init_coord_extension_extent(uf_coord_t *, loff_t offset);
141 int get_block_address_extent(const coord_t *, sector_t block,
142 sector_t * result);
144 /* these are used in flush.c
145 FIXME-VS: should they be somewhere in item_plugin? */
146 int allocate_extent_item_in_place(coord_t *, lock_handle *, flush_pos_t * pos);
147 int allocate_and_copy_extent(znode * left, coord_t * right, flush_pos_t * pos,
148 reiser4_key * stop_key);
150 int extent_is_unallocated(const coord_t * item); /* True if this extent is unallocated (i.e., not a hole, not allocated). */
151 __u64 extent_unit_index(const coord_t * item); /* Block offset of this unit. */
152 __u64 extent_unit_width(const coord_t * item); /* Number of blocks in this unit. */
154 /* plugin->u.item.f. */
155 int reiser4_scan_extent(flush_scan * scan);
156 extern int key_by_offset_extent(struct inode *, loff_t, reiser4_key *);
158 reiser4_item_data *init_new_extent(reiser4_item_data * data, void *ext_unit,
159 int nr_extents);
160 reiser4_block_nr reiser4_extent_size(const coord_t * coord, pos_in_node_t nr);
161 extent_state state_of_extent(reiser4_extent * ext);
162 void reiser4_set_extent(reiser4_extent *, reiser4_block_nr start,
163 reiser4_block_nr width);
164 int reiser4_update_extent(struct inode *, jnode *, loff_t pos,
165 int *plugged_hole);
167 #include "../../coord.h"
168 #include "../../lock.h"
169 #include "../../tap.h"
171 struct replace_handle {
172 /* these are to be set before calling reiser4_replace_extent */
173 coord_t *coord;
174 lock_handle *lh;
175 reiser4_key key;
176 reiser4_key *pkey;
177 reiser4_extent overwrite;
178 reiser4_extent new_extents[2];
179 int nr_new_extents;
180 unsigned flags;
182 /* these are used by reiser4_replace_extent */
183 reiser4_item_data item;
184 coord_t coord_after;
185 lock_handle lh_after;
186 tap_t watch;
187 reiser4_key paste_key;
188 #if REISER4_DEBUG
189 reiser4_extent orig_ext;
190 reiser4_key tmp;
191 #endif
194 /* this structure is kmalloced before calling make_extent to avoid excessive
195 stack consumption on plug_hole->reiser4_replace_extent */
196 struct make_extent_handle {
197 uf_coord_t *uf_coord;
198 reiser4_block_nr blocknr;
199 int created;
200 struct inode *inode;
201 union {
202 struct {
203 } append;
204 struct replace_handle replace;
205 } u;
208 int reiser4_replace_extent(struct replace_handle *,
209 int return_inserted_position);
210 lock_handle *znode_lh(znode *);
212 /* the reiser4 repacker support */
213 struct repacker_cursor;
214 extern int process_extent_backward_for_repacking(tap_t *,
215 struct repacker_cursor *);
216 extern int mark_extent_for_repacking(tap_t *, int);
218 #define coord_by_uf_coord(uf_coord) (&((uf_coord)->coord))
219 #define ext_coord_by_uf_coord(uf_coord) (&((uf_coord)->extension.extent))
221 /* __REISER4_EXTENT_H__ */
222 #endif
224 Local variables:
225 c-indentation-style: "K&R"
226 mode-name: "LC"
227 c-basic-offset: 8
228 tab-width: 8
229 fill-column: 120
230 End: