xref: /netbsd-src/sys/fs/udf/udf_subr.h (revision b5677b36047b601b9addaaa494a58ceae82c2a6c)
1 /* $NetBSD: udf_subr.h,v 1.13 2009/02/08 19:14:52 reinoud Exp $ */
2 
3 /*
4  * Copyright (c) 2006, 2008 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_UDF_UDF_SUBR_H_
30 #define _FS_UDF_UDF_SUBR_H_
31 
32 /* handies */
33 #define	VFSTOUDF(mp)	((struct udf_mount *)mp->mnt_data)
34 
35 
36 /* device information updating */
37 int udf_update_trackinfo(struct udf_mount *ump, struct mmc_trackinfo *trackinfo);
38 int udf_update_discinfo(struct udf_mount *ump);
39 int udf_search_tracks(struct udf_mount *ump, struct udf_args *args,
40 		  int *first_tracknr, int *last_tracknr);
41 int udf_search_writing_tracks(struct udf_mount *ump);
42 int udf_setup_writeparams(struct udf_mount *ump);
43 int udf_synchronise_caches(struct udf_mount *ump);
44 
45 /* tags operations */
46 int udf_fidsize(struct fileid_desc *fid);
47 int udf_check_tag(void *blob);
48 int udf_check_tag_payload(void *blob, uint32_t max_length);
49 void udf_validate_tag_sum(void *blob);
50 void udf_validate_tag_and_crc_sums(void *blob);
51 int udf_tagsize(union dscrptr *dscr, uint32_t udf_sector_size);
52 
53 /* read/write descriptors */
54 int udf_read_phys_sectors(struct udf_mount *ump, int what, void *blob,
55 	uint32_t start, uint32_t sectors);
56 int udf_write_phys_sectors(struct udf_mount *ump, int what, void *blob,
57 	uint32_t start, uint32_t sectors);
58 int udf_read_phys_dscr(
59 		struct udf_mount *ump,
60 		uint32_t sector,
61 		struct malloc_type *mtype,		/* where to allocate */
62 		union dscrptr **dstp);			/* out */
63 
64 int udf_write_phys_dscr_sync(struct udf_mount *ump, struct udf_node *udf_node,
65 		int what, union dscrptr *dscr,
66 		uint32_t sector, uint32_t logsector);
67 int udf_write_phys_dscr_async(struct udf_mount *ump, struct udf_node *udf_node,
68 		      int what, union dscrptr *dscr,
69 		      uint32_t sector, uint32_t logsector,
70 		      void (*dscrwr_callback)(struct buf *));
71 
72 /* read/write node descriptors */
73 int udf_create_logvol_dscr(struct udf_mount *ump, struct udf_node *udf_node,
74 	struct long_ad *icb, union dscrptr **dscrptr);
75 void udf_free_logvol_dscr(struct udf_mount *ump, struct long_ad *icb_loc,
76 	void *dscr);
77 int udf_read_logvol_dscr(struct udf_mount *ump, struct long_ad *icb,
78 	union dscrptr **dscrptr);
79 int udf_write_logvol_dscr(struct udf_node *udf_node, union dscrptr *dscr,
80 	struct long_ad *icb, int waitfor);
81 
82 
83 /* volume descriptors readers and checkers */
84 int udf_read_anchors(struct udf_mount *ump);
85 int udf_read_vds_space(struct udf_mount *ump);
86 int udf_process_vds(struct udf_mount *ump);
87 int udf_read_vds_tables(struct udf_mount *ump);
88 int udf_read_rootdirs(struct udf_mount *ump);
89 
90 /* open/close and sync volumes */
91 int udf_open_logvol(struct udf_mount *ump);
92 int udf_close_logvol(struct udf_mount *ump, int mntflags);
93 int udf_writeout_vat(struct udf_mount *ump);
94 int udf_write_physical_partition_spacetables(struct udf_mount *ump, int waitfor);
95 int udf_write_metadata_partition_spacetable(struct udf_mount *ump, int waitfor);
96 void udf_do_sync(struct udf_mount *ump, kauth_cred_t cred, int waitfor);
97 
98 /* translation services */
99 int udf_translate_vtop(struct udf_mount *ump, struct long_ad *icb_loc,
100 		uint32_t *lb_numres, uint32_t *extres);
101 void udf_translate_vtop_list(struct udf_mount *ump, uint32_t sectors,
102 		uint16_t vpart_num, uint64_t *lmapping, uint64_t *pmapping);
103 int udf_translate_file_extent(struct udf_node *node,
104 		uint32_t from, uint32_t num_lb, uint64_t *map);
105 void udf_get_adslot(struct udf_node *udf_node, int slot, struct long_ad *icb, int *eof);
106 int udf_append_adslot(struct udf_node *udf_node, int *slot, struct long_ad *icb);
107 
108 int udf_vat_read(struct udf_node *vat_node, uint8_t *blob, int size, uint32_t offset);
109 int udf_vat_write(struct udf_node *vat_node, uint8_t *blob, int size, uint32_t offset);
110 
111 /* disc allocation */
112 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);
113 void udf_free_allocated_space(struct udf_mount *ump, uint32_t lb_num, uint16_t vpart_num, uint32_t num_lb);
114 int udf_pre_allocate_space(struct udf_mount *ump, int udf_c_type, uint32_t num_lb, uint16_t vpartnr, uint64_t *lmapping);
115 int udf_grow_node(struct udf_node *node, uint64_t new_size);
116 int udf_shrink_node(struct udf_node *node, uint64_t new_size);
117 
118 /* node readers and writers */
119 uint64_t udf_advance_uniqueid(struct udf_mount *ump);
120 
121 #define UDF_LOCK_NODE(udf_node, flag) udf_lock_node(udf_node, (flag), __FILE__, __LINE__)
122 #define UDF_UNLOCK_NODE(udf_node, flag) udf_unlock_node(udf_node, (flag))
123 void udf_lock_node(struct udf_node *udf_node, int flag, char const *fname, const int lineno);
124 void udf_unlock_node(struct udf_node *udf_node, int flag);
125 
126 int udf_get_node(struct udf_mount *ump, struct long_ad *icbloc, struct udf_node **noderes);
127 int udf_writeout_node(struct udf_node *udf_node, int waitfor);
128 int udf_dispose_node(struct udf_node *node);
129 
130 /* node ops */
131 int udf_resize_node(struct udf_node *node, uint64_t new_size, int *extended);
132 int udf_extattr_search_intern(struct udf_node *node, uint32_t sattr, char const *sattrname, uint32_t *offsetp, uint32_t *lengthp);
133 
134 /* node data buffer read/write */
135 void udf_read_filebuf(struct udf_node *node, struct buf *buf);
136 void udf_write_filebuf(struct udf_node *node, struct buf *buf);
137 void udf_fixup_fid_block(uint8_t *blob, int lb_size, int rfix_pos, int max_rfix_pos, uint32_t lb_num);
138 void udf_fixup_internal_extattr(uint8_t *blob, uint32_t lb_num);
139 void udf_fixup_node_internals(struct udf_mount *ump, uint8_t *blob, int udf_c_type);
140 
141 /* device strategy */
142 void udf_discstrat_init(struct udf_mount *ump);
143 void udf_discstrat_finish(struct udf_mount *ump);
144 void udf_discstrat_queuebuf(struct udf_mount *ump, struct buf *nestbuf);
145 
146 /* structure writers */
147 int udf_write_terminator(struct udf_mount *ump, uint32_t sector);
148 
149 /* structure creators */
150 void udf_inittag(struct udf_mount *ump, struct desc_tag *tag, int tagid, uint32_t sector);
151 void udf_set_regid(struct regid *regid, char const *name);
152 void udf_add_domain_regid(struct udf_mount *ump, struct regid *regid);
153 void udf_add_udf_regid(struct udf_mount *ump, struct regid *regid);
154 void udf_add_impl_regid(struct udf_mount *ump, struct regid *regid);
155 void udf_add_app_regid(struct udf_mount *ump, struct regid *regid);
156 
157 /* directory operations and helpers */
158 void udf_osta_charset(struct charspec *charspec);
159 int udf_read_fid_stream(struct vnode *vp, uint64_t *offset, struct fileid_desc *fid, struct dirent *dirent);
160 int udf_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen, struct long_ad *icb_loc, int *found);
161 int udf_create_node(struct vnode *dvp, struct vnode **vpp, struct vattr *vap, struct componentname *cnp);
162 void udf_delete_node(struct udf_node *udf_node);
163 
164 int udf_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred);
165 int udf_dir_detach(struct udf_mount *ump, struct udf_node *dir_node, struct udf_node *udf_node, struct componentname *cnp);
166 int udf_dir_attach(struct udf_mount *ump, struct udf_node *dir_node, struct udf_node *udf_node, struct vattr *vap, struct componentname *cnp);
167 
168 /* update and times */
169 void udf_add_to_dirtylist(struct udf_node *udf_node);
170 void udf_remove_from_dirtylist(struct udf_node *udf_node);
171 void udf_itimes(struct udf_node *udf_node, struct timespec *acc,
172 	struct timespec *mod, struct timespec *birth);
173 int  udf_update(struct vnode *node, struct timespec *acc,
174 	struct timespec *mod, struct timespec *birth, int updflags);
175 
176 /* helpers and converters */
177 long udf_calchash(struct long_ad *icbptr);    /* for `inode' numbering */
178 uint32_t udf_getaccessmode(struct udf_node *node);
179 void udf_setaccessmode(struct udf_node *udf_node, mode_t mode);
180 void udf_getownership(struct udf_node *udf_node, uid_t *uidp, gid_t *gidp);
181 void udf_setownership(struct udf_node *udf_node, uid_t uid, gid_t gid);
182 
183 void udf_to_unix_name(char *result, int result_len, char *id, int len, struct charspec *chsp);
184 void unix_to_udf_name(char *result, uint8_t *result_len, char const *name, int name_len, struct charspec *chsp);
185 
186 void udf_timestamp_to_timespec(struct udf_mount *ump, struct timestamp *timestamp, struct timespec *timespec);
187 void udf_timespec_to_timestamp(struct timespec *timespec, struct timestamp *timestamp);
188 
189 /* vnode operations */
190 int udf_inactive(void *v);
191 int udf_reclaim(void *v);
192 int udf_readdir(void *v);
193 int udf_getattr(void *v);
194 int udf_setattr(void *v);
195 int udf_pathconf(void *v);
196 int udf_open(void *v);
197 int udf_close(void *v);
198 int udf_access(void *v);
199 int udf_read(void *v);
200 int udf_write(void *v);
201 int udf_trivial_bmap(void *v);
202 int udf_vfsstrategy(void *v);
203 int udf_lookup(void *v);
204 int udf_create(void *v);
205 int udf_mknod(void *v);
206 int udf_link(void *);
207 int udf_symlink(void *v);
208 int udf_readlink(void *v);
209 int udf_rename(void *v);
210 int udf_remove(void *v);
211 int udf_mkdir(void *v);
212 int udf_rmdir(void *v);
213 int udf_fsync(void *v);
214 int udf_advlock(void *v);
215 
216 #endif	/* !_FS_UDF_UDF_SUBR_H_ */
217