nilfs_subr.h revision 1.2 1 /* $NetBSD: nilfs_subr.h,v 1.2 2014/10/15 09:03:53 hannken Exp $ */
2
3 /*
4 * Copyright (c) 2008, 2009 Reinoud Zandijk
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #ifndef _FS_NILFS_NILFS_SUBR_H_
30 #define _FS_NILFS_NILFS_SUBR_H_
31
32 /* handies */
33 #define VFSTONILFS(mp) ((struct nilfs_mount *)mp->mnt_data)
34
35 /* basic calculators */
36 uint64_t nilfs_get_segnum_of_block(struct nilfs_device *nilfsdev, uint64_t blocknr);
37 void nilfs_get_segment_range(struct nilfs_device *nilfsdev, uint64_t segnum,
38 uint64_t *seg_start, uint64_t *seg_end);
39 void nilfs_calc_mdt_consts(struct nilfs_device *nilfsdev,
40 struct nilfs_mdt *mdt, int entry_size);
41 uint32_t crc32_le(uint32_t crc, const uint8_t *buf, size_t len);
42
43 /* log reading / volume helpers */
44 int nilfs_get_segment_log(struct nilfs_device *nilfsdev, uint64_t *blocknr,
45 uint64_t *offset, struct buf **bpp, int len, void *blob);
46 void nilfs_search_super_root(struct nilfs_device *nilfsdev);
47
48 /* reading */
49 int nilfs_bread(struct nilfs_node *node, uint64_t blocknr, struct kauth_cred *cred,
50 int flags, struct buf **bpp);
51
52 /* btree operations */
53 int nilfs_btree_nlookup(struct nilfs_node *node, uint64_t from, uint64_t blks, uint64_t *l2vmap);
54
55 /* vtop operations */
56 int nilfs_nvtop(struct nilfs_node *node, uint64_t blks, uint64_t *l2vmap, uint64_t *v2pmap);
57
58 /* node action implementators */
59 void nilfs_deregister_node(struct nilfs_node *);
60 int nilfs_get_node(struct mount *mp, uint64_t ino, struct vnode **vpp);
61 int nilfs_get_node_raw(struct nilfs_device *nilfsdev, struct nilfs_mount *ump, uint64_t ino, struct nilfs_inode *inode, struct nilfs_node **nodep);
62 void nilfs_dispose_node(struct nilfs_node **node);
63
64 int nilfs_grow_node(struct nilfs_node *node, uint64_t new_size);
65 int nilfs_shrink_node(struct nilfs_node *node, uint64_t new_size);
66 void nilfs_itimes(struct nilfs_node *nilfs_node, struct timespec *acc,
67 struct timespec *mod, struct timespec *birth);
68 int nilfs_update(struct vnode *node, struct timespec *acc,
69 struct timespec *mod, struct timespec *birth, int updflags);
70
71 /* return vpp? */
72 int nilfs_lookup_name_in_dir(struct vnode *dvp, const char *name, int namelen, uint64_t *ino, int *found);
73 int nilfs_create_node(struct vnode *dvp, struct vnode **vpp, struct vattr *vap, struct componentname *cnp);
74 void nilfs_delete_node(struct nilfs_node *nilfs_node);
75
76 int nilfs_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred);
77 int nilfs_dir_detach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct componentname *cnp);
78 int nilfs_dir_attach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct vattr *vap, struct componentname *cnp);
79
80
81 /* vnode operations */
82 int nilfs_inactive(void *v);
83 int nilfs_reclaim(void *v);
84 int nilfs_readdir(void *v);
85 int nilfs_getattr(void *v);
86 int nilfs_setattr(void *v);
87 int nilfs_pathconf(void *v);
88 int nilfs_open(void *v);
89 int nilfs_close(void *v);
90 int nilfs_access(void *v);
91 int nilfs_read(void *v);
92 int nilfs_write(void *v);
93 int nilfs_trivial_bmap(void *v);
94 int nilfs_vfsstrategy(void *v);
95 int nilfs_lookup(void *v);
96 int nilfs_create(void *v);
97 int nilfs_mknod(void *v);
98 int nilfs_link(void *);
99 int nilfs_symlink(void *v);
100 int nilfs_readlink(void *v);
101 int nilfs_rename(void *v);
102 int nilfs_remove(void *v);
103 int nilfs_mkdir(void *v);
104 int nilfs_rmdir(void *v);
105 int nilfs_fsync(void *v);
106 int nilfs_advlock(void *v);
107
108 #endif /* !_FS_NILFS_NILFS_SUBR_H_ */
109
110 #if 0
111 /* device information updating */
112 int nilfs_update_trackinfo(struct nilfs_mount *ump, struct mmc_trackinfo *trackinfo);
113 int nilfs_update_discinfo(struct nilfs_mount *ump);
114 int nilfs_search_tracks(struct nilfs_mount *ump, struct nilfs_args *args,
115 int *first_tracknr, int *last_tracknr);
116 int nilfs_search_writing_tracks(struct nilfs_mount *ump);
117 int nilfs_setup_writeparams(struct nilfs_mount *ump);
118 int nilfs_synchronise_caches(struct nilfs_mount *ump);
119
120 /* tags operations */
121 int nilfs_fidsize(struct fileid_desc *fid);
122 int nilfs_check_tag(void *blob);
123 int nilfs_check_tag_payload(void *blob, uint32_t max_length);
124 void nilfs_validate_tag_sum(void *blob);
125 void nilfs_validate_tag_and_crc_sums(void *blob);
126 int nilfs_tagsize(union dscrptr *dscr, uint32_t nilfs_sector_size);
127
128 /* read/write descriptors */
129 int nilfs_read_phys_dscr(
130 struct nilfs_mount *ump,
131 uint32_t sector,
132 struct malloc_type *mtype, /* where to allocate */
133 union dscrptr **dstp); /* out */
134
135 int nilfs_write_phys_dscr_sync(struct nilfs_mount *ump, struct nilfs_node *nilfs_node,
136 int what, union dscrptr *dscr,
137 uint32_t sector, uint32_t logsector);
138 int nilfs_write_phys_dscr_async(struct nilfs_mount *ump, struct nilfs_node *nilfs_node,
139 int what, union dscrptr *dscr,
140 uint32_t sector, uint32_t logsector,
141 void (*dscrwr_callback)(struct buf *));
142
143 /* read/write node descriptors */
144 int nilfs_create_logvol_dscr(struct nilfs_mount *ump, struct nilfs_node *nilfs_node,
145 struct long_ad *icb, union dscrptr **dscrptr);
146 void nilfs_free_logvol_dscr(struct nilfs_mount *ump, struct long_ad *icb_loc,
147 void *dscr);
148 int nilfs_read_logvol_dscr(struct nilfs_mount *ump, struct long_ad *icb,
149 union dscrptr **dscrptr);
150 int nilfs_write_logvol_dscr(struct nilfs_node *nilfs_node, union dscrptr *dscr,
151 struct long_ad *icb, int waitfor);
152
153
154 /* volume descriptors readers and checkers */
155 int nilfs_read_anchors(struct nilfs_mount *ump);
156 int nilfs_read_vds_space(struct nilfs_mount *ump);
157 int nilfs_process_vds(struct nilfs_mount *ump);
158 int nilfs_read_vds_tables(struct nilfs_mount *ump);
159 int nilfs_read_rootdirs(struct nilfs_mount *ump);
160
161 /* open/close and sync volumes */
162 int nilfs_open_logvol(struct nilfs_mount *ump);
163 int nilfs_close_logvol(struct nilfs_mount *ump, int mntflags);
164 int nilfs_writeout_vat(struct nilfs_mount *ump);
165 int nilfs_write_physical_partition_spacetables(struct nilfs_mount *ump, int waitfor);
166 int nilfs_write_metadata_partition_spacetable(struct nilfs_mount *ump, int waitfor);
167 void nilfs_do_sync(struct nilfs_mount *ump, kauth_cred_t cred, int waitfor);
168
169 /* translation services */
170 int nilfs_translate_vtop(struct nilfs_mount *ump, struct long_ad *icb_loc,
171 uint32_t *lb_numres, uint32_t *extres);
172 void nilfs_translate_vtop_list(struct nilfs_mount *ump, uint32_t sectors,
173 uint16_t vpart_num, uint64_t *lmapping, uint64_t *pmapping);
174 int nilfs_translate_file_extent(struct nilfs_node *node,
175 uint32_t from, uint32_t num_lb, uint64_t *map);
176 void nilfs_get_adslot(struct nilfs_node *nilfs_node, int slot, struct long_ad *icb, int *eof);
177 int nilfs_append_adslot(struct nilfs_node *nilfs_node, int *slot, struct long_ad *icb);
178
179 int nilfs_vat_read(struct nilfs_node *vat_node, uint8_t *blob, int size, uint32_t offset);
180 int nilfs_vat_write(struct nilfs_node *vat_node, uint8_t *blob, int size, uint32_t offset);
181
182 /* disc allocation */
183 void nilfs_late_allocate_buf(struct nilfs_mount *ump, struct buf *buf, uint64_t *lmapping, struct long_ad *node_ad_cpy, uint16_t *vpart_num);
184 void nilfs_free_allocated_space(struct nilfs_mount *ump, uint32_t lb_num, uint16_t vpart_num, uint32_t num_lb);
185 int nilfs_pre_allocate_space(struct nilfs_mount *ump, int nilfs_c_type, uint32_t num_lb, uint16_t vpartnr, uint64_t *lmapping);
186 int nilfs_grow_node(struct nilfs_node *node, uint64_t new_size);
187 int nilfs_shrink_node(struct nilfs_node *node, uint64_t new_size);
188
189 /* node readers and writers */
190 uint64_t nilfs_advance_uniqueid(struct nilfs_mount *ump);
191
192 #define NILFS_LOCK_NODE(nilfs_node, flag) nilfs_lock_node(nilfs_node, (flag), __FILE__, __LINE__)
193 #define NILFS_UNLOCK_NODE(nilfs_node, flag) nilfs_unlock_node(nilfs_node, (flag))
194 void nilfs_lock_node(struct nilfs_node *nilfs_node, int flag, char const *fname, const int lineno);
195 void nilfs_unlock_node(struct nilfs_node *nilfs_node, int flag);
196
197 int nilfs_get_node(struct nilfs_mount *ump, struct long_ad *icbloc, struct nilfs_node **noderes);
198 int nilfs_writeout_node(struct nilfs_node *nilfs_node, int waitfor);
199 int nilfs_dispose_node(struct nilfs_node *node);
200
201 /* node ops */
202 int nilfs_resize_node(struct nilfs_node *node, uint64_t new_size, int *extended);
203 int nilfs_extattr_search_intern(struct nilfs_node *node, uint32_t sattr, char const *sattrname, uint32_t *offsetp, uint32_t *lengthp);
204
205 /* node data buffer read/write */
206 void nilfs_read_filebuf(struct nilfs_node *node, struct buf *buf);
207 void nilfs_write_filebuf(struct nilfs_node *node, struct buf *buf);
208 void nilfs_fixup_fid_block(uint8_t *blob, int lb_size, int rfix_pos, int max_rfix_pos, uint32_t lb_num);
209 void nilfs_fixup_internal_extattr(uint8_t *blob, uint32_t lb_num);
210 void nilfs_fixup_node_internals(struct nilfs_mount *ump, uint8_t *blob, int nilfs_c_type);
211
212 /* device strategy */
213 void nilfs_discstrat_init(struct nilfs_mount *ump);
214 void nilfs_discstrat_finish(struct nilfs_mount *ump);
215 void nilfs_discstrat_queuebuf(struct nilfs_mount *ump, struct buf *nestbuf);
216
217 /* structure writers */
218 int nilfs_write_terminator(struct nilfs_mount *ump, uint32_t sector);
219
220 /* structure creators */
221 void nilfs_inittag(struct nilfs_mount *ump, struct desc_tag *tag, int tagid, uint32_t sector);
222 void nilfs_set_regid(struct regid *regid, char const *name);
223 void nilfs_add_domain_regid(struct nilfs_mount *ump, struct regid *regid);
224 void nilfs_add_nilfs_regid(struct nilfs_mount *ump, struct regid *regid);
225 void nilfs_add_impl_regid(struct nilfs_mount *ump, struct regid *regid);
226 void nilfs_add_app_regid(struct nilfs_mount *ump, struct regid *regid);
227
228 /* directory operations and helpers */
229 void nilfs_osta_charset(struct charspec *charspec);
230 int nilfs_read_fid_stream(struct vnode *vp, uint64_t *offset, struct fileid_desc *fid, struct dirent *dirent);
231 int nilfs_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen, struct long_ad *icb_loc, int *found);
232 int nilfs_create_node(struct vnode *dvp, struct vnode **vpp, struct vattr *vap, struct componentname *cnp);
233 void nilfs_delete_node(struct nilfs_node *nilfs_node);
234
235 int nilfs_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred);
236 int nilfs_dir_detach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct componentname *cnp);
237 int nilfs_dir_attach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct vattr *vap, struct componentname *cnp);
238
239 /* update and times */
240 void nilfs_add_to_dirtylist(struct nilfs_node *nilfs_node);
241 void nilfs_remove_from_dirtylist(struct nilfs_node *nilfs_node);
242 void nilfs_itimes(struct nilfs_node *nilfs_node, struct timespec *acc,
243 struct timespec *mod, struct timespec *birth);
244 int nilfs_update(struct vnode *node, struct timespec *acc,
245 struct timespec *mod, struct timespec *birth, int updflags);
246
247 /* helpers and converters */
248 long nilfs_calchash(struct long_ad *icbptr); /* for `inode' numbering */
249 uint32_t nilfs_getaccessmode(struct nilfs_node *node);
250 void nilfs_setaccessmode(struct nilfs_node *nilfs_node, mode_t mode);
251 void nilfs_getownership(struct nilfs_node *nilfs_node, uid_t *uidp, gid_t *gidp);
252 void nilfs_setownership(struct nilfs_node *nilfs_node, uid_t uid, gid_t gid);
253
254 void nilfs_to_unix_name(char *result, int result_len, char *id, int len, struct charspec *chsp);
255 void unix_to_nilfs_name(char *result, uint8_t *result_len, char const *name, int name_len, struct charspec *chsp);
256
257 void nilfs_timestamp_to_timespec(struct nilfs_mount *ump, struct timestamp *timestamp, struct timespec *timespec);
258 void nilfs_timespec_to_timestamp(struct timespec *timespec, struct timestamp *timestamp);
259 #endif
260