udf_subr.h revision 1.15 1 1.15 reinoud /* $NetBSD: udf_subr.h,v 1.15 2009/06/24 17:09:13 reinoud Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.5 reinoud * Copyright (c) 2006, 2008 Reinoud Zandijk
5 1.1 reinoud * All rights reserved.
6 1.1 reinoud *
7 1.1 reinoud * Redistribution and use in source and binary forms, with or without
8 1.1 reinoud * modification, are permitted provided that the following conditions
9 1.1 reinoud * are met:
10 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
11 1.1 reinoud * notice, this list of conditions and the following disclaimer.
12 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
14 1.1 reinoud * documentation and/or other materials provided with the distribution.
15 1.1 reinoud *
16 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 reinoud *
27 1.1 reinoud */
28 1.1 reinoud
29 1.3 reinoud #ifndef _FS_UDF_UDF_SUBR_H_
30 1.3 reinoud #define _FS_UDF_UDF_SUBR_H_
31 1.1 reinoud
32 1.5 reinoud /* handies */
33 1.5 reinoud #define VFSTOUDF(mp) ((struct udf_mount *)mp->mnt_data)
34 1.5 reinoud
35 1.5 reinoud
36 1.1 reinoud /* device information updating */
37 1.1 reinoud int udf_update_trackinfo(struct udf_mount *ump, struct mmc_trackinfo *trackinfo);
38 1.1 reinoud int udf_update_discinfo(struct udf_mount *ump);
39 1.5 reinoud int udf_search_tracks(struct udf_mount *ump, struct udf_args *args,
40 1.5 reinoud int *first_tracknr, int *last_tracknr);
41 1.5 reinoud int udf_search_writing_tracks(struct udf_mount *ump);
42 1.5 reinoud int udf_setup_writeparams(struct udf_mount *ump);
43 1.5 reinoud int udf_synchronise_caches(struct udf_mount *ump);
44 1.1 reinoud
45 1.5 reinoud /* tags operations */
46 1.5 reinoud int udf_fidsize(struct fileid_desc *fid);
47 1.1 reinoud int udf_check_tag(void *blob);
48 1.1 reinoud int udf_check_tag_payload(void *blob, uint32_t max_length);
49 1.5 reinoud void udf_validate_tag_sum(void *blob);
50 1.5 reinoud void udf_validate_tag_and_crc_sums(void *blob);
51 1.1 reinoud int udf_tagsize(union dscrptr *dscr, uint32_t udf_sector_size);
52 1.1 reinoud
53 1.5 reinoud /* read/write descriptors */
54 1.13 reinoud int udf_read_phys_sectors(struct udf_mount *ump, int what, void *blob,
55 1.13 reinoud uint32_t start, uint32_t sectors);
56 1.13 reinoud int udf_write_phys_sectors(struct udf_mount *ump, int what, void *blob,
57 1.13 reinoud uint32_t start, uint32_t sectors);
58 1.5 reinoud int udf_read_phys_dscr(
59 1.1 reinoud struct udf_mount *ump,
60 1.1 reinoud uint32_t sector,
61 1.1 reinoud struct malloc_type *mtype, /* where to allocate */
62 1.1 reinoud union dscrptr **dstp); /* out */
63 1.1 reinoud
64 1.5 reinoud int udf_write_phys_dscr_sync(struct udf_mount *ump, struct udf_node *udf_node,
65 1.5 reinoud int what, union dscrptr *dscr,
66 1.5 reinoud uint32_t sector, uint32_t logsector);
67 1.5 reinoud int udf_write_phys_dscr_async(struct udf_mount *ump, struct udf_node *udf_node,
68 1.5 reinoud int what, union dscrptr *dscr,
69 1.5 reinoud uint32_t sector, uint32_t logsector,
70 1.5 reinoud void (*dscrwr_callback)(struct buf *));
71 1.5 reinoud
72 1.5 reinoud /* read/write node descriptors */
73 1.5 reinoud int udf_create_logvol_dscr(struct udf_mount *ump, struct udf_node *udf_node,
74 1.5 reinoud struct long_ad *icb, union dscrptr **dscrptr);
75 1.5 reinoud void udf_free_logvol_dscr(struct udf_mount *ump, struct long_ad *icb_loc,
76 1.5 reinoud void *dscr);
77 1.5 reinoud int udf_read_logvol_dscr(struct udf_mount *ump, struct long_ad *icb,
78 1.5 reinoud union dscrptr **dscrptr);
79 1.5 reinoud int udf_write_logvol_dscr(struct udf_node *udf_node, union dscrptr *dscr,
80 1.5 reinoud struct long_ad *icb, int waitfor);
81 1.5 reinoud
82 1.1 reinoud
83 1.1 reinoud /* volume descriptors readers and checkers */
84 1.5 reinoud int udf_read_anchors(struct udf_mount *ump);
85 1.1 reinoud int udf_read_vds_space(struct udf_mount *ump);
86 1.5 reinoud int udf_process_vds(struct udf_mount *ump);
87 1.5 reinoud int udf_read_vds_tables(struct udf_mount *ump);
88 1.5 reinoud int udf_read_rootdirs(struct udf_mount *ump);
89 1.5 reinoud
90 1.5 reinoud /* open/close and sync volumes */
91 1.5 reinoud int udf_open_logvol(struct udf_mount *ump);
92 1.5 reinoud int udf_close_logvol(struct udf_mount *ump, int mntflags);
93 1.5 reinoud int udf_writeout_vat(struct udf_mount *ump);
94 1.10 reinoud int udf_write_physical_partition_spacetables(struct udf_mount *ump, int waitfor);
95 1.11 reinoud int udf_write_metadata_partition_spacetable(struct udf_mount *ump, int waitfor);
96 1.5 reinoud void udf_do_sync(struct udf_mount *ump, kauth_cred_t cred, int waitfor);
97 1.1 reinoud
98 1.1 reinoud /* translation services */
99 1.5 reinoud int udf_translate_vtop(struct udf_mount *ump, struct long_ad *icb_loc,
100 1.5 reinoud uint32_t *lb_numres, uint32_t *extres);
101 1.11 reinoud void udf_translate_vtop_list(struct udf_mount *ump, uint32_t sectors,
102 1.11 reinoud uint16_t vpart_num, uint64_t *lmapping, uint64_t *pmapping);
103 1.5 reinoud int udf_translate_file_extent(struct udf_node *node,
104 1.5 reinoud uint32_t from, uint32_t num_lb, uint64_t *map);
105 1.5 reinoud void udf_get_adslot(struct udf_node *udf_node, int slot, struct long_ad *icb, int *eof);
106 1.8 reinoud int udf_append_adslot(struct udf_node *udf_node, int *slot, struct long_ad *icb);
107 1.5 reinoud
108 1.5 reinoud int udf_vat_read(struct udf_node *vat_node, uint8_t *blob, int size, uint32_t offset);
109 1.5 reinoud int udf_vat_write(struct udf_node *vat_node, uint8_t *blob, int size, uint32_t offset);
110 1.5 reinoud
111 1.5 reinoud /* disc allocation */
112 1.15 reinoud int udf_get_c_type(struct udf_node *udf_node);
113 1.15 reinoud int udf_get_record_vpart(struct udf_mount *ump, int udf_c_type);
114 1.15 reinoud void udf_do_reserve_space(struct udf_mount *ump, struct udf_node *udf_node, uint16_t vpart_num, uint32_t num_lb);
115 1.15 reinoud void udf_do_unreserve_space(struct udf_mount *ump, struct udf_node *udf_node, uint16_t vpart_num, uint32_t num_lb);
116 1.15 reinoud int udf_reserve_space(struct udf_mount *ump, struct udf_node *udf_node, int udf_c_type, uint16_t vpart_num, uint32_t num_lb, int can_fail);
117 1.15 reinoud void udf_cleanup_reservation(struct udf_node *udf_node);
118 1.15 reinoud int udf_allocate_space(struct udf_mount *ump, struct udf_node *udf_node, int udf_c_type, uint16_t vpart_num, uint32_t num_lb, uint64_t *lmapping);
119 1.15 reinoud void udf_free_allocated_space(struct udf_mount *ump, uint32_t lb_num, uint16_t vpart_num, uint32_t num_lb);
120 1.11 reinoud void udf_late_allocate_buf(struct udf_mount *ump, struct buf *buf, uint64_t *lmapping, struct long_ad *node_ad_cpy, uint16_t *vpart_num);
121 1.5 reinoud int udf_grow_node(struct udf_node *node, uint64_t new_size);
122 1.5 reinoud int udf_shrink_node(struct udf_node *node, uint64_t new_size);
123 1.15 reinoud void udf_calc_freespace(struct udf_mount *ump, uint64_t *sizeblks, uint64_t *freeblks);
124 1.1 reinoud
125 1.1 reinoud /* node readers and writers */
126 1.5 reinoud uint64_t udf_advance_uniqueid(struct udf_mount *ump);
127 1.5 reinoud
128 1.5 reinoud #define UDF_LOCK_NODE(udf_node, flag) udf_lock_node(udf_node, (flag), __FILE__, __LINE__)
129 1.5 reinoud #define UDF_UNLOCK_NODE(udf_node, flag) udf_unlock_node(udf_node, (flag))
130 1.5 reinoud void udf_lock_node(struct udf_node *udf_node, int flag, char const *fname, const int lineno);
131 1.5 reinoud void udf_unlock_node(struct udf_node *udf_node, int flag);
132 1.5 reinoud
133 1.1 reinoud int udf_get_node(struct udf_mount *ump, struct long_ad *icbloc, struct udf_node **noderes);
134 1.5 reinoud int udf_writeout_node(struct udf_node *udf_node, int waitfor);
135 1.1 reinoud int udf_dispose_node(struct udf_node *node);
136 1.5 reinoud
137 1.5 reinoud /* node ops */
138 1.5 reinoud int udf_resize_node(struct udf_node *node, uint64_t new_size, int *extended);
139 1.5 reinoud int udf_extattr_search_intern(struct udf_node *node, uint32_t sattr, char const *sattrname, uint32_t *offsetp, uint32_t *lengthp);
140 1.5 reinoud
141 1.5 reinoud /* node data buffer read/write */
142 1.1 reinoud void udf_read_filebuf(struct udf_node *node, struct buf *buf);
143 1.5 reinoud void udf_write_filebuf(struct udf_node *node, struct buf *buf);
144 1.5 reinoud void udf_fixup_fid_block(uint8_t *blob, int lb_size, int rfix_pos, int max_rfix_pos, uint32_t lb_num);
145 1.5 reinoud void udf_fixup_internal_extattr(uint8_t *blob, uint32_t lb_num);
146 1.5 reinoud void udf_fixup_node_internals(struct udf_mount *ump, uint8_t *blob, int udf_c_type);
147 1.5 reinoud
148 1.5 reinoud /* device strategy */
149 1.5 reinoud void udf_discstrat_init(struct udf_mount *ump);
150 1.5 reinoud void udf_discstrat_finish(struct udf_mount *ump);
151 1.5 reinoud void udf_discstrat_queuebuf(struct udf_mount *ump, struct buf *nestbuf);
152 1.5 reinoud
153 1.5 reinoud /* structure writers */
154 1.5 reinoud int udf_write_terminator(struct udf_mount *ump, uint32_t sector);
155 1.5 reinoud
156 1.5 reinoud /* structure creators */
157 1.8 reinoud void udf_inittag(struct udf_mount *ump, struct desc_tag *tag, int tagid, uint32_t sector);
158 1.5 reinoud void udf_set_regid(struct regid *regid, char const *name);
159 1.5 reinoud void udf_add_domain_regid(struct udf_mount *ump, struct regid *regid);
160 1.5 reinoud void udf_add_udf_regid(struct udf_mount *ump, struct regid *regid);
161 1.5 reinoud void udf_add_impl_regid(struct udf_mount *ump, struct regid *regid);
162 1.5 reinoud void udf_add_app_regid(struct udf_mount *ump, struct regid *regid);
163 1.5 reinoud
164 1.5 reinoud /* directory operations and helpers */
165 1.5 reinoud void udf_osta_charset(struct charspec *charspec);
166 1.5 reinoud int udf_read_fid_stream(struct vnode *vp, uint64_t *offset, struct fileid_desc *fid, struct dirent *dirent);
167 1.9 reinoud int udf_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen, struct long_ad *icb_loc, int *found);
168 1.5 reinoud int udf_create_node(struct vnode *dvp, struct vnode **vpp, struct vattr *vap, struct componentname *cnp);
169 1.5 reinoud void udf_delete_node(struct udf_node *udf_node);
170 1.5 reinoud
171 1.5 reinoud int udf_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred);
172 1.5 reinoud int udf_dir_detach(struct udf_mount *ump, struct udf_node *dir_node, struct udf_node *udf_node, struct componentname *cnp);
173 1.5 reinoud int udf_dir_attach(struct udf_mount *ump, struct udf_node *dir_node, struct udf_node *udf_node, struct vattr *vap, struct componentname *cnp);
174 1.14 reinoud int udf_dir_update_rootentry(struct udf_mount *ump, struct udf_node *dir_node, struct udf_node *new_parent_node);
175 1.5 reinoud
176 1.5 reinoud /* update and times */
177 1.5 reinoud void udf_add_to_dirtylist(struct udf_node *udf_node);
178 1.5 reinoud void udf_remove_from_dirtylist(struct udf_node *udf_node);
179 1.5 reinoud void udf_itimes(struct udf_node *udf_node, struct timespec *acc,
180 1.7 reinoud struct timespec *mod, struct timespec *birth);
181 1.5 reinoud int udf_update(struct vnode *node, struct timespec *acc,
182 1.7 reinoud struct timespec *mod, struct timespec *birth, int updflags);
183 1.5 reinoud
184 1.5 reinoud /* helpers and converters */
185 1.5 reinoud long udf_calchash(struct long_ad *icbptr); /* for `inode' numbering */
186 1.5 reinoud uint32_t udf_getaccessmode(struct udf_node *node);
187 1.5 reinoud void udf_setaccessmode(struct udf_node *udf_node, mode_t mode);
188 1.5 reinoud void udf_getownership(struct udf_node *udf_node, uid_t *uidp, gid_t *gidp);
189 1.5 reinoud void udf_setownership(struct udf_node *udf_node, uid_t uid, gid_t gid);
190 1.1 reinoud
191 1.6 reinoud void udf_to_unix_name(char *result, int result_len, char *id, int len, struct charspec *chsp);
192 1.5 reinoud void unix_to_udf_name(char *result, uint8_t *result_len, char const *name, int name_len, struct charspec *chsp);
193 1.5 reinoud
194 1.5 reinoud void udf_timestamp_to_timespec(struct udf_mount *ump, struct timestamp *timestamp, struct timespec *timespec);
195 1.5 reinoud void udf_timespec_to_timestamp(struct timespec *timespec, struct timestamp *timestamp);
196 1.1 reinoud
197 1.1 reinoud /* vnode operations */
198 1.1 reinoud int udf_inactive(void *v);
199 1.1 reinoud int udf_reclaim(void *v);
200 1.1 reinoud int udf_readdir(void *v);
201 1.1 reinoud int udf_getattr(void *v);
202 1.1 reinoud int udf_setattr(void *v);
203 1.1 reinoud int udf_pathconf(void *v);
204 1.1 reinoud int udf_open(void *v);
205 1.1 reinoud int udf_close(void *v);
206 1.1 reinoud int udf_access(void *v);
207 1.1 reinoud int udf_read(void *v);
208 1.1 reinoud int udf_write(void *v);
209 1.1 reinoud int udf_trivial_bmap(void *v);
210 1.5 reinoud int udf_vfsstrategy(void *v);
211 1.1 reinoud int udf_lookup(void *v);
212 1.1 reinoud int udf_create(void *v);
213 1.1 reinoud int udf_mknod(void *v);
214 1.1 reinoud int udf_link(void *);
215 1.1 reinoud int udf_symlink(void *v);
216 1.1 reinoud int udf_readlink(void *v);
217 1.1 reinoud int udf_rename(void *v);
218 1.1 reinoud int udf_remove(void *v);
219 1.1 reinoud int udf_mkdir(void *v);
220 1.1 reinoud int udf_rmdir(void *v);
221 1.1 reinoud int udf_fsync(void *v);
222 1.1 reinoud int udf_advlock(void *v);
223 1.1 reinoud
224 1.3 reinoud #endif /* !_FS_UDF_UDF_SUBR_H_ */
225