udf_vnops.c revision 1.6 1 1.6 christos /* $NetBSD: udf_vnops.c,v 1.6 2006/06/12 00:20:21 christos Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 2006 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 * 3. All advertising materials mentioning features or use of this software
16 1.1 reinoud * must display the following acknowledgement:
17 1.1 reinoud * This product includes software developed for the
18 1.1 reinoud * NetBSD Project. See http://www.NetBSD.org/ for
19 1.1 reinoud * information about NetBSD.
20 1.1 reinoud * 4. The name of the author may not be used to endorse or promote products
21 1.1 reinoud * derived from this software without specific prior written permission.
22 1.1 reinoud *
23 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 reinoud *
34 1.1 reinoud */
35 1.1 reinoud
36 1.1 reinoud
37 1.1 reinoud #include <sys/cdefs.h>
38 1.1 reinoud #ifndef lint
39 1.6 christos __RCSID("$NetBSD: udf_vnops.c,v 1.6 2006/06/12 00:20:21 christos Exp $");
40 1.1 reinoud #endif /* not lint */
41 1.1 reinoud
42 1.1 reinoud
43 1.1 reinoud #include <sys/param.h>
44 1.1 reinoud #include <sys/systm.h>
45 1.1 reinoud #include <sys/namei.h>
46 1.1 reinoud #include <sys/resourcevar.h> /* defines plimit structure in proc struct */
47 1.1 reinoud #include <sys/kernel.h>
48 1.1 reinoud #include <sys/file.h> /* define FWRITE ... */
49 1.1 reinoud #include <sys/stat.h>
50 1.1 reinoud #include <sys/buf.h>
51 1.1 reinoud #include <sys/proc.h>
52 1.1 reinoud #include <sys/mount.h>
53 1.1 reinoud #include <sys/vnode.h>
54 1.1 reinoud #include <sys/signalvar.h>
55 1.1 reinoud #include <sys/malloc.h>
56 1.1 reinoud #include <sys/dirent.h>
57 1.1 reinoud #include <sys/lockf.h>
58 1.1 reinoud
59 1.1 reinoud #include <miscfs/genfs/genfs.h>
60 1.1 reinoud #include <uvm/uvm_extern.h>
61 1.1 reinoud
62 1.1 reinoud #include <fs/udf/ecma167-udf.h>
63 1.1 reinoud #include <fs/udf/udf_mount.h>
64 1.1 reinoud #include "udf.h"
65 1.1 reinoud #include "udf_subr.h"
66 1.1 reinoud #include "udf_bswap.h"
67 1.1 reinoud
68 1.1 reinoud
69 1.1 reinoud #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
70 1.1 reinoud
71 1.1 reinoud
72 1.1 reinoud /* externs */
73 1.1 reinoud extern int prtactive;
74 1.1 reinoud
75 1.1 reinoud
76 1.1 reinoud /* implementations of vnode functions; table follows at end */
77 1.1 reinoud /* --------------------------------------------------------------------- */
78 1.1 reinoud
79 1.1 reinoud int
80 1.1 reinoud udf_inactive(void *v)
81 1.1 reinoud {
82 1.1 reinoud struct vop_inactive_args /* {
83 1.1 reinoud struct vnode *a_vp;
84 1.1 reinoud struct proc *a_p;
85 1.1 reinoud } */ *ap = v;
86 1.1 reinoud struct vnode *vp = ap->a_vp;
87 1.1 reinoud
88 1.1 reinoud if (prtactive && vp->v_usecount != 0)
89 1.1 reinoud vprint("udf_inactive(): pushing active", vp);
90 1.1 reinoud
91 1.1 reinoud VOP_UNLOCK(vp, 0);
92 1.1 reinoud
93 1.1 reinoud DPRINTF(LOCKING, ("udf_inactive called for node %p\n", VTOI(vp)));
94 1.1 reinoud
95 1.1 reinoud /*
96 1.1 reinoud * Optionally flush metadata to disc. If the file has not been
97 1.1 reinoud * referenced anymore in a directory we ought to free up the resources
98 1.1 reinoud * on disc if applicable.
99 1.1 reinoud */
100 1.1 reinoud
101 1.1 reinoud return 0;
102 1.1 reinoud }
103 1.1 reinoud
104 1.1 reinoud /* --------------------------------------------------------------------- */
105 1.1 reinoud
106 1.1 reinoud int
107 1.1 reinoud udf_reclaim(void *v)
108 1.1 reinoud {
109 1.1 reinoud struct vop_reclaim_args /* {
110 1.1 reinoud struct vnode *a_vp;
111 1.1 reinoud } */ *ap = v;
112 1.1 reinoud struct vnode *vp = ap->a_vp;
113 1.1 reinoud struct udf_node *node = VTOI(vp);
114 1.1 reinoud
115 1.1 reinoud if (prtactive && vp->v_usecount != 0)
116 1.1 reinoud vprint("udf_reclaim(): pushing active", vp);
117 1.1 reinoud
118 1.1 reinoud /* purge old data from namei */
119 1.1 reinoud cache_purge(vp);
120 1.1 reinoud
121 1.1 reinoud DPRINTF(LOCKING, ("udf_reclaim called for node %p\n", node));
122 1.1 reinoud /* dispose all node knowledge */
123 1.1 reinoud udf_dispose_node(node);
124 1.1 reinoud
125 1.1 reinoud return 0;
126 1.1 reinoud }
127 1.1 reinoud
128 1.1 reinoud /* --------------------------------------------------------------------- */
129 1.1 reinoud
130 1.1 reinoud int
131 1.1 reinoud udf_read(void *v)
132 1.1 reinoud {
133 1.1 reinoud struct vop_read_args /* {
134 1.1 reinoud struct vnode *a_vp;
135 1.1 reinoud struct uio *a_uio;
136 1.1 reinoud int a_ioflag;
137 1.5 elad kauth_cred_t a_cred;
138 1.1 reinoud } */ *ap = v;
139 1.1 reinoud struct vnode *vp = ap->a_vp;
140 1.1 reinoud struct uio *uio = ap->a_uio;
141 1.1 reinoud int ioflag = ap->a_ioflag;
142 1.1 reinoud struct uvm_object *uobj;
143 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
144 1.1 reinoud struct file_entry *fe;
145 1.1 reinoud struct extfile_entry *efe;
146 1.1 reinoud uint64_t file_size;
147 1.1 reinoud vsize_t len;
148 1.1 reinoud void *win;
149 1.1 reinoud int error;
150 1.1 reinoud int flags;
151 1.1 reinoud
152 1.1 reinoud /* XXX how to deal with xtended attributes (files) */
153 1.1 reinoud
154 1.1 reinoud DPRINTF(READ, ("udf_read called\n"));
155 1.1 reinoud
156 1.1 reinoud /* can this happen? some filingsystems have this check */
157 1.1 reinoud if (uio->uio_offset < 0)
158 1.1 reinoud return EINVAL;
159 1.1 reinoud
160 1.1 reinoud assert(udf_node);
161 1.1 reinoud assert(udf_node->fe || udf_node->efe);
162 1.1 reinoud
163 1.1 reinoud /* TODO set access time */
164 1.1 reinoud
165 1.1 reinoud /* get directory filesize */
166 1.1 reinoud if (udf_node->fe) {
167 1.1 reinoud fe = udf_node->fe;
168 1.1 reinoud file_size = udf_rw64(fe->inf_len);
169 1.1 reinoud } else {
170 1.1 reinoud assert(udf_node->efe);
171 1.1 reinoud efe = udf_node->efe;
172 1.1 reinoud file_size = udf_rw64(efe->inf_len);
173 1.6 christos }
174 1.1 reinoud
175 1.1 reinoud if (vp->v_type == VDIR) {
176 1.1 reinoud /* protect against rogue programs reading raw directories */
177 1.1 reinoud if ((ioflag & IO_ALTSEMANTICS) == 0)
178 1.1 reinoud return EISDIR;
179 1.6 christos }
180 1.1 reinoud if (vp->v_type == VREG || vp->v_type == VDIR) {
181 1.1 reinoud const int advice = IO_ADV_DECODE(ap->a_ioflag);
182 1.1 reinoud
183 1.1 reinoud /* read contents using buffercache */
184 1.1 reinoud uobj = &vp->v_uobj;
185 1.1 reinoud flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
186 1.1 reinoud error = 0;
187 1.1 reinoud while (uio->uio_resid > 0) {
188 1.1 reinoud /* reached end? */
189 1.1 reinoud if (file_size <= uio->uio_offset)
190 1.1 reinoud break;
191 1.1 reinoud
192 1.1 reinoud /* maximise length to file extremity */
193 1.1 reinoud len = MIN(file_size - uio->uio_offset, uio->uio_resid);
194 1.1 reinoud if (len == 0)
195 1.1 reinoud break;
196 1.1 reinoud
197 1.1 reinoud /* ubc, here we come, prepare to trap */
198 1.1 reinoud win = ubc_alloc(uobj, uio->uio_offset, &len,
199 1.1 reinoud advice, UBC_READ);
200 1.1 reinoud error = uiomove(win, len, uio);
201 1.1 reinoud ubc_release(win, flags);
202 1.1 reinoud if (error)
203 1.1 reinoud break;
204 1.1 reinoud }
205 1.1 reinoud /* TODO note access time */
206 1.1 reinoud return error;
207 1.6 christos }
208 1.1 reinoud
209 1.1 reinoud return EINVAL;
210 1.1 reinoud }
211 1.1 reinoud
212 1.1 reinoud /* --------------------------------------------------------------------- */
213 1.1 reinoud
214 1.1 reinoud int
215 1.1 reinoud udf_write(void *v)
216 1.1 reinoud {
217 1.1 reinoud struct vop_write_args /* {
218 1.1 reinoud struct vnode *a_vp;
219 1.1 reinoud struct uio *a_uio;
220 1.1 reinoud int a_ioflag;
221 1.5 elad kauth_cred_t a_cred;
222 1.1 reinoud } */ *ap = v;
223 1.1 reinoud
224 1.1 reinoud DPRINTF(NOTIMPL, ("udf_write called\n"));
225 1.1 reinoud ap = ap; /* shut up gcc */
226 1.1 reinoud
227 1.1 reinoud /* TODO implement writing */
228 1.1 reinoud return EROFS;
229 1.1 reinoud }
230 1.1 reinoud
231 1.1 reinoud
232 1.1 reinoud /* --------------------------------------------------------------------- */
233 1.1 reinoud
234 1.1 reinoud /*
235 1.1 reinoud * `Special' bmap functionality that translates all incomming requests to
236 1.1 reinoud * translate to vop_strategy() calls with the same blocknumbers effectively
237 1.1 reinoud * not translating at all.
238 1.1 reinoud */
239 1.1 reinoud
240 1.1 reinoud int
241 1.1 reinoud udf_trivial_bmap(void *v)
242 1.1 reinoud {
243 1.1 reinoud struct vop_bmap_args /* {
244 1.1 reinoud struct vnode *a_vp;
245 1.1 reinoud daddr_t a_bn;
246 1.1 reinoud struct vnode **a_vpp;
247 1.1 reinoud daddr_t *a_bnp;
248 1.1 reinoud int *a_runp;
249 1.1 reinoud } */ *ap = v;
250 1.1 reinoud struct vnode *vp = ap->a_vp; /* our node */
251 1.1 reinoud struct vnode **vpp = ap->a_vpp; /* return node */
252 1.1 reinoud daddr_t *bnp = ap->a_bnp; /* translated */
253 1.1 reinoud daddr_t bn = ap->a_bn; /* origional */
254 1.1 reinoud int *runp = ap->a_runp;
255 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
256 1.1 reinoud uint32_t lb_size;
257 1.1 reinoud
258 1.1 reinoud /* get logical block size */
259 1.1 reinoud lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
260 1.1 reinoud
261 1.1 reinoud /* could return `-1' to indicate holes/zeros */
262 1.1 reinoud /* translate 1:1 */
263 1.1 reinoud *bnp = bn;
264 1.1 reinoud
265 1.1 reinoud /* set the vnode to read the data from with strategy on itself */
266 1.1 reinoud if (vpp)
267 1.1 reinoud *vpp = vp;
268 1.1 reinoud
269 1.1 reinoud /* set runlength of maximum block size */
270 1.1 reinoud if (runp)
271 1.1 reinoud *runp = MAXPHYS / lb_size; /* or with -1 ? */
272 1.1 reinoud
273 1.1 reinoud /* return success */
274 1.1 reinoud return 0;
275 1.1 reinoud }
276 1.1 reinoud
277 1.1 reinoud /* --------------------------------------------------------------------- */
278 1.1 reinoud
279 1.1 reinoud int
280 1.1 reinoud udf_strategy(void *v)
281 1.1 reinoud {
282 1.1 reinoud struct vop_strategy_args /* {
283 1.1 reinoud struct vnode *a_vp;
284 1.1 reinoud struct buf *a_bp;
285 1.1 reinoud } */ *ap = v;
286 1.1 reinoud struct vnode *vp = ap->a_vp;
287 1.1 reinoud struct buf *bp = ap->a_bp;
288 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
289 1.1 reinoud uint32_t lb_size, from, sectors;
290 1.1 reinoud int error;
291 1.1 reinoud
292 1.1 reinoud DPRINTF(STRATEGY, ("udf_strategy called\n"));
293 1.1 reinoud
294 1.1 reinoud /* check if we ought to be here */
295 1.1 reinoud if (vp->v_type == VBLK || vp->v_type == VCHR)
296 1.1 reinoud panic("udf_strategy: spec");
297 1.1 reinoud
298 1.1 reinoud /* only filebuffers ought to be read by this, no descriptors */
299 1.1 reinoud assert(bp->b_blkno >= 0);
300 1.1 reinoud
301 1.1 reinoud /* get sector size */
302 1.1 reinoud lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
303 1.1 reinoud
304 1.1 reinoud /* calculate sector to start from */
305 1.1 reinoud from = bp->b_blkno;
306 1.1 reinoud
307 1.1 reinoud /* calculate length to fetch/store in sectors */
308 1.1 reinoud sectors = bp->b_bcount / lb_size;
309 1.1 reinoud assert(bp->b_bcount > 0);
310 1.1 reinoud
311 1.3 snj /* NEVER assume later that this buffer is already translated */
312 1.1 reinoud /* bp->b_lblkno = bp->b_blkno; */
313 1.1 reinoud
314 1.1 reinoud DPRINTF(STRATEGY, ("\tread vp %p buf %p (blk no %"PRIu64")"
315 1.1 reinoud ", sector %d for %d sectors\n",
316 1.1 reinoud vp, bp, bp->b_blkno, from, sectors));
317 1.1 reinoud
318 1.1 reinoud /* check assertions: we OUGHT to allways get multiples of this */
319 1.1 reinoud assert(sectors * lb_size == bp->b_bcount);
320 1.1 reinoud
321 1.1 reinoud /* determine mode */
322 1.1 reinoud error = 0;
323 1.1 reinoud if (bp->b_flags & B_READ) {
324 1.1 reinoud /* read buffer from the udf_node, translate vtop on the way*/
325 1.1 reinoud udf_read_filebuf(udf_node, bp);
326 1.1 reinoud return bp->b_error;
327 1.6 christos }
328 1.1 reinoud
329 1.1 reinoud printf("udf_strategy: can't write yet\n");
330 1.1 reinoud return ENOTSUP;
331 1.1 reinoud }
332 1.1 reinoud
333 1.1 reinoud /* --------------------------------------------------------------------- */
334 1.1 reinoud
335 1.1 reinoud int
336 1.1 reinoud udf_readdir(void *v)
337 1.1 reinoud {
338 1.1 reinoud struct vop_readdir_args /* {
339 1.1 reinoud struct vnode *a_vp;
340 1.1 reinoud struct uio *a_uio;
341 1.5 elad kauth_cred_t a_cred;
342 1.1 reinoud int *a_eofflag;
343 1.1 reinoud off_t **a_cookies;
344 1.1 reinoud int *a_ncookies;
345 1.1 reinoud } */ *ap = v;
346 1.1 reinoud struct uio *uio = ap->a_uio;
347 1.1 reinoud struct vnode *vp = ap->a_vp;
348 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
349 1.1 reinoud struct file_entry *fe;
350 1.1 reinoud struct extfile_entry *efe;
351 1.1 reinoud struct fileid_desc *fid;
352 1.1 reinoud struct dirent dirent;
353 1.1 reinoud uint64_t file_size, diroffset, transoffset;
354 1.1 reinoud uint32_t lb_size;
355 1.1 reinoud int error;
356 1.1 reinoud
357 1.1 reinoud DPRINTF(READDIR, ("udf_readdir called\n"));
358 1.1 reinoud
359 1.1 reinoud /* This operation only makes sense on directory nodes. */
360 1.1 reinoud if (vp->v_type != VDIR)
361 1.1 reinoud return ENOTDIR;
362 1.1 reinoud
363 1.1 reinoud /* get directory filesize */
364 1.1 reinoud if (udf_node->fe) {
365 1.1 reinoud fe = udf_node->fe;
366 1.1 reinoud file_size = udf_rw64(fe->inf_len);
367 1.1 reinoud } else {
368 1.1 reinoud assert(udf_node->efe);
369 1.1 reinoud efe = udf_node->efe;
370 1.1 reinoud file_size = udf_rw64(efe->inf_len);
371 1.6 christos }
372 1.1 reinoud
373 1.1 reinoud /*
374 1.1 reinoud * Add `.' pseudo entry if at offset zero since its not in the fid
375 1.1 reinoud * stream
376 1.1 reinoud */
377 1.1 reinoud if (uio->uio_offset == 0) {
378 1.1 reinoud DPRINTF(READDIR, ("\t'.' inserted\n"));
379 1.1 reinoud memset(&dirent, 0, sizeof(struct dirent));
380 1.1 reinoud strcpy(dirent.d_name, ".");
381 1.1 reinoud dirent.d_fileno = udf_calchash(&udf_node->loc);
382 1.1 reinoud dirent.d_type = DT_DIR;
383 1.1 reinoud dirent.d_namlen = strlen(dirent.d_name);
384 1.1 reinoud dirent.d_reclen = _DIRENT_SIZE(&dirent);
385 1.1 reinoud uiomove(&dirent, _DIRENT_SIZE(&dirent), uio);
386 1.1 reinoud
387 1.1 reinoud /* mark with magic value that we have done the dummy */
388 1.1 reinoud uio->uio_offset = UDF_DIRCOOKIE_DOT;
389 1.6 christos }
390 1.1 reinoud
391 1.1 reinoud /* we are called just as long as we keep on pushing data in */
392 1.1 reinoud error = 0;
393 1.1 reinoud if ((uio->uio_offset < file_size) &&
394 1.1 reinoud (uio->uio_resid >= sizeof(struct dirent))) {
395 1.1 reinoud /* allocate temporary space for fid */
396 1.1 reinoud lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
397 1.1 reinoud fid = malloc(lb_size, M_TEMP, M_WAITOK);
398 1.1 reinoud
399 1.1 reinoud if (uio->uio_offset == UDF_DIRCOOKIE_DOT)
400 1.1 reinoud uio->uio_offset = 0;
401 1.1 reinoud
402 1.1 reinoud diroffset = uio->uio_offset;
403 1.1 reinoud transoffset = diroffset;
404 1.1 reinoud while (diroffset < file_size) {
405 1.1 reinoud DPRINTF(READDIR, ("\tread in fid stream\n"));
406 1.1 reinoud /* transfer a new fid/dirent */
407 1.1 reinoud error = udf_read_fid_stream(vp, &diroffset,
408 1.1 reinoud fid, &dirent);
409 1.1 reinoud DPRINTFIF(READDIR, error, ("read error in read fid "
410 1.1 reinoud "stream : %d\n", error));
411 1.1 reinoud if (error)
412 1.1 reinoud break;
413 1.1 reinoud
414 1.1 reinoud /*
415 1.1 reinoud * If there isn't enough space in the uio to return a
416 1.1 reinoud * whole dirent, break off read
417 1.1 reinoud */
418 1.1 reinoud if (uio->uio_resid < _DIRENT_SIZE(&dirent))
419 1.1 reinoud break;
420 1.1 reinoud
421 1.1 reinoud /* remember the last entry we transfered */
422 1.1 reinoud transoffset = diroffset;
423 1.1 reinoud
424 1.1 reinoud /* skip deleted entries */
425 1.1 reinoud if (fid->file_char & UDF_FILE_CHAR_DEL)
426 1.1 reinoud continue;
427 1.1 reinoud
428 1.1 reinoud /* skip not visible files */
429 1.1 reinoud if (fid->file_char & UDF_FILE_CHAR_VIS)
430 1.1 reinoud continue;
431 1.1 reinoud
432 1.1 reinoud /* copy dirent to the caller */
433 1.1 reinoud DPRINTF(READDIR, ("\tread dirent `%s', type %d\n",
434 1.1 reinoud dirent.d_name, dirent.d_type));
435 1.1 reinoud uiomove(&dirent, _DIRENT_SIZE(&dirent), uio);
436 1.6 christos }
437 1.1 reinoud
438 1.1 reinoud /* pass on last transfered offset */
439 1.1 reinoud uio->uio_offset = transoffset;
440 1.1 reinoud free(fid, M_TEMP);
441 1.6 christos }
442 1.1 reinoud
443 1.1 reinoud if (ap->a_eofflag)
444 1.1 reinoud *ap->a_eofflag = (uio->uio_offset == file_size);
445 1.1 reinoud
446 1.1 reinoud #ifdef DEBUG
447 1.1 reinoud if (udf_verbose & UDF_DEBUG_READDIR) {
448 1.1 reinoud printf("returning offset %d\n", (uint32_t) uio->uio_offset);
449 1.1 reinoud if (ap->a_eofflag)
450 1.1 reinoud printf("returning EOF ? %d\n", *ap->a_eofflag);
451 1.1 reinoud if (error)
452 1.1 reinoud printf("readdir returning error %d\n", error);
453 1.6 christos }
454 1.1 reinoud #endif
455 1.1 reinoud
456 1.1 reinoud return error;
457 1.1 reinoud }
458 1.1 reinoud
459 1.1 reinoud /* --------------------------------------------------------------------- */
460 1.1 reinoud
461 1.1 reinoud int
462 1.1 reinoud udf_lookup(void *v)
463 1.1 reinoud {
464 1.1 reinoud struct vop_lookup_args /* {
465 1.1 reinoud struct vnode *a_dvp;
466 1.1 reinoud struct vnode **a_vpp;
467 1.1 reinoud struct componentname *a_cnp;
468 1.1 reinoud } */ *ap = v;
469 1.1 reinoud struct vnode *dvp = ap->a_dvp;
470 1.1 reinoud struct vnode **vpp = ap->a_vpp;
471 1.1 reinoud struct componentname *cnp = ap->a_cnp;
472 1.1 reinoud struct udf_node *dir_node, *res_node;
473 1.1 reinoud struct udf_mount *ump;
474 1.1 reinoud struct long_ad icb_loc;
475 1.1 reinoud const char *name;
476 1.1 reinoud int namelen, nameiop, islastcn, lock_parent, mounted_ro;
477 1.1 reinoud int vnodetp;
478 1.1 reinoud int error, found;
479 1.1 reinoud
480 1.1 reinoud dir_node = VTOI(dvp);
481 1.1 reinoud ump = dir_node->ump;
482 1.1 reinoud *vpp = NULL;
483 1.1 reinoud
484 1.1 reinoud DPRINTF(LOOKUP, ("udf_lookup called\n"));
485 1.1 reinoud
486 1.1 reinoud /* simplify/clarification flags */
487 1.1 reinoud nameiop = cnp->cn_nameiop;
488 1.1 reinoud islastcn = cnp->cn_flags & ISLASTCN;
489 1.1 reinoud lock_parent = cnp->cn_flags & LOCKPARENT;
490 1.1 reinoud mounted_ro = dvp->v_mount->mnt_flag & MNT_RDONLY;
491 1.1 reinoud
492 1.1 reinoud /* check exec/dirread permissions first */
493 1.1 reinoud error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, cnp->cn_lwp);
494 1.1 reinoud if (error)
495 1.1 reinoud return error;
496 1.1 reinoud
497 1.1 reinoud DPRINTF(LOOKUP, ("\taccess ok\n"));
498 1.1 reinoud
499 1.1 reinoud /*
500 1.1 reinoud * If requesting a modify on the last path element on a read-only
501 1.1 reinoud * filingsystem, reject lookup; XXX why is this repeated in every FS ?
502 1.1 reinoud */
503 1.1 reinoud if (islastcn && mounted_ro && (nameiop == DELETE || nameiop == RENAME))
504 1.1 reinoud return EROFS;
505 1.1 reinoud
506 1.1 reinoud DPRINTF(LOOKUP, ("\tlooking up cnp->cn_nameptr '%s'\n",
507 1.1 reinoud cnp->cn_nameptr));
508 1.1 reinoud /* look in the nami cache; returns 0 on success!! */
509 1.1 reinoud error = cache_lookup(dvp, vpp, cnp);
510 1.1 reinoud if (error >= 0)
511 1.1 reinoud return error;
512 1.1 reinoud
513 1.1 reinoud DPRINTF(LOOKUP, ("\tNOT found in cache\n"));
514 1.1 reinoud
515 1.1 reinoud /*
516 1.1 reinoud * Obviously, the file is not (anymore) in the namecache, we have to
517 1.1 reinoud * search for it. There are three basic cases: '.', '..' and others.
518 1.1 reinoud *
519 1.1 reinoud * Following the guidelines of VOP_LOOKUP manpage and tmpfs.
520 1.1 reinoud */
521 1.1 reinoud error = 0;
522 1.1 reinoud if ((cnp->cn_namelen == 1) && (cnp->cn_nameptr[0] == '.')) {
523 1.1 reinoud DPRINTF(LOOKUP, ("\tlookup '.'\n"));
524 1.1 reinoud /* special case 1 '.' */
525 1.1 reinoud VREF(dvp);
526 1.1 reinoud *vpp = dvp;
527 1.1 reinoud /* done */
528 1.1 reinoud } else if (cnp->cn_flags & ISDOTDOT) {
529 1.1 reinoud /* special case 2 '..' */
530 1.1 reinoud DPRINTF(LOOKUP, ("\tlookup '..'\n"));
531 1.1 reinoud
532 1.1 reinoud /* first unlock parent */
533 1.1 reinoud VOP_UNLOCK(dvp, 0);
534 1.1 reinoud cnp->cn_flags |= PDIRUNLOCK;
535 1.1 reinoud
536 1.1 reinoud /* get our node */
537 1.1 reinoud name = "..";
538 1.1 reinoud namelen = 2;
539 1.1 reinoud found = udf_lookup_name_in_dir(dvp, name, namelen, &icb_loc);
540 1.1 reinoud if (!found)
541 1.1 reinoud error = ENOENT;
542 1.1 reinoud
543 1.1 reinoud if (!error) {
544 1.1 reinoud DPRINTF(LOOKUP, ("\tfound '..'\n"));
545 1.1 reinoud /* try to create/reuse the node */
546 1.1 reinoud error = udf_get_node(ump, &icb_loc, &res_node);
547 1.1 reinoud
548 1.1 reinoud if (!error) {
549 1.1 reinoud DPRINTF(LOOKUP, ("\tnode retrieved/created OK\n"));
550 1.1 reinoud *vpp = res_node->vnode;
551 1.6 christos }
552 1.6 christos }
553 1.1 reinoud
554 1.1 reinoud /* see if we're requested to lock the parent */
555 1.1 reinoud if (lock_parent && islastcn) {
556 1.1 reinoud if (vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY) == 0)
557 1.1 reinoud cnp->cn_flags &= ~PDIRUNLOCK;
558 1.6 christos }
559 1.1 reinoud /* done */
560 1.1 reinoud } else {
561 1.1 reinoud DPRINTF(LOOKUP, ("\tlookup file\n"));
562 1.1 reinoud /* all other files */
563 1.1 reinoud /* lookup filename in the directory; location icb_loc */
564 1.1 reinoud name = cnp->cn_nameptr;
565 1.1 reinoud namelen = cnp->cn_namelen;
566 1.1 reinoud found = udf_lookup_name_in_dir(dvp, name, namelen, &icb_loc);
567 1.1 reinoud if (!found) {
568 1.1 reinoud DPRINTF(LOOKUP, ("\tNOT found\n"));
569 1.1 reinoud /*
570 1.1 reinoud * UGH, didn't find name. If we're creating or naming
571 1.1 reinoud * on the last name this is OK and we ought to return
572 1.1 reinoud * EJUSTRETURN if its allowed to be created.
573 1.1 reinoud */
574 1.1 reinoud error = ENOENT;
575 1.1 reinoud if (islastcn &&
576 1.1 reinoud (nameiop == CREATE || nameiop == RENAME))
577 1.1 reinoud error = 0;
578 1.1 reinoud if (!error) {
579 1.1 reinoud error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred,
580 1.1 reinoud cnp->cn_lwp);
581 1.1 reinoud if (!error) {
582 1.1 reinoud /* keep the component name */
583 1.1 reinoud cnp->cn_flags |= SAVENAME;
584 1.1 reinoud error = EJUSTRETURN;
585 1.6 christos }
586 1.6 christos }
587 1.1 reinoud /* done */
588 1.1 reinoud } else {
589 1.1 reinoud /* try to create/reuse the node */
590 1.1 reinoud error = udf_get_node(ump, &icb_loc, &res_node);
591 1.1 reinoud if (!error) {
592 1.1 reinoud /*
593 1.1 reinoud * If we are not at the last path component
594 1.1 reinoud * and found a non-directory or non-link entry
595 1.1 reinoud * (which may itself be pointing to a
596 1.1 reinoud * directory), raise an error.
597 1.1 reinoud */
598 1.1 reinoud vnodetp = res_node->vnode->v_type;
599 1.1 reinoud if ((vnodetp != VDIR) && (vnodetp != VLNK)) {
600 1.1 reinoud if (!islastcn)
601 1.1 reinoud error = ENOTDIR;
602 1.1 reinoud }
603 1.1 reinoud
604 1.6 christos }
605 1.1 reinoud if (!error) {
606 1.1 reinoud /*
607 1.1 reinoud * If LOCKPARENT or ISLASTCN is not set, dvp
608 1.1 reinoud * is returned unlocked on a successful
609 1.1 reinoud * lookup.
610 1.1 reinoud */
611 1.1 reinoud *vpp = res_node->vnode;
612 1.1 reinoud if (!lock_parent || !islastcn)
613 1.1 reinoud VOP_UNLOCK(dvp, 0);
614 1.6 christos }
615 1.1 reinoud /* done */
616 1.6 christos }
617 1.1 reinoud /* done */
618 1.1 reinoud }
619 1.1 reinoud
620 1.1 reinoud /*
621 1.1 reinoud * Store result in the cache if requested. If we are creating a file,
622 1.1 reinoud * the file might not be found and thus putting it into the namecache
623 1.1 reinoud * might be seen as negative caching.
624 1.1 reinoud */
625 1.1 reinoud if (cnp->cn_flags & MAKEENTRY)
626 1.1 reinoud cache_enter(dvp, *vpp, cnp);
627 1.1 reinoud
628 1.1 reinoud DPRINTFIF(LOOKUP, error, ("udf_lookup returing error %d\n", error));
629 1.1 reinoud
630 1.1 reinoud return error;
631 1.1 reinoud }
632 1.1 reinoud
633 1.1 reinoud /* --------------------------------------------------------------------- */
634 1.1 reinoud
635 1.1 reinoud int
636 1.1 reinoud udf_getattr(void *v)
637 1.1 reinoud {
638 1.1 reinoud struct vop_getattr_args /* {
639 1.1 reinoud struct vnode *a_vp;
640 1.1 reinoud struct vattr *a_vap;
641 1.5 elad kauth_cred_t a_cred;
642 1.1 reinoud struct proc *a_p;
643 1.1 reinoud } */ *ap = v;
644 1.1 reinoud struct vnode *vp = ap->a_vp;
645 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
646 1.1 reinoud struct udf_mount *ump = udf_node->ump;
647 1.1 reinoud struct vattr *vap = ap->a_vap;
648 1.1 reinoud struct file_entry *fe;
649 1.1 reinoud struct extfile_entry *efe;
650 1.1 reinoud struct timestamp *atime, *mtime, *attrtime;
651 1.1 reinoud uint32_t nlink;
652 1.1 reinoud uint64_t filesize, blkssize;
653 1.1 reinoud uid_t uid;
654 1.1 reinoud gid_t gid;
655 1.1 reinoud
656 1.1 reinoud DPRINTF(CALL, ("udf_getattr called\n"));
657 1.1 reinoud
658 1.1 reinoud /* get descriptor information */
659 1.1 reinoud if (udf_node->fe) {
660 1.1 reinoud fe = udf_node->fe;
661 1.1 reinoud nlink = udf_rw16(fe->link_cnt);
662 1.1 reinoud uid = (uid_t)udf_rw32(fe->uid);
663 1.1 reinoud gid = (gid_t)udf_rw32(fe->gid);
664 1.1 reinoud filesize = udf_rw64(fe->inf_len);
665 1.1 reinoud blkssize = udf_rw64(fe->logblks_rec);
666 1.1 reinoud atime = &fe->atime;
667 1.1 reinoud mtime = &fe->mtime;
668 1.1 reinoud attrtime = &fe->attrtime;
669 1.1 reinoud } else {
670 1.1 reinoud assert(udf_node->efe);
671 1.1 reinoud efe = udf_node->efe;
672 1.1 reinoud nlink = udf_rw16(efe->link_cnt);
673 1.1 reinoud uid = (uid_t)udf_rw32(efe->uid);
674 1.1 reinoud gid = (gid_t)udf_rw32(efe->gid);
675 1.1 reinoud filesize = udf_rw64(efe->inf_len); /* XXX or obj_size? */
676 1.1 reinoud blkssize = udf_rw64(efe->logblks_rec);
677 1.1 reinoud atime = &efe->atime;
678 1.1 reinoud mtime = &efe->mtime;
679 1.1 reinoud attrtime = &efe->attrtime;
680 1.6 christos }
681 1.1 reinoud
682 1.1 reinoud /* do the uid/gid translation game */
683 1.1 reinoud if ((uid == (uid_t) -1) && (gid == (gid_t) -1)) {
684 1.1 reinoud uid = ump->mount_args.anon_uid;
685 1.1 reinoud gid = ump->mount_args.anon_gid;
686 1.6 christos }
687 1.1 reinoud
688 1.1 reinoud /* fill in struct vattr with values from the node */
689 1.1 reinoud VATTR_NULL(vap);
690 1.1 reinoud vap->va_type = vp->v_type;
691 1.1 reinoud vap->va_mode = udf_getaccessmode(udf_node);
692 1.1 reinoud vap->va_nlink = nlink;
693 1.1 reinoud vap->va_uid = uid;
694 1.1 reinoud vap->va_gid = gid;
695 1.1 reinoud vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
696 1.1 reinoud vap->va_fileid = udf_calchash(&udf_node->loc); /* inode hash XXX */
697 1.1 reinoud vap->va_size = filesize;
698 1.1 reinoud vap->va_blocksize = udf_node->ump->discinfo.sector_size; /* wise? */
699 1.1 reinoud
700 1.1 reinoud /*
701 1.1 reinoud * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to add
702 1.1 reinoud * 1 to the link count if its a directory we're requested attributes
703 1.1 reinoud * of.
704 1.1 reinoud */
705 1.1 reinoud if (vap->va_type == VDIR)
706 1.1 reinoud vap->va_nlink++;
707 1.1 reinoud
708 1.1 reinoud /* access times */
709 1.1 reinoud udf_timestamp_to_timespec(ump, atime, &vap->va_atime);
710 1.1 reinoud udf_timestamp_to_timespec(ump, mtime, &vap->va_mtime);
711 1.1 reinoud udf_timestamp_to_timespec(ump, attrtime, &vap->va_ctime);
712 1.1 reinoud
713 1.1 reinoud vap->va_gen = 1; /* no multiple generations yes (!?) */
714 1.1 reinoud vap->va_flags = 0; /* no flags */
715 1.1 reinoud vap->va_rdev = udf_node->rdev;
716 1.1 reinoud vap->va_bytes = udf_node->ump->discinfo.sector_size * blkssize;
717 1.1 reinoud vap->va_filerev = 1; /* TODO file revision numbers? */
718 1.1 reinoud vap->va_vaflags = 0; /* TODO which va_vaflags? */
719 1.1 reinoud
720 1.1 reinoud return 0;
721 1.1 reinoud }
722 1.1 reinoud
723 1.1 reinoud /* --------------------------------------------------------------------- */
724 1.1 reinoud
725 1.1 reinoud int
726 1.1 reinoud udf_setattr(void *v)
727 1.1 reinoud {
728 1.1 reinoud struct vop_setattr_args /* {
729 1.1 reinoud struct vnode *a_vp;
730 1.1 reinoud struct vattr *a_vap;
731 1.5 elad kauth_cred_t a_cred;
732 1.1 reinoud struct proc *a_p;
733 1.1 reinoud } */ *ap = v;
734 1.1 reinoud struct vnode *vp = ap->a_vp;
735 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
736 1.1 reinoud struct udf_mount *ump = udf_node->ump;
737 1.1 reinoud struct vattr *vap = ap->a_vap;
738 1.1 reinoud uid_t uid, nobody_uid;
739 1.1 reinoud gid_t gid, nobody_gid;
740 1.1 reinoud
741 1.1 reinoud /* shut up gcc for now */
742 1.1 reinoud ap = ap;
743 1.1 reinoud vp = vp;
744 1.4 mrg uid = 0; /* XXX gcc */
745 1.4 mrg gid = 0; /* XXX gcc */
746 1.1 reinoud udf_node = udf_node;
747 1.1 reinoud
748 1.1 reinoud DPRINTF(NOTIMPL, ("udf_setattr called\n"));
749 1.1 reinoud
750 1.1 reinoud /*
751 1.1 reinoud * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to
752 1.1 reinoud * subtract 1 to the link count if its a directory we're setting
753 1.1 reinoud * attributes on. See getattr.
754 1.1 reinoud */
755 1.1 reinoud if (vap->va_type == VDIR)
756 1.1 reinoud vap->va_nlink--;
757 1.1 reinoud
758 1.1 reinoud /* do the uid/gid translation game */
759 1.1 reinoud nobody_uid = ump->mount_args.nobody_uid;
760 1.1 reinoud nobody_gid = ump->mount_args.nobody_gid;
761 1.1 reinoud if ((uid == nobody_uid) && (gid == nobody_gid)) {
762 1.1 reinoud uid = (uid_t) -1;
763 1.1 reinoud gid = (gid_t) -1;
764 1.6 christos }
765 1.1 reinoud
766 1.1 reinoud /* TODO implement setattr!! NOT IMPLEMENTED yet */
767 1.1 reinoud return 0;
768 1.1 reinoud }
769 1.1 reinoud
770 1.1 reinoud /* --------------------------------------------------------------------- */
771 1.1 reinoud
772 1.1 reinoud /*
773 1.1 reinoud * Return POSIX pathconf information for UDF file systems.
774 1.1 reinoud */
775 1.1 reinoud int
776 1.1 reinoud udf_pathconf(void *v)
777 1.1 reinoud {
778 1.1 reinoud struct vop_pathconf_args /* {
779 1.1 reinoud struct vnode *a_vp;
780 1.1 reinoud int a_name;
781 1.1 reinoud register_t *a_retval;
782 1.1 reinoud } */ *ap = v;
783 1.1 reinoud struct vnode *vp = ap->a_vp;
784 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
785 1.1 reinoud uint32_t bits;
786 1.1 reinoud
787 1.1 reinoud DPRINTF(CALL, ("udf_pathconf called\n"));
788 1.1 reinoud
789 1.1 reinoud switch (ap->a_name) {
790 1.1 reinoud case _PC_LINK_MAX:
791 1.1 reinoud *ap->a_retval = (1<<16)-1; /* 16 bits */
792 1.1 reinoud return 0;
793 1.1 reinoud case _PC_NAME_MAX:
794 1.1 reinoud *ap->a_retval = NAME_MAX;
795 1.1 reinoud return 0;
796 1.1 reinoud case _PC_PATH_MAX:
797 1.1 reinoud *ap->a_retval = PATH_MAX;
798 1.1 reinoud return 0;
799 1.1 reinoud case _PC_PIPE_BUF:
800 1.1 reinoud *ap->a_retval = PIPE_BUF;
801 1.1 reinoud return 0;
802 1.1 reinoud case _PC_CHOWN_RESTRICTED:
803 1.1 reinoud *ap->a_retval = 1;
804 1.1 reinoud return 0;
805 1.1 reinoud case _PC_NO_TRUNC:
806 1.1 reinoud *ap->a_retval = 1;
807 1.1 reinoud return 0;
808 1.1 reinoud case _PC_SYNC_IO:
809 1.1 reinoud *ap->a_retval = 0; /* synchronised is off for performance */
810 1.1 reinoud return 0;
811 1.1 reinoud case _PC_FILESIZEBITS:
812 1.1 reinoud bits = 32;
813 1.1 reinoud if (udf_node)
814 1.1 reinoud bits = 32 * vp->v_mount->mnt_dev_bshift;
815 1.1 reinoud *ap->a_retval = bits;
816 1.1 reinoud return 0;
817 1.6 christos }
818 1.1 reinoud
819 1.1 reinoud return EINVAL;
820 1.1 reinoud }
821 1.1 reinoud
822 1.1 reinoud
823 1.1 reinoud /* --------------------------------------------------------------------- */
824 1.1 reinoud
825 1.1 reinoud int
826 1.1 reinoud udf_open(void *v)
827 1.1 reinoud {
828 1.1 reinoud struct vop_open_args /* {
829 1.1 reinoud struct vnode *a_vp;
830 1.1 reinoud int a_mode;
831 1.5 elad kauth_cred_t a_cred;
832 1.1 reinoud struct proc *a_p;
833 1.1 reinoud } */ *ap;
834 1.1 reinoud
835 1.1 reinoud DPRINTF(CALL, ("udf_open called\n"));
836 1.4 mrg ap = 0; /* XXX gcc */
837 1.1 reinoud
838 1.1 reinoud return 0;
839 1.1 reinoud }
840 1.1 reinoud
841 1.1 reinoud
842 1.1 reinoud /* --------------------------------------------------------------------- */
843 1.1 reinoud
844 1.1 reinoud int
845 1.1 reinoud udf_close(void *v)
846 1.1 reinoud {
847 1.1 reinoud struct vop_close_args /* {
848 1.1 reinoud struct vnode *a_vp;
849 1.1 reinoud int a_fflag;
850 1.5 elad kauth_cred_t a_cred;
851 1.1 reinoud struct proc *a_p;
852 1.1 reinoud } */ *ap = v;
853 1.1 reinoud struct vnode *vp = ap->a_vp;
854 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
855 1.1 reinoud
856 1.1 reinoud DPRINTF(CALL, ("udf_close called\n"));
857 1.1 reinoud udf_node = udf_node; /* shut up gcc */
858 1.1 reinoud
859 1.1 reinoud simple_lock(&vp->v_interlock);
860 1.1 reinoud if (vp->v_usecount > 1) {
861 1.1 reinoud /* TODO update times */
862 1.6 christos }
863 1.1 reinoud simple_unlock(&vp->v_interlock);
864 1.1 reinoud
865 1.1 reinoud return 0;
866 1.1 reinoud }
867 1.1 reinoud
868 1.1 reinoud
869 1.1 reinoud /* --------------------------------------------------------------------- */
870 1.1 reinoud
871 1.1 reinoud int
872 1.1 reinoud udf_access(void *v)
873 1.1 reinoud {
874 1.1 reinoud struct vop_access_args /* {
875 1.1 reinoud struct vnode *a_vp;
876 1.1 reinoud int a_mode;
877 1.5 elad kauth_cred_t a_cred;
878 1.1 reinoud struct proc *a_p;
879 1.1 reinoud } */ *ap = v;
880 1.1 reinoud struct vnode *vp = ap->a_vp;
881 1.1 reinoud mode_t mode = ap->a_mode;
882 1.5 elad kauth_cred_t cred = ap->a_cred;
883 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
884 1.1 reinoud struct file_entry *fe;
885 1.1 reinoud struct extfile_entry *efe;
886 1.1 reinoud mode_t node_mode;
887 1.1 reinoud uid_t uid;
888 1.1 reinoud gid_t gid;
889 1.1 reinoud
890 1.1 reinoud DPRINTF(CALL, ("udf_access called\n"));
891 1.1 reinoud
892 1.1 reinoud /* get access mode to compare to */
893 1.1 reinoud node_mode = udf_getaccessmode(udf_node);
894 1.1 reinoud
895 1.1 reinoud /* get uid/gid pair */
896 1.1 reinoud if (udf_node->fe) {
897 1.1 reinoud fe = udf_node->fe;
898 1.1 reinoud uid = (uid_t)udf_rw32(fe->uid);
899 1.1 reinoud gid = (gid_t)udf_rw32(fe->gid);
900 1.1 reinoud } else {
901 1.1 reinoud assert(udf_node->efe);
902 1.1 reinoud efe = udf_node->efe;
903 1.1 reinoud uid = (uid_t)udf_rw32(efe->uid);
904 1.1 reinoud gid = (gid_t)udf_rw32(efe->gid);
905 1.6 christos }
906 1.1 reinoud
907 1.1 reinoud /* check if we are allowed to write */
908 1.1 reinoud switch (vp->v_type) {
909 1.1 reinoud case VDIR:
910 1.1 reinoud case VLNK:
911 1.1 reinoud case VREG:
912 1.1 reinoud /*
913 1.1 reinoud * normal nodes: check if we're on a read-only mounted
914 1.1 reinoud * filingsystem and bomb out if we're trying to write.
915 1.1 reinoud */
916 1.1 reinoud if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY))
917 1.1 reinoud return EROFS;
918 1.1 reinoud break;
919 1.1 reinoud case VBLK:
920 1.1 reinoud case VCHR:
921 1.1 reinoud case VSOCK:
922 1.1 reinoud case VFIFO:
923 1.1 reinoud /*
924 1.1 reinoud * special nodes: even on read-only mounted filingsystems
925 1.1 reinoud * these are allowed to be written to if permissions allow.
926 1.1 reinoud */
927 1.1 reinoud break;
928 1.1 reinoud default:
929 1.1 reinoud /* no idea what this is */
930 1.1 reinoud return EINVAL;
931 1.1 reinoud }
932 1.1 reinoud
933 1.1 reinoud /* TODO support for chflags checking i.e. IMMUTABLE flag */
934 1.1 reinoud
935 1.1 reinoud /* ask the generic vaccess to advice on security */
936 1.1 reinoud return vaccess(vp->v_type, node_mode, uid, gid, mode, cred);
937 1.1 reinoud }
938 1.1 reinoud
939 1.1 reinoud /* --------------------------------------------------------------------- */
940 1.1 reinoud
941 1.1 reinoud int
942 1.1 reinoud udf_create(void *v)
943 1.1 reinoud {
944 1.1 reinoud struct vop_create_args /* {
945 1.1 reinoud struct vnode *a_dvp;
946 1.1 reinoud struct vnode **a_vpp;
947 1.1 reinoud struct componentname *a_cnp;
948 1.1 reinoud struct vattr *a_vap;
949 1.1 reinoud } */ *ap = v;
950 1.1 reinoud struct componentname *cnp = ap->a_cnp;
951 1.1 reinoud
952 1.1 reinoud DPRINTF(NOTIMPL, ("udf_create called\n"));
953 1.1 reinoud
954 1.1 reinoud /* error out */
955 1.1 reinoud PNBUF_PUT(cnp->cn_pnbuf);
956 1.1 reinoud vput(ap->a_dvp);
957 1.1 reinoud return ENOTSUP;
958 1.1 reinoud }
959 1.1 reinoud
960 1.1 reinoud /* --------------------------------------------------------------------- */
961 1.1 reinoud
962 1.1 reinoud int
963 1.1 reinoud udf_mknod(void *v)
964 1.1 reinoud {
965 1.1 reinoud struct vop_mknod_args /* {
966 1.1 reinoud struct vnode *a_dvp;
967 1.1 reinoud struct vnode **a_vpp;
968 1.1 reinoud struct componentname *a_cnp;
969 1.1 reinoud struct vattr *a_vap;
970 1.1 reinoud } */ *ap = v;
971 1.1 reinoud
972 1.1 reinoud DPRINTF(NOTIMPL, ("udf_mknod called\n"));
973 1.1 reinoud
974 1.1 reinoud /* error out */
975 1.1 reinoud PNBUF_PUT(ap->a_cnp->cn_pnbuf);
976 1.1 reinoud vput(ap->a_dvp);
977 1.1 reinoud return ENOTSUP;
978 1.1 reinoud }
979 1.1 reinoud
980 1.1 reinoud /* --------------------------------------------------------------------- */
981 1.1 reinoud
982 1.1 reinoud int
983 1.1 reinoud udf_remove(void *v)
984 1.1 reinoud {
985 1.1 reinoud struct vop_remove_args /* {
986 1.1 reinoud struct vnode *a_dvp;
987 1.1 reinoud struct vnode *a_vp;
988 1.1 reinoud struct componentname *a_cnp;
989 1.1 reinoud } */ *ap = v;
990 1.1 reinoud struct vnode *dvp = ap->a_dvp;
991 1.1 reinoud struct vnode *vp = ap->a_vp;
992 1.1 reinoud
993 1.1 reinoud DPRINTF(NOTIMPL, ("udf_remove called\n"));
994 1.1 reinoud
995 1.1 reinoud /* error out */
996 1.1 reinoud vput(dvp);
997 1.1 reinoud vput(vp);
998 1.1 reinoud
999 1.1 reinoud return ENOTSUP;
1000 1.1 reinoud }
1001 1.1 reinoud
1002 1.1 reinoud /* --------------------------------------------------------------------- */
1003 1.1 reinoud
1004 1.1 reinoud int
1005 1.1 reinoud udf_link(void *v)
1006 1.1 reinoud {
1007 1.1 reinoud struct vop_link_args /* {
1008 1.1 reinoud struct vnode *a_dvp;
1009 1.1 reinoud struct vnode *a_vp;
1010 1.1 reinoud struct componentname *a_cnp;
1011 1.1 reinoud } */ *ap = v;
1012 1.1 reinoud struct vnode *dvp = ap->a_dvp;
1013 1.1 reinoud struct vnode *vp = ap->a_vp;
1014 1.1 reinoud struct componentname *cnp = ap->a_cnp;
1015 1.1 reinoud
1016 1.1 reinoud DPRINTF(NOTIMPL, ("udf_link called\n"));
1017 1.1 reinoud
1018 1.1 reinoud /* error out */
1019 1.1 reinoud /* XXX or just VOP_ABORTOP(dvp, a_cnp); ? */
1020 1.1 reinoud if (VOP_ISLOCKED(vp))
1021 1.1 reinoud VOP_UNLOCK(vp, 0);
1022 1.1 reinoud PNBUF_PUT(cnp->cn_pnbuf);
1023 1.1 reinoud vput(dvp);
1024 1.1 reinoud
1025 1.1 reinoud return ENOTSUP;
1026 1.1 reinoud }
1027 1.1 reinoud
1028 1.1 reinoud /* --------------------------------------------------------------------- */
1029 1.1 reinoud
1030 1.1 reinoud int
1031 1.1 reinoud udf_symlink(void *v)
1032 1.1 reinoud {
1033 1.1 reinoud struct vop_symlink_args /* {
1034 1.1 reinoud struct vnode *a_dvp;
1035 1.1 reinoud struct vnode **a_vpp;
1036 1.1 reinoud struct componentname *a_cnp;
1037 1.1 reinoud struct vattr *a_vap;
1038 1.1 reinoud char *a_target;
1039 1.1 reinoud } */ *ap = v;
1040 1.1 reinoud struct vnode *dvp = ap->a_dvp;
1041 1.1 reinoud struct componentname *cnp = ap->a_cnp;
1042 1.1 reinoud
1043 1.1 reinoud DPRINTF(NOTIMPL, ("udf_symlink called\n"));
1044 1.1 reinoud
1045 1.1 reinoud /* error out */
1046 1.1 reinoud VOP_ABORTOP(dvp, cnp);
1047 1.1 reinoud vput(dvp);
1048 1.1 reinoud
1049 1.1 reinoud return ENOTSUP;
1050 1.1 reinoud }
1051 1.1 reinoud
1052 1.1 reinoud /* --------------------------------------------------------------------- */
1053 1.1 reinoud
1054 1.1 reinoud int
1055 1.1 reinoud udf_readlink(void *v)
1056 1.1 reinoud {
1057 1.1 reinoud struct vop_readlink_args /* {
1058 1.1 reinoud struct vnode *a_vp;
1059 1.1 reinoud struct uio *a_uio;
1060 1.5 elad kauth_cred_t a_cred;
1061 1.1 reinoud } */ *ap = v;
1062 1.1 reinoud #ifdef notyet
1063 1.1 reinoud struct vnode *vp = ap->a_vp;
1064 1.1 reinoud struct uio *uio = ap->a_uio;
1065 1.5 elad kauth_cred_t cred = ap->a_cred;
1066 1.1 reinoud #endif
1067 1.1 reinoud
1068 1.1 reinoud ap = ap; /* shut up gcc */
1069 1.1 reinoud
1070 1.1 reinoud DPRINTF(NOTIMPL, ("udf_readlink called\n"));
1071 1.1 reinoud
1072 1.1 reinoud /* TODO read `file' contents and process pathcomponents into a path */
1073 1.1 reinoud return ENOTSUP;
1074 1.1 reinoud }
1075 1.1 reinoud
1076 1.1 reinoud /* --------------------------------------------------------------------- */
1077 1.1 reinoud
1078 1.1 reinoud int
1079 1.1 reinoud udf_rename(void *v)
1080 1.1 reinoud {
1081 1.1 reinoud struct vop_rename_args /* {
1082 1.1 reinoud struct vnode *a_fdvp;
1083 1.1 reinoud struct vnode *a_fvp;
1084 1.1 reinoud struct componentname *a_fcnp;
1085 1.1 reinoud struct vnode *a_tdvp;
1086 1.1 reinoud struct vnode *a_tvp;
1087 1.1 reinoud struct componentname *a_tcnp;
1088 1.1 reinoud } */ *ap = v;
1089 1.1 reinoud struct vnode *tvp = ap->a_tvp;
1090 1.1 reinoud struct vnode *tdvp = ap->a_tdvp;
1091 1.1 reinoud struct vnode *fvp = ap->a_fvp;
1092 1.1 reinoud struct vnode *fdvp = ap->a_fdvp;
1093 1.1 reinoud
1094 1.1 reinoud DPRINTF(NOTIMPL, ("udf_rename called\n"));
1095 1.1 reinoud
1096 1.1 reinoud /* error out */
1097 1.1 reinoud if (tdvp == tvp)
1098 1.1 reinoud vrele(tdvp);
1099 1.1 reinoud else
1100 1.1 reinoud vput(tdvp);
1101 1.1 reinoud if (tvp != NULL)
1102 1.1 reinoud vput(tvp);
1103 1.1 reinoud
1104 1.1 reinoud /* release source nodes. */
1105 1.1 reinoud vrele(fdvp);
1106 1.1 reinoud vrele(fvp);
1107 1.1 reinoud
1108 1.1 reinoud return ENOTSUP;
1109 1.1 reinoud }
1110 1.1 reinoud
1111 1.1 reinoud /* --------------------------------------------------------------------- */
1112 1.1 reinoud
1113 1.1 reinoud int
1114 1.1 reinoud udf_mkdir(void *v)
1115 1.1 reinoud {
1116 1.1 reinoud struct vop_mkdir_args /* {
1117 1.1 reinoud struct vnode *a_dvp;
1118 1.1 reinoud struct vnode **a_vpp;
1119 1.1 reinoud struct componentname *a_cnp;
1120 1.1 reinoud struct vattr *a_vap;
1121 1.1 reinoud } */ *ap = v;
1122 1.1 reinoud struct vnode *dvp = ap->a_dvp;
1123 1.1 reinoud struct componentname *cnp = ap->a_cnp;
1124 1.1 reinoud
1125 1.1 reinoud DPRINTF(NOTIMPL, ("udf_mkdir called\n"));
1126 1.1 reinoud
1127 1.1 reinoud /* error out */
1128 1.1 reinoud PNBUF_PUT(cnp->cn_pnbuf);
1129 1.1 reinoud vput(dvp);
1130 1.1 reinoud
1131 1.1 reinoud return ENOTSUP;
1132 1.1 reinoud }
1133 1.1 reinoud
1134 1.1 reinoud /* --------------------------------------------------------------------- */
1135 1.1 reinoud
1136 1.1 reinoud int
1137 1.1 reinoud udf_rmdir(void *v)
1138 1.1 reinoud {
1139 1.1 reinoud struct vop_rmdir_args /* {
1140 1.1 reinoud struct vnode *a_dvp;
1141 1.1 reinoud struct vnode *a_vp;
1142 1.1 reinoud struct componentname *a_cnp;
1143 1.1 reinoud } */ *ap = v;
1144 1.1 reinoud struct vnode *vp = ap->a_vp;
1145 1.1 reinoud struct vnode *dvp = ap->a_dvp;
1146 1.1 reinoud struct componentname *cnp = ap->a_cnp;
1147 1.1 reinoud int error;
1148 1.1 reinoud
1149 1.1 reinoud cnp = cnp; /* shut up gcc */
1150 1.1 reinoud
1151 1.1 reinoud DPRINTF(NOTIMPL, ("udf_rmdir called\n"));
1152 1.1 reinoud
1153 1.1 reinoud error = ENOTSUP;
1154 1.1 reinoud /* error out */
1155 1.1 reinoud if (error != 0) {
1156 1.1 reinoud vput(dvp);
1157 1.1 reinoud vput(vp);
1158 1.1 reinoud }
1159 1.1 reinoud
1160 1.1 reinoud return error;
1161 1.1 reinoud }
1162 1.1 reinoud
1163 1.1 reinoud /* --------------------------------------------------------------------- */
1164 1.1 reinoud
1165 1.1 reinoud int
1166 1.1 reinoud udf_fsync(void *v)
1167 1.1 reinoud {
1168 1.1 reinoud struct vop_fsync_args /* {
1169 1.1 reinoud struct vnode *a_vp;
1170 1.5 elad kauth_cred_t a_cred;
1171 1.1 reinoud int a_flags;
1172 1.1 reinoud off_t offlo;
1173 1.1 reinoud off_t offhi;
1174 1.1 reinoud struct proc *a_p;
1175 1.1 reinoud } */ *ap = v;
1176 1.1 reinoud struct vnode *vp = ap->a_vp;
1177 1.1 reinoud
1178 1.1 reinoud DPRINTF(NOTIMPL, ("udf_fsync called\n"));
1179 1.1 reinoud
1180 1.1 reinoud vp = vp; /* shut up gcc */
1181 1.1 reinoud
1182 1.1 reinoud return 0;
1183 1.1 reinoud }
1184 1.1 reinoud
1185 1.1 reinoud /* --------------------------------------------------------------------- */
1186 1.1 reinoud
1187 1.1 reinoud int
1188 1.1 reinoud udf_advlock(void *v)
1189 1.1 reinoud {
1190 1.1 reinoud struct vop_advlock_args /* {
1191 1.1 reinoud struct vnode *a_vp;
1192 1.1 reinoud void *a_id;
1193 1.1 reinoud int a_op;
1194 1.1 reinoud struct flock *a_fl;
1195 1.1 reinoud int a_flags;
1196 1.1 reinoud } */ *ap = v;
1197 1.1 reinoud struct vnode *vp = ap->a_vp;
1198 1.1 reinoud struct udf_node *udf_node = VTOI(vp);
1199 1.1 reinoud struct file_entry *fe;
1200 1.1 reinoud struct extfile_entry *efe;
1201 1.1 reinoud uint64_t file_size;
1202 1.1 reinoud
1203 1.1 reinoud DPRINTF(LOCKING, ("udf_advlock called\n"));
1204 1.1 reinoud
1205 1.1 reinoud /* get directory filesize */
1206 1.1 reinoud if (udf_node->fe) {
1207 1.1 reinoud fe = udf_node->fe;
1208 1.1 reinoud file_size = udf_rw64(fe->inf_len);
1209 1.1 reinoud } else {
1210 1.1 reinoud assert(udf_node->efe);
1211 1.1 reinoud efe = udf_node->efe;
1212 1.1 reinoud file_size = udf_rw64(efe->inf_len);
1213 1.6 christos }
1214 1.1 reinoud
1215 1.1 reinoud return lf_advlock(ap, &udf_node->lockf, file_size);
1216 1.1 reinoud }
1217 1.1 reinoud
1218 1.1 reinoud /* --------------------------------------------------------------------- */
1219 1.1 reinoud
1220 1.1 reinoud
1221 1.1 reinoud /* Global vfs vnode data structures for udfs */
1222 1.1 reinoud int (**udf_vnodeop_p) __P((void *));
1223 1.1 reinoud
1224 1.1 reinoud const struct vnodeopv_entry_desc udf_vnodeop_entries[] = {
1225 1.1 reinoud { &vop_default_desc, vn_default_error },
1226 1.1 reinoud { &vop_lookup_desc, udf_lookup }, /* lookup */
1227 1.1 reinoud { &vop_create_desc, udf_create }, /* create */ /* TODO */
1228 1.1 reinoud { &vop_mknod_desc, udf_mknod }, /* mknod */ /* TODO */
1229 1.1 reinoud { &vop_open_desc, udf_open }, /* open */
1230 1.1 reinoud { &vop_close_desc, udf_close }, /* close */
1231 1.1 reinoud { &vop_access_desc, udf_access }, /* access */
1232 1.1 reinoud { &vop_getattr_desc, udf_getattr }, /* getattr */
1233 1.1 reinoud { &vop_setattr_desc, udf_setattr }, /* setattr */ /* TODO */
1234 1.1 reinoud { &vop_read_desc, udf_read }, /* read */
1235 1.1 reinoud { &vop_write_desc, udf_write }, /* write */ /* WRITE */
1236 1.1 reinoud { &vop_lease_desc, genfs_lease_check }, /* lease */ /* TODO? */
1237 1.1 reinoud { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ /* TODO? */
1238 1.1 reinoud { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */ /* TODO? */
1239 1.1 reinoud { &vop_poll_desc, genfs_poll }, /* poll */ /* TODO/OK? */
1240 1.1 reinoud { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ /* ? */
1241 1.1 reinoud { &vop_revoke_desc, genfs_revoke }, /* revoke */ /* TODO? */
1242 1.1 reinoud { &vop_mmap_desc, genfs_mmap }, /* mmap */ /* OK? */
1243 1.1 reinoud { &vop_fsync_desc, udf_fsync }, /* fsync */ /* TODO */
1244 1.1 reinoud { &vop_seek_desc, genfs_seek }, /* seek */
1245 1.1 reinoud { &vop_remove_desc, udf_remove }, /* remove */ /* TODO */
1246 1.1 reinoud { &vop_link_desc, udf_link }, /* link */ /* TODO */
1247 1.1 reinoud { &vop_rename_desc, udf_rename }, /* rename */ /* TODO */
1248 1.1 reinoud { &vop_mkdir_desc, udf_mkdir }, /* mkdir */ /* TODO */
1249 1.1 reinoud { &vop_rmdir_desc, udf_rmdir }, /* rmdir */ /* TODO */
1250 1.1 reinoud { &vop_symlink_desc, udf_symlink }, /* symlink */ /* TODO */
1251 1.1 reinoud { &vop_readdir_desc, udf_readdir }, /* readdir */
1252 1.1 reinoud { &vop_readlink_desc, udf_readlink }, /* readlink */ /* TEST ME */
1253 1.1 reinoud { &vop_abortop_desc, genfs_abortop }, /* abortop */ /* TODO/OK? */
1254 1.1 reinoud { &vop_inactive_desc, udf_inactive }, /* inactive */
1255 1.1 reinoud { &vop_reclaim_desc, udf_reclaim }, /* reclaim */
1256 1.1 reinoud { &vop_lock_desc, genfs_lock }, /* lock */
1257 1.1 reinoud { &vop_unlock_desc, genfs_unlock }, /* unlock */
1258 1.1 reinoud { &vop_bmap_desc, udf_trivial_bmap }, /* bmap */ /* 1:1 bmap */
1259 1.1 reinoud { &vop_strategy_desc, udf_strategy }, /* strategy */
1260 1.1 reinoud /* { &vop_print_desc, udf_print }, */ /* print */
1261 1.1 reinoud { &vop_islocked_desc, genfs_islocked }, /* islocked */
1262 1.1 reinoud { &vop_pathconf_desc, udf_pathconf }, /* pathconf */
1263 1.1 reinoud { &vop_advlock_desc, udf_advlock }, /* advlock */ /* TEST ME */
1264 1.1 reinoud { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ /* ->strategy */
1265 1.1 reinoud { &vop_getpages_desc, genfs_getpages }, /* getpages */
1266 1.1 reinoud { &vop_putpages_desc, genfs_putpages }, /* putpages */
1267 1.1 reinoud { NULL, NULL }
1268 1.1 reinoud };
1269 1.1 reinoud
1270 1.1 reinoud
1271 1.1 reinoud const struct vnodeopv_desc udf_vnodeop_opv_desc = {
1272 1.1 reinoud &udf_vnodeop_p, udf_vnodeop_entries
1273 1.1 reinoud };
1274 1.1 reinoud
1275