1*9f988b79SJean-Baptiste Boric /* $NetBSD: udf_readwrite.c,v 1.11 2011/06/12 03:35:55 rmind Exp $ */
2*9f988b79SJean-Baptiste Boric
3*9f988b79SJean-Baptiste Boric /*
4*9f988b79SJean-Baptiste Boric * Copyright (c) 2007, 2008 Reinoud Zandijk
5*9f988b79SJean-Baptiste Boric * All rights reserved.
6*9f988b79SJean-Baptiste Boric *
7*9f988b79SJean-Baptiste Boric * Redistribution and use in source and binary forms, with or without
8*9f988b79SJean-Baptiste Boric * modification, are permitted provided that the following conditions
9*9f988b79SJean-Baptiste Boric * are met:
10*9f988b79SJean-Baptiste Boric * 1. Redistributions of source code must retain the above copyright
11*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer.
12*9f988b79SJean-Baptiste Boric * 2. Redistributions in binary form must reproduce the above copyright
13*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer in the
14*9f988b79SJean-Baptiste Boric * documentation and/or other materials provided with the distribution.
15*9f988b79SJean-Baptiste Boric *
16*9f988b79SJean-Baptiste Boric * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*9f988b79SJean-Baptiste Boric * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*9f988b79SJean-Baptiste Boric * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*9f988b79SJean-Baptiste Boric * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*9f988b79SJean-Baptiste Boric * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21*9f988b79SJean-Baptiste Boric * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22*9f988b79SJean-Baptiste Boric * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23*9f988b79SJean-Baptiste Boric * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*9f988b79SJean-Baptiste Boric * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25*9f988b79SJean-Baptiste Boric * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*9f988b79SJean-Baptiste Boric *
27*9f988b79SJean-Baptiste Boric */
28*9f988b79SJean-Baptiste Boric
29*9f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
30*9f988b79SJean-Baptiste Boric #ifndef lint
31*9f988b79SJean-Baptiste Boric __KERNEL_RCSID(0, "$NetBSD: udf_readwrite.c,v 1.11 2011/06/12 03:35:55 rmind Exp $");
32*9f988b79SJean-Baptiste Boric #endif /* not lint */
33*9f988b79SJean-Baptiste Boric
34*9f988b79SJean-Baptiste Boric
35*9f988b79SJean-Baptiste Boric #if defined(_KERNEL_OPT)
36*9f988b79SJean-Baptiste Boric #include "opt_compat_netbsd.h"
37*9f988b79SJean-Baptiste Boric #endif
38*9f988b79SJean-Baptiste Boric
39*9f988b79SJean-Baptiste Boric #include <sys/param.h>
40*9f988b79SJean-Baptiste Boric #include <sys/systm.h>
41*9f988b79SJean-Baptiste Boric #include <sys/sysctl.h>
42*9f988b79SJean-Baptiste Boric #include <sys/namei.h>
43*9f988b79SJean-Baptiste Boric #include <sys/proc.h>
44*9f988b79SJean-Baptiste Boric #include <sys/kernel.h>
45*9f988b79SJean-Baptiste Boric #include <sys/vnode.h>
46*9f988b79SJean-Baptiste Boric #include <miscfs/genfs/genfs_node.h>
47*9f988b79SJean-Baptiste Boric #include <sys/mount.h>
48*9f988b79SJean-Baptiste Boric #include <sys/buf.h>
49*9f988b79SJean-Baptiste Boric #include <sys/file.h>
50*9f988b79SJean-Baptiste Boric #include <sys/device.h>
51*9f988b79SJean-Baptiste Boric #include <sys/disklabel.h>
52*9f988b79SJean-Baptiste Boric #include <sys/ioctl.h>
53*9f988b79SJean-Baptiste Boric #include <sys/malloc.h>
54*9f988b79SJean-Baptiste Boric #include <sys/dirent.h>
55*9f988b79SJean-Baptiste Boric #include <sys/stat.h>
56*9f988b79SJean-Baptiste Boric #include <sys/conf.h>
57*9f988b79SJean-Baptiste Boric #include <sys/kauth.h>
58*9f988b79SJean-Baptiste Boric #include <sys/kthread.h>
59*9f988b79SJean-Baptiste Boric #include <dev/clock_subr.h>
60*9f988b79SJean-Baptiste Boric
61*9f988b79SJean-Baptiste Boric #include <fs/udf/ecma167-udf.h>
62*9f988b79SJean-Baptiste Boric #include <fs/udf/udf_mount.h>
63*9f988b79SJean-Baptiste Boric
64*9f988b79SJean-Baptiste Boric #include "udf.h"
65*9f988b79SJean-Baptiste Boric #include "udf_subr.h"
66*9f988b79SJean-Baptiste Boric #include "udf_bswap.h"
67*9f988b79SJean-Baptiste Boric
68*9f988b79SJean-Baptiste Boric
69*9f988b79SJean-Baptiste Boric #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
70*9f988b79SJean-Baptiste Boric
71*9f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
72*9f988b79SJean-Baptiste Boric
73*9f988b79SJean-Baptiste Boric void
udf_fixup_fid_block(uint8_t * blob,int lb_size,int rfix_pos,int max_rfix_pos,uint32_t lb_num)74*9f988b79SJean-Baptiste Boric udf_fixup_fid_block(uint8_t *blob, int lb_size,
75*9f988b79SJean-Baptiste Boric int rfix_pos, int max_rfix_pos, uint32_t lb_num)
76*9f988b79SJean-Baptiste Boric {
77*9f988b79SJean-Baptiste Boric struct fileid_desc *fid;
78*9f988b79SJean-Baptiste Boric uint8_t *fid_pos;
79*9f988b79SJean-Baptiste Boric int fid_len, found;
80*9f988b79SJean-Baptiste Boric
81*9f988b79SJean-Baptiste Boric /* needs to be word aligned */
82*9f988b79SJean-Baptiste Boric KASSERT(rfix_pos % 4 == 0);
83*9f988b79SJean-Baptiste Boric
84*9f988b79SJean-Baptiste Boric /* first resync with the FID stream !!! */
85*9f988b79SJean-Baptiste Boric found = 0;
86*9f988b79SJean-Baptiste Boric while (rfix_pos + sizeof(struct desc_tag) <= max_rfix_pos) {
87*9f988b79SJean-Baptiste Boric fid_pos = blob + rfix_pos;
88*9f988b79SJean-Baptiste Boric fid = (struct fileid_desc *) fid_pos;
89*9f988b79SJean-Baptiste Boric if (udf_rw16(fid->tag.id) == TAGID_FID) {
90*9f988b79SJean-Baptiste Boric if (udf_check_tag((union dscrptr *) fid) == 0)
91*9f988b79SJean-Baptiste Boric found = 1;
92*9f988b79SJean-Baptiste Boric }
93*9f988b79SJean-Baptiste Boric if (found)
94*9f988b79SJean-Baptiste Boric break;
95*9f988b79SJean-Baptiste Boric /* try next location; can only be 4 bytes aligned */
96*9f988b79SJean-Baptiste Boric rfix_pos += 4;
97*9f988b79SJean-Baptiste Boric }
98*9f988b79SJean-Baptiste Boric
99*9f988b79SJean-Baptiste Boric /* walk over the fids */
100*9f988b79SJean-Baptiste Boric fid_pos = blob + rfix_pos;
101*9f988b79SJean-Baptiste Boric while (rfix_pos + sizeof(struct desc_tag) <= max_rfix_pos) {
102*9f988b79SJean-Baptiste Boric fid = (struct fileid_desc *) fid_pos;
103*9f988b79SJean-Baptiste Boric if (udf_rw16(fid->tag.id) != TAGID_FID) {
104*9f988b79SJean-Baptiste Boric /* end of FID stream; end of directory or currupted */
105*9f988b79SJean-Baptiste Boric break;
106*9f988b79SJean-Baptiste Boric }
107*9f988b79SJean-Baptiste Boric
108*9f988b79SJean-Baptiste Boric /* update sector number and recalculate checkum */
109*9f988b79SJean-Baptiste Boric fid->tag.tag_loc = udf_rw32(lb_num);
110*9f988b79SJean-Baptiste Boric udf_validate_tag_sum((union dscrptr *) fid);
111*9f988b79SJean-Baptiste Boric
112*9f988b79SJean-Baptiste Boric /* if the FID crosses the memory, we're done! */
113*9f988b79SJean-Baptiste Boric if (rfix_pos + UDF_FID_SIZE >= max_rfix_pos)
114*9f988b79SJean-Baptiste Boric break;
115*9f988b79SJean-Baptiste Boric
116*9f988b79SJean-Baptiste Boric fid_len = udf_fidsize(fid);
117*9f988b79SJean-Baptiste Boric fid_pos += fid_len;
118*9f988b79SJean-Baptiste Boric rfix_pos += fid_len;
119*9f988b79SJean-Baptiste Boric }
120*9f988b79SJean-Baptiste Boric }
121*9f988b79SJean-Baptiste Boric
122*9f988b79SJean-Baptiste Boric
123*9f988b79SJean-Baptiste Boric void
udf_fixup_internal_extattr(uint8_t * blob,uint32_t lb_num)124*9f988b79SJean-Baptiste Boric udf_fixup_internal_extattr(uint8_t *blob, uint32_t lb_num)
125*9f988b79SJean-Baptiste Boric {
126*9f988b79SJean-Baptiste Boric struct desc_tag *tag;
127*9f988b79SJean-Baptiste Boric struct file_entry *fe;
128*9f988b79SJean-Baptiste Boric struct extfile_entry *efe;
129*9f988b79SJean-Baptiste Boric struct extattrhdr_desc *eahdr;
130*9f988b79SJean-Baptiste Boric int l_ea;
131*9f988b79SJean-Baptiste Boric
132*9f988b79SJean-Baptiste Boric /* get information from fe/efe */
133*9f988b79SJean-Baptiste Boric tag = (struct desc_tag *) blob;
134*9f988b79SJean-Baptiste Boric switch (udf_rw16(tag->id)) {
135*9f988b79SJean-Baptiste Boric case TAGID_FENTRY :
136*9f988b79SJean-Baptiste Boric fe = (struct file_entry *) blob;
137*9f988b79SJean-Baptiste Boric l_ea = udf_rw32(fe->l_ea);
138*9f988b79SJean-Baptiste Boric eahdr = (struct extattrhdr_desc *) fe->data;
139*9f988b79SJean-Baptiste Boric break;
140*9f988b79SJean-Baptiste Boric case TAGID_EXTFENTRY :
141*9f988b79SJean-Baptiste Boric efe = (struct extfile_entry *) blob;
142*9f988b79SJean-Baptiste Boric l_ea = udf_rw32(efe->l_ea);
143*9f988b79SJean-Baptiste Boric eahdr = (struct extattrhdr_desc *) efe->data;
144*9f988b79SJean-Baptiste Boric break;
145*9f988b79SJean-Baptiste Boric case TAGID_INDIRECTENTRY :
146*9f988b79SJean-Baptiste Boric case TAGID_ALLOCEXTENT :
147*9f988b79SJean-Baptiste Boric case TAGID_EXTATTR_HDR :
148*9f988b79SJean-Baptiste Boric return;
149*9f988b79SJean-Baptiste Boric default:
150*9f988b79SJean-Baptiste Boric panic("%s: passed bad tag\n", __func__);
151*9f988b79SJean-Baptiste Boric }
152*9f988b79SJean-Baptiste Boric
153*9f988b79SJean-Baptiste Boric /* something recorded here? (why am i called?) */
154*9f988b79SJean-Baptiste Boric if (l_ea == 0)
155*9f988b79SJean-Baptiste Boric return;
156*9f988b79SJean-Baptiste Boric
157*9f988b79SJean-Baptiste Boric #if 0
158*9f988b79SJean-Baptiste Boric /* check extended attribute tag */
159*9f988b79SJean-Baptiste Boric /* TODO XXX what to do when we encounter an error here? */
160*9f988b79SJean-Baptiste Boric error = udf_check_tag(eahdr);
161*9f988b79SJean-Baptiste Boric if (error)
162*9f988b79SJean-Baptiste Boric return; /* for now */
163*9f988b79SJean-Baptiste Boric if (udf_rw16(eahdr->tag.id) != TAGID_EXTATTR_HDR)
164*9f988b79SJean-Baptiste Boric return; /* for now */
165*9f988b79SJean-Baptiste Boric error = udf_check_tag_payload(eahdr, sizeof(struct extattrhdr_desc));
166*9f988b79SJean-Baptiste Boric if (error)
167*9f988b79SJean-Baptiste Boric return; /* for now */
168*9f988b79SJean-Baptiste Boric #endif
169*9f988b79SJean-Baptiste Boric
170*9f988b79SJean-Baptiste Boric DPRINTF(EXTATTR, ("node fixup: found %d bytes of extended attributes\n",
171*9f988b79SJean-Baptiste Boric l_ea));
172*9f988b79SJean-Baptiste Boric
173*9f988b79SJean-Baptiste Boric /* fixup eahdr tag */
174*9f988b79SJean-Baptiste Boric eahdr->tag.tag_loc = udf_rw32(lb_num);
175*9f988b79SJean-Baptiste Boric udf_validate_tag_and_crc_sums((union dscrptr *) eahdr);
176*9f988b79SJean-Baptiste Boric }
177*9f988b79SJean-Baptiste Boric
178*9f988b79SJean-Baptiste Boric
179*9f988b79SJean-Baptiste Boric void
udf_fixup_node_internals(struct udf_mount * ump,uint8_t * blob,int udf_c_type)180*9f988b79SJean-Baptiste Boric udf_fixup_node_internals(struct udf_mount *ump, uint8_t *blob, int udf_c_type)
181*9f988b79SJean-Baptiste Boric {
182*9f988b79SJean-Baptiste Boric struct desc_tag *tag, *sbm_tag;
183*9f988b79SJean-Baptiste Boric struct file_entry *fe;
184*9f988b79SJean-Baptiste Boric struct extfile_entry *efe;
185*9f988b79SJean-Baptiste Boric struct alloc_ext_entry *ext;
186*9f988b79SJean-Baptiste Boric uint32_t lb_size, lb_num;
187*9f988b79SJean-Baptiste Boric uint32_t intern_pos, max_intern_pos;
188*9f988b79SJean-Baptiste Boric int icbflags, addr_type, file_type, intern, has_fids, has_sbm, l_ea;
189*9f988b79SJean-Baptiste Boric
190*9f988b79SJean-Baptiste Boric lb_size = udf_rw32(ump->logical_vol->lb_size);
191*9f988b79SJean-Baptiste Boric /* if its not a node we're done */
192*9f988b79SJean-Baptiste Boric if (udf_c_type != UDF_C_NODE)
193*9f988b79SJean-Baptiste Boric return;
194*9f988b79SJean-Baptiste Boric
195*9f988b79SJean-Baptiste Boric /* NOTE this could also be done in write_internal */
196*9f988b79SJean-Baptiste Boric /* start of a descriptor */
197*9f988b79SJean-Baptiste Boric l_ea = 0;
198*9f988b79SJean-Baptiste Boric has_fids = 0;
199*9f988b79SJean-Baptiste Boric has_sbm = 0;
200*9f988b79SJean-Baptiste Boric intern = 0;
201*9f988b79SJean-Baptiste Boric file_type = 0;
202*9f988b79SJean-Baptiste Boric max_intern_pos = intern_pos = lb_num = 0; /* shut up gcc! */
203*9f988b79SJean-Baptiste Boric
204*9f988b79SJean-Baptiste Boric tag = (struct desc_tag *) blob;
205*9f988b79SJean-Baptiste Boric switch (udf_rw16(tag->id)) {
206*9f988b79SJean-Baptiste Boric case TAGID_FENTRY :
207*9f988b79SJean-Baptiste Boric fe = (struct file_entry *) tag;
208*9f988b79SJean-Baptiste Boric l_ea = udf_rw32(fe->l_ea);
209*9f988b79SJean-Baptiste Boric icbflags = udf_rw16(fe->icbtag.flags);
210*9f988b79SJean-Baptiste Boric addr_type = (icbflags & UDF_ICB_TAG_FLAGS_ALLOC_MASK);
211*9f988b79SJean-Baptiste Boric file_type = fe->icbtag.file_type;
212*9f988b79SJean-Baptiste Boric intern = (addr_type == UDF_ICB_INTERN_ALLOC);
213*9f988b79SJean-Baptiste Boric intern_pos = UDF_FENTRY_SIZE + l_ea;
214*9f988b79SJean-Baptiste Boric max_intern_pos = intern_pos + udf_rw64(fe->inf_len);
215*9f988b79SJean-Baptiste Boric lb_num = udf_rw32(fe->tag.tag_loc);
216*9f988b79SJean-Baptiste Boric break;
217*9f988b79SJean-Baptiste Boric case TAGID_EXTFENTRY :
218*9f988b79SJean-Baptiste Boric efe = (struct extfile_entry *) tag;
219*9f988b79SJean-Baptiste Boric l_ea = udf_rw32(efe->l_ea);
220*9f988b79SJean-Baptiste Boric icbflags = udf_rw16(efe->icbtag.flags);
221*9f988b79SJean-Baptiste Boric addr_type = (icbflags & UDF_ICB_TAG_FLAGS_ALLOC_MASK);
222*9f988b79SJean-Baptiste Boric file_type = efe->icbtag.file_type;
223*9f988b79SJean-Baptiste Boric intern = (addr_type == UDF_ICB_INTERN_ALLOC);
224*9f988b79SJean-Baptiste Boric intern_pos = UDF_EXTFENTRY_SIZE + l_ea;
225*9f988b79SJean-Baptiste Boric max_intern_pos = intern_pos + udf_rw64(efe->inf_len);
226*9f988b79SJean-Baptiste Boric lb_num = udf_rw32(efe->tag.tag_loc);
227*9f988b79SJean-Baptiste Boric break;
228*9f988b79SJean-Baptiste Boric case TAGID_INDIRECTENTRY :
229*9f988b79SJean-Baptiste Boric case TAGID_EXTATTR_HDR :
230*9f988b79SJean-Baptiste Boric break;
231*9f988b79SJean-Baptiste Boric case TAGID_ALLOCEXTENT :
232*9f988b79SJean-Baptiste Boric /* force crclen to 8 for UDF version < 2.01 */
233*9f988b79SJean-Baptiste Boric ext = (struct alloc_ext_entry *) tag;
234*9f988b79SJean-Baptiste Boric if (udf_rw16(ump->logvol_info->min_udf_readver) <= 0x200)
235*9f988b79SJean-Baptiste Boric ext->tag.desc_crc_len = udf_rw16(8);
236*9f988b79SJean-Baptiste Boric break;
237*9f988b79SJean-Baptiste Boric default:
238*9f988b79SJean-Baptiste Boric panic("%s: passed bad tag\n", __func__);
239*9f988b79SJean-Baptiste Boric break;
240*9f988b79SJean-Baptiste Boric }
241*9f988b79SJean-Baptiste Boric
242*9f988b79SJean-Baptiste Boric /* determine what to fix if its internally recorded */
243*9f988b79SJean-Baptiste Boric if (intern) {
244*9f988b79SJean-Baptiste Boric has_fids = (file_type == UDF_ICB_FILETYPE_DIRECTORY) ||
245*9f988b79SJean-Baptiste Boric (file_type == UDF_ICB_FILETYPE_STREAMDIR);
246*9f988b79SJean-Baptiste Boric has_sbm = (file_type == UDF_ICB_FILETYPE_META_BITMAP);
247*9f988b79SJean-Baptiste Boric }
248*9f988b79SJean-Baptiste Boric
249*9f988b79SJean-Baptiste Boric /* fixup internal extended attributes if present */
250*9f988b79SJean-Baptiste Boric if (l_ea)
251*9f988b79SJean-Baptiste Boric udf_fixup_internal_extattr(blob, lb_num);
252*9f988b79SJean-Baptiste Boric
253*9f988b79SJean-Baptiste Boric /* fixup fids lb numbers */
254*9f988b79SJean-Baptiste Boric if (has_fids)
255*9f988b79SJean-Baptiste Boric udf_fixup_fid_block(blob, lb_size, intern_pos,
256*9f988b79SJean-Baptiste Boric max_intern_pos, lb_num);
257*9f988b79SJean-Baptiste Boric
258*9f988b79SJean-Baptiste Boric /* fixup space bitmap descriptor */
259*9f988b79SJean-Baptiste Boric if (has_sbm) {
260*9f988b79SJean-Baptiste Boric sbm_tag = (struct desc_tag *) (blob + intern_pos);
261*9f988b79SJean-Baptiste Boric sbm_tag->tag_loc = tag->tag_loc;
262*9f988b79SJean-Baptiste Boric udf_validate_tag_and_crc_sums((uint8_t *) sbm_tag);
263*9f988b79SJean-Baptiste Boric }
264*9f988b79SJean-Baptiste Boric
265*9f988b79SJean-Baptiste Boric udf_validate_tag_and_crc_sums(blob);
266*9f988b79SJean-Baptiste Boric }
267*9f988b79SJean-Baptiste Boric
268*9f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
269*9f988b79SJean-Baptiste Boric
270*9f988b79SJean-Baptiste Boric /*
271*9f988b79SJean-Baptiste Boric * Set of generic descriptor readers and writers and their helper functions.
272*9f988b79SJean-Baptiste Boric * Descriptors inside `logical space' i.e. inside logically mapped partitions
273*9f988b79SJean-Baptiste Boric * can never be longer than one logical sector.
274*9f988b79SJean-Baptiste Boric *
275*9f988b79SJean-Baptiste Boric * NOTE that these functions *can* be used by the sheduler backends to read
276*9f988b79SJean-Baptiste Boric * node descriptors too.
277*9f988b79SJean-Baptiste Boric *
278*9f988b79SJean-Baptiste Boric * For reading, the size of allocated piece is returned in multiple of sector
279*9f988b79SJean-Baptiste Boric * size due to udf_calc_udf_malloc_size().
280*9f988b79SJean-Baptiste Boric */
281*9f988b79SJean-Baptiste Boric
282*9f988b79SJean-Baptiste Boric
283*9f988b79SJean-Baptiste Boric /* SYNC reading of n blocks from specified sector */
284*9f988b79SJean-Baptiste Boric int
udf_read_phys_sectors(struct udf_mount * ump,int what,void * blob,uint32_t start,uint32_t sectors)285*9f988b79SJean-Baptiste Boric udf_read_phys_sectors(struct udf_mount *ump, int what, void *blob,
286*9f988b79SJean-Baptiste Boric uint32_t start, uint32_t sectors)
287*9f988b79SJean-Baptiste Boric {
288*9f988b79SJean-Baptiste Boric struct buf *buf, *nestbuf;
289*9f988b79SJean-Baptiste Boric uint32_t buf_offset;
290*9f988b79SJean-Baptiste Boric off_t lblkno, rblkno;
291*9f988b79SJean-Baptiste Boric int sector_size = ump->discinfo.sector_size;
292*9f988b79SJean-Baptiste Boric int blks = sector_size / DEV_BSIZE;
293*9f988b79SJean-Baptiste Boric int piece;
294*9f988b79SJean-Baptiste Boric int error;
295*9f988b79SJean-Baptiste Boric
296*9f988b79SJean-Baptiste Boric DPRINTF(READ, ("udf_intbreadn() : sectors = %d, sector_size = %d\n",
297*9f988b79SJean-Baptiste Boric sectors, sector_size));
298*9f988b79SJean-Baptiste Boric buf = getiobuf(ump->devvp, true);
299*9f988b79SJean-Baptiste Boric buf->b_flags = B_READ;
300*9f988b79SJean-Baptiste Boric buf->b_cflags = BC_BUSY; /* needed? */
301*9f988b79SJean-Baptiste Boric buf->b_iodone = NULL;
302*9f988b79SJean-Baptiste Boric buf->b_data = blob;
303*9f988b79SJean-Baptiste Boric buf->b_bcount = sectors * sector_size;
304*9f988b79SJean-Baptiste Boric buf->b_resid = buf->b_bcount;
305*9f988b79SJean-Baptiste Boric buf->b_bufsize = buf->b_bcount;
306*9f988b79SJean-Baptiste Boric buf->b_private = NULL; /* not needed yet */
307*9f988b79SJean-Baptiste Boric BIO_SETPRIO(buf, BPRIO_DEFAULT);
308*9f988b79SJean-Baptiste Boric buf->b_lblkno = buf->b_blkno = buf->b_rawblkno = start * blks;
309*9f988b79SJean-Baptiste Boric buf->b_proc = NULL;
310*9f988b79SJean-Baptiste Boric
311*9f988b79SJean-Baptiste Boric error = 0;
312*9f988b79SJean-Baptiste Boric buf_offset = 0;
313*9f988b79SJean-Baptiste Boric rblkno = start;
314*9f988b79SJean-Baptiste Boric lblkno = 0;
315*9f988b79SJean-Baptiste Boric while ((sectors > 0) && (error == 0)) {
316*9f988b79SJean-Baptiste Boric piece = MIN(MAXPHYS/sector_size, sectors);
317*9f988b79SJean-Baptiste Boric DPRINTF(READ, ("read in %d + %d\n", (uint32_t) rblkno, piece));
318*9f988b79SJean-Baptiste Boric
319*9f988b79SJean-Baptiste Boric nestbuf = getiobuf(NULL, true);
320*9f988b79SJean-Baptiste Boric nestiobuf_setup(buf, nestbuf, buf_offset, piece * sector_size);
321*9f988b79SJean-Baptiste Boric /* nestbuf is B_ASYNC */
322*9f988b79SJean-Baptiste Boric
323*9f988b79SJean-Baptiste Boric /* identify this nestbuf */
324*9f988b79SJean-Baptiste Boric nestbuf->b_lblkno = lblkno;
325*9f988b79SJean-Baptiste Boric
326*9f988b79SJean-Baptiste Boric /* CD shedules on raw blkno */
327*9f988b79SJean-Baptiste Boric nestbuf->b_blkno = rblkno * blks;
328*9f988b79SJean-Baptiste Boric nestbuf->b_proc = NULL;
329*9f988b79SJean-Baptiste Boric nestbuf->b_rawblkno = rblkno * blks;
330*9f988b79SJean-Baptiste Boric nestbuf->b_udf_c_type = what;
331*9f988b79SJean-Baptiste Boric
332*9f988b79SJean-Baptiste Boric udf_discstrat_queuebuf(ump, nestbuf);
333*9f988b79SJean-Baptiste Boric
334*9f988b79SJean-Baptiste Boric lblkno += piece;
335*9f988b79SJean-Baptiste Boric rblkno += piece;
336*9f988b79SJean-Baptiste Boric buf_offset += piece * sector_size;
337*9f988b79SJean-Baptiste Boric sectors -= piece;
338*9f988b79SJean-Baptiste Boric }
339*9f988b79SJean-Baptiste Boric error = biowait(buf);
340*9f988b79SJean-Baptiste Boric putiobuf(buf);
341*9f988b79SJean-Baptiste Boric
342*9f988b79SJean-Baptiste Boric return error;
343*9f988b79SJean-Baptiste Boric }
344*9f988b79SJean-Baptiste Boric
345*9f988b79SJean-Baptiste Boric
346*9f988b79SJean-Baptiste Boric /* synchronous generic descriptor read */
347*9f988b79SJean-Baptiste Boric int
udf_read_phys_dscr(struct udf_mount * ump,uint32_t sector,struct malloc_type * mtype,union dscrptr ** dstp)348*9f988b79SJean-Baptiste Boric udf_read_phys_dscr(struct udf_mount *ump, uint32_t sector,
349*9f988b79SJean-Baptiste Boric struct malloc_type *mtype, union dscrptr **dstp)
350*9f988b79SJean-Baptiste Boric {
351*9f988b79SJean-Baptiste Boric union dscrptr *dst, *new_dst;
352*9f988b79SJean-Baptiste Boric uint8_t *pos;
353*9f988b79SJean-Baptiste Boric int sectors, dscrlen;
354*9f988b79SJean-Baptiste Boric int i, error, sector_size;
355*9f988b79SJean-Baptiste Boric
356*9f988b79SJean-Baptiste Boric sector_size = ump->discinfo.sector_size;
357*9f988b79SJean-Baptiste Boric
358*9f988b79SJean-Baptiste Boric *dstp = dst = NULL;
359*9f988b79SJean-Baptiste Boric dscrlen = sector_size;
360*9f988b79SJean-Baptiste Boric
361*9f988b79SJean-Baptiste Boric /* read initial piece */
362*9f988b79SJean-Baptiste Boric dst = malloc(sector_size, mtype, M_WAITOK);
363*9f988b79SJean-Baptiste Boric error = udf_read_phys_sectors(ump, UDF_C_DSCR, dst, sector, 1);
364*9f988b79SJean-Baptiste Boric DPRINTFIF(DESCRIPTOR, error, ("read error (%d)\n", error));
365*9f988b79SJean-Baptiste Boric
366*9f988b79SJean-Baptiste Boric if (!error) {
367*9f988b79SJean-Baptiste Boric /* check if its a valid tag */
368*9f988b79SJean-Baptiste Boric error = udf_check_tag(dst);
369*9f988b79SJean-Baptiste Boric if (error) {
370*9f988b79SJean-Baptiste Boric /* check if its an empty block */
371*9f988b79SJean-Baptiste Boric pos = (uint8_t *) dst;
372*9f988b79SJean-Baptiste Boric for (i = 0; i < sector_size; i++, pos++) {
373*9f988b79SJean-Baptiste Boric if (*pos) break;
374*9f988b79SJean-Baptiste Boric }
375*9f988b79SJean-Baptiste Boric if (i == sector_size) {
376*9f988b79SJean-Baptiste Boric /* return no error but with no dscrptr */
377*9f988b79SJean-Baptiste Boric /* dispose first block */
378*9f988b79SJean-Baptiste Boric free(dst, mtype);
379*9f988b79SJean-Baptiste Boric return 0;
380*9f988b79SJean-Baptiste Boric }
381*9f988b79SJean-Baptiste Boric }
382*9f988b79SJean-Baptiste Boric /* calculate descriptor size */
383*9f988b79SJean-Baptiste Boric dscrlen = udf_tagsize(dst, sector_size);
384*9f988b79SJean-Baptiste Boric }
385*9f988b79SJean-Baptiste Boric DPRINTFIF(DESCRIPTOR, error, ("bad tag checksum\n"));
386*9f988b79SJean-Baptiste Boric
387*9f988b79SJean-Baptiste Boric if (!error && (dscrlen > sector_size)) {
388*9f988b79SJean-Baptiste Boric DPRINTF(DESCRIPTOR, ("multi block descriptor read\n"));
389*9f988b79SJean-Baptiste Boric /*
390*9f988b79SJean-Baptiste Boric * Read the rest of descriptor. Since it is only used at mount
391*9f988b79SJean-Baptiste Boric * time its overdone to define and use a specific udf_intbreadn
392*9f988b79SJean-Baptiste Boric * for this alone.
393*9f988b79SJean-Baptiste Boric */
394*9f988b79SJean-Baptiste Boric
395*9f988b79SJean-Baptiste Boric new_dst = realloc(dst, dscrlen, mtype, M_WAITOK);
396*9f988b79SJean-Baptiste Boric if (new_dst == NULL) {
397*9f988b79SJean-Baptiste Boric free(dst, mtype);
398*9f988b79SJean-Baptiste Boric return ENOMEM;
399*9f988b79SJean-Baptiste Boric }
400*9f988b79SJean-Baptiste Boric dst = new_dst;
401*9f988b79SJean-Baptiste Boric
402*9f988b79SJean-Baptiste Boric sectors = (dscrlen + sector_size -1) / sector_size;
403*9f988b79SJean-Baptiste Boric DPRINTF(DESCRIPTOR, ("dscrlen = %d (%d blk)\n", dscrlen, sectors));
404*9f988b79SJean-Baptiste Boric
405*9f988b79SJean-Baptiste Boric pos = (uint8_t *) dst + sector_size;
406*9f988b79SJean-Baptiste Boric error = udf_read_phys_sectors(ump, UDF_C_DSCR, pos,
407*9f988b79SJean-Baptiste Boric sector + 1, sectors-1);
408*9f988b79SJean-Baptiste Boric
409*9f988b79SJean-Baptiste Boric DPRINTFIF(DESCRIPTOR, error, ("read error on multi (%d)\n",
410*9f988b79SJean-Baptiste Boric error));
411*9f988b79SJean-Baptiste Boric }
412*9f988b79SJean-Baptiste Boric if (!error) {
413*9f988b79SJean-Baptiste Boric error = udf_check_tag_payload(dst, dscrlen);
414*9f988b79SJean-Baptiste Boric DPRINTFIF(DESCRIPTOR, error, ("bad payload check sum\n"));
415*9f988b79SJean-Baptiste Boric }
416*9f988b79SJean-Baptiste Boric if (error && dst) {
417*9f988b79SJean-Baptiste Boric free(dst, mtype);
418*9f988b79SJean-Baptiste Boric dst = NULL;
419*9f988b79SJean-Baptiste Boric }
420*9f988b79SJean-Baptiste Boric *dstp = dst;
421*9f988b79SJean-Baptiste Boric
422*9f988b79SJean-Baptiste Boric return error;
423*9f988b79SJean-Baptiste Boric }
424*9f988b79SJean-Baptiste Boric
425*9f988b79SJean-Baptiste Boric
426*9f988b79SJean-Baptiste Boric static void
udf_write_phys_buf(struct udf_mount * ump,int what,struct buf * buf)427*9f988b79SJean-Baptiste Boric udf_write_phys_buf(struct udf_mount *ump, int what, struct buf *buf)
428*9f988b79SJean-Baptiste Boric {
429*9f988b79SJean-Baptiste Boric struct buf *nestbuf;
430*9f988b79SJean-Baptiste Boric uint32_t buf_offset;
431*9f988b79SJean-Baptiste Boric off_t lblkno, rblkno;
432*9f988b79SJean-Baptiste Boric int sector_size = ump->discinfo.sector_size;
433*9f988b79SJean-Baptiste Boric int blks = sector_size / DEV_BSIZE;
434*9f988b79SJean-Baptiste Boric uint32_t sectors;
435*9f988b79SJean-Baptiste Boric int piece;
436*9f988b79SJean-Baptiste Boric int error;
437*9f988b79SJean-Baptiste Boric
438*9f988b79SJean-Baptiste Boric sectors = buf->b_bcount / sector_size;
439*9f988b79SJean-Baptiste Boric DPRINTF(WRITE, ("udf_intbwriten() : sectors = %d, sector_size = %d\n",
440*9f988b79SJean-Baptiste Boric sectors, sector_size));
441*9f988b79SJean-Baptiste Boric
442*9f988b79SJean-Baptiste Boric /* don't forget to increase pending count for the bwrite itself */
443*9f988b79SJean-Baptiste Boric /* panic("NO WRITING\n"); */
444*9f988b79SJean-Baptiste Boric if (buf->b_vp) {
445*9f988b79SJean-Baptiste Boric mutex_enter(buf->b_vp->v_interlock);
446*9f988b79SJean-Baptiste Boric buf->b_vp->v_numoutput++;
447*9f988b79SJean-Baptiste Boric mutex_exit(buf->b_vp->v_interlock);
448*9f988b79SJean-Baptiste Boric }
449*9f988b79SJean-Baptiste Boric
450*9f988b79SJean-Baptiste Boric error = 0;
451*9f988b79SJean-Baptiste Boric buf_offset = 0;
452*9f988b79SJean-Baptiste Boric rblkno = buf->b_blkno / blks;
453*9f988b79SJean-Baptiste Boric lblkno = 0;
454*9f988b79SJean-Baptiste Boric while ((sectors > 0) && (error == 0)) {
455*9f988b79SJean-Baptiste Boric piece = MIN(MAXPHYS/sector_size, sectors);
456*9f988b79SJean-Baptiste Boric DPRINTF(WRITE, ("write out %d + %d\n",
457*9f988b79SJean-Baptiste Boric (uint32_t) rblkno, piece));
458*9f988b79SJean-Baptiste Boric
459*9f988b79SJean-Baptiste Boric nestbuf = getiobuf(NULL, true);
460*9f988b79SJean-Baptiste Boric nestiobuf_setup(buf, nestbuf, buf_offset, piece * sector_size);
461*9f988b79SJean-Baptiste Boric /* nestbuf is B_ASYNC */
462*9f988b79SJean-Baptiste Boric
463*9f988b79SJean-Baptiste Boric /* identify this nestbuf */
464*9f988b79SJean-Baptiste Boric nestbuf->b_lblkno = lblkno;
465*9f988b79SJean-Baptiste Boric
466*9f988b79SJean-Baptiste Boric /* CD shedules on raw blkno */
467*9f988b79SJean-Baptiste Boric nestbuf->b_blkno = rblkno * blks;
468*9f988b79SJean-Baptiste Boric nestbuf->b_proc = NULL;
469*9f988b79SJean-Baptiste Boric nestbuf->b_rawblkno = rblkno * blks;
470*9f988b79SJean-Baptiste Boric nestbuf->b_udf_c_type = what;
471*9f988b79SJean-Baptiste Boric
472*9f988b79SJean-Baptiste Boric udf_discstrat_queuebuf(ump, nestbuf);
473*9f988b79SJean-Baptiste Boric
474*9f988b79SJean-Baptiste Boric lblkno += piece;
475*9f988b79SJean-Baptiste Boric rblkno += piece;
476*9f988b79SJean-Baptiste Boric buf_offset += piece * sector_size;
477*9f988b79SJean-Baptiste Boric sectors -= piece;
478*9f988b79SJean-Baptiste Boric }
479*9f988b79SJean-Baptiste Boric }
480*9f988b79SJean-Baptiste Boric
481*9f988b79SJean-Baptiste Boric
482*9f988b79SJean-Baptiste Boric /* SYNC writing of n blocks from specified sector */
483*9f988b79SJean-Baptiste Boric int
udf_write_phys_sectors(struct udf_mount * ump,int what,void * blob,uint32_t start,uint32_t sectors)484*9f988b79SJean-Baptiste Boric udf_write_phys_sectors(struct udf_mount *ump, int what, void *blob,
485*9f988b79SJean-Baptiste Boric uint32_t start, uint32_t sectors)
486*9f988b79SJean-Baptiste Boric {
487*9f988b79SJean-Baptiste Boric struct vnode *vp;
488*9f988b79SJean-Baptiste Boric struct buf *buf;
489*9f988b79SJean-Baptiste Boric int sector_size = ump->discinfo.sector_size;
490*9f988b79SJean-Baptiste Boric int blks = sector_size / DEV_BSIZE;
491*9f988b79SJean-Baptiste Boric int error;
492*9f988b79SJean-Baptiste Boric
493*9f988b79SJean-Baptiste Boric /* get transfer buffer */
494*9f988b79SJean-Baptiste Boric vp = ump->devvp;
495*9f988b79SJean-Baptiste Boric buf = getiobuf(vp, true);
496*9f988b79SJean-Baptiste Boric buf->b_flags = B_WRITE;
497*9f988b79SJean-Baptiste Boric buf->b_cflags = BC_BUSY; /* needed? */
498*9f988b79SJean-Baptiste Boric buf->b_iodone = NULL;
499*9f988b79SJean-Baptiste Boric buf->b_data = blob;
500*9f988b79SJean-Baptiste Boric buf->b_bcount = sectors * sector_size;
501*9f988b79SJean-Baptiste Boric buf->b_resid = buf->b_bcount;
502*9f988b79SJean-Baptiste Boric buf->b_bufsize = buf->b_bcount;
503*9f988b79SJean-Baptiste Boric buf->b_private = NULL; /* not needed yet */
504*9f988b79SJean-Baptiste Boric BIO_SETPRIO(buf, BPRIO_DEFAULT);
505*9f988b79SJean-Baptiste Boric buf->b_lblkno = buf->b_blkno = buf->b_rawblkno = start * blks;
506*9f988b79SJean-Baptiste Boric buf->b_proc = NULL;
507*9f988b79SJean-Baptiste Boric
508*9f988b79SJean-Baptiste Boric /* do the write, wait and return error */
509*9f988b79SJean-Baptiste Boric udf_write_phys_buf(ump, what, buf);
510*9f988b79SJean-Baptiste Boric error = biowait(buf);
511*9f988b79SJean-Baptiste Boric putiobuf(buf);
512*9f988b79SJean-Baptiste Boric
513*9f988b79SJean-Baptiste Boric return error;
514*9f988b79SJean-Baptiste Boric }
515*9f988b79SJean-Baptiste Boric
516*9f988b79SJean-Baptiste Boric
517*9f988b79SJean-Baptiste Boric /* synchronous generic descriptor write */
518*9f988b79SJean-Baptiste Boric int
udf_write_phys_dscr_sync(struct udf_mount * ump,struct udf_node * udf_node,int what,union dscrptr * dscr,uint32_t sector,uint32_t logsector)519*9f988b79SJean-Baptiste Boric udf_write_phys_dscr_sync(struct udf_mount *ump, struct udf_node *udf_node, int what,
520*9f988b79SJean-Baptiste Boric union dscrptr *dscr, uint32_t sector, uint32_t logsector)
521*9f988b79SJean-Baptiste Boric {
522*9f988b79SJean-Baptiste Boric struct vnode *vp;
523*9f988b79SJean-Baptiste Boric struct buf *buf;
524*9f988b79SJean-Baptiste Boric int sector_size = ump->discinfo.sector_size;
525*9f988b79SJean-Baptiste Boric int blks = sector_size / DEV_BSIZE;
526*9f988b79SJean-Baptiste Boric int dscrlen;
527*9f988b79SJean-Baptiste Boric int error;
528*9f988b79SJean-Baptiste Boric
529*9f988b79SJean-Baptiste Boric /* set sector number in the descriptor and validate */
530*9f988b79SJean-Baptiste Boric dscr->tag.tag_loc = udf_rw32(logsector);
531*9f988b79SJean-Baptiste Boric udf_validate_tag_and_crc_sums(dscr);
532*9f988b79SJean-Baptiste Boric
533*9f988b79SJean-Baptiste Boric /* calculate descriptor size */
534*9f988b79SJean-Baptiste Boric dscrlen = udf_tagsize(dscr, sector_size);
535*9f988b79SJean-Baptiste Boric
536*9f988b79SJean-Baptiste Boric /* get transfer buffer */
537*9f988b79SJean-Baptiste Boric vp = udf_node ? udf_node->vnode : ump->devvp;
538*9f988b79SJean-Baptiste Boric buf = getiobuf(vp, true);
539*9f988b79SJean-Baptiste Boric buf->b_flags = B_WRITE;
540*9f988b79SJean-Baptiste Boric buf->b_cflags = BC_BUSY; /* needed? */
541*9f988b79SJean-Baptiste Boric buf->b_iodone = NULL;
542*9f988b79SJean-Baptiste Boric buf->b_data = (void *) dscr;
543*9f988b79SJean-Baptiste Boric buf->b_bcount = dscrlen;
544*9f988b79SJean-Baptiste Boric buf->b_resid = buf->b_bcount;
545*9f988b79SJean-Baptiste Boric buf->b_bufsize = buf->b_bcount;
546*9f988b79SJean-Baptiste Boric buf->b_private = NULL; /* not needed yet */
547*9f988b79SJean-Baptiste Boric BIO_SETPRIO(buf, BPRIO_DEFAULT);
548*9f988b79SJean-Baptiste Boric buf->b_lblkno = buf->b_blkno = buf->b_rawblkno = sector * blks;
549*9f988b79SJean-Baptiste Boric buf->b_proc = NULL;
550*9f988b79SJean-Baptiste Boric
551*9f988b79SJean-Baptiste Boric /* do the write, wait and return error */
552*9f988b79SJean-Baptiste Boric udf_write_phys_buf(ump, what, buf);
553*9f988b79SJean-Baptiste Boric error = biowait(buf);
554*9f988b79SJean-Baptiste Boric putiobuf(buf);
555*9f988b79SJean-Baptiste Boric
556*9f988b79SJean-Baptiste Boric return error;
557*9f988b79SJean-Baptiste Boric }
558*9f988b79SJean-Baptiste Boric
559*9f988b79SJean-Baptiste Boric
560*9f988b79SJean-Baptiste Boric /* asynchronous generic descriptor write */
561*9f988b79SJean-Baptiste Boric int
udf_write_phys_dscr_async(struct udf_mount * ump,struct udf_node * udf_node,int what,union dscrptr * dscr,uint32_t sector,uint32_t logsector,void (* dscrwr_callback)(struct buf *))562*9f988b79SJean-Baptiste Boric udf_write_phys_dscr_async(struct udf_mount *ump, struct udf_node *udf_node,
563*9f988b79SJean-Baptiste Boric int what, union dscrptr *dscr,
564*9f988b79SJean-Baptiste Boric uint32_t sector, uint32_t logsector,
565*9f988b79SJean-Baptiste Boric void (*dscrwr_callback)(struct buf *))
566*9f988b79SJean-Baptiste Boric {
567*9f988b79SJean-Baptiste Boric struct vnode *vp;
568*9f988b79SJean-Baptiste Boric struct buf *buf;
569*9f988b79SJean-Baptiste Boric int dscrlen;
570*9f988b79SJean-Baptiste Boric int sector_size = ump->discinfo.sector_size;
571*9f988b79SJean-Baptiste Boric int blks = sector_size / DEV_BSIZE;
572*9f988b79SJean-Baptiste Boric
573*9f988b79SJean-Baptiste Boric KASSERT(dscrwr_callback);
574*9f988b79SJean-Baptiste Boric DPRINTF(NODE, ("udf_write_phys_dscr_async() called\n"));
575*9f988b79SJean-Baptiste Boric
576*9f988b79SJean-Baptiste Boric /* set sector number in the descriptor and validate */
577*9f988b79SJean-Baptiste Boric dscr->tag.tag_loc = udf_rw32(logsector);
578*9f988b79SJean-Baptiste Boric udf_validate_tag_and_crc_sums(dscr);
579*9f988b79SJean-Baptiste Boric
580*9f988b79SJean-Baptiste Boric /* calculate descriptor size */
581*9f988b79SJean-Baptiste Boric dscrlen = udf_tagsize(dscr, sector_size);
582*9f988b79SJean-Baptiste Boric
583*9f988b79SJean-Baptiste Boric /* get transfer buffer */
584*9f988b79SJean-Baptiste Boric vp = udf_node ? udf_node->vnode : ump->devvp;
585*9f988b79SJean-Baptiste Boric buf = getiobuf(vp, true);
586*9f988b79SJean-Baptiste Boric buf->b_flags = B_WRITE; // | B_ASYNC;
587*9f988b79SJean-Baptiste Boric buf->b_cflags = BC_BUSY;
588*9f988b79SJean-Baptiste Boric buf->b_iodone = dscrwr_callback;
589*9f988b79SJean-Baptiste Boric buf->b_data = dscr;
590*9f988b79SJean-Baptiste Boric buf->b_bcount = dscrlen;
591*9f988b79SJean-Baptiste Boric buf->b_resid = buf->b_bcount;
592*9f988b79SJean-Baptiste Boric buf->b_bufsize = buf->b_bcount;
593*9f988b79SJean-Baptiste Boric buf->b_private = NULL; /* not needed yet */
594*9f988b79SJean-Baptiste Boric BIO_SETPRIO(buf, BPRIO_DEFAULT);
595*9f988b79SJean-Baptiste Boric buf->b_lblkno = buf->b_blkno = buf->b_rawblkno = sector * blks;
596*9f988b79SJean-Baptiste Boric buf->b_proc = NULL;
597*9f988b79SJean-Baptiste Boric
598*9f988b79SJean-Baptiste Boric /* do the write and return no error */
599*9f988b79SJean-Baptiste Boric udf_write_phys_buf(ump, what, buf);
600*9f988b79SJean-Baptiste Boric return 0;
601*9f988b79SJean-Baptiste Boric }
602*9f988b79SJean-Baptiste Boric
603*9f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
604*9f988b79SJean-Baptiste Boric
605*9f988b79SJean-Baptiste Boric /* disc strategy dispatchers */
606*9f988b79SJean-Baptiste Boric
607*9f988b79SJean-Baptiste Boric int
udf_create_logvol_dscr(struct udf_mount * ump,struct udf_node * udf_node,struct long_ad * icb,union dscrptr ** dscrptr)608*9f988b79SJean-Baptiste Boric udf_create_logvol_dscr(struct udf_mount *ump, struct udf_node *udf_node, struct long_ad *icb,
609*9f988b79SJean-Baptiste Boric union dscrptr **dscrptr)
610*9f988b79SJean-Baptiste Boric {
611*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = ump->strategy;
612*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
613*9f988b79SJean-Baptiste Boric int error;
614*9f988b79SJean-Baptiste Boric
615*9f988b79SJean-Baptiste Boric KASSERT(strategy);
616*9f988b79SJean-Baptiste Boric args.ump = ump;
617*9f988b79SJean-Baptiste Boric args.udf_node = udf_node;
618*9f988b79SJean-Baptiste Boric args.icb = icb;
619*9f988b79SJean-Baptiste Boric args.dscr = NULL;
620*9f988b79SJean-Baptiste Boric
621*9f988b79SJean-Baptiste Boric error = (strategy->create_logvol_dscr)(&args);
622*9f988b79SJean-Baptiste Boric *dscrptr = args.dscr;
623*9f988b79SJean-Baptiste Boric
624*9f988b79SJean-Baptiste Boric return error;
625*9f988b79SJean-Baptiste Boric }
626*9f988b79SJean-Baptiste Boric
627*9f988b79SJean-Baptiste Boric
628*9f988b79SJean-Baptiste Boric void
udf_free_logvol_dscr(struct udf_mount * ump,struct long_ad * icb,void * dscr)629*9f988b79SJean-Baptiste Boric udf_free_logvol_dscr(struct udf_mount *ump, struct long_ad *icb,
630*9f988b79SJean-Baptiste Boric void *dscr)
631*9f988b79SJean-Baptiste Boric {
632*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = ump->strategy;
633*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
634*9f988b79SJean-Baptiste Boric
635*9f988b79SJean-Baptiste Boric KASSERT(strategy);
636*9f988b79SJean-Baptiste Boric args.ump = ump;
637*9f988b79SJean-Baptiste Boric args.icb = icb;
638*9f988b79SJean-Baptiste Boric args.dscr = dscr;
639*9f988b79SJean-Baptiste Boric
640*9f988b79SJean-Baptiste Boric (strategy->free_logvol_dscr)(&args);
641*9f988b79SJean-Baptiste Boric }
642*9f988b79SJean-Baptiste Boric
643*9f988b79SJean-Baptiste Boric
644*9f988b79SJean-Baptiste Boric int
udf_read_logvol_dscr(struct udf_mount * ump,struct long_ad * icb,union dscrptr ** dscrptr)645*9f988b79SJean-Baptiste Boric udf_read_logvol_dscr(struct udf_mount *ump, struct long_ad *icb,
646*9f988b79SJean-Baptiste Boric union dscrptr **dscrptr)
647*9f988b79SJean-Baptiste Boric {
648*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = ump->strategy;
649*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
650*9f988b79SJean-Baptiste Boric int error;
651*9f988b79SJean-Baptiste Boric
652*9f988b79SJean-Baptiste Boric KASSERT(strategy);
653*9f988b79SJean-Baptiste Boric args.ump = ump;
654*9f988b79SJean-Baptiste Boric args.icb = icb;
655*9f988b79SJean-Baptiste Boric args.dscr = NULL;
656*9f988b79SJean-Baptiste Boric
657*9f988b79SJean-Baptiste Boric error = (strategy->read_logvol_dscr)(&args);
658*9f988b79SJean-Baptiste Boric *dscrptr = args.dscr;
659*9f988b79SJean-Baptiste Boric
660*9f988b79SJean-Baptiste Boric return error;
661*9f988b79SJean-Baptiste Boric }
662*9f988b79SJean-Baptiste Boric
663*9f988b79SJean-Baptiste Boric
664*9f988b79SJean-Baptiste Boric int
udf_write_logvol_dscr(struct udf_node * udf_node,union dscrptr * dscr,struct long_ad * icb,int waitfor)665*9f988b79SJean-Baptiste Boric udf_write_logvol_dscr(struct udf_node *udf_node, union dscrptr *dscr,
666*9f988b79SJean-Baptiste Boric struct long_ad *icb, int waitfor)
667*9f988b79SJean-Baptiste Boric {
668*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = udf_node->ump->strategy;
669*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
670*9f988b79SJean-Baptiste Boric int error;
671*9f988b79SJean-Baptiste Boric
672*9f988b79SJean-Baptiste Boric KASSERT(strategy);
673*9f988b79SJean-Baptiste Boric args.ump = udf_node->ump;
674*9f988b79SJean-Baptiste Boric args.udf_node = udf_node;
675*9f988b79SJean-Baptiste Boric args.icb = icb;
676*9f988b79SJean-Baptiste Boric args.dscr = dscr;
677*9f988b79SJean-Baptiste Boric args.waitfor = waitfor;
678*9f988b79SJean-Baptiste Boric
679*9f988b79SJean-Baptiste Boric error = (strategy->write_logvol_dscr)(&args);
680*9f988b79SJean-Baptiste Boric return error;
681*9f988b79SJean-Baptiste Boric }
682*9f988b79SJean-Baptiste Boric
683*9f988b79SJean-Baptiste Boric
684*9f988b79SJean-Baptiste Boric void
udf_discstrat_queuebuf(struct udf_mount * ump,struct buf * nestbuf)685*9f988b79SJean-Baptiste Boric udf_discstrat_queuebuf(struct udf_mount *ump, struct buf *nestbuf)
686*9f988b79SJean-Baptiste Boric {
687*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = ump->strategy;
688*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
689*9f988b79SJean-Baptiste Boric
690*9f988b79SJean-Baptiste Boric KASSERT(strategy);
691*9f988b79SJean-Baptiste Boric args.ump = ump;
692*9f988b79SJean-Baptiste Boric args.nestbuf = nestbuf;
693*9f988b79SJean-Baptiste Boric
694*9f988b79SJean-Baptiste Boric (strategy->queuebuf)(&args);
695*9f988b79SJean-Baptiste Boric }
696*9f988b79SJean-Baptiste Boric
697*9f988b79SJean-Baptiste Boric
698*9f988b79SJean-Baptiste Boric void
udf_discstrat_init(struct udf_mount * ump)699*9f988b79SJean-Baptiste Boric udf_discstrat_init(struct udf_mount *ump)
700*9f988b79SJean-Baptiste Boric {
701*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = ump->strategy;
702*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
703*9f988b79SJean-Baptiste Boric
704*9f988b79SJean-Baptiste Boric KASSERT(strategy);
705*9f988b79SJean-Baptiste Boric args.ump = ump;
706*9f988b79SJean-Baptiste Boric (strategy->discstrat_init)(&args);
707*9f988b79SJean-Baptiste Boric }
708*9f988b79SJean-Baptiste Boric
709*9f988b79SJean-Baptiste Boric
udf_discstrat_finish(struct udf_mount * ump)710*9f988b79SJean-Baptiste Boric void udf_discstrat_finish(struct udf_mount *ump)
711*9f988b79SJean-Baptiste Boric {
712*9f988b79SJean-Baptiste Boric struct udf_strategy *strategy = ump->strategy;
713*9f988b79SJean-Baptiste Boric struct udf_strat_args args;
714*9f988b79SJean-Baptiste Boric
715*9f988b79SJean-Baptiste Boric /* strategy might not have been set, so ignore if not set */
716*9f988b79SJean-Baptiste Boric if (strategy) {
717*9f988b79SJean-Baptiste Boric args.ump = ump;
718*9f988b79SJean-Baptiste Boric (strategy->discstrat_finish)(&args);
719*9f988b79SJean-Baptiste Boric }
720*9f988b79SJean-Baptiste Boric }
721*9f988b79SJean-Baptiste Boric
722*9f988b79SJean-Baptiste Boric /* --------------------------------------------------------------------- */
723*9f988b79SJean-Baptiste Boric
724