17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5aa59c4cbSrsb * Common Development and Distribution License (the "License").
6aa59c4cbSrsb * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
213b862e9aSRoger A. Faulkner
227c478bd9Sstevel@tonic-gate /*
23b39a0235SMilan Cermak * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
26*72102e74SBryan Cantrill /*
27*72102e74SBryan Cantrill * Copyright (c) 2013, Joyent, Inc. All rights reserved.
28*72102e74SBryan Cantrill */
29*72102e74SBryan Cantrill
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/time.h>
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
367c478bd9Sstevel@tonic-gate #include <sys/resource.h>
377c478bd9Sstevel@tonic-gate #include <sys/signal.h>
387c478bd9Sstevel@tonic-gate #include <sys/cred.h>
397c478bd9Sstevel@tonic-gate #include <sys/user.h>
407c478bd9Sstevel@tonic-gate #include <sys/buf.h>
417c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
42aa59c4cbSrsb #include <sys/vfs_opreg.h>
437c478bd9Sstevel@tonic-gate #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
457c478bd9Sstevel@tonic-gate #include <sys/mode.h>
467c478bd9Sstevel@tonic-gate #include <sys/proc.h>
477c478bd9Sstevel@tonic-gate #include <sys/disp.h>
487c478bd9Sstevel@tonic-gate #include <sys/file.h>
497c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
507c478bd9Sstevel@tonic-gate #include <sys/flock.h>
517c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
527c478bd9Sstevel@tonic-gate #include <sys/uio.h>
537c478bd9Sstevel@tonic-gate #include <sys/dnlc.h>
547c478bd9Sstevel@tonic-gate #include <sys/conf.h>
557c478bd9Sstevel@tonic-gate #include <sys/errno.h>
567c478bd9Sstevel@tonic-gate #include <sys/mman.h>
577c478bd9Sstevel@tonic-gate #include <sys/fbuf.h>
587c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
597c478bd9Sstevel@tonic-gate #include <sys/debug.h>
607c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
617c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
627c478bd9Sstevel@tonic-gate #include <sys/dirent.h>
637c478bd9Sstevel@tonic-gate #include <sys/errno.h>
647c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
657c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
667c478bd9Sstevel@tonic-gate #include <sys/mount.h>
677c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
687c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
697c478bd9Sstevel@tonic-gate #include <sys/policy.h>
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate #include <vm/hat.h>
727c478bd9Sstevel@tonic-gate #include <vm/page.h>
737c478bd9Sstevel@tonic-gate #include <vm/pvn.h>
747c478bd9Sstevel@tonic-gate #include <vm/as.h>
757c478bd9Sstevel@tonic-gate #include <vm/seg.h>
767c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
777c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
787c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
797c478bd9Sstevel@tonic-gate #include <vm/rm.h>
807c478bd9Sstevel@tonic-gate #include <vm/page.h>
817c478bd9Sstevel@tonic-gate #include <sys/swap.h>
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
867c478bd9Sstevel@tonic-gate #include <sys/fs/udf_inode.h>
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate static int32_t udf_open(struct vnode **,
89da6c28aaSamw int32_t, struct cred *, caller_context_t *);
907c478bd9Sstevel@tonic-gate static int32_t udf_close(struct vnode *,
91da6c28aaSamw int32_t, int32_t, offset_t, struct cred *, caller_context_t *);
927c478bd9Sstevel@tonic-gate static int32_t udf_read(struct vnode *,
93da6c28aaSamw struct uio *, int32_t, struct cred *, caller_context_t *);
947c478bd9Sstevel@tonic-gate static int32_t udf_write(struct vnode *,
95da6c28aaSamw struct uio *, int32_t, struct cred *, caller_context_t *);
967c478bd9Sstevel@tonic-gate static int32_t udf_ioctl(struct vnode *,
97da6c28aaSamw int32_t, intptr_t, int32_t, struct cred *, int32_t *,
98da6c28aaSamw caller_context_t *);
997c478bd9Sstevel@tonic-gate static int32_t udf_getattr(struct vnode *,
100da6c28aaSamw struct vattr *, int32_t, struct cred *, caller_context_t *);
1017c478bd9Sstevel@tonic-gate static int32_t udf_setattr(struct vnode *,
1027c478bd9Sstevel@tonic-gate struct vattr *, int32_t, struct cred *, caller_context_t *);
1037c478bd9Sstevel@tonic-gate static int32_t udf_access(struct vnode *,
104da6c28aaSamw int32_t, int32_t, struct cred *, caller_context_t *);
1057c478bd9Sstevel@tonic-gate static int32_t udf_lookup(struct vnode *,
1067c478bd9Sstevel@tonic-gate char *, struct vnode **, struct pathname *,
107da6c28aaSamw int32_t, struct vnode *, struct cred *,
108da6c28aaSamw caller_context_t *, int *, pathname_t *);
1097c478bd9Sstevel@tonic-gate static int32_t udf_create(struct vnode *,
1107c478bd9Sstevel@tonic-gate char *, struct vattr *, enum vcexcl,
111da6c28aaSamw int32_t, struct vnode **, struct cred *, int32_t,
112da6c28aaSamw caller_context_t *, vsecattr_t *);
1137c478bd9Sstevel@tonic-gate static int32_t udf_remove(struct vnode *,
114da6c28aaSamw char *, struct cred *, caller_context_t *, int);
1157c478bd9Sstevel@tonic-gate static int32_t udf_link(struct vnode *,
116da6c28aaSamw struct vnode *, char *, struct cred *, caller_context_t *, int);
1177c478bd9Sstevel@tonic-gate static int32_t udf_rename(struct vnode *,
118da6c28aaSamw char *, struct vnode *, char *, struct cred *, caller_context_t *, int);
1197c478bd9Sstevel@tonic-gate static int32_t udf_mkdir(struct vnode *,
120da6c28aaSamw char *, struct vattr *, struct vnode **, struct cred *,
121da6c28aaSamw caller_context_t *, int, vsecattr_t *);
1227c478bd9Sstevel@tonic-gate static int32_t udf_rmdir(struct vnode *,
123da6c28aaSamw char *, struct vnode *, struct cred *, caller_context_t *, int);
1247c478bd9Sstevel@tonic-gate static int32_t udf_readdir(struct vnode *,
125da6c28aaSamw struct uio *, struct cred *, int32_t *, caller_context_t *, int);
1267c478bd9Sstevel@tonic-gate static int32_t udf_symlink(struct vnode *,
127da6c28aaSamw char *, struct vattr *, char *, struct cred *, caller_context_t *, int);
1287c478bd9Sstevel@tonic-gate static int32_t udf_readlink(struct vnode *,
129da6c28aaSamw struct uio *, struct cred *, caller_context_t *);
1307c478bd9Sstevel@tonic-gate static int32_t udf_fsync(struct vnode *,
131da6c28aaSamw int32_t, struct cred *, caller_context_t *);
1327c478bd9Sstevel@tonic-gate static void udf_inactive(struct vnode *,
133da6c28aaSamw struct cred *, caller_context_t *);
134da6c28aaSamw static int32_t udf_fid(struct vnode *, struct fid *, caller_context_t *);
1357c478bd9Sstevel@tonic-gate static int udf_rwlock(struct vnode *, int32_t, caller_context_t *);
1367c478bd9Sstevel@tonic-gate static void udf_rwunlock(struct vnode *, int32_t, caller_context_t *);
137da6c28aaSamw static int32_t udf_seek(struct vnode *, offset_t, offset_t *,
138da6c28aaSamw caller_context_t *);
1397c478bd9Sstevel@tonic-gate static int32_t udf_frlock(struct vnode *, int32_t,
140da6c28aaSamw struct flock64 *, int32_t, offset_t, struct flk_callback *, cred_t *,
141da6c28aaSamw caller_context_t *);
1427c478bd9Sstevel@tonic-gate static int32_t udf_space(struct vnode *, int32_t,
1437c478bd9Sstevel@tonic-gate struct flock64 *, int32_t, offset_t, cred_t *, caller_context_t *);
1447c478bd9Sstevel@tonic-gate static int32_t udf_getpage(struct vnode *, offset_t,
1457c478bd9Sstevel@tonic-gate size_t, uint32_t *, struct page **, size_t,
146da6c28aaSamw struct seg *, caddr_t, enum seg_rw, struct cred *, caller_context_t *);
1477c478bd9Sstevel@tonic-gate static int32_t udf_putpage(struct vnode *, offset_t,
148da6c28aaSamw size_t, int32_t, struct cred *, caller_context_t *);
1497c478bd9Sstevel@tonic-gate static int32_t udf_map(struct vnode *, offset_t, struct as *,
150da6c28aaSamw caddr_t *, size_t, uint8_t, uint8_t, uint32_t, struct cred *,
151da6c28aaSamw caller_context_t *);
1527c478bd9Sstevel@tonic-gate static int32_t udf_addmap(struct vnode *, offset_t, struct as *,
153da6c28aaSamw caddr_t, size_t, uint8_t, uint8_t, uint32_t, struct cred *,
154da6c28aaSamw caller_context_t *);
1557c478bd9Sstevel@tonic-gate static int32_t udf_delmap(struct vnode *, offset_t, struct as *,
156da6c28aaSamw caddr_t, size_t, uint32_t, uint32_t, uint32_t, struct cred *,
157da6c28aaSamw caller_context_t *);
1587c478bd9Sstevel@tonic-gate static int32_t udf_l_pathconf(struct vnode *, int32_t,
159da6c28aaSamw ulong_t *, struct cred *, caller_context_t *);
1607c478bd9Sstevel@tonic-gate static int32_t udf_pageio(struct vnode *, struct page *,
161da6c28aaSamw u_offset_t, size_t, int32_t, struct cred *, caller_context_t *);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate int32_t ud_getpage_miss(struct vnode *, u_offset_t,
1647c478bd9Sstevel@tonic-gate size_t, struct seg *, caddr_t, page_t *pl[],
1657c478bd9Sstevel@tonic-gate size_t, enum seg_rw, int32_t);
1667c478bd9Sstevel@tonic-gate void ud_getpage_ra(struct vnode *, u_offset_t, struct seg *, caddr_t);
1677c478bd9Sstevel@tonic-gate int32_t ud_putpages(struct vnode *, offset_t, size_t, int32_t, struct cred *);
1687c478bd9Sstevel@tonic-gate int32_t ud_page_fill(struct ud_inode *, page_t *,
1697c478bd9Sstevel@tonic-gate u_offset_t, uint32_t, u_offset_t *);
1707c478bd9Sstevel@tonic-gate int32_t ud_iodone(struct buf *);
1717c478bd9Sstevel@tonic-gate int32_t ud_rdip(struct ud_inode *, struct uio *, int32_t, cred_t *);
1727c478bd9Sstevel@tonic-gate int32_t ud_wrip(struct ud_inode *, struct uio *, int32_t, cred_t *);
1737c478bd9Sstevel@tonic-gate int32_t ud_multi_strat(struct ud_inode *, page_t *, struct buf *, u_offset_t);
1747c478bd9Sstevel@tonic-gate int32_t ud_slave_done(struct buf *);
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate * Structures to control multiple IO operations to get or put pages
1787c478bd9Sstevel@tonic-gate * that are backed by discontiguous blocks. The master struct is
1797c478bd9Sstevel@tonic-gate * a dummy that holds the original bp from pageio_setup. The
1807c478bd9Sstevel@tonic-gate * slave struct holds the working bp's to do the actual IO. Once
1817c478bd9Sstevel@tonic-gate * all the slave IOs complete. The master is processed as if a single
1827c478bd9Sstevel@tonic-gate * IO op has completed.
1837c478bd9Sstevel@tonic-gate */
1847c478bd9Sstevel@tonic-gate uint32_t master_index = 0;
1857c478bd9Sstevel@tonic-gate typedef struct mio_master {
1867c478bd9Sstevel@tonic-gate kmutex_t mm_mutex; /* protect the fields below */
1877c478bd9Sstevel@tonic-gate int32_t mm_size;
1887c478bd9Sstevel@tonic-gate buf_t *mm_bp; /* original bp */
1897c478bd9Sstevel@tonic-gate int32_t mm_resid; /* bytes remaining to transfer */
1907c478bd9Sstevel@tonic-gate int32_t mm_error; /* accumulated error from slaves */
1917c478bd9Sstevel@tonic-gate int32_t mm_index; /* XXX debugging */
1927c478bd9Sstevel@tonic-gate } mio_master_t;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate typedef struct mio_slave {
1957c478bd9Sstevel@tonic-gate buf_t ms_buf; /* working buffer for this IO chunk */
1967c478bd9Sstevel@tonic-gate mio_master_t *ms_ptr; /* pointer to master */
1977c478bd9Sstevel@tonic-gate } mio_slave_t;
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate struct vnodeops *udf_vnodeops;
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate const fs_operation_def_t udf_vnodeops_template[] = {
202aa59c4cbSrsb VOPNAME_OPEN, { .vop_open = udf_open },
203aa59c4cbSrsb VOPNAME_CLOSE, { .vop_close = udf_close },
204aa59c4cbSrsb VOPNAME_READ, { .vop_read = udf_read },
205aa59c4cbSrsb VOPNAME_WRITE, { .vop_write = udf_write },
206aa59c4cbSrsb VOPNAME_IOCTL, { .vop_ioctl = udf_ioctl },
207aa59c4cbSrsb VOPNAME_GETATTR, { .vop_getattr = udf_getattr },
208aa59c4cbSrsb VOPNAME_SETATTR, { .vop_setattr = udf_setattr },
209aa59c4cbSrsb VOPNAME_ACCESS, { .vop_access = udf_access },
210aa59c4cbSrsb VOPNAME_LOOKUP, { .vop_lookup = udf_lookup },
211aa59c4cbSrsb VOPNAME_CREATE, { .vop_create = udf_create },
212aa59c4cbSrsb VOPNAME_REMOVE, { .vop_remove = udf_remove },
213aa59c4cbSrsb VOPNAME_LINK, { .vop_link = udf_link },
214aa59c4cbSrsb VOPNAME_RENAME, { .vop_rename = udf_rename },
215aa59c4cbSrsb VOPNAME_MKDIR, { .vop_mkdir = udf_mkdir },
216aa59c4cbSrsb VOPNAME_RMDIR, { .vop_rmdir = udf_rmdir },
217aa59c4cbSrsb VOPNAME_READDIR, { .vop_readdir = udf_readdir },
218aa59c4cbSrsb VOPNAME_SYMLINK, { .vop_symlink = udf_symlink },
219aa59c4cbSrsb VOPNAME_READLINK, { .vop_readlink = udf_readlink },
220aa59c4cbSrsb VOPNAME_FSYNC, { .vop_fsync = udf_fsync },
221aa59c4cbSrsb VOPNAME_INACTIVE, { .vop_inactive = udf_inactive },
222aa59c4cbSrsb VOPNAME_FID, { .vop_fid = udf_fid },
223aa59c4cbSrsb VOPNAME_RWLOCK, { .vop_rwlock = udf_rwlock },
224aa59c4cbSrsb VOPNAME_RWUNLOCK, { .vop_rwunlock = udf_rwunlock },
225aa59c4cbSrsb VOPNAME_SEEK, { .vop_seek = udf_seek },
226aa59c4cbSrsb VOPNAME_FRLOCK, { .vop_frlock = udf_frlock },
227aa59c4cbSrsb VOPNAME_SPACE, { .vop_space = udf_space },
228aa59c4cbSrsb VOPNAME_GETPAGE, { .vop_getpage = udf_getpage },
229aa59c4cbSrsb VOPNAME_PUTPAGE, { .vop_putpage = udf_putpage },
230aa59c4cbSrsb VOPNAME_MAP, { .vop_map = udf_map },
231aa59c4cbSrsb VOPNAME_ADDMAP, { .vop_addmap = udf_addmap },
232aa59c4cbSrsb VOPNAME_DELMAP, { .vop_delmap = udf_delmap },
233aa59c4cbSrsb VOPNAME_PATHCONF, { .vop_pathconf = udf_l_pathconf },
234aa59c4cbSrsb VOPNAME_PAGEIO, { .vop_pageio = udf_pageio },
235aa59c4cbSrsb VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
2367c478bd9Sstevel@tonic-gate NULL, NULL
2377c478bd9Sstevel@tonic-gate };
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /* ARGSUSED */
2407c478bd9Sstevel@tonic-gate static int32_t
udf_open(struct vnode ** vpp,int32_t flag,struct cred * cr,caller_context_t * ct)241da6c28aaSamw udf_open(
242da6c28aaSamw struct vnode **vpp,
243da6c28aaSamw int32_t flag,
244da6c28aaSamw struct cred *cr,
245da6c28aaSamw caller_context_t *ct)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate ud_printf("udf_open\n");
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate return (0);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate /* ARGSUSED */
2537c478bd9Sstevel@tonic-gate static int32_t
udf_close(struct vnode * vp,int32_t flag,int32_t count,offset_t offset,struct cred * cr,caller_context_t * ct)254da6c28aaSamw udf_close(
255da6c28aaSamw struct vnode *vp,
256da6c28aaSamw int32_t flag,
257da6c28aaSamw int32_t count,
258da6c28aaSamw offset_t offset,
259da6c28aaSamw struct cred *cr,
260da6c28aaSamw caller_context_t *ct)
2617c478bd9Sstevel@tonic-gate {
2627c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate ud_printf("udf_close\n");
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate ITIMES(ip);
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate cleanlocks(vp, ttoproc(curthread)->p_pid, 0);
2697c478bd9Sstevel@tonic-gate cleanshares(vp, ttoproc(curthread)->p_pid);
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate * Push partially filled cluster at last close.
2737c478bd9Sstevel@tonic-gate * ``last close'' is approximated because the dnlc
2747c478bd9Sstevel@tonic-gate * may have a hold on the vnode.
2757c478bd9Sstevel@tonic-gate */
2767c478bd9Sstevel@tonic-gate if (vp->v_count <= 2 && vp->v_type != VBAD) {
2777c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
2787c478bd9Sstevel@tonic-gate if (ip->i_delaylen) {
2797c478bd9Sstevel@tonic-gate (void) ud_putpages(vp, ip->i_delayoff, ip->i_delaylen,
2807c478bd9Sstevel@tonic-gate B_ASYNC | B_FREE, cr);
2817c478bd9Sstevel@tonic-gate ip->i_delaylen = 0;
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate return (0);
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
288da6c28aaSamw /* ARGSUSED */
2897c478bd9Sstevel@tonic-gate static int32_t
udf_read(struct vnode * vp,struct uio * uiop,int32_t ioflag,struct cred * cr,caller_context_t * ct)290da6c28aaSamw udf_read(
291da6c28aaSamw struct vnode *vp,
292da6c28aaSamw struct uio *uiop,
293da6c28aaSamw int32_t ioflag,
294da6c28aaSamw struct cred *cr,
295da6c28aaSamw caller_context_t *ct)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
2987c478bd9Sstevel@tonic-gate int32_t error;
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate ud_printf("udf_read\n");
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate #ifdef __lock_lint
3037c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_READER);
3047c478bd9Sstevel@tonic-gate #endif
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate ASSERT(RW_READ_HELD(&ip->i_rwlock));
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate if (MANDLOCK(vp, ip->i_char)) {
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate * udf_getattr ends up being called by chklock
3117c478bd9Sstevel@tonic-gate */
3127c478bd9Sstevel@tonic-gate error = chklock(vp, FREAD, uiop->uio_loffset,
3137c478bd9Sstevel@tonic-gate uiop->uio_resid, uiop->uio_fmode, ct);
3147c478bd9Sstevel@tonic-gate if (error) {
3157c478bd9Sstevel@tonic-gate goto end;
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
3207c478bd9Sstevel@tonic-gate error = ud_rdip(ip, uiop, ioflag, cr);
3217c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate end:
3247c478bd9Sstevel@tonic-gate #ifdef __lock_lint
3257c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
3267c478bd9Sstevel@tonic-gate #endif
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate return (error);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate int32_t ud_WRITES = 1;
3337c478bd9Sstevel@tonic-gate int32_t ud_HW = 96 * 1024;
3347c478bd9Sstevel@tonic-gate int32_t ud_LW = 64 * 1024;
3357c478bd9Sstevel@tonic-gate int32_t ud_throttles = 0;
3367c478bd9Sstevel@tonic-gate
337da6c28aaSamw /* ARGSUSED */
3387c478bd9Sstevel@tonic-gate static int32_t
udf_write(struct vnode * vp,struct uio * uiop,int32_t ioflag,struct cred * cr,caller_context_t * ct)339da6c28aaSamw udf_write(
340da6c28aaSamw struct vnode *vp,
341da6c28aaSamw struct uio *uiop,
342da6c28aaSamw int32_t ioflag,
343da6c28aaSamw struct cred *cr,
344da6c28aaSamw caller_context_t *ct)
3457c478bd9Sstevel@tonic-gate {
3467c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
3477c478bd9Sstevel@tonic-gate int32_t error = 0;
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate ud_printf("udf_write\n");
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate #ifdef __lock_lint
3527c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
3537c478bd9Sstevel@tonic-gate #endif
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&ip->i_rwlock));
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate if (MANDLOCK(vp, ip->i_char)) {
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate * ud_getattr ends up being called by chklock
3607c478bd9Sstevel@tonic-gate */
3617c478bd9Sstevel@tonic-gate error = chklock(vp, FWRITE, uiop->uio_loffset,
3627c478bd9Sstevel@tonic-gate uiop->uio_resid, uiop->uio_fmode, ct);
3637c478bd9Sstevel@tonic-gate if (error) {
3647c478bd9Sstevel@tonic-gate goto end;
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate * Throttle writes.
3697c478bd9Sstevel@tonic-gate */
3707c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
3717c478bd9Sstevel@tonic-gate if (ud_WRITES && (ip->i_writes > ud_HW)) {
3727c478bd9Sstevel@tonic-gate while (ip->i_writes > ud_HW) {
3737c478bd9Sstevel@tonic-gate ud_throttles++;
3747c478bd9Sstevel@tonic-gate cv_wait(&ip->i_wrcv, &ip->i_tlock);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate * Write to the file
3817c478bd9Sstevel@tonic-gate */
3827c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
3837c478bd9Sstevel@tonic-gate if ((ioflag & FAPPEND) != 0 && (ip->i_type == VREG)) {
3847c478bd9Sstevel@tonic-gate /*
3857c478bd9Sstevel@tonic-gate * In append mode start at end of file.
3867c478bd9Sstevel@tonic-gate */
3877c478bd9Sstevel@tonic-gate uiop->uio_loffset = ip->i_size;
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate error = ud_wrip(ip, uiop, ioflag, cr);
3907c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate end:
3937c478bd9Sstevel@tonic-gate #ifdef __lock_lint
3947c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
3957c478bd9Sstevel@tonic-gate #endif
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate return (error);
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate /* ARGSUSED */
4017c478bd9Sstevel@tonic-gate static int32_t
udf_ioctl(struct vnode * vp,int32_t cmd,intptr_t arg,int32_t flag,struct cred * cr,int32_t * rvalp,caller_context_t * ct)402da6c28aaSamw udf_ioctl(
403da6c28aaSamw struct vnode *vp,
404da6c28aaSamw int32_t cmd,
405da6c28aaSamw intptr_t arg,
406da6c28aaSamw int32_t flag,
407da6c28aaSamw struct cred *cr,
408da6c28aaSamw int32_t *rvalp,
409da6c28aaSamw caller_context_t *ct)
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate return (ENOTTY);
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate /* ARGSUSED */
4157c478bd9Sstevel@tonic-gate static int32_t
udf_getattr(struct vnode * vp,struct vattr * vap,int32_t flags,struct cred * cr,caller_context_t * ct)416da6c28aaSamw udf_getattr(
417da6c28aaSamw struct vnode *vp,
418da6c28aaSamw struct vattr *vap,
419da6c28aaSamw int32_t flags,
420da6c28aaSamw struct cred *cr,
421da6c28aaSamw caller_context_t *ct)
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate ud_printf("udf_getattr\n");
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate if (vap->va_mask == AT_SIZE) {
4287c478bd9Sstevel@tonic-gate /*
4297c478bd9Sstevel@tonic-gate * for performance, if only the size is requested don't bother
4307c478bd9Sstevel@tonic-gate * with anything else.
4317c478bd9Sstevel@tonic-gate */
4327c478bd9Sstevel@tonic-gate vap->va_size = ip->i_size;
4337c478bd9Sstevel@tonic-gate return (0);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate vap->va_type = vp->v_type;
4397c478bd9Sstevel@tonic-gate vap->va_mode = UD2VA_PERM(ip->i_perm) | ip->i_char;
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate vap->va_uid = ip->i_uid;
4427c478bd9Sstevel@tonic-gate vap->va_gid = ip->i_gid;
4437c478bd9Sstevel@tonic-gate vap->va_fsid = ip->i_dev;
4447c478bd9Sstevel@tonic-gate vap->va_nodeid = ip->i_icb_lbano;
4457c478bd9Sstevel@tonic-gate vap->va_nlink = ip->i_nlink;
4467c478bd9Sstevel@tonic-gate vap->va_size = ip->i_size;
4477c478bd9Sstevel@tonic-gate vap->va_seq = ip->i_seq;
4487c478bd9Sstevel@tonic-gate if (vp->v_type == VCHR || vp->v_type == VBLK) {
4497c478bd9Sstevel@tonic-gate vap->va_rdev = ip->i_rdev;
4507c478bd9Sstevel@tonic-gate } else {
4517c478bd9Sstevel@tonic-gate vap->va_rdev = 0;
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
4557c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(ip); /* mark correct time in inode */
4567c478bd9Sstevel@tonic-gate vap->va_atime.tv_sec = (time_t)ip->i_atime.tv_sec;
4577c478bd9Sstevel@tonic-gate vap->va_atime.tv_nsec = ip->i_atime.tv_nsec;
4587c478bd9Sstevel@tonic-gate vap->va_mtime.tv_sec = (time_t)ip->i_mtime.tv_sec;
4597c478bd9Sstevel@tonic-gate vap->va_mtime.tv_nsec = ip->i_mtime.tv_nsec;
4607c478bd9Sstevel@tonic-gate vap->va_ctime.tv_sec = (time_t)ip->i_ctime.tv_sec;
4617c478bd9Sstevel@tonic-gate vap->va_ctime.tv_nsec = ip->i_ctime.tv_nsec;
4627c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate switch (ip->i_type) {
4657c478bd9Sstevel@tonic-gate case VBLK:
4667c478bd9Sstevel@tonic-gate vap->va_blksize = MAXBSIZE;
4677c478bd9Sstevel@tonic-gate break;
4687c478bd9Sstevel@tonic-gate case VCHR:
4697c478bd9Sstevel@tonic-gate vap->va_blksize = MAXBSIZE;
4707c478bd9Sstevel@tonic-gate break;
4717c478bd9Sstevel@tonic-gate default:
4727c478bd9Sstevel@tonic-gate vap->va_blksize = ip->i_udf->udf_lbsize;
4737c478bd9Sstevel@tonic-gate break;
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate vap->va_nblocks = ip->i_lbr << ip->i_udf->udf_l2d_shift;
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate return (0);
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate static int
ud_iaccess_vmode(void * ip,int mode,struct cred * cr)4837c478bd9Sstevel@tonic-gate ud_iaccess_vmode(void *ip, int mode, struct cred *cr)
4847c478bd9Sstevel@tonic-gate {
485b39a0235SMilan Cermak return (ud_iaccess(ip, UD_UPERM2DPERM(mode), cr, 0));
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate /*ARGSUSED4*/
4897c478bd9Sstevel@tonic-gate static int32_t
udf_setattr(struct vnode * vp,struct vattr * vap,int32_t flags,struct cred * cr,caller_context_t * ct)4907c478bd9Sstevel@tonic-gate udf_setattr(
4917c478bd9Sstevel@tonic-gate struct vnode *vp,
4927c478bd9Sstevel@tonic-gate struct vattr *vap,
4937c478bd9Sstevel@tonic-gate int32_t flags,
4947c478bd9Sstevel@tonic-gate struct cred *cr,
4957c478bd9Sstevel@tonic-gate caller_context_t *ct)
4967c478bd9Sstevel@tonic-gate {
4977c478bd9Sstevel@tonic-gate int32_t error = 0;
4987c478bd9Sstevel@tonic-gate uint32_t mask = vap->va_mask;
4997c478bd9Sstevel@tonic-gate struct ud_inode *ip;
5007c478bd9Sstevel@tonic-gate timestruc_t now;
5017c478bd9Sstevel@tonic-gate struct vattr ovap;
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate ud_printf("udf_setattr\n");
5047c478bd9Sstevel@tonic-gate
5057c478bd9Sstevel@tonic-gate ip = VTOI(vp);
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate * not updates allowed to 4096 files
5097c478bd9Sstevel@tonic-gate */
5107c478bd9Sstevel@tonic-gate if (ip->i_astrat == STRAT_TYPE4096) {
5117c478bd9Sstevel@tonic-gate return (EINVAL);
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate * Cannot set these attributes
5167c478bd9Sstevel@tonic-gate */
5177c478bd9Sstevel@tonic-gate if (mask & AT_NOSET) {
5187c478bd9Sstevel@tonic-gate return (EINVAL);
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
5227c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate ovap.va_uid = ip->i_uid;
5257c478bd9Sstevel@tonic-gate ovap.va_mode = UD2VA_PERM(ip->i_perm) | ip->i_char;
5267c478bd9Sstevel@tonic-gate error = secpolicy_vnode_setattr(cr, vp, vap, &ovap, flags,
5277c478bd9Sstevel@tonic-gate ud_iaccess_vmode, ip);
5287c478bd9Sstevel@tonic-gate if (error)
5297c478bd9Sstevel@tonic-gate goto update_inode;
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate mask = vap->va_mask;
5327c478bd9Sstevel@tonic-gate /*
5337c478bd9Sstevel@tonic-gate * Change file access modes.
5347c478bd9Sstevel@tonic-gate */
5357c478bd9Sstevel@tonic-gate if (mask & AT_MODE) {
5367c478bd9Sstevel@tonic-gate ip->i_perm = VA2UD_PERM(vap->va_mode);
5377c478bd9Sstevel@tonic-gate ip->i_char = vap->va_mode & (VSUID | VSGID | VSVTX);
5387c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
5397c478bd9Sstevel@tonic-gate ip->i_flag |= ICHG;
5407c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
5417c478bd9Sstevel@tonic-gate }
5427c478bd9Sstevel@tonic-gate if (mask & (AT_UID|AT_GID)) {
5437c478bd9Sstevel@tonic-gate if (mask & AT_UID) {
5447c478bd9Sstevel@tonic-gate ip->i_uid = vap->va_uid;
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate if (mask & AT_GID) {
5477c478bd9Sstevel@tonic-gate ip->i_gid = vap->va_gid;
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
5507c478bd9Sstevel@tonic-gate ip->i_flag |= ICHG;
5517c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate /*
5547c478bd9Sstevel@tonic-gate * Truncate file. Must have write permission and not be a directory.
5557c478bd9Sstevel@tonic-gate */
5567c478bd9Sstevel@tonic-gate if (mask & AT_SIZE) {
5577c478bd9Sstevel@tonic-gate if (vp->v_type == VDIR) {
5587c478bd9Sstevel@tonic-gate error = EISDIR;
5597c478bd9Sstevel@tonic-gate goto update_inode;
5607c478bd9Sstevel@tonic-gate }
561b39a0235SMilan Cermak if (error = ud_iaccess(ip, IWRITE, cr, 0)) {
5627c478bd9Sstevel@tonic-gate goto update_inode;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate if (vap->va_size > MAXOFFSET_T) {
5657c478bd9Sstevel@tonic-gate error = EFBIG;
5667c478bd9Sstevel@tonic-gate goto update_inode;
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate if (error = ud_itrunc(ip, vap->va_size, 0, cr)) {
5697c478bd9Sstevel@tonic-gate goto update_inode;
5707c478bd9Sstevel@tonic-gate }
571*72102e74SBryan Cantrill
572*72102e74SBryan Cantrill if (vap->va_size == 0)
573*72102e74SBryan Cantrill vnevent_truncate(vp, ct);
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate /*
5767c478bd9Sstevel@tonic-gate * Change file access or modified times.
5777c478bd9Sstevel@tonic-gate */
5787c478bd9Sstevel@tonic-gate if (mask & (AT_ATIME|AT_MTIME)) {
5797c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
5807c478bd9Sstevel@tonic-gate if (mask & AT_ATIME) {
5817c478bd9Sstevel@tonic-gate ip->i_atime.tv_sec = vap->va_atime.tv_sec;
5827c478bd9Sstevel@tonic-gate ip->i_atime.tv_nsec = vap->va_atime.tv_nsec;
5837c478bd9Sstevel@tonic-gate ip->i_flag &= ~IACC;
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate if (mask & AT_MTIME) {
5867c478bd9Sstevel@tonic-gate ip->i_mtime.tv_sec = vap->va_mtime.tv_sec;
5877c478bd9Sstevel@tonic-gate ip->i_mtime.tv_nsec = vap->va_mtime.tv_nsec;
5887c478bd9Sstevel@tonic-gate gethrestime(&now);
5897c478bd9Sstevel@tonic-gate ip->i_ctime.tv_sec = now.tv_sec;
5907c478bd9Sstevel@tonic-gate ip->i_ctime.tv_nsec = now.tv_nsec;
5917c478bd9Sstevel@tonic-gate ip->i_flag &= ~(IUPD|ICHG);
5927c478bd9Sstevel@tonic-gate ip->i_flag |= IMODTIME;
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate ip->i_flag |= IMOD;
5957c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate update_inode:
5997c478bd9Sstevel@tonic-gate if (curthread->t_flag & T_DONTPEND) {
6007c478bd9Sstevel@tonic-gate ud_iupdat(ip, 1);
6017c478bd9Sstevel@tonic-gate } else {
6027c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(ip);
6037c478bd9Sstevel@tonic-gate }
6047c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
6057c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate return (error);
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate
6107c478bd9Sstevel@tonic-gate /* ARGSUSED */
6117c478bd9Sstevel@tonic-gate static int32_t
udf_access(struct vnode * vp,int32_t mode,int32_t flags,struct cred * cr,caller_context_t * ct)612da6c28aaSamw udf_access(
613da6c28aaSamw struct vnode *vp,
614da6c28aaSamw int32_t mode,
615da6c28aaSamw int32_t flags,
616da6c28aaSamw struct cred *cr,
617da6c28aaSamw caller_context_t *ct)
6187c478bd9Sstevel@tonic-gate {
6197c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
6207c478bd9Sstevel@tonic-gate
6217c478bd9Sstevel@tonic-gate ud_printf("udf_access\n");
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate if (ip->i_udf == NULL) {
6247c478bd9Sstevel@tonic-gate return (EIO);
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate
627b39a0235SMilan Cermak return (ud_iaccess(ip, UD_UPERM2DPERM(mode), cr, 1));
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate int32_t udfs_stickyhack = 1;
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate /* ARGSUSED */
6337c478bd9Sstevel@tonic-gate static int32_t
udf_lookup(struct vnode * dvp,char * nm,struct vnode ** vpp,struct pathname * pnp,int32_t flags,struct vnode * rdir,struct cred * cr,caller_context_t * ct,int * direntflags,pathname_t * realpnp)634da6c28aaSamw udf_lookup(
635da6c28aaSamw struct vnode *dvp,
636da6c28aaSamw char *nm,
637da6c28aaSamw struct vnode **vpp,
638da6c28aaSamw struct pathname *pnp,
639da6c28aaSamw int32_t flags,
640da6c28aaSamw struct vnode *rdir,
641da6c28aaSamw struct cred *cr,
642da6c28aaSamw caller_context_t *ct,
643da6c28aaSamw int *direntflags,
644da6c28aaSamw pathname_t *realpnp)
6457c478bd9Sstevel@tonic-gate {
6467c478bd9Sstevel@tonic-gate int32_t error;
6477c478bd9Sstevel@tonic-gate struct vnode *vp;
6487c478bd9Sstevel@tonic-gate struct ud_inode *ip, *xip;
6497c478bd9Sstevel@tonic-gate
6507c478bd9Sstevel@tonic-gate ud_printf("udf_lookup\n");
6517c478bd9Sstevel@tonic-gate /*
6527c478bd9Sstevel@tonic-gate * Null component name is a synonym for directory being searched.
6537c478bd9Sstevel@tonic-gate */
6547c478bd9Sstevel@tonic-gate if (*nm == '\0') {
6557c478bd9Sstevel@tonic-gate VN_HOLD(dvp);
6567c478bd9Sstevel@tonic-gate *vpp = dvp;
6577c478bd9Sstevel@tonic-gate error = 0;
6587c478bd9Sstevel@tonic-gate goto out;
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate /*
6627c478bd9Sstevel@tonic-gate * Fast path: Check the directory name lookup cache.
6637c478bd9Sstevel@tonic-gate */
6647c478bd9Sstevel@tonic-gate ip = VTOI(dvp);
6657c478bd9Sstevel@tonic-gate if (vp = dnlc_lookup(dvp, nm)) {
6667c478bd9Sstevel@tonic-gate /*
6677c478bd9Sstevel@tonic-gate * Check accessibility of directory.
6687c478bd9Sstevel@tonic-gate */
669b39a0235SMilan Cermak if ((error = ud_iaccess(ip, IEXEC, cr, 1)) != 0) {
6707c478bd9Sstevel@tonic-gate VN_RELE(vp);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate xip = VTOI(vp);
6737c478bd9Sstevel@tonic-gate } else {
6747c478bd9Sstevel@tonic-gate error = ud_dirlook(ip, nm, &xip, cr, 1);
6757c478bd9Sstevel@tonic-gate ITIMES(ip);
6767c478bd9Sstevel@tonic-gate }
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate if (error == 0) {
6797c478bd9Sstevel@tonic-gate ip = xip;
6807c478bd9Sstevel@tonic-gate *vpp = ITOV(ip);
6817c478bd9Sstevel@tonic-gate if ((ip->i_type != VDIR) &&
6827c478bd9Sstevel@tonic-gate (ip->i_char & ISVTX) &&
6837c478bd9Sstevel@tonic-gate ((ip->i_perm & IEXEC) == 0) &&
6847c478bd9Sstevel@tonic-gate udfs_stickyhack) {
6857c478bd9Sstevel@tonic-gate mutex_enter(&(*vpp)->v_lock);
6867c478bd9Sstevel@tonic-gate (*vpp)->v_flag |= VISSWAP;
6877c478bd9Sstevel@tonic-gate mutex_exit(&(*vpp)->v_lock);
6887c478bd9Sstevel@tonic-gate }
6897c478bd9Sstevel@tonic-gate ITIMES(ip);
6907c478bd9Sstevel@tonic-gate /*
6917c478bd9Sstevel@tonic-gate * If vnode is a device return special vnode instead.
6927c478bd9Sstevel@tonic-gate */
6937c478bd9Sstevel@tonic-gate if (IS_DEVVP(*vpp)) {
6947c478bd9Sstevel@tonic-gate struct vnode *newvp;
6957c478bd9Sstevel@tonic-gate newvp = specvp(*vpp, (*vpp)->v_rdev,
6967c478bd9Sstevel@tonic-gate (*vpp)->v_type, cr);
6977c478bd9Sstevel@tonic-gate VN_RELE(*vpp);
6987c478bd9Sstevel@tonic-gate if (newvp == NULL) {
6997c478bd9Sstevel@tonic-gate error = ENOSYS;
7007c478bd9Sstevel@tonic-gate } else {
7017c478bd9Sstevel@tonic-gate *vpp = newvp;
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate out:
7067c478bd9Sstevel@tonic-gate return (error);
7077c478bd9Sstevel@tonic-gate }
7087c478bd9Sstevel@tonic-gate
7097c478bd9Sstevel@tonic-gate /* ARGSUSED */
7107c478bd9Sstevel@tonic-gate static int32_t
udf_create(struct vnode * dvp,char * name,struct vattr * vap,enum vcexcl excl,int32_t mode,struct vnode ** vpp,struct cred * cr,int32_t flag,caller_context_t * ct,vsecattr_t * vsecp)711da6c28aaSamw udf_create(
712da6c28aaSamw struct vnode *dvp,
713da6c28aaSamw char *name,
714da6c28aaSamw struct vattr *vap,
715da6c28aaSamw enum vcexcl excl,
716da6c28aaSamw int32_t mode,
717da6c28aaSamw struct vnode **vpp,
718da6c28aaSamw struct cred *cr,
719da6c28aaSamw int32_t flag,
720da6c28aaSamw caller_context_t *ct,
721da6c28aaSamw vsecattr_t *vsecp)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate int32_t error;
7247c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(dvp), *xip;
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate ud_printf("udf_create\n");
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr) != 0)
7297c478bd9Sstevel@tonic-gate vap->va_mode &= ~VSVTX;
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate if (*name == '\0') {
7327c478bd9Sstevel@tonic-gate /*
7337c478bd9Sstevel@tonic-gate * Null component name refers to the directory itself.
7347c478bd9Sstevel@tonic-gate */
7357c478bd9Sstevel@tonic-gate VN_HOLD(dvp);
7367c478bd9Sstevel@tonic-gate ITIMES(ip);
7377c478bd9Sstevel@tonic-gate error = EEXIST;
7387c478bd9Sstevel@tonic-gate } else {
7397c478bd9Sstevel@tonic-gate xip = NULL;
7407c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
7417c478bd9Sstevel@tonic-gate error = ud_direnter(ip, name, DE_CREATE,
7427c478bd9Sstevel@tonic-gate (struct ud_inode *)0, (struct ud_inode *)0,
743da6c28aaSamw vap, &xip, cr, ct);
7447c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
7457c478bd9Sstevel@tonic-gate ITIMES(ip);
7467c478bd9Sstevel@tonic-gate ip = xip;
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate #ifdef __lock_lint
7497c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
7507c478bd9Sstevel@tonic-gate #else
7517c478bd9Sstevel@tonic-gate if (ip != NULL) {
7527c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
7537c478bd9Sstevel@tonic-gate }
7547c478bd9Sstevel@tonic-gate #endif
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate /*
7577c478bd9Sstevel@tonic-gate * If the file already exists and this is a non-exclusive create,
7587c478bd9Sstevel@tonic-gate * check permissions and allow access for non-directories.
7597c478bd9Sstevel@tonic-gate * Read-only create of an existing directory is also allowed.
7607c478bd9Sstevel@tonic-gate * We fail an exclusive create of anything which already exists.
7617c478bd9Sstevel@tonic-gate */
7627c478bd9Sstevel@tonic-gate if (error == EEXIST) {
7637c478bd9Sstevel@tonic-gate if (excl == NONEXCL) {
7647c478bd9Sstevel@tonic-gate if ((ip->i_type == VDIR) && (mode & VWRITE)) {
7657c478bd9Sstevel@tonic-gate error = EISDIR;
7667c478bd9Sstevel@tonic-gate } else if (mode) {
7677c478bd9Sstevel@tonic-gate error = ud_iaccess(ip,
768b39a0235SMilan Cermak UD_UPERM2DPERM(mode), cr, 0);
7697c478bd9Sstevel@tonic-gate } else {
7707c478bd9Sstevel@tonic-gate error = 0;
7717c478bd9Sstevel@tonic-gate }
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate if (error) {
7747c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
7757c478bd9Sstevel@tonic-gate VN_RELE(ITOV(ip));
7767c478bd9Sstevel@tonic-gate goto out;
7777c478bd9Sstevel@tonic-gate } else if ((ip->i_type == VREG) &&
7787c478bd9Sstevel@tonic-gate (vap->va_mask & AT_SIZE) && vap->va_size == 0) {
7797c478bd9Sstevel@tonic-gate /*
7807c478bd9Sstevel@tonic-gate * Truncate regular files, if requested by caller.
7817c478bd9Sstevel@tonic-gate * Grab i_rwlock to make sure no one else is
7827c478bd9Sstevel@tonic-gate * currently writing to the file (we promised
7837c478bd9Sstevel@tonic-gate * bmap we would do this).
7847c478bd9Sstevel@tonic-gate * Must get the locks in the correct order.
7857c478bd9Sstevel@tonic-gate */
7867c478bd9Sstevel@tonic-gate if (ip->i_size == 0) {
7877c478bd9Sstevel@tonic-gate ip->i_flag |= ICHG | IUPD;
7887c478bd9Sstevel@tonic-gate } else {
7897c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
7907c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
7917c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
7927c478bd9Sstevel@tonic-gate (void) ud_itrunc(ip, 0, 0, cr);
7937c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
7947c478bd9Sstevel@tonic-gate }
795da6c28aaSamw vnevent_create(ITOV(ip), ct);
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate }
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate if (error == 0) {
8007c478bd9Sstevel@tonic-gate *vpp = ITOV(ip);
8017c478bd9Sstevel@tonic-gate ITIMES(ip);
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate #ifdef __lock_lint
8047c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
8057c478bd9Sstevel@tonic-gate #else
8067c478bd9Sstevel@tonic-gate if (ip != NULL) {
8077c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate #endif
8107c478bd9Sstevel@tonic-gate if (error) {
8117c478bd9Sstevel@tonic-gate goto out;
8127c478bd9Sstevel@tonic-gate }
8137c478bd9Sstevel@tonic-gate
8147c478bd9Sstevel@tonic-gate /*
8157c478bd9Sstevel@tonic-gate * If vnode is a device return special vnode instead.
8167c478bd9Sstevel@tonic-gate */
8177c478bd9Sstevel@tonic-gate if (!error && IS_DEVVP(*vpp)) {
8187c478bd9Sstevel@tonic-gate struct vnode *newvp;
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate newvp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
8217c478bd9Sstevel@tonic-gate VN_RELE(*vpp);
8227c478bd9Sstevel@tonic-gate if (newvp == NULL) {
8237c478bd9Sstevel@tonic-gate error = ENOSYS;
8247c478bd9Sstevel@tonic-gate goto out;
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate *vpp = newvp;
8277c478bd9Sstevel@tonic-gate }
8287c478bd9Sstevel@tonic-gate out:
8297c478bd9Sstevel@tonic-gate return (error);
8307c478bd9Sstevel@tonic-gate }
8317c478bd9Sstevel@tonic-gate
832da6c28aaSamw /* ARGSUSED */
8337c478bd9Sstevel@tonic-gate static int32_t
udf_remove(struct vnode * vp,char * nm,struct cred * cr,caller_context_t * ct,int flags)834da6c28aaSamw udf_remove(
835da6c28aaSamw struct vnode *vp,
836da6c28aaSamw char *nm,
837da6c28aaSamw struct cred *cr,
838da6c28aaSamw caller_context_t *ct,
839da6c28aaSamw int flags)
8407c478bd9Sstevel@tonic-gate {
8417c478bd9Sstevel@tonic-gate int32_t error;
8427c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate ud_printf("udf_remove\n");
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
8477c478bd9Sstevel@tonic-gate error = ud_dirremove(ip, nm,
848da6c28aaSamw (struct ud_inode *)0, (struct vnode *)0, DR_REMOVE, cr, ct);
8497c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
8507c478bd9Sstevel@tonic-gate ITIMES(ip);
8517c478bd9Sstevel@tonic-gate
8527c478bd9Sstevel@tonic-gate return (error);
8537c478bd9Sstevel@tonic-gate }
8547c478bd9Sstevel@tonic-gate
855da6c28aaSamw /* ARGSUSED */
8567c478bd9Sstevel@tonic-gate static int32_t
udf_link(struct vnode * tdvp,struct vnode * svp,char * tnm,struct cred * cr,caller_context_t * ct,int flags)857da6c28aaSamw udf_link(
858da6c28aaSamw struct vnode *tdvp,
859da6c28aaSamw struct vnode *svp,
860da6c28aaSamw char *tnm,
861da6c28aaSamw struct cred *cr,
862da6c28aaSamw caller_context_t *ct,
863da6c28aaSamw int flags)
8647c478bd9Sstevel@tonic-gate {
8657c478bd9Sstevel@tonic-gate int32_t error;
8667c478bd9Sstevel@tonic-gate struct vnode *realvp;
8677c478bd9Sstevel@tonic-gate struct ud_inode *sip;
8687c478bd9Sstevel@tonic-gate struct ud_inode *tdp;
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate ud_printf("udf_link\n");
871da6c28aaSamw if (VOP_REALVP(svp, &realvp, ct) == 0) {
8727c478bd9Sstevel@tonic-gate svp = realvp;
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate /*
8767c478bd9Sstevel@tonic-gate * Do not allow links to directories
8777c478bd9Sstevel@tonic-gate */
8787c478bd9Sstevel@tonic-gate if (svp->v_type == VDIR) {
8797c478bd9Sstevel@tonic-gate return (EPERM);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate
8827c478bd9Sstevel@tonic-gate sip = VTOI(svp);
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate if (sip->i_uid != crgetuid(cr) && secpolicy_basic_link(cr) != 0)
8857c478bd9Sstevel@tonic-gate return (EPERM);
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate tdp = VTOI(tdvp);
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate rw_enter(&tdp->i_rwlock, RW_WRITER);
8907c478bd9Sstevel@tonic-gate error = ud_direnter(tdp, tnm, DE_LINK, (struct ud_inode *)0,
891da6c28aaSamw sip, (struct vattr *)0, (struct ud_inode **)0, cr, ct);
8927c478bd9Sstevel@tonic-gate rw_exit(&tdp->i_rwlock);
8937c478bd9Sstevel@tonic-gate ITIMES(sip);
8947c478bd9Sstevel@tonic-gate ITIMES(tdp);
8957c478bd9Sstevel@tonic-gate
896df2381bfSpraks if (error == 0) {
897da6c28aaSamw vnevent_link(svp, ct);
898df2381bfSpraks }
899df2381bfSpraks
9007c478bd9Sstevel@tonic-gate return (error);
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gate /* ARGSUSED */
9047c478bd9Sstevel@tonic-gate static int32_t
udf_rename(struct vnode * sdvp,char * snm,struct vnode * tdvp,char * tnm,struct cred * cr,caller_context_t * ct,int flags)905da6c28aaSamw udf_rename(
906da6c28aaSamw struct vnode *sdvp,
907da6c28aaSamw char *snm,
908da6c28aaSamw struct vnode *tdvp,
909da6c28aaSamw char *tnm,
910da6c28aaSamw struct cred *cr,
911da6c28aaSamw caller_context_t *ct,
912da6c28aaSamw int flags)
9137c478bd9Sstevel@tonic-gate {
9147c478bd9Sstevel@tonic-gate int32_t error = 0;
9157c478bd9Sstevel@tonic-gate struct udf_vfs *udf_vfsp;
9167c478bd9Sstevel@tonic-gate struct ud_inode *sip; /* source inode */
9177c478bd9Sstevel@tonic-gate struct ud_inode *sdp, *tdp; /* source and target parent inode */
9187c478bd9Sstevel@tonic-gate struct vnode *realvp;
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate ud_printf("udf_rename\n");
9217c478bd9Sstevel@tonic-gate
922da6c28aaSamw if (VOP_REALVP(tdvp, &realvp, ct) == 0) {
9237c478bd9Sstevel@tonic-gate tdvp = realvp;
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate sdp = VTOI(sdvp);
9277c478bd9Sstevel@tonic-gate tdp = VTOI(tdvp);
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate udf_vfsp = sdp->i_udf;
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate mutex_enter(&udf_vfsp->udf_rename_lck);
9327c478bd9Sstevel@tonic-gate /*
9337c478bd9Sstevel@tonic-gate * Look up inode of file we're supposed to rename.
9347c478bd9Sstevel@tonic-gate */
9357c478bd9Sstevel@tonic-gate if (error = ud_dirlook(sdp, snm, &sip, cr, 0)) {
9367c478bd9Sstevel@tonic-gate mutex_exit(&udf_vfsp->udf_rename_lck);
9377c478bd9Sstevel@tonic-gate return (error);
9387c478bd9Sstevel@tonic-gate }
9397c478bd9Sstevel@tonic-gate /*
9407c478bd9Sstevel@tonic-gate * be sure this is not a directory with another file system mounted
9417c478bd9Sstevel@tonic-gate * over it. If it is just give up the locks, and return with
9427c478bd9Sstevel@tonic-gate * EBUSY
9437c478bd9Sstevel@tonic-gate */
9447c478bd9Sstevel@tonic-gate if (vn_mountedvfs(ITOV(sip)) != NULL) {
9457c478bd9Sstevel@tonic-gate error = EBUSY;
9467c478bd9Sstevel@tonic-gate goto errout;
9477c478bd9Sstevel@tonic-gate }
9487c478bd9Sstevel@tonic-gate /*
9497c478bd9Sstevel@tonic-gate * Make sure we can delete the source entry. This requires
9507c478bd9Sstevel@tonic-gate * write permission on the containing directory. If that
9517c478bd9Sstevel@tonic-gate * directory is "sticky" it further requires (except for
9527c478bd9Sstevel@tonic-gate * privileged users) that the user own the directory or the
9537c478bd9Sstevel@tonic-gate * source entry, or else have permission to write the source
9547c478bd9Sstevel@tonic-gate * entry.
9557c478bd9Sstevel@tonic-gate */
9567c478bd9Sstevel@tonic-gate rw_enter(&sdp->i_contents, RW_READER);
9577c478bd9Sstevel@tonic-gate rw_enter(&sip->i_contents, RW_READER);
958b39a0235SMilan Cermak if ((error = ud_iaccess(sdp, IWRITE, cr, 0)) != 0 ||
9597c478bd9Sstevel@tonic-gate (error = ud_sticky_remove_access(sdp, sip, cr)) != 0) {
9607c478bd9Sstevel@tonic-gate rw_exit(&sip->i_contents);
9617c478bd9Sstevel@tonic-gate rw_exit(&sdp->i_contents);
9627c478bd9Sstevel@tonic-gate ITIMES(sip);
9637c478bd9Sstevel@tonic-gate goto errout;
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate /*
9677c478bd9Sstevel@tonic-gate * Check for renaming '.' or '..' or alias of '.'
9687c478bd9Sstevel@tonic-gate */
9697c478bd9Sstevel@tonic-gate if ((strcmp(snm, ".") == 0) ||
9707c478bd9Sstevel@tonic-gate (strcmp(snm, "..") == 0) ||
9717c478bd9Sstevel@tonic-gate (sdp == sip)) {
9727c478bd9Sstevel@tonic-gate error = EINVAL;
9737c478bd9Sstevel@tonic-gate rw_exit(&sip->i_contents);
9747c478bd9Sstevel@tonic-gate rw_exit(&sdp->i_contents);
9757c478bd9Sstevel@tonic-gate goto errout;
9767c478bd9Sstevel@tonic-gate }
9777c478bd9Sstevel@tonic-gate rw_exit(&sip->i_contents);
9787c478bd9Sstevel@tonic-gate rw_exit(&sdp->i_contents);
9797c478bd9Sstevel@tonic-gate
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate /*
9827c478bd9Sstevel@tonic-gate * Link source to the target.
9837c478bd9Sstevel@tonic-gate */
9847c478bd9Sstevel@tonic-gate rw_enter(&tdp->i_rwlock, RW_WRITER);
9857c478bd9Sstevel@tonic-gate if (error = ud_direnter(tdp, tnm, DE_RENAME, sdp, sip,
986da6c28aaSamw (struct vattr *)0, (struct ud_inode **)0, cr, ct)) {
9877c478bd9Sstevel@tonic-gate /*
9887c478bd9Sstevel@tonic-gate * ESAME isn't really an error; it indicates that the
9897c478bd9Sstevel@tonic-gate * operation should not be done because the source and target
9907c478bd9Sstevel@tonic-gate * are the same file, but that no error should be reported.
9917c478bd9Sstevel@tonic-gate */
9927c478bd9Sstevel@tonic-gate if (error == ESAME) {
9937c478bd9Sstevel@tonic-gate error = 0;
9947c478bd9Sstevel@tonic-gate }
9957c478bd9Sstevel@tonic-gate rw_exit(&tdp->i_rwlock);
9967c478bd9Sstevel@tonic-gate goto errout;
9977c478bd9Sstevel@tonic-gate }
998da6c28aaSamw vnevent_rename_src(ITOV(sip), sdvp, snm, ct);
9997c478bd9Sstevel@tonic-gate rw_exit(&tdp->i_rwlock);
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate rw_enter(&sdp->i_rwlock, RW_WRITER);
10027c478bd9Sstevel@tonic-gate /*
10037c478bd9Sstevel@tonic-gate * Unlink the source.
10047c478bd9Sstevel@tonic-gate * Remove the source entry. ud_dirremove() checks that the entry
10057c478bd9Sstevel@tonic-gate * still reflects sip, and returns an error if it doesn't.
10067c478bd9Sstevel@tonic-gate * If the entry has changed just forget about it. Release
10077c478bd9Sstevel@tonic-gate * the source inode.
10087c478bd9Sstevel@tonic-gate */
10097c478bd9Sstevel@tonic-gate if ((error = ud_dirremove(sdp, snm, sip, (struct vnode *)0,
1010da6c28aaSamw DR_RENAME, cr, ct)) == ENOENT) {
10117c478bd9Sstevel@tonic-gate error = 0;
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate rw_exit(&sdp->i_rwlock);
10147c478bd9Sstevel@tonic-gate errout:
10157c478bd9Sstevel@tonic-gate ITIMES(sdp);
10167c478bd9Sstevel@tonic-gate ITIMES(tdp);
10177c478bd9Sstevel@tonic-gate VN_RELE(ITOV(sip));
10187c478bd9Sstevel@tonic-gate mutex_exit(&udf_vfsp->udf_rename_lck);
10197c478bd9Sstevel@tonic-gate
10207c478bd9Sstevel@tonic-gate return (error);
10217c478bd9Sstevel@tonic-gate }
10227c478bd9Sstevel@tonic-gate
1023da6c28aaSamw /* ARGSUSED */
10247c478bd9Sstevel@tonic-gate static int32_t
udf_mkdir(struct vnode * dvp,char * dirname,struct vattr * vap,struct vnode ** vpp,struct cred * cr,caller_context_t * ct,int flags,vsecattr_t * vsecp)1025da6c28aaSamw udf_mkdir(
1026da6c28aaSamw struct vnode *dvp,
1027da6c28aaSamw char *dirname,
1028da6c28aaSamw struct vattr *vap,
1029da6c28aaSamw struct vnode **vpp,
1030da6c28aaSamw struct cred *cr,
1031da6c28aaSamw caller_context_t *ct,
1032da6c28aaSamw int flags,
1033da6c28aaSamw vsecattr_t *vsecp)
10347c478bd9Sstevel@tonic-gate {
10357c478bd9Sstevel@tonic-gate int32_t error;
10367c478bd9Sstevel@tonic-gate struct ud_inode *ip;
10377c478bd9Sstevel@tonic-gate struct ud_inode *xip;
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gate ASSERT((vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate ud_printf("udf_mkdir\n");
10427c478bd9Sstevel@tonic-gate
10437c478bd9Sstevel@tonic-gate ip = VTOI(dvp);
10447c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
10457c478bd9Sstevel@tonic-gate error = ud_direnter(ip, dirname, DE_MKDIR,
1046da6c28aaSamw (struct ud_inode *)0, (struct ud_inode *)0, vap, &xip, cr, ct);
10477c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
10487c478bd9Sstevel@tonic-gate ITIMES(ip);
10497c478bd9Sstevel@tonic-gate if (error == 0) {
10507c478bd9Sstevel@tonic-gate ip = xip;
10517c478bd9Sstevel@tonic-gate *vpp = ITOV(ip);
10527c478bd9Sstevel@tonic-gate ITIMES(ip);
10537c478bd9Sstevel@tonic-gate } else if (error == EEXIST) {
10547c478bd9Sstevel@tonic-gate ITIMES(xip);
10557c478bd9Sstevel@tonic-gate VN_RELE(ITOV(xip));
10567c478bd9Sstevel@tonic-gate }
10577c478bd9Sstevel@tonic-gate
10587c478bd9Sstevel@tonic-gate return (error);
10597c478bd9Sstevel@tonic-gate }
10607c478bd9Sstevel@tonic-gate
1061da6c28aaSamw /* ARGSUSED */
10627c478bd9Sstevel@tonic-gate static int32_t
udf_rmdir(struct vnode * vp,char * nm,struct vnode * cdir,struct cred * cr,caller_context_t * ct,int flags)1063da6c28aaSamw udf_rmdir(
1064da6c28aaSamw struct vnode *vp,
1065da6c28aaSamw char *nm,
1066da6c28aaSamw struct vnode *cdir,
1067da6c28aaSamw struct cred *cr,
1068da6c28aaSamw caller_context_t *ct,
1069da6c28aaSamw int flags)
10707c478bd9Sstevel@tonic-gate {
10717c478bd9Sstevel@tonic-gate int32_t error;
10727c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
10737c478bd9Sstevel@tonic-gate
10747c478bd9Sstevel@tonic-gate ud_printf("udf_rmdir\n");
10757c478bd9Sstevel@tonic-gate
10767c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
1077da6c28aaSamw error = ud_dirremove(ip, nm, (struct ud_inode *)0, cdir, DR_RMDIR,
1078da6c28aaSamw cr, ct);
10797c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
10807c478bd9Sstevel@tonic-gate ITIMES(ip);
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate return (error);
10837c478bd9Sstevel@tonic-gate }
10847c478bd9Sstevel@tonic-gate
10857c478bd9Sstevel@tonic-gate /* ARGSUSED */
10867c478bd9Sstevel@tonic-gate static int32_t
udf_readdir(struct vnode * vp,struct uio * uiop,struct cred * cr,int32_t * eofp,caller_context_t * ct,int flags)1087da6c28aaSamw udf_readdir(
1088da6c28aaSamw struct vnode *vp,
1089da6c28aaSamw struct uio *uiop,
1090da6c28aaSamw struct cred *cr,
1091da6c28aaSamw int32_t *eofp,
1092da6c28aaSamw caller_context_t *ct,
1093da6c28aaSamw int flags)
10947c478bd9Sstevel@tonic-gate {
10957c478bd9Sstevel@tonic-gate struct ud_inode *ip;
10967c478bd9Sstevel@tonic-gate struct dirent64 *nd;
10977c478bd9Sstevel@tonic-gate struct udf_vfs *udf_vfsp;
10987c478bd9Sstevel@tonic-gate int32_t error = 0, len, outcount = 0;
10997c478bd9Sstevel@tonic-gate uint32_t dirsiz, offset;
11007c478bd9Sstevel@tonic-gate uint32_t bufsize, ndlen, dummy;
11017c478bd9Sstevel@tonic-gate caddr_t outbuf;
11027c478bd9Sstevel@tonic-gate caddr_t outb, end_outb;
11037c478bd9Sstevel@tonic-gate struct iovec *iovp;
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate uint8_t *dname;
11067c478bd9Sstevel@tonic-gate int32_t length;
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate uint8_t *buf = NULL;
11097c478bd9Sstevel@tonic-gate
11107c478bd9Sstevel@tonic-gate struct fbuf *fbp = NULL;
11117c478bd9Sstevel@tonic-gate struct file_id *fid;
11127c478bd9Sstevel@tonic-gate uint8_t *name;
11137c478bd9Sstevel@tonic-gate
11147c478bd9Sstevel@tonic-gate
11157c478bd9Sstevel@tonic-gate ud_printf("udf_readdir\n");
11167c478bd9Sstevel@tonic-gate
11177c478bd9Sstevel@tonic-gate ip = VTOI(vp);
11187c478bd9Sstevel@tonic-gate udf_vfsp = ip->i_udf;
11197c478bd9Sstevel@tonic-gate
11207c478bd9Sstevel@tonic-gate dirsiz = ip->i_size;
11217c478bd9Sstevel@tonic-gate if ((uiop->uio_offset >= dirsiz) ||
11227c478bd9Sstevel@tonic-gate (ip->i_nlink <= 0)) {
11237c478bd9Sstevel@tonic-gate if (eofp) {
11247c478bd9Sstevel@tonic-gate *eofp = 1;
11257c478bd9Sstevel@tonic-gate }
11267c478bd9Sstevel@tonic-gate return (0);
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate
11297c478bd9Sstevel@tonic-gate offset = uiop->uio_offset;
11307c478bd9Sstevel@tonic-gate iovp = uiop->uio_iov;
11317c478bd9Sstevel@tonic-gate bufsize = iovp->iov_len;
11327c478bd9Sstevel@tonic-gate
11337c478bd9Sstevel@tonic-gate outb = outbuf = (char *)kmem_alloc((uint32_t)bufsize, KM_SLEEP);
11347c478bd9Sstevel@tonic-gate end_outb = outb + bufsize;
11357c478bd9Sstevel@tonic-gate nd = (struct dirent64 *)outbuf;
11367c478bd9Sstevel@tonic-gate
11377c478bd9Sstevel@tonic-gate dname = (uint8_t *)kmem_zalloc(1024, KM_SLEEP);
11387c478bd9Sstevel@tonic-gate buf = (uint8_t *)kmem_zalloc(udf_vfsp->udf_lbsize, KM_SLEEP);
11397c478bd9Sstevel@tonic-gate
11407c478bd9Sstevel@tonic-gate if (offset == 0) {
11417c478bd9Sstevel@tonic-gate len = DIRENT64_RECLEN(1);
11427c478bd9Sstevel@tonic-gate if (((caddr_t)nd + len) >= end_outb) {
11437c478bd9Sstevel@tonic-gate error = EINVAL;
11447c478bd9Sstevel@tonic-gate goto end;
11457c478bd9Sstevel@tonic-gate }
11467c478bd9Sstevel@tonic-gate nd->d_ino = ip->i_icb_lbano;
11477c478bd9Sstevel@tonic-gate nd->d_reclen = (uint16_t)len;
11487c478bd9Sstevel@tonic-gate nd->d_off = 0x10;
11497c478bd9Sstevel@tonic-gate nd->d_name[0] = '.';
11507c478bd9Sstevel@tonic-gate bzero(&nd->d_name[1], DIRENT64_NAMELEN(len) - 1);
11517c478bd9Sstevel@tonic-gate nd = (struct dirent64 *)((char *)nd + nd->d_reclen);
11527c478bd9Sstevel@tonic-gate outcount++;
11537c478bd9Sstevel@tonic-gate } else if (offset == 0x10) {
11547c478bd9Sstevel@tonic-gate offset = 0;
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate
11577c478bd9Sstevel@tonic-gate while (offset < dirsiz) {
11587c478bd9Sstevel@tonic-gate error = ud_get_next_fid(ip, &fbp,
11597c478bd9Sstevel@tonic-gate offset, &fid, &name, buf);
11607c478bd9Sstevel@tonic-gate if (error != 0) {
11617c478bd9Sstevel@tonic-gate break;
11627c478bd9Sstevel@tonic-gate }
11637c478bd9Sstevel@tonic-gate
11647c478bd9Sstevel@tonic-gate if ((fid->fid_flags & FID_DELETED) == 0) {
11657c478bd9Sstevel@tonic-gate if (fid->fid_flags & FID_PARENT) {
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate len = DIRENT64_RECLEN(2);
11687c478bd9Sstevel@tonic-gate if (((caddr_t)nd + len) >= end_outb) {
11697c478bd9Sstevel@tonic-gate error = EINVAL;
11707c478bd9Sstevel@tonic-gate break;
11717c478bd9Sstevel@tonic-gate }
11727c478bd9Sstevel@tonic-gate
11737c478bd9Sstevel@tonic-gate nd->d_ino = ip->i_icb_lbano;
11747c478bd9Sstevel@tonic-gate nd->d_reclen = (uint16_t)len;
11757c478bd9Sstevel@tonic-gate nd->d_off = offset + FID_LEN(fid);
11767c478bd9Sstevel@tonic-gate nd->d_name[0] = '.';
11777c478bd9Sstevel@tonic-gate nd->d_name[1] = '.';
11787c478bd9Sstevel@tonic-gate bzero(&nd->d_name[2],
11797c478bd9Sstevel@tonic-gate DIRENT64_NAMELEN(len) - 2);
11807c478bd9Sstevel@tonic-gate nd = (struct dirent64 *)
11817c478bd9Sstevel@tonic-gate ((char *)nd + nd->d_reclen);
11827c478bd9Sstevel@tonic-gate } else {
11837c478bd9Sstevel@tonic-gate if ((error = ud_uncompress(fid->fid_idlen,
11847c478bd9Sstevel@tonic-gate &length, name, dname)) != 0) {
11857c478bd9Sstevel@tonic-gate break;
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate if (length == 0) {
11887c478bd9Sstevel@tonic-gate offset += FID_LEN(fid);
11897c478bd9Sstevel@tonic-gate continue;
11907c478bd9Sstevel@tonic-gate }
11917c478bd9Sstevel@tonic-gate len = DIRENT64_RECLEN(length);
11927c478bd9Sstevel@tonic-gate if (((caddr_t)nd + len) >= end_outb) {
11937c478bd9Sstevel@tonic-gate if (!outcount) {
11947c478bd9Sstevel@tonic-gate error = EINVAL;
11957c478bd9Sstevel@tonic-gate }
11967c478bd9Sstevel@tonic-gate break;
11977c478bd9Sstevel@tonic-gate }
11987c478bd9Sstevel@tonic-gate (void) strncpy(nd->d_name,
11997c478bd9Sstevel@tonic-gate (caddr_t)dname, length);
12007c478bd9Sstevel@tonic-gate bzero(&nd->d_name[length],
12017c478bd9Sstevel@tonic-gate DIRENT64_NAMELEN(len) - length);
12027c478bd9Sstevel@tonic-gate nd->d_ino = ud_xlate_to_daddr(udf_vfsp,
12037c478bd9Sstevel@tonic-gate SWAP_16(fid->fid_icb.lad_ext_prn),
12047c478bd9Sstevel@tonic-gate SWAP_32(fid->fid_icb.lad_ext_loc), 1,
12057c478bd9Sstevel@tonic-gate &dummy);
12067c478bd9Sstevel@tonic-gate nd->d_reclen = (uint16_t)len;
12077c478bd9Sstevel@tonic-gate nd->d_off = offset + FID_LEN(fid);
12087c478bd9Sstevel@tonic-gate nd = (struct dirent64 *)
12097c478bd9Sstevel@tonic-gate ((char *)nd + nd->d_reclen);
12107c478bd9Sstevel@tonic-gate }
12117c478bd9Sstevel@tonic-gate outcount++;
12127c478bd9Sstevel@tonic-gate }
12137c478bd9Sstevel@tonic-gate
12147c478bd9Sstevel@tonic-gate offset += FID_LEN(fid);
12157c478bd9Sstevel@tonic-gate }
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate end:
12187c478bd9Sstevel@tonic-gate if (fbp != NULL) {
12197c478bd9Sstevel@tonic-gate fbrelse(fbp, S_OTHER);
12207c478bd9Sstevel@tonic-gate }
12217c478bd9Sstevel@tonic-gate ndlen = ((char *)nd - outbuf);
12227c478bd9Sstevel@tonic-gate /*
12237c478bd9Sstevel@tonic-gate * In case of error do not call uiomove.
12247c478bd9Sstevel@tonic-gate * Return the error to the caller.
12257c478bd9Sstevel@tonic-gate */
12267c478bd9Sstevel@tonic-gate if ((error == 0) && (ndlen != 0)) {
12277c478bd9Sstevel@tonic-gate error = uiomove(outbuf, (long)ndlen, UIO_READ, uiop);
12287c478bd9Sstevel@tonic-gate uiop->uio_offset = offset;
12297c478bd9Sstevel@tonic-gate }
12307c478bd9Sstevel@tonic-gate kmem_free((caddr_t)buf, udf_vfsp->udf_lbsize);
12317c478bd9Sstevel@tonic-gate kmem_free((caddr_t)dname, 1024);
12327c478bd9Sstevel@tonic-gate kmem_free(outbuf, (uint32_t)bufsize);
12337c478bd9Sstevel@tonic-gate if (eofp && error == 0) {
12347c478bd9Sstevel@tonic-gate *eofp = (uiop->uio_offset >= dirsiz);
12357c478bd9Sstevel@tonic-gate }
12367c478bd9Sstevel@tonic-gate return (error);
12377c478bd9Sstevel@tonic-gate }
12387c478bd9Sstevel@tonic-gate
12397c478bd9Sstevel@tonic-gate /* ARGSUSED */
12407c478bd9Sstevel@tonic-gate static int32_t
udf_symlink(struct vnode * dvp,char * linkname,struct vattr * vap,char * target,struct cred * cr,caller_context_t * ct,int flags)1241da6c28aaSamw udf_symlink(
1242da6c28aaSamw struct vnode *dvp,
1243da6c28aaSamw char *linkname,
1244da6c28aaSamw struct vattr *vap,
1245da6c28aaSamw char *target,
1246da6c28aaSamw struct cred *cr,
1247da6c28aaSamw caller_context_t *ct,
1248da6c28aaSamw int flags)
12497c478bd9Sstevel@tonic-gate {
12507c478bd9Sstevel@tonic-gate int32_t error = 0, outlen;
12517c478bd9Sstevel@tonic-gate uint32_t ioflag = 0;
12527c478bd9Sstevel@tonic-gate struct ud_inode *ip, *dip = VTOI(dvp);
12537c478bd9Sstevel@tonic-gate
12547c478bd9Sstevel@tonic-gate struct path_comp *pc;
12557c478bd9Sstevel@tonic-gate int8_t *dname = NULL, *uname = NULL, *sp;
12567c478bd9Sstevel@tonic-gate
12577c478bd9Sstevel@tonic-gate ud_printf("udf_symlink\n");
12587c478bd9Sstevel@tonic-gate
12597c478bd9Sstevel@tonic-gate ip = (struct ud_inode *)0;
12607c478bd9Sstevel@tonic-gate vap->va_type = VLNK;
12617c478bd9Sstevel@tonic-gate vap->va_rdev = 0;
12627c478bd9Sstevel@tonic-gate
12637c478bd9Sstevel@tonic-gate rw_enter(&dip->i_rwlock, RW_WRITER);
12647c478bd9Sstevel@tonic-gate error = ud_direnter(dip, linkname, DE_CREATE,
1265da6c28aaSamw (struct ud_inode *)0, (struct ud_inode *)0, vap, &ip, cr, ct);
12667c478bd9Sstevel@tonic-gate rw_exit(&dip->i_rwlock);
12677c478bd9Sstevel@tonic-gate if (error == 0) {
12687c478bd9Sstevel@tonic-gate dname = kmem_zalloc(1024, KM_SLEEP);
12697c478bd9Sstevel@tonic-gate uname = kmem_zalloc(PAGESIZE, KM_SLEEP);
12707c478bd9Sstevel@tonic-gate
12717c478bd9Sstevel@tonic-gate pc = (struct path_comp *)uname;
12727c478bd9Sstevel@tonic-gate /*
12737c478bd9Sstevel@tonic-gate * If the first character in target is "/"
12747c478bd9Sstevel@tonic-gate * then skip it and create entry for it
12757c478bd9Sstevel@tonic-gate */
12767c478bd9Sstevel@tonic-gate if (*target == '/') {
12777c478bd9Sstevel@tonic-gate pc->pc_type = 2;
12787c478bd9Sstevel@tonic-gate pc->pc_len = 0;
12797c478bd9Sstevel@tonic-gate pc = (struct path_comp *)(((char *)pc) + 4);
12807c478bd9Sstevel@tonic-gate while (*target == '/') {
12817c478bd9Sstevel@tonic-gate target++;
12827c478bd9Sstevel@tonic-gate }
12837c478bd9Sstevel@tonic-gate }
12847c478bd9Sstevel@tonic-gate
12857c478bd9Sstevel@tonic-gate while (*target != NULL) {
12867c478bd9Sstevel@tonic-gate sp = target;
12877c478bd9Sstevel@tonic-gate while ((*target != '/') && (*target != '\0')) {
12887c478bd9Sstevel@tonic-gate target ++;
12897c478bd9Sstevel@tonic-gate }
12907c478bd9Sstevel@tonic-gate /*
12917c478bd9Sstevel@tonic-gate * We got the next component of the
12927c478bd9Sstevel@tonic-gate * path name. Create path_comp of
12937c478bd9Sstevel@tonic-gate * appropriate type
12947c478bd9Sstevel@tonic-gate */
12957c478bd9Sstevel@tonic-gate if (((target - sp) == 1) && (*sp == '.')) {
12967c478bd9Sstevel@tonic-gate /*
12977c478bd9Sstevel@tonic-gate * Dot entry.
12987c478bd9Sstevel@tonic-gate */
12997c478bd9Sstevel@tonic-gate pc->pc_type = 4;
13007c478bd9Sstevel@tonic-gate pc = (struct path_comp *)(((char *)pc) + 4);
13017c478bd9Sstevel@tonic-gate } else if (((target - sp) == 2) &&
13027c478bd9Sstevel@tonic-gate (*sp == '.') && ((*(sp + 1)) == '.')) {
13037c478bd9Sstevel@tonic-gate /*
13047c478bd9Sstevel@tonic-gate * DotDot entry.
13057c478bd9Sstevel@tonic-gate */
13067c478bd9Sstevel@tonic-gate pc->pc_type = 3;
13077c478bd9Sstevel@tonic-gate pc = (struct path_comp *)(((char *)pc) + 4);
13087c478bd9Sstevel@tonic-gate } else {
13097c478bd9Sstevel@tonic-gate /*
13107c478bd9Sstevel@tonic-gate * convert the user given name
13117c478bd9Sstevel@tonic-gate * into appropriate form to be put
13127c478bd9Sstevel@tonic-gate * on the media
13137c478bd9Sstevel@tonic-gate */
13147c478bd9Sstevel@tonic-gate outlen = 1024; /* set to size of dname */
13157c478bd9Sstevel@tonic-gate if (error = ud_compress(target - sp, &outlen,
13167c478bd9Sstevel@tonic-gate (uint8_t *)sp, (uint8_t *)dname)) {
13177c478bd9Sstevel@tonic-gate break;
13187c478bd9Sstevel@tonic-gate }
13197c478bd9Sstevel@tonic-gate pc->pc_type = 5;
13207c478bd9Sstevel@tonic-gate /* LINTED */
13217c478bd9Sstevel@tonic-gate pc->pc_len = outlen;
13227c478bd9Sstevel@tonic-gate dname[outlen] = '\0';
13237c478bd9Sstevel@tonic-gate (void) strcpy((char *)pc->pc_id, dname);
13247c478bd9Sstevel@tonic-gate pc = (struct path_comp *)
13257c478bd9Sstevel@tonic-gate (((char *)pc) + 4 + outlen);
13267c478bd9Sstevel@tonic-gate }
13277c478bd9Sstevel@tonic-gate while (*target == '/') {
13287c478bd9Sstevel@tonic-gate target++;
13297c478bd9Sstevel@tonic-gate }
13307c478bd9Sstevel@tonic-gate if (*target == NULL) {
13317c478bd9Sstevel@tonic-gate break;
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate }
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
13367c478bd9Sstevel@tonic-gate if (error == 0) {
13377c478bd9Sstevel@tonic-gate ioflag = FWRITE;
13387c478bd9Sstevel@tonic-gate if (curthread->t_flag & T_DONTPEND) {
13397c478bd9Sstevel@tonic-gate ioflag |= FDSYNC;
13407c478bd9Sstevel@tonic-gate }
13417c478bd9Sstevel@tonic-gate error = ud_rdwri(UIO_WRITE, ioflag, ip,
13427c478bd9Sstevel@tonic-gate uname, ((int8_t *)pc) - uname,
13437c478bd9Sstevel@tonic-gate (offset_t)0, UIO_SYSSPACE, (int32_t *)0, cr);
13447c478bd9Sstevel@tonic-gate }
13457c478bd9Sstevel@tonic-gate if (error) {
13467c478bd9Sstevel@tonic-gate ud_idrop(ip);
13477c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
13487c478bd9Sstevel@tonic-gate rw_enter(&dip->i_rwlock, RW_WRITER);
13497c478bd9Sstevel@tonic-gate (void) ud_dirremove(dip, linkname, (struct ud_inode *)0,
1350da6c28aaSamw (struct vnode *)0, DR_REMOVE, cr, ct);
13517c478bd9Sstevel@tonic-gate rw_exit(&dip->i_rwlock);
13527c478bd9Sstevel@tonic-gate goto update_inode;
13537c478bd9Sstevel@tonic-gate }
13547c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
13557c478bd9Sstevel@tonic-gate }
13567c478bd9Sstevel@tonic-gate
13577c478bd9Sstevel@tonic-gate if ((error == 0) || (error == EEXIST)) {
13587c478bd9Sstevel@tonic-gate VN_RELE(ITOV(ip));
13597c478bd9Sstevel@tonic-gate }
13607c478bd9Sstevel@tonic-gate
13617c478bd9Sstevel@tonic-gate update_inode:
13627c478bd9Sstevel@tonic-gate ITIMES(VTOI(dvp));
13637c478bd9Sstevel@tonic-gate if (uname != NULL) {
13647c478bd9Sstevel@tonic-gate kmem_free(uname, PAGESIZE);
13657c478bd9Sstevel@tonic-gate }
13667c478bd9Sstevel@tonic-gate if (dname != NULL) {
13677c478bd9Sstevel@tonic-gate kmem_free(dname, 1024);
13687c478bd9Sstevel@tonic-gate }
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate return (error);
13717c478bd9Sstevel@tonic-gate }
13727c478bd9Sstevel@tonic-gate
13737c478bd9Sstevel@tonic-gate /* ARGSUSED */
13747c478bd9Sstevel@tonic-gate static int32_t
udf_readlink(struct vnode * vp,struct uio * uiop,struct cred * cr,caller_context_t * ct)1375da6c28aaSamw udf_readlink(
1376da6c28aaSamw struct vnode *vp,
1377da6c28aaSamw struct uio *uiop,
1378da6c28aaSamw struct cred *cr,
1379da6c28aaSamw caller_context_t *ct)
13807c478bd9Sstevel@tonic-gate {
13817c478bd9Sstevel@tonic-gate int32_t error = 0, off, id_len, size, len;
13827c478bd9Sstevel@tonic-gate int8_t *dname = NULL, *uname = NULL;
13837c478bd9Sstevel@tonic-gate struct ud_inode *ip;
13847c478bd9Sstevel@tonic-gate struct fbuf *fbp = NULL;
13857c478bd9Sstevel@tonic-gate struct path_comp *pc;
13867c478bd9Sstevel@tonic-gate
13877c478bd9Sstevel@tonic-gate ud_printf("udf_readlink\n");
13887c478bd9Sstevel@tonic-gate
13897c478bd9Sstevel@tonic-gate if (vp->v_type != VLNK) {
13907c478bd9Sstevel@tonic-gate return (EINVAL);
13917c478bd9Sstevel@tonic-gate }
13927c478bd9Sstevel@tonic-gate
13937c478bd9Sstevel@tonic-gate ip = VTOI(vp);
13947c478bd9Sstevel@tonic-gate size = ip->i_size;
13957c478bd9Sstevel@tonic-gate if (size > PAGESIZE) {
13967c478bd9Sstevel@tonic-gate return (EIO);
13977c478bd9Sstevel@tonic-gate }
13987c478bd9Sstevel@tonic-gate
13997c478bd9Sstevel@tonic-gate if (size == 0) {
14007c478bd9Sstevel@tonic-gate return (0);
14017c478bd9Sstevel@tonic-gate }
14027c478bd9Sstevel@tonic-gate
14037c478bd9Sstevel@tonic-gate dname = kmem_zalloc(1024, KM_SLEEP);
14047c478bd9Sstevel@tonic-gate uname = kmem_zalloc(PAGESIZE, KM_SLEEP);
14057c478bd9Sstevel@tonic-gate
14067c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
14077c478bd9Sstevel@tonic-gate
14087c478bd9Sstevel@tonic-gate if ((error = fbread(vp, 0, size, S_READ, &fbp)) != 0) {
14097c478bd9Sstevel@tonic-gate goto end;
14107c478bd9Sstevel@tonic-gate }
14117c478bd9Sstevel@tonic-gate
14127c478bd9Sstevel@tonic-gate off = 0;
14137c478bd9Sstevel@tonic-gate
14147c478bd9Sstevel@tonic-gate while (off < size) {
14157c478bd9Sstevel@tonic-gate pc = (struct path_comp *)(fbp->fb_addr + off);
14167c478bd9Sstevel@tonic-gate switch (pc->pc_type) {
14177c478bd9Sstevel@tonic-gate case 1 :
14187c478bd9Sstevel@tonic-gate (void) strcpy(uname, ip->i_udf->udf_fsmnt);
14197c478bd9Sstevel@tonic-gate (void) strcat(uname, "/");
14207c478bd9Sstevel@tonic-gate break;
14217c478bd9Sstevel@tonic-gate case 2 :
14227c478bd9Sstevel@tonic-gate if (pc->pc_len != 0) {
14237c478bd9Sstevel@tonic-gate goto end;
14247c478bd9Sstevel@tonic-gate }
14257c478bd9Sstevel@tonic-gate uname[0] = '/';
14267c478bd9Sstevel@tonic-gate uname[1] = '\0';
14277c478bd9Sstevel@tonic-gate break;
14287c478bd9Sstevel@tonic-gate case 3 :
14297c478bd9Sstevel@tonic-gate (void) strcat(uname, "../");
14307c478bd9Sstevel@tonic-gate break;
14317c478bd9Sstevel@tonic-gate case 4 :
14327c478bd9Sstevel@tonic-gate (void) strcat(uname, "./");
14337c478bd9Sstevel@tonic-gate break;
14347c478bd9Sstevel@tonic-gate case 5 :
14357c478bd9Sstevel@tonic-gate if ((error = ud_uncompress(pc->pc_len, &id_len,
14367c478bd9Sstevel@tonic-gate pc->pc_id, (uint8_t *)dname)) != 0) {
14377c478bd9Sstevel@tonic-gate break;
14387c478bd9Sstevel@tonic-gate }
14397c478bd9Sstevel@tonic-gate dname[id_len] = '\0';
14407c478bd9Sstevel@tonic-gate (void) strcat(uname, dname);
14417c478bd9Sstevel@tonic-gate (void) strcat(uname, "/");
14427c478bd9Sstevel@tonic-gate break;
14437c478bd9Sstevel@tonic-gate default :
14447c478bd9Sstevel@tonic-gate error = EINVAL;
14457c478bd9Sstevel@tonic-gate goto end;
14467c478bd9Sstevel@tonic-gate }
14477c478bd9Sstevel@tonic-gate off += 4 + pc->pc_len;
14487c478bd9Sstevel@tonic-gate }
14497c478bd9Sstevel@tonic-gate len = strlen(uname) - 1;
14507c478bd9Sstevel@tonic-gate if (uname[len] == '/') {
14517c478bd9Sstevel@tonic-gate if (len == 0) {
14527c478bd9Sstevel@tonic-gate /*
14537c478bd9Sstevel@tonic-gate * special case link to /
14547c478bd9Sstevel@tonic-gate */
14557c478bd9Sstevel@tonic-gate len = 1;
14567c478bd9Sstevel@tonic-gate } else {
14577c478bd9Sstevel@tonic-gate uname[len] = '\0';
14587c478bd9Sstevel@tonic-gate }
14597c478bd9Sstevel@tonic-gate }
14607c478bd9Sstevel@tonic-gate
14617c478bd9Sstevel@tonic-gate error = uiomove(uname, len, UIO_READ, uiop);
14627c478bd9Sstevel@tonic-gate
14637c478bd9Sstevel@tonic-gate ITIMES(ip);
14647c478bd9Sstevel@tonic-gate
14657c478bd9Sstevel@tonic-gate end:
14667c478bd9Sstevel@tonic-gate if (fbp != NULL) {
14677c478bd9Sstevel@tonic-gate fbrelse(fbp, S_OTHER);
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
14707c478bd9Sstevel@tonic-gate if (uname != NULL) {
14717c478bd9Sstevel@tonic-gate kmem_free(uname, PAGESIZE);
14727c478bd9Sstevel@tonic-gate }
14737c478bd9Sstevel@tonic-gate if (dname != NULL) {
14747c478bd9Sstevel@tonic-gate kmem_free(dname, 1024);
14757c478bd9Sstevel@tonic-gate }
14767c478bd9Sstevel@tonic-gate return (error);
14777c478bd9Sstevel@tonic-gate }
14787c478bd9Sstevel@tonic-gate
14797c478bd9Sstevel@tonic-gate /* ARGSUSED */
14807c478bd9Sstevel@tonic-gate static int32_t
udf_fsync(struct vnode * vp,int32_t syncflag,struct cred * cr,caller_context_t * ct)1481da6c28aaSamw udf_fsync(
1482da6c28aaSamw struct vnode *vp,
1483da6c28aaSamw int32_t syncflag,
1484da6c28aaSamw struct cred *cr,
1485da6c28aaSamw caller_context_t *ct)
14867c478bd9Sstevel@tonic-gate {
14877c478bd9Sstevel@tonic-gate int32_t error = 0;
14887c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
14897c478bd9Sstevel@tonic-gate
14907c478bd9Sstevel@tonic-gate ud_printf("udf_fsync\n");
14917c478bd9Sstevel@tonic-gate
14927c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
14937c478bd9Sstevel@tonic-gate if (!(IS_SWAPVP(vp))) {
14947c478bd9Sstevel@tonic-gate error = ud_syncip(ip, 0, I_SYNC); /* Do synchronous writes */
14957c478bd9Sstevel@tonic-gate }
14967c478bd9Sstevel@tonic-gate if (error == 0) {
14977c478bd9Sstevel@tonic-gate error = ud_sync_indir(ip);
14987c478bd9Sstevel@tonic-gate }
14997c478bd9Sstevel@tonic-gate ITIMES(ip); /* XXX: is this necessary ??? */
15007c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
15017c478bd9Sstevel@tonic-gate
15027c478bd9Sstevel@tonic-gate return (error);
15037c478bd9Sstevel@tonic-gate }
15047c478bd9Sstevel@tonic-gate
15057c478bd9Sstevel@tonic-gate /* ARGSUSED */
15067c478bd9Sstevel@tonic-gate static void
udf_inactive(struct vnode * vp,struct cred * cr,caller_context_t * ct)1507da6c28aaSamw udf_inactive(struct vnode *vp, struct cred *cr, caller_context_t *ct)
15087c478bd9Sstevel@tonic-gate {
15097c478bd9Sstevel@tonic-gate ud_printf("udf_iinactive\n");
15107c478bd9Sstevel@tonic-gate
15117c478bd9Sstevel@tonic-gate ud_iinactive(VTOI(vp), cr);
15127c478bd9Sstevel@tonic-gate }
15137c478bd9Sstevel@tonic-gate
1514da6c28aaSamw /* ARGSUSED */
15157c478bd9Sstevel@tonic-gate static int32_t
udf_fid(struct vnode * vp,struct fid * fidp,caller_context_t * ct)1516da6c28aaSamw udf_fid(struct vnode *vp, struct fid *fidp, caller_context_t *ct)
15177c478bd9Sstevel@tonic-gate {
15187c478bd9Sstevel@tonic-gate struct udf_fid *udfidp;
15197c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
15207c478bd9Sstevel@tonic-gate
15217c478bd9Sstevel@tonic-gate ud_printf("udf_fid\n");
15227c478bd9Sstevel@tonic-gate
15237c478bd9Sstevel@tonic-gate if (fidp->fid_len < (sizeof (struct udf_fid) - sizeof (uint16_t))) {
15247c478bd9Sstevel@tonic-gate fidp->fid_len = sizeof (struct udf_fid) - sizeof (uint16_t);
15257c478bd9Sstevel@tonic-gate return (ENOSPC);
15267c478bd9Sstevel@tonic-gate }
15277c478bd9Sstevel@tonic-gate
15287c478bd9Sstevel@tonic-gate udfidp = (struct udf_fid *)fidp;
15297c478bd9Sstevel@tonic-gate bzero((char *)udfidp, sizeof (struct udf_fid));
15307c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
15317c478bd9Sstevel@tonic-gate udfidp->udfid_len = sizeof (struct udf_fid) - sizeof (uint16_t);
15327c478bd9Sstevel@tonic-gate udfidp->udfid_uinq_lo = ip->i_uniqid & 0xffffffff;
15337c478bd9Sstevel@tonic-gate udfidp->udfid_prn = ip->i_icb_prn;
15347c478bd9Sstevel@tonic-gate udfidp->udfid_icb_lbn = ip->i_icb_block;
15357c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
15367c478bd9Sstevel@tonic-gate
15377c478bd9Sstevel@tonic-gate return (0);
15387c478bd9Sstevel@tonic-gate }
15397c478bd9Sstevel@tonic-gate
15407c478bd9Sstevel@tonic-gate /* ARGSUSED2 */
15417c478bd9Sstevel@tonic-gate static int
udf_rwlock(struct vnode * vp,int32_t write_lock,caller_context_t * ctp)15427c478bd9Sstevel@tonic-gate udf_rwlock(struct vnode *vp, int32_t write_lock, caller_context_t *ctp)
15437c478bd9Sstevel@tonic-gate {
15447c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
15457c478bd9Sstevel@tonic-gate
15467c478bd9Sstevel@tonic-gate ud_printf("udf_rwlock\n");
15477c478bd9Sstevel@tonic-gate
15487c478bd9Sstevel@tonic-gate if (write_lock) {
15497c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
15507c478bd9Sstevel@tonic-gate } else {
15517c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_READER);
15527c478bd9Sstevel@tonic-gate }
15537c478bd9Sstevel@tonic-gate #ifdef __lock_lint
15547c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
15557c478bd9Sstevel@tonic-gate #endif
15567c478bd9Sstevel@tonic-gate return (write_lock);
15577c478bd9Sstevel@tonic-gate }
15587c478bd9Sstevel@tonic-gate
15597c478bd9Sstevel@tonic-gate /* ARGSUSED */
15607c478bd9Sstevel@tonic-gate static void
udf_rwunlock(struct vnode * vp,int32_t write_lock,caller_context_t * ctp)15617c478bd9Sstevel@tonic-gate udf_rwunlock(struct vnode *vp, int32_t write_lock, caller_context_t *ctp)
15627c478bd9Sstevel@tonic-gate {
15637c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
15647c478bd9Sstevel@tonic-gate
15657c478bd9Sstevel@tonic-gate ud_printf("udf_rwunlock\n");
15667c478bd9Sstevel@tonic-gate
15677c478bd9Sstevel@tonic-gate #ifdef __lock_lint
15687c478bd9Sstevel@tonic-gate rw_enter(&ip->i_rwlock, RW_WRITER);
15697c478bd9Sstevel@tonic-gate #endif
15707c478bd9Sstevel@tonic-gate
15717c478bd9Sstevel@tonic-gate rw_exit(&ip->i_rwlock);
15727c478bd9Sstevel@tonic-gate
15737c478bd9Sstevel@tonic-gate }
15747c478bd9Sstevel@tonic-gate
15757c478bd9Sstevel@tonic-gate /* ARGSUSED */
15767c478bd9Sstevel@tonic-gate static int32_t
udf_seek(struct vnode * vp,offset_t ooff,offset_t * noffp,caller_context_t * ct)1577da6c28aaSamw udf_seek(struct vnode *vp, offset_t ooff, offset_t *noffp, caller_context_t *ct)
15787c478bd9Sstevel@tonic-gate {
15797c478bd9Sstevel@tonic-gate return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
15807c478bd9Sstevel@tonic-gate }
15817c478bd9Sstevel@tonic-gate
15827c478bd9Sstevel@tonic-gate static int32_t
udf_frlock(struct vnode * vp,int32_t cmd,struct flock64 * bfp,int32_t flag,offset_t offset,struct flk_callback * flk_cbp,cred_t * cr,caller_context_t * ct)1583da6c28aaSamw udf_frlock(
1584da6c28aaSamw struct vnode *vp,
1585da6c28aaSamw int32_t cmd,
1586da6c28aaSamw struct flock64 *bfp,
1587da6c28aaSamw int32_t flag,
1588da6c28aaSamw offset_t offset,
1589da6c28aaSamw struct flk_callback *flk_cbp,
1590da6c28aaSamw cred_t *cr,
1591da6c28aaSamw caller_context_t *ct)
15927c478bd9Sstevel@tonic-gate {
15937c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
15947c478bd9Sstevel@tonic-gate
15957c478bd9Sstevel@tonic-gate ud_printf("udf_frlock\n");
15967c478bd9Sstevel@tonic-gate
15977c478bd9Sstevel@tonic-gate /*
15987c478bd9Sstevel@tonic-gate * If file is being mapped, disallow frlock.
15997c478bd9Sstevel@tonic-gate * XXX I am not holding tlock while checking i_mapcnt because the
16007c478bd9Sstevel@tonic-gate * current locking strategy drops all locks before calling fs_frlock.
16017c478bd9Sstevel@tonic-gate * So, mapcnt could change before we enter fs_frlock making is
16027c478bd9Sstevel@tonic-gate * meaningless to have held tlock in the first place.
16037c478bd9Sstevel@tonic-gate */
16047c478bd9Sstevel@tonic-gate if ((ip->i_mapcnt > 0) &&
16057c478bd9Sstevel@tonic-gate (MANDLOCK(vp, ip->i_char))) {
16067c478bd9Sstevel@tonic-gate return (EAGAIN);
16077c478bd9Sstevel@tonic-gate }
16087c478bd9Sstevel@tonic-gate
1609da6c28aaSamw return (fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct));
16107c478bd9Sstevel@tonic-gate }
16117c478bd9Sstevel@tonic-gate
16127c478bd9Sstevel@tonic-gate /*ARGSUSED6*/
16137c478bd9Sstevel@tonic-gate static int32_t
udf_space(struct vnode * vp,int32_t cmd,struct flock64 * bfp,int32_t flag,offset_t offset,cred_t * cr,caller_context_t * ct)16147c478bd9Sstevel@tonic-gate udf_space(
16157c478bd9Sstevel@tonic-gate struct vnode *vp,
16167c478bd9Sstevel@tonic-gate int32_t cmd,
16177c478bd9Sstevel@tonic-gate struct flock64 *bfp,
16187c478bd9Sstevel@tonic-gate int32_t flag,
16197c478bd9Sstevel@tonic-gate offset_t offset,
16207c478bd9Sstevel@tonic-gate cred_t *cr,
16217c478bd9Sstevel@tonic-gate caller_context_t *ct)
16227c478bd9Sstevel@tonic-gate {
16237c478bd9Sstevel@tonic-gate int32_t error = 0;
16247c478bd9Sstevel@tonic-gate
16257c478bd9Sstevel@tonic-gate ud_printf("udf_space\n");
16267c478bd9Sstevel@tonic-gate
16277c478bd9Sstevel@tonic-gate if (cmd != F_FREESP) {
16287c478bd9Sstevel@tonic-gate error = EINVAL;
16297c478bd9Sstevel@tonic-gate } else if ((error = convoff(vp, bfp, 0, offset)) == 0) {
16307c478bd9Sstevel@tonic-gate error = ud_freesp(vp, bfp, flag, cr);
1631*72102e74SBryan Cantrill
1632*72102e74SBryan Cantrill if (error == 0 && bfp->l_start == 0)
1633*72102e74SBryan Cantrill vnevent_truncate(vp, ct);
16347c478bd9Sstevel@tonic-gate }
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate return (error);
16377c478bd9Sstevel@tonic-gate }
16387c478bd9Sstevel@tonic-gate
16397c478bd9Sstevel@tonic-gate /* ARGSUSED */
16407c478bd9Sstevel@tonic-gate static int32_t
udf_getpage(struct vnode * vp,offset_t off,size_t len,uint32_t * protp,struct page ** plarr,size_t plsz,struct seg * seg,caddr_t addr,enum seg_rw rw,struct cred * cr,caller_context_t * ct)1641da6c28aaSamw udf_getpage(
1642da6c28aaSamw struct vnode *vp,
1643da6c28aaSamw offset_t off,
1644da6c28aaSamw size_t len,
1645da6c28aaSamw uint32_t *protp,
1646da6c28aaSamw struct page **plarr,
1647da6c28aaSamw size_t plsz,
1648da6c28aaSamw struct seg *seg,
1649da6c28aaSamw caddr_t addr,
1650da6c28aaSamw enum seg_rw rw,
1651da6c28aaSamw struct cred *cr,
1652da6c28aaSamw caller_context_t *ct)
16537c478bd9Sstevel@tonic-gate {
16547c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
16557c478bd9Sstevel@tonic-gate int32_t error, has_holes, beyond_eof, seqmode, dolock;
16567c478bd9Sstevel@tonic-gate int32_t pgsize = PAGESIZE;
16577c478bd9Sstevel@tonic-gate struct udf_vfs *udf_vfsp = ip->i_udf;
16587c478bd9Sstevel@tonic-gate page_t **pl;
16597c478bd9Sstevel@tonic-gate u_offset_t pgoff, eoff, uoff;
16607c478bd9Sstevel@tonic-gate krw_t rwtype;
16617c478bd9Sstevel@tonic-gate caddr_t pgaddr;
16627c478bd9Sstevel@tonic-gate
16637c478bd9Sstevel@tonic-gate ud_printf("udf_getpage\n");
16647c478bd9Sstevel@tonic-gate
16657c478bd9Sstevel@tonic-gate uoff = (u_offset_t)off; /* type conversion */
16667c478bd9Sstevel@tonic-gate if (protp) {
16677c478bd9Sstevel@tonic-gate *protp = PROT_ALL;
16687c478bd9Sstevel@tonic-gate }
16697c478bd9Sstevel@tonic-gate if (vp->v_flag & VNOMAP) {
16707c478bd9Sstevel@tonic-gate return (ENOSYS);
16717c478bd9Sstevel@tonic-gate }
16727c478bd9Sstevel@tonic-gate seqmode = ip->i_nextr == uoff && rw != S_CREATE;
16737c478bd9Sstevel@tonic-gate
16747c478bd9Sstevel@tonic-gate rwtype = RW_READER;
16757c478bd9Sstevel@tonic-gate dolock = (rw_owner(&ip->i_contents) != curthread);
16767c478bd9Sstevel@tonic-gate retrylock:
16777c478bd9Sstevel@tonic-gate #ifdef __lock_lint
16787c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, rwtype);
16797c478bd9Sstevel@tonic-gate #else
16807c478bd9Sstevel@tonic-gate if (dolock) {
16817c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, rwtype);
16827c478bd9Sstevel@tonic-gate }
16837c478bd9Sstevel@tonic-gate #endif
16847c478bd9Sstevel@tonic-gate
16857c478bd9Sstevel@tonic-gate /*
16867c478bd9Sstevel@tonic-gate * We may be getting called as a side effect of a bmap using
16877c478bd9Sstevel@tonic-gate * fbread() when the blocks might be being allocated and the
16887c478bd9Sstevel@tonic-gate * size has not yet been up'ed. In this case we want to be
16897c478bd9Sstevel@tonic-gate * able to return zero pages if we get back UDF_HOLE from
16907c478bd9Sstevel@tonic-gate * calling bmap for a non write case here. We also might have
16917c478bd9Sstevel@tonic-gate * to read some frags from the disk into a page if we are
16927c478bd9Sstevel@tonic-gate * extending the number of frags for a given lbn in bmap().
16937c478bd9Sstevel@tonic-gate */
16947c478bd9Sstevel@tonic-gate beyond_eof = uoff + len > ip->i_size + PAGEOFFSET;
16957c478bd9Sstevel@tonic-gate if (beyond_eof && seg != segkmap) {
16967c478bd9Sstevel@tonic-gate #ifdef __lock_lint
16977c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
16987c478bd9Sstevel@tonic-gate #else
16997c478bd9Sstevel@tonic-gate if (dolock) {
17007c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
17017c478bd9Sstevel@tonic-gate }
17027c478bd9Sstevel@tonic-gate #endif
17037c478bd9Sstevel@tonic-gate return (EFAULT);
17047c478bd9Sstevel@tonic-gate }
17057c478bd9Sstevel@tonic-gate
17067c478bd9Sstevel@tonic-gate /*
17077c478bd9Sstevel@tonic-gate * Must hold i_contents lock throughout the call to pvn_getpages
17087c478bd9Sstevel@tonic-gate * since locked pages are returned from each call to ud_getapage.
17097c478bd9Sstevel@tonic-gate * Must *not* return locked pages and then try for contents lock
17107c478bd9Sstevel@tonic-gate * due to lock ordering requirements (inode > page)
17117c478bd9Sstevel@tonic-gate */
17127c478bd9Sstevel@tonic-gate
17137c478bd9Sstevel@tonic-gate has_holes = ud_bmap_has_holes(ip);
17147c478bd9Sstevel@tonic-gate
17157c478bd9Sstevel@tonic-gate if ((rw == S_WRITE || rw == S_CREATE) && (has_holes || beyond_eof)) {
17167c478bd9Sstevel@tonic-gate int32_t blk_size, count;
17177c478bd9Sstevel@tonic-gate u_offset_t offset;
17187c478bd9Sstevel@tonic-gate
17197c478bd9Sstevel@tonic-gate /*
17207c478bd9Sstevel@tonic-gate * We must acquire the RW_WRITER lock in order to
17217c478bd9Sstevel@tonic-gate * call bmap_write().
17227c478bd9Sstevel@tonic-gate */
17237c478bd9Sstevel@tonic-gate if (dolock && rwtype == RW_READER) {
17247c478bd9Sstevel@tonic-gate rwtype = RW_WRITER;
17257c478bd9Sstevel@tonic-gate
17267c478bd9Sstevel@tonic-gate if (!rw_tryupgrade(&ip->i_contents)) {
17277c478bd9Sstevel@tonic-gate
17287c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
17297c478bd9Sstevel@tonic-gate
17307c478bd9Sstevel@tonic-gate goto retrylock;
17317c478bd9Sstevel@tonic-gate }
17327c478bd9Sstevel@tonic-gate }
17337c478bd9Sstevel@tonic-gate
17347c478bd9Sstevel@tonic-gate /*
17357c478bd9Sstevel@tonic-gate * May be allocating disk blocks for holes here as
17367c478bd9Sstevel@tonic-gate * a result of mmap faults. write(2) does the bmap_write
17377c478bd9Sstevel@tonic-gate * in rdip/wrip, not here. We are not dealing with frags
17387c478bd9Sstevel@tonic-gate * in this case.
17397c478bd9Sstevel@tonic-gate */
17407c478bd9Sstevel@tonic-gate offset = uoff;
17417c478bd9Sstevel@tonic-gate while ((offset < uoff + len) &&
17427c478bd9Sstevel@tonic-gate (offset < ip->i_size)) {
17437c478bd9Sstevel@tonic-gate /*
17447c478bd9Sstevel@tonic-gate * the variable "bnp" is to simplify the expression for
17457c478bd9Sstevel@tonic-gate * the compiler; * just passing in &bn to bmap_write
17467c478bd9Sstevel@tonic-gate * causes a compiler "loop"
17477c478bd9Sstevel@tonic-gate */
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate blk_size = udf_vfsp->udf_lbsize;
17507c478bd9Sstevel@tonic-gate if ((offset + blk_size) > ip->i_size) {
17517c478bd9Sstevel@tonic-gate count = ip->i_size - offset;
17527c478bd9Sstevel@tonic-gate } else {
17537c478bd9Sstevel@tonic-gate count = blk_size;
17547c478bd9Sstevel@tonic-gate }
17557c478bd9Sstevel@tonic-gate error = ud_bmap_write(ip, offset, count, 0, cr);
17567c478bd9Sstevel@tonic-gate if (error) {
17577c478bd9Sstevel@tonic-gate goto update_inode;
17587c478bd9Sstevel@tonic-gate }
17597c478bd9Sstevel@tonic-gate offset += count; /* XXX - make this contig */
17607c478bd9Sstevel@tonic-gate }
17617c478bd9Sstevel@tonic-gate }
17627c478bd9Sstevel@tonic-gate
17637c478bd9Sstevel@tonic-gate /*
17647c478bd9Sstevel@tonic-gate * Can be a reader from now on.
17657c478bd9Sstevel@tonic-gate */
17667c478bd9Sstevel@tonic-gate #ifdef __lock_lint
17677c478bd9Sstevel@tonic-gate if (rwtype == RW_WRITER) {
17687c478bd9Sstevel@tonic-gate rw_downgrade(&ip->i_contents);
17697c478bd9Sstevel@tonic-gate }
17707c478bd9Sstevel@tonic-gate #else
17717c478bd9Sstevel@tonic-gate if (dolock && rwtype == RW_WRITER) {
17727c478bd9Sstevel@tonic-gate rw_downgrade(&ip->i_contents);
17737c478bd9Sstevel@tonic-gate }
17747c478bd9Sstevel@tonic-gate #endif
17757c478bd9Sstevel@tonic-gate
17767c478bd9Sstevel@tonic-gate /*
17777c478bd9Sstevel@tonic-gate * We remove PROT_WRITE in cases when the file has UDF holes
17787c478bd9Sstevel@tonic-gate * because we don't want to call bmap_read() to check each
17797c478bd9Sstevel@tonic-gate * page if it is backed with a disk block.
17807c478bd9Sstevel@tonic-gate */
17817c478bd9Sstevel@tonic-gate if (protp && has_holes && rw != S_WRITE && rw != S_CREATE) {
17827c478bd9Sstevel@tonic-gate *protp &= ~PROT_WRITE;
17837c478bd9Sstevel@tonic-gate }
17847c478bd9Sstevel@tonic-gate
17857c478bd9Sstevel@tonic-gate error = 0;
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gate /*
17887c478bd9Sstevel@tonic-gate * The loop looks up pages in the range <off, off + len).
17897c478bd9Sstevel@tonic-gate * For each page, we first check if we should initiate an asynchronous
17907c478bd9Sstevel@tonic-gate * read ahead before we call page_lookup (we may sleep in page_lookup
17917c478bd9Sstevel@tonic-gate * for a previously initiated disk read).
17927c478bd9Sstevel@tonic-gate */
17937c478bd9Sstevel@tonic-gate eoff = (uoff + len);
17947c478bd9Sstevel@tonic-gate for (pgoff = uoff, pgaddr = addr, pl = plarr;
17957c478bd9Sstevel@tonic-gate pgoff < eoff; /* empty */) {
17967c478bd9Sstevel@tonic-gate page_t *pp;
17977c478bd9Sstevel@tonic-gate u_offset_t nextrio;
17987c478bd9Sstevel@tonic-gate se_t se;
17997c478bd9Sstevel@tonic-gate
18007c478bd9Sstevel@tonic-gate se = ((rw == S_CREATE) ? SE_EXCL : SE_SHARED);
18017c478bd9Sstevel@tonic-gate
18027c478bd9Sstevel@tonic-gate /*
18037c478bd9Sstevel@tonic-gate * Handle async getpage (faultahead)
18047c478bd9Sstevel@tonic-gate */
18057c478bd9Sstevel@tonic-gate if (plarr == NULL) {
18067c478bd9Sstevel@tonic-gate ip->i_nextrio = pgoff;
18077c478bd9Sstevel@tonic-gate ud_getpage_ra(vp, pgoff, seg, pgaddr);
18087c478bd9Sstevel@tonic-gate pgoff += pgsize;
18097c478bd9Sstevel@tonic-gate pgaddr += pgsize;
18107c478bd9Sstevel@tonic-gate continue;
18117c478bd9Sstevel@tonic-gate }
18127c478bd9Sstevel@tonic-gate
18137c478bd9Sstevel@tonic-gate /*
18147c478bd9Sstevel@tonic-gate * Check if we should initiate read ahead of next cluster.
18157c478bd9Sstevel@tonic-gate * We call page_exists only when we need to confirm that
18167c478bd9Sstevel@tonic-gate * we have the current page before we initiate the read ahead.
18177c478bd9Sstevel@tonic-gate */
18187c478bd9Sstevel@tonic-gate nextrio = ip->i_nextrio;
18197c478bd9Sstevel@tonic-gate if (seqmode &&
18207c478bd9Sstevel@tonic-gate pgoff + RD_CLUSTSZ(ip) >= nextrio && pgoff <= nextrio &&
18217c478bd9Sstevel@tonic-gate nextrio < ip->i_size && page_exists(vp, pgoff))
18227c478bd9Sstevel@tonic-gate ud_getpage_ra(vp, pgoff, seg, pgaddr);
18237c478bd9Sstevel@tonic-gate
18247c478bd9Sstevel@tonic-gate if ((pp = page_lookup(vp, pgoff, se)) != NULL) {
18257c478bd9Sstevel@tonic-gate
18267c478bd9Sstevel@tonic-gate /*
18277c478bd9Sstevel@tonic-gate * We found the page in the page cache.
18287c478bd9Sstevel@tonic-gate */
18297c478bd9Sstevel@tonic-gate *pl++ = pp;
18307c478bd9Sstevel@tonic-gate pgoff += pgsize;
18317c478bd9Sstevel@tonic-gate pgaddr += pgsize;
18327c478bd9Sstevel@tonic-gate len -= pgsize;
18337c478bd9Sstevel@tonic-gate plsz -= pgsize;
18347c478bd9Sstevel@tonic-gate } else {
18357c478bd9Sstevel@tonic-gate
18367c478bd9Sstevel@tonic-gate /*
18377c478bd9Sstevel@tonic-gate * We have to create the page, or read it from disk.
18387c478bd9Sstevel@tonic-gate */
18397c478bd9Sstevel@tonic-gate if (error = ud_getpage_miss(vp, pgoff, len,
18407c478bd9Sstevel@tonic-gate seg, pgaddr, pl, plsz, rw, seqmode)) {
18417c478bd9Sstevel@tonic-gate goto error_out;
18427c478bd9Sstevel@tonic-gate }
18437c478bd9Sstevel@tonic-gate
18447c478bd9Sstevel@tonic-gate while (*pl != NULL) {
18457c478bd9Sstevel@tonic-gate pl++;
18467c478bd9Sstevel@tonic-gate pgoff += pgsize;
18477c478bd9Sstevel@tonic-gate pgaddr += pgsize;
18487c478bd9Sstevel@tonic-gate len -= pgsize;
18497c478bd9Sstevel@tonic-gate plsz -= pgsize;
18507c478bd9Sstevel@tonic-gate }
18517c478bd9Sstevel@tonic-gate }
18527c478bd9Sstevel@tonic-gate }
18537c478bd9Sstevel@tonic-gate
18547c478bd9Sstevel@tonic-gate /*
18557c478bd9Sstevel@tonic-gate * Return pages up to plsz if they are in the page cache.
18567c478bd9Sstevel@tonic-gate * We cannot return pages if there is a chance that they are
18577c478bd9Sstevel@tonic-gate * backed with a UDF hole and rw is S_WRITE or S_CREATE.
18587c478bd9Sstevel@tonic-gate */
18597c478bd9Sstevel@tonic-gate if (plarr && !(has_holes && (rw == S_WRITE || rw == S_CREATE))) {
18607c478bd9Sstevel@tonic-gate
18617c478bd9Sstevel@tonic-gate ASSERT((protp == NULL) ||
18627c478bd9Sstevel@tonic-gate !(has_holes && (*protp & PROT_WRITE)));
18637c478bd9Sstevel@tonic-gate
18647c478bd9Sstevel@tonic-gate eoff = pgoff + plsz;
18657c478bd9Sstevel@tonic-gate while (pgoff < eoff) {
18667c478bd9Sstevel@tonic-gate page_t *pp;
18677c478bd9Sstevel@tonic-gate
18687c478bd9Sstevel@tonic-gate if ((pp = page_lookup_nowait(vp, pgoff,
18697c478bd9Sstevel@tonic-gate SE_SHARED)) == NULL)
18707c478bd9Sstevel@tonic-gate break;
18717c478bd9Sstevel@tonic-gate
18727c478bd9Sstevel@tonic-gate *pl++ = pp;
18737c478bd9Sstevel@tonic-gate pgoff += pgsize;
18747c478bd9Sstevel@tonic-gate plsz -= pgsize;
18757c478bd9Sstevel@tonic-gate }
18767c478bd9Sstevel@tonic-gate }
18777c478bd9Sstevel@tonic-gate
18787c478bd9Sstevel@tonic-gate if (plarr)
18797c478bd9Sstevel@tonic-gate *pl = NULL; /* Terminate page list */
18807c478bd9Sstevel@tonic-gate ip->i_nextr = pgoff;
18817c478bd9Sstevel@tonic-gate
18827c478bd9Sstevel@tonic-gate error_out:
18837c478bd9Sstevel@tonic-gate if (error && plarr) {
18847c478bd9Sstevel@tonic-gate /*
18857c478bd9Sstevel@tonic-gate * Release any pages we have locked.
18867c478bd9Sstevel@tonic-gate */
18877c478bd9Sstevel@tonic-gate while (pl > &plarr[0])
18887c478bd9Sstevel@tonic-gate page_unlock(*--pl);
18897c478bd9Sstevel@tonic-gate
18907c478bd9Sstevel@tonic-gate plarr[0] = NULL;
18917c478bd9Sstevel@tonic-gate }
18927c478bd9Sstevel@tonic-gate
18937c478bd9Sstevel@tonic-gate update_inode:
18947c478bd9Sstevel@tonic-gate #ifdef __lock_lint
18957c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
18967c478bd9Sstevel@tonic-gate #else
18977c478bd9Sstevel@tonic-gate if (dolock) {
18987c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
18997c478bd9Sstevel@tonic-gate }
19007c478bd9Sstevel@tonic-gate #endif
19017c478bd9Sstevel@tonic-gate
19027c478bd9Sstevel@tonic-gate /*
19037c478bd9Sstevel@tonic-gate * If the inode is not already marked for IACC (in rwip() for read)
19047c478bd9Sstevel@tonic-gate * and the inode is not marked for no access time update (in rwip()
19057c478bd9Sstevel@tonic-gate * for write) then update the inode access time and mod time now.
19067c478bd9Sstevel@tonic-gate */
19077c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
19087c478bd9Sstevel@tonic-gate if ((ip->i_flag & (IACC | INOACC)) == 0) {
19097c478bd9Sstevel@tonic-gate if ((rw != S_OTHER) && (ip->i_type != VDIR)) {
19107c478bd9Sstevel@tonic-gate ip->i_flag |= IACC;
19117c478bd9Sstevel@tonic-gate }
19127c478bd9Sstevel@tonic-gate if (rw == S_WRITE) {
19137c478bd9Sstevel@tonic-gate ip->i_flag |= IUPD;
19147c478bd9Sstevel@tonic-gate }
19157c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(ip);
19167c478bd9Sstevel@tonic-gate }
19177c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
19187c478bd9Sstevel@tonic-gate
19197c478bd9Sstevel@tonic-gate return (error);
19207c478bd9Sstevel@tonic-gate }
19217c478bd9Sstevel@tonic-gate
19227c478bd9Sstevel@tonic-gate int32_t ud_delay = 1;
19237c478bd9Sstevel@tonic-gate
19247c478bd9Sstevel@tonic-gate /* ARGSUSED */
19257c478bd9Sstevel@tonic-gate static int32_t
udf_putpage(struct vnode * vp,offset_t off,size_t len,int32_t flags,struct cred * cr,caller_context_t * ct)1926da6c28aaSamw udf_putpage(
1927da6c28aaSamw struct vnode *vp,
1928da6c28aaSamw offset_t off,
1929da6c28aaSamw size_t len,
1930da6c28aaSamw int32_t flags,
1931da6c28aaSamw struct cred *cr,
1932da6c28aaSamw caller_context_t *ct)
19337c478bd9Sstevel@tonic-gate {
19347c478bd9Sstevel@tonic-gate struct ud_inode *ip;
19357c478bd9Sstevel@tonic-gate int32_t error = 0;
19367c478bd9Sstevel@tonic-gate
19377c478bd9Sstevel@tonic-gate ud_printf("udf_putpage\n");
19387c478bd9Sstevel@tonic-gate
19397c478bd9Sstevel@tonic-gate ip = VTOI(vp);
19407c478bd9Sstevel@tonic-gate #ifdef __lock_lint
19417c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
19427c478bd9Sstevel@tonic-gate #endif
19437c478bd9Sstevel@tonic-gate
19447c478bd9Sstevel@tonic-gate if (vp->v_count == 0) {
19457c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "ud_putpage : bad v_count");
19467c478bd9Sstevel@tonic-gate error = EINVAL;
19477c478bd9Sstevel@tonic-gate goto out;
19487c478bd9Sstevel@tonic-gate }
19497c478bd9Sstevel@tonic-gate
19507c478bd9Sstevel@tonic-gate if (vp->v_flag & VNOMAP) {
19517c478bd9Sstevel@tonic-gate error = ENOSYS;
19527c478bd9Sstevel@tonic-gate goto out;
19537c478bd9Sstevel@tonic-gate }
19547c478bd9Sstevel@tonic-gate
19557c478bd9Sstevel@tonic-gate if (flags & B_ASYNC) {
19567c478bd9Sstevel@tonic-gate if (ud_delay && len &&
19577c478bd9Sstevel@tonic-gate (flags & ~(B_ASYNC|B_DONTNEED|B_FREE)) == 0) {
19587c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
19597c478bd9Sstevel@tonic-gate
19607c478bd9Sstevel@tonic-gate /*
19617c478bd9Sstevel@tonic-gate * If nobody stalled, start a new cluster.
19627c478bd9Sstevel@tonic-gate */
19637c478bd9Sstevel@tonic-gate if (ip->i_delaylen == 0) {
19647c478bd9Sstevel@tonic-gate ip->i_delayoff = off;
19657c478bd9Sstevel@tonic-gate ip->i_delaylen = len;
19667c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
19677c478bd9Sstevel@tonic-gate goto out;
19687c478bd9Sstevel@tonic-gate }
19697c478bd9Sstevel@tonic-gate
19707c478bd9Sstevel@tonic-gate /*
19717c478bd9Sstevel@tonic-gate * If we have a full cluster or they are not contig,
19727c478bd9Sstevel@tonic-gate * then push last cluster and start over.
19737c478bd9Sstevel@tonic-gate */
19747c478bd9Sstevel@tonic-gate if (ip->i_delaylen >= WR_CLUSTSZ(ip) ||
19757c478bd9Sstevel@tonic-gate ip->i_delayoff + ip->i_delaylen != off) {
19767c478bd9Sstevel@tonic-gate u_offset_t doff;
19777c478bd9Sstevel@tonic-gate size_t dlen;
19787c478bd9Sstevel@tonic-gate
19797c478bd9Sstevel@tonic-gate doff = ip->i_delayoff;
19807c478bd9Sstevel@tonic-gate dlen = ip->i_delaylen;
19817c478bd9Sstevel@tonic-gate ip->i_delayoff = off;
19827c478bd9Sstevel@tonic-gate ip->i_delaylen = len;
19837c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
19847c478bd9Sstevel@tonic-gate error = ud_putpages(vp, doff, dlen, flags, cr);
19857c478bd9Sstevel@tonic-gate /* LMXXX - flags are new val, not old */
19867c478bd9Sstevel@tonic-gate goto out;
19877c478bd9Sstevel@tonic-gate }
19887c478bd9Sstevel@tonic-gate
19897c478bd9Sstevel@tonic-gate /*
19907c478bd9Sstevel@tonic-gate * There is something there, it's not full, and
19917c478bd9Sstevel@tonic-gate * it is contig.
19927c478bd9Sstevel@tonic-gate */
19937c478bd9Sstevel@tonic-gate ip->i_delaylen += len;
19947c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
19957c478bd9Sstevel@tonic-gate goto out;
19967c478bd9Sstevel@tonic-gate }
19977c478bd9Sstevel@tonic-gate
19987c478bd9Sstevel@tonic-gate /*
19997c478bd9Sstevel@tonic-gate * Must have weird flags or we are not clustering.
20007c478bd9Sstevel@tonic-gate */
20017c478bd9Sstevel@tonic-gate }
20027c478bd9Sstevel@tonic-gate
20037c478bd9Sstevel@tonic-gate error = ud_putpages(vp, off, len, flags, cr);
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gate out:
20067c478bd9Sstevel@tonic-gate #ifdef __lock_lint
20077c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
20087c478bd9Sstevel@tonic-gate #endif
20097c478bd9Sstevel@tonic-gate return (error);
20107c478bd9Sstevel@tonic-gate }
20117c478bd9Sstevel@tonic-gate
2012da6c28aaSamw /* ARGSUSED */
20137c478bd9Sstevel@tonic-gate static int32_t
udf_map(struct vnode * vp,offset_t off,struct as * as,caddr_t * addrp,size_t len,uint8_t prot,uint8_t maxprot,uint32_t flags,struct cred * cr,caller_context_t * ct)2014da6c28aaSamw udf_map(
2015da6c28aaSamw struct vnode *vp,
2016da6c28aaSamw offset_t off,
2017da6c28aaSamw struct as *as,
2018da6c28aaSamw caddr_t *addrp,
2019da6c28aaSamw size_t len,
2020da6c28aaSamw uint8_t prot,
2021da6c28aaSamw uint8_t maxprot,
2022da6c28aaSamw uint32_t flags,
2023da6c28aaSamw struct cred *cr,
2024da6c28aaSamw caller_context_t *ct)
20257c478bd9Sstevel@tonic-gate {
20267c478bd9Sstevel@tonic-gate struct segvn_crargs vn_a;
20277c478bd9Sstevel@tonic-gate int32_t error = 0;
20287c478bd9Sstevel@tonic-gate
20297c478bd9Sstevel@tonic-gate ud_printf("udf_map\n");
20307c478bd9Sstevel@tonic-gate
20317c478bd9Sstevel@tonic-gate if (vp->v_flag & VNOMAP) {
20327c478bd9Sstevel@tonic-gate error = ENOSYS;
20337c478bd9Sstevel@tonic-gate goto end;
20347c478bd9Sstevel@tonic-gate }
20357c478bd9Sstevel@tonic-gate
20367c478bd9Sstevel@tonic-gate if ((off < (offset_t)0) ||
20377c478bd9Sstevel@tonic-gate ((off + len) < (offset_t)0)) {
20387c478bd9Sstevel@tonic-gate error = EINVAL;
20397c478bd9Sstevel@tonic-gate goto end;
20407c478bd9Sstevel@tonic-gate }
20417c478bd9Sstevel@tonic-gate
20427c478bd9Sstevel@tonic-gate if (vp->v_type != VREG) {
20437c478bd9Sstevel@tonic-gate error = ENODEV;
20447c478bd9Sstevel@tonic-gate goto end;
20457c478bd9Sstevel@tonic-gate }
20467c478bd9Sstevel@tonic-gate
20477c478bd9Sstevel@tonic-gate /*
20487c478bd9Sstevel@tonic-gate * If file is being locked, disallow mapping.
20497c478bd9Sstevel@tonic-gate */
20507c478bd9Sstevel@tonic-gate if (vn_has_mandatory_locks(vp, VTOI(vp)->i_char)) {
20517c478bd9Sstevel@tonic-gate error = EAGAIN;
20527c478bd9Sstevel@tonic-gate goto end;
20537c478bd9Sstevel@tonic-gate }
20547c478bd9Sstevel@tonic-gate
20557c478bd9Sstevel@tonic-gate as_rangelock(as);
205660946fe0Smec error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
205760946fe0Smec if (error != 0) {
20587c478bd9Sstevel@tonic-gate as_rangeunlock(as);
20597c478bd9Sstevel@tonic-gate goto end;
20607c478bd9Sstevel@tonic-gate }
20617c478bd9Sstevel@tonic-gate
20627c478bd9Sstevel@tonic-gate vn_a.vp = vp;
20637c478bd9Sstevel@tonic-gate vn_a.offset = off;
20647c478bd9Sstevel@tonic-gate vn_a.type = flags & MAP_TYPE;
20657c478bd9Sstevel@tonic-gate vn_a.prot = prot;
20667c478bd9Sstevel@tonic-gate vn_a.maxprot = maxprot;
20677c478bd9Sstevel@tonic-gate vn_a.cred = cr;
20687c478bd9Sstevel@tonic-gate vn_a.amp = NULL;
20697c478bd9Sstevel@tonic-gate vn_a.flags = flags & ~MAP_TYPE;
20707c478bd9Sstevel@tonic-gate vn_a.szc = 0;
20717c478bd9Sstevel@tonic-gate vn_a.lgrp_mem_policy_flags = 0;
20727c478bd9Sstevel@tonic-gate
20737c478bd9Sstevel@tonic-gate error = as_map(as, *addrp, len, segvn_create, (caddr_t)&vn_a);
20747c478bd9Sstevel@tonic-gate as_rangeunlock(as);
20757c478bd9Sstevel@tonic-gate
20767c478bd9Sstevel@tonic-gate end:
20777c478bd9Sstevel@tonic-gate return (error);
20787c478bd9Sstevel@tonic-gate }
20797c478bd9Sstevel@tonic-gate
20807c478bd9Sstevel@tonic-gate /* ARGSUSED */
20817c478bd9Sstevel@tonic-gate static int32_t
udf_addmap(struct vnode * vp,offset_t off,struct as * as,caddr_t addr,size_t len,uint8_t prot,uint8_t maxprot,uint32_t flags,struct cred * cr,caller_context_t * ct)2082da6c28aaSamw udf_addmap(struct vnode *vp,
2083da6c28aaSamw offset_t off,
2084da6c28aaSamw struct as *as,
2085da6c28aaSamw caddr_t addr,
2086da6c28aaSamw size_t len,
2087da6c28aaSamw uint8_t prot,
2088da6c28aaSamw uint8_t maxprot,
2089da6c28aaSamw uint32_t flags,
2090da6c28aaSamw struct cred *cr,
2091da6c28aaSamw caller_context_t *ct)
20927c478bd9Sstevel@tonic-gate {
20937c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
20947c478bd9Sstevel@tonic-gate
20957c478bd9Sstevel@tonic-gate ud_printf("udf_addmap\n");
20967c478bd9Sstevel@tonic-gate
20977c478bd9Sstevel@tonic-gate if (vp->v_flag & VNOMAP) {
20987c478bd9Sstevel@tonic-gate return (ENOSYS);
20997c478bd9Sstevel@tonic-gate }
21007c478bd9Sstevel@tonic-gate
21017c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
21027c478bd9Sstevel@tonic-gate ip->i_mapcnt += btopr(len);
21037c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
21047c478bd9Sstevel@tonic-gate
21057c478bd9Sstevel@tonic-gate return (0);
21067c478bd9Sstevel@tonic-gate }
21077c478bd9Sstevel@tonic-gate
21087c478bd9Sstevel@tonic-gate /* ARGSUSED */
21097c478bd9Sstevel@tonic-gate static int32_t
udf_delmap(struct vnode * vp,offset_t off,struct as * as,caddr_t addr,size_t len,uint32_t prot,uint32_t maxprot,uint32_t flags,struct cred * cr,caller_context_t * ct)2110da6c28aaSamw udf_delmap(
2111da6c28aaSamw struct vnode *vp, offset_t off,
2112da6c28aaSamw struct as *as,
2113da6c28aaSamw caddr_t addr,
2114da6c28aaSamw size_t len,
2115da6c28aaSamw uint32_t prot,
2116da6c28aaSamw uint32_t maxprot,
2117da6c28aaSamw uint32_t flags,
2118da6c28aaSamw struct cred *cr,
2119da6c28aaSamw caller_context_t *ct)
21207c478bd9Sstevel@tonic-gate {
21217c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
21227c478bd9Sstevel@tonic-gate
21237c478bd9Sstevel@tonic-gate ud_printf("udf_delmap\n");
21247c478bd9Sstevel@tonic-gate
21257c478bd9Sstevel@tonic-gate if (vp->v_flag & VNOMAP) {
21267c478bd9Sstevel@tonic-gate return (ENOSYS);
21277c478bd9Sstevel@tonic-gate }
21287c478bd9Sstevel@tonic-gate
21297c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
21307c478bd9Sstevel@tonic-gate ip->i_mapcnt -= btopr(len); /* Count released mappings */
21317c478bd9Sstevel@tonic-gate ASSERT(ip->i_mapcnt >= 0);
21327c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
21337c478bd9Sstevel@tonic-gate
21347c478bd9Sstevel@tonic-gate return (0);
21357c478bd9Sstevel@tonic-gate }
21367c478bd9Sstevel@tonic-gate
2137da6c28aaSamw /* ARGSUSED */
21387c478bd9Sstevel@tonic-gate static int32_t
udf_l_pathconf(struct vnode * vp,int32_t cmd,ulong_t * valp,struct cred * cr,caller_context_t * ct)2139da6c28aaSamw udf_l_pathconf(
2140da6c28aaSamw struct vnode *vp,
2141da6c28aaSamw int32_t cmd,
2142da6c28aaSamw ulong_t *valp,
2143da6c28aaSamw struct cred *cr,
2144da6c28aaSamw caller_context_t *ct)
21457c478bd9Sstevel@tonic-gate {
21467c478bd9Sstevel@tonic-gate int32_t error = 0;
21477c478bd9Sstevel@tonic-gate
21487c478bd9Sstevel@tonic-gate ud_printf("udf_l_pathconf\n");
21497c478bd9Sstevel@tonic-gate
21507c478bd9Sstevel@tonic-gate if (cmd == _PC_FILESIZEBITS) {
21517c478bd9Sstevel@tonic-gate /*
21527c478bd9Sstevel@tonic-gate * udf supports 64 bits as file size
21537c478bd9Sstevel@tonic-gate * but there are several other restrictions
21547c478bd9Sstevel@tonic-gate * it only supports 32-bit block numbers and
21557c478bd9Sstevel@tonic-gate * daddr32_t is only and int32_t so taking these
21567c478bd9Sstevel@tonic-gate * into account we can stay just as where ufs is
21577c478bd9Sstevel@tonic-gate */
21587c478bd9Sstevel@tonic-gate *valp = 41;
21593b862e9aSRoger A. Faulkner } else if (cmd == _PC_TIMESTAMP_RESOLUTION) {
21603b862e9aSRoger A. Faulkner /* nanosecond timestamp resolution */
21613b862e9aSRoger A. Faulkner *valp = 1L;
21627c478bd9Sstevel@tonic-gate } else {
2163da6c28aaSamw error = fs_pathconf(vp, cmd, valp, cr, ct);
21647c478bd9Sstevel@tonic-gate }
21657c478bd9Sstevel@tonic-gate
21667c478bd9Sstevel@tonic-gate return (error);
21677c478bd9Sstevel@tonic-gate }
21687c478bd9Sstevel@tonic-gate
21697c478bd9Sstevel@tonic-gate uint32_t ud_pageio_reads = 0, ud_pageio_writes = 0;
21707c478bd9Sstevel@tonic-gate #ifndef __lint
21717c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("safe sharing", ud_pageio_reads))
21727c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("safe sharing", ud_pageio_writes))
21737c478bd9Sstevel@tonic-gate #endif
21747c478bd9Sstevel@tonic-gate /*
21757c478bd9Sstevel@tonic-gate * Assumption is that there will not be a pageio request
21767c478bd9Sstevel@tonic-gate * to a enbedded file
21777c478bd9Sstevel@tonic-gate */
21787c478bd9Sstevel@tonic-gate /* ARGSUSED */
21797c478bd9Sstevel@tonic-gate static int32_t
udf_pageio(struct vnode * vp,struct page * pp,u_offset_t io_off,size_t io_len,int32_t flags,struct cred * cr,caller_context_t * ct)2180da6c28aaSamw udf_pageio(
2181da6c28aaSamw struct vnode *vp,
2182da6c28aaSamw struct page *pp,
2183da6c28aaSamw u_offset_t io_off,
2184da6c28aaSamw size_t io_len,
2185da6c28aaSamw int32_t flags,
2186da6c28aaSamw struct cred *cr,
2187da6c28aaSamw caller_context_t *ct)
21887c478bd9Sstevel@tonic-gate {
21897c478bd9Sstevel@tonic-gate daddr_t bn;
21907c478bd9Sstevel@tonic-gate struct buf *bp;
21917c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
21927c478bd9Sstevel@tonic-gate int32_t dolock, error = 0, contig, multi_io;
21937c478bd9Sstevel@tonic-gate size_t done_len = 0, cur_len = 0;
21947c478bd9Sstevel@tonic-gate page_t *npp = NULL, *opp = NULL, *cpp = pp;
21957c478bd9Sstevel@tonic-gate
21967c478bd9Sstevel@tonic-gate if (pp == NULL) {
21977c478bd9Sstevel@tonic-gate return (EINVAL);
21987c478bd9Sstevel@tonic-gate }
21997c478bd9Sstevel@tonic-gate
22007c478bd9Sstevel@tonic-gate dolock = (rw_owner(&ip->i_contents) != curthread);
22017c478bd9Sstevel@tonic-gate
22027c478bd9Sstevel@tonic-gate /*
22037c478bd9Sstevel@tonic-gate * We need a better check. Ideally, we would use another
22047c478bd9Sstevel@tonic-gate * vnodeops so that hlocked and forcibly unmounted file
22057c478bd9Sstevel@tonic-gate * systems would return EIO where appropriate and w/o the
22067c478bd9Sstevel@tonic-gate * need for these checks.
22077c478bd9Sstevel@tonic-gate */
22087c478bd9Sstevel@tonic-gate if (ip->i_udf == NULL) {
22097c478bd9Sstevel@tonic-gate return (EIO);
22107c478bd9Sstevel@tonic-gate }
22117c478bd9Sstevel@tonic-gate
22127c478bd9Sstevel@tonic-gate #ifdef __lock_lint
22137c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
22147c478bd9Sstevel@tonic-gate #else
22157c478bd9Sstevel@tonic-gate if (dolock) {
22167c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
22177c478bd9Sstevel@tonic-gate }
22187c478bd9Sstevel@tonic-gate #endif
22197c478bd9Sstevel@tonic-gate
22207c478bd9Sstevel@tonic-gate /*
22217c478bd9Sstevel@tonic-gate * Break the io request into chunks, one for each contiguous
22227c478bd9Sstevel@tonic-gate * stretch of disk blocks in the target file.
22237c478bd9Sstevel@tonic-gate */
22247c478bd9Sstevel@tonic-gate while (done_len < io_len) {
22257c478bd9Sstevel@tonic-gate ASSERT(cpp);
22267c478bd9Sstevel@tonic-gate bp = NULL;
22277c478bd9Sstevel@tonic-gate contig = 0;
22287c478bd9Sstevel@tonic-gate if (error = ud_bmap_read(ip, (u_offset_t)(io_off + done_len),
22297c478bd9Sstevel@tonic-gate &bn, &contig)) {
22307c478bd9Sstevel@tonic-gate break;
22317c478bd9Sstevel@tonic-gate }
22327c478bd9Sstevel@tonic-gate
22337c478bd9Sstevel@tonic-gate if (bn == UDF_HOLE) { /* No holey swapfiles */
22347c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "SWAP file has HOLES");
22357c478bd9Sstevel@tonic-gate error = EINVAL;
22367c478bd9Sstevel@tonic-gate break;
22377c478bd9Sstevel@tonic-gate }
22387c478bd9Sstevel@tonic-gate
22397c478bd9Sstevel@tonic-gate cur_len = MIN(io_len - done_len, contig);
22407c478bd9Sstevel@tonic-gate
22417c478bd9Sstevel@tonic-gate /*
22427c478bd9Sstevel@tonic-gate * Check if more than one I/O is
22437c478bd9Sstevel@tonic-gate * required to complete the given
22447c478bd9Sstevel@tonic-gate * I/O operation
22457c478bd9Sstevel@tonic-gate */
22467c478bd9Sstevel@tonic-gate if (ip->i_udf->udf_lbsize < PAGESIZE) {
22477c478bd9Sstevel@tonic-gate if (cur_len >= PAGESIZE) {
22487c478bd9Sstevel@tonic-gate multi_io = 0;
22497c478bd9Sstevel@tonic-gate cur_len &= PAGEMASK;
22507c478bd9Sstevel@tonic-gate } else {
22517c478bd9Sstevel@tonic-gate multi_io = 1;
22527c478bd9Sstevel@tonic-gate cur_len = MIN(io_len - done_len, PAGESIZE);
22537c478bd9Sstevel@tonic-gate }
22547c478bd9Sstevel@tonic-gate }
22557c478bd9Sstevel@tonic-gate page_list_break(&cpp, &npp, btop(cur_len));
22567c478bd9Sstevel@tonic-gate
22577c478bd9Sstevel@tonic-gate bp = pageio_setup(cpp, cur_len, ip->i_devvp, flags);
22587c478bd9Sstevel@tonic-gate ASSERT(bp != NULL);
22597c478bd9Sstevel@tonic-gate
22607c478bd9Sstevel@tonic-gate bp->b_edev = ip->i_dev;
22617c478bd9Sstevel@tonic-gate bp->b_dev = cmpdev(ip->i_dev);
22627c478bd9Sstevel@tonic-gate bp->b_blkno = bn;
22637c478bd9Sstevel@tonic-gate bp->b_un.b_addr = (caddr_t)0;
22647c478bd9Sstevel@tonic-gate bp->b_file = vp;
22657c478bd9Sstevel@tonic-gate bp->b_offset = (offset_t)(io_off + done_len);
22667c478bd9Sstevel@tonic-gate
22677c478bd9Sstevel@tonic-gate /*
22687c478bd9Sstevel@tonic-gate * ub.ub_pageios.value.ul++;
22697c478bd9Sstevel@tonic-gate */
22707c478bd9Sstevel@tonic-gate if (multi_io == 0) {
22717c478bd9Sstevel@tonic-gate (void) bdev_strategy(bp);
22727c478bd9Sstevel@tonic-gate } else {
22737c478bd9Sstevel@tonic-gate error = ud_multi_strat(ip, cpp, bp,
22747c478bd9Sstevel@tonic-gate (u_offset_t)(io_off + done_len));
22757c478bd9Sstevel@tonic-gate if (error != 0) {
22767c478bd9Sstevel@tonic-gate pageio_done(bp);
22777c478bd9Sstevel@tonic-gate break;
22787c478bd9Sstevel@tonic-gate }
22797c478bd9Sstevel@tonic-gate }
22807c478bd9Sstevel@tonic-gate if (flags & B_READ) {
22817c478bd9Sstevel@tonic-gate ud_pageio_reads++;
22827c478bd9Sstevel@tonic-gate } else {
22837c478bd9Sstevel@tonic-gate ud_pageio_writes++;
22847c478bd9Sstevel@tonic-gate }
22857c478bd9Sstevel@tonic-gate
22867c478bd9Sstevel@tonic-gate /*
22877c478bd9Sstevel@tonic-gate * If the request is not B_ASYNC, wait for i/o to complete
22887c478bd9Sstevel@tonic-gate * and re-assemble the page list to return to the caller.
22897c478bd9Sstevel@tonic-gate * If it is B_ASYNC we leave the page list in pieces and
22907c478bd9Sstevel@tonic-gate * cleanup() will dispose of them.
22917c478bd9Sstevel@tonic-gate */
22927c478bd9Sstevel@tonic-gate if ((flags & B_ASYNC) == 0) {
22937c478bd9Sstevel@tonic-gate error = biowait(bp);
22947c478bd9Sstevel@tonic-gate pageio_done(bp);
22957c478bd9Sstevel@tonic-gate if (error) {
22967c478bd9Sstevel@tonic-gate break;
22977c478bd9Sstevel@tonic-gate }
22987c478bd9Sstevel@tonic-gate page_list_concat(&opp, &cpp);
22997c478bd9Sstevel@tonic-gate }
23007c478bd9Sstevel@tonic-gate cpp = npp;
23017c478bd9Sstevel@tonic-gate npp = NULL;
23027c478bd9Sstevel@tonic-gate done_len += cur_len;
23037c478bd9Sstevel@tonic-gate }
23047c478bd9Sstevel@tonic-gate
23057c478bd9Sstevel@tonic-gate ASSERT(error || (cpp == NULL && npp == NULL && done_len == io_len));
23067c478bd9Sstevel@tonic-gate if (error) {
23077c478bd9Sstevel@tonic-gate if (flags & B_ASYNC) {
23087c478bd9Sstevel@tonic-gate /* Cleanup unprocessed parts of list */
23097c478bd9Sstevel@tonic-gate page_list_concat(&cpp, &npp);
23107c478bd9Sstevel@tonic-gate if (flags & B_READ) {
23117c478bd9Sstevel@tonic-gate pvn_read_done(cpp, B_ERROR);
23127c478bd9Sstevel@tonic-gate } else {
23137c478bd9Sstevel@tonic-gate pvn_write_done(cpp, B_ERROR);
23147c478bd9Sstevel@tonic-gate }
23157c478bd9Sstevel@tonic-gate } else {
23167c478bd9Sstevel@tonic-gate /* Re-assemble list and let caller clean up */
23177c478bd9Sstevel@tonic-gate page_list_concat(&opp, &cpp);
23187c478bd9Sstevel@tonic-gate page_list_concat(&opp, &npp);
23197c478bd9Sstevel@tonic-gate }
23207c478bd9Sstevel@tonic-gate }
23217c478bd9Sstevel@tonic-gate
23227c478bd9Sstevel@tonic-gate #ifdef __lock_lint
23237c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
23247c478bd9Sstevel@tonic-gate #else
23257c478bd9Sstevel@tonic-gate if (dolock) {
23267c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
23277c478bd9Sstevel@tonic-gate }
23287c478bd9Sstevel@tonic-gate #endif
23297c478bd9Sstevel@tonic-gate return (error);
23307c478bd9Sstevel@tonic-gate }
23317c478bd9Sstevel@tonic-gate
23327c478bd9Sstevel@tonic-gate
23337c478bd9Sstevel@tonic-gate
23347c478bd9Sstevel@tonic-gate
23357c478bd9Sstevel@tonic-gate /* -------------------- local functions --------------------------- */
23367c478bd9Sstevel@tonic-gate
23377c478bd9Sstevel@tonic-gate
23387c478bd9Sstevel@tonic-gate
23397c478bd9Sstevel@tonic-gate int32_t
ud_rdwri(enum uio_rw rw,int32_t ioflag,struct ud_inode * ip,caddr_t base,int32_t len,offset_t offset,enum uio_seg seg,int32_t * aresid,struct cred * cr)23407c478bd9Sstevel@tonic-gate ud_rdwri(enum uio_rw rw, int32_t ioflag,
23417c478bd9Sstevel@tonic-gate struct ud_inode *ip, caddr_t base, int32_t len,
23427c478bd9Sstevel@tonic-gate offset_t offset, enum uio_seg seg, int32_t *aresid, struct cred *cr)
23437c478bd9Sstevel@tonic-gate {
23447c478bd9Sstevel@tonic-gate int32_t error;
23457c478bd9Sstevel@tonic-gate struct uio auio;
23467c478bd9Sstevel@tonic-gate struct iovec aiov;
23477c478bd9Sstevel@tonic-gate
23487c478bd9Sstevel@tonic-gate ud_printf("ud_rdwri\n");
23497c478bd9Sstevel@tonic-gate
23507c478bd9Sstevel@tonic-gate bzero((caddr_t)&auio, sizeof (uio_t));
23517c478bd9Sstevel@tonic-gate bzero((caddr_t)&aiov, sizeof (iovec_t));
23527c478bd9Sstevel@tonic-gate
23537c478bd9Sstevel@tonic-gate aiov.iov_base = base;
23547c478bd9Sstevel@tonic-gate aiov.iov_len = len;
23557c478bd9Sstevel@tonic-gate auio.uio_iov = &aiov;
23567c478bd9Sstevel@tonic-gate auio.uio_iovcnt = 1;
23577c478bd9Sstevel@tonic-gate auio.uio_loffset = offset;
23587c478bd9Sstevel@tonic-gate auio.uio_segflg = (int16_t)seg;
23597c478bd9Sstevel@tonic-gate auio.uio_resid = len;
23607c478bd9Sstevel@tonic-gate
23617c478bd9Sstevel@tonic-gate if (rw == UIO_WRITE) {
23627c478bd9Sstevel@tonic-gate auio.uio_fmode = FWRITE;
23637c478bd9Sstevel@tonic-gate auio.uio_extflg = UIO_COPY_DEFAULT;
23647c478bd9Sstevel@tonic-gate auio.uio_llimit = curproc->p_fsz_ctl;
23657c478bd9Sstevel@tonic-gate error = ud_wrip(ip, &auio, ioflag, cr);
23667c478bd9Sstevel@tonic-gate } else {
23677c478bd9Sstevel@tonic-gate auio.uio_fmode = FREAD;
23687c478bd9Sstevel@tonic-gate auio.uio_extflg = UIO_COPY_CACHED;
23697c478bd9Sstevel@tonic-gate auio.uio_llimit = MAXOFFSET_T;
23707c478bd9Sstevel@tonic-gate error = ud_rdip(ip, &auio, ioflag, cr);
23717c478bd9Sstevel@tonic-gate }
23727c478bd9Sstevel@tonic-gate
23737c478bd9Sstevel@tonic-gate if (aresid) {
23747c478bd9Sstevel@tonic-gate *aresid = auio.uio_resid;
23757c478bd9Sstevel@tonic-gate } else if (auio.uio_resid) {
23767c478bd9Sstevel@tonic-gate error = EIO;
23777c478bd9Sstevel@tonic-gate }
23787c478bd9Sstevel@tonic-gate return (error);
23797c478bd9Sstevel@tonic-gate }
23807c478bd9Sstevel@tonic-gate
23817c478bd9Sstevel@tonic-gate /*
23827c478bd9Sstevel@tonic-gate * Free behind hacks. The pager is busted.
23837c478bd9Sstevel@tonic-gate * XXX - need to pass the information down to writedone() in a flag like B_SEQ
23847c478bd9Sstevel@tonic-gate * or B_FREE_IF_TIGHT_ON_MEMORY.
23857c478bd9Sstevel@tonic-gate */
23867c478bd9Sstevel@tonic-gate int32_t ud_freebehind = 1;
23877c478bd9Sstevel@tonic-gate int32_t ud_smallfile = 32 * 1024;
23887c478bd9Sstevel@tonic-gate
23897c478bd9Sstevel@tonic-gate /* ARGSUSED */
23907c478bd9Sstevel@tonic-gate int32_t
ud_getpage_miss(struct vnode * vp,u_offset_t off,size_t len,struct seg * seg,caddr_t addr,page_t * pl[],size_t plsz,enum seg_rw rw,int32_t seq)23917c478bd9Sstevel@tonic-gate ud_getpage_miss(struct vnode *vp, u_offset_t off,
23927c478bd9Sstevel@tonic-gate size_t len, struct seg *seg, caddr_t addr, page_t *pl[],
23937c478bd9Sstevel@tonic-gate size_t plsz, enum seg_rw rw, int32_t seq)
23947c478bd9Sstevel@tonic-gate {
23957c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
23967c478bd9Sstevel@tonic-gate int32_t err = 0;
23977c478bd9Sstevel@tonic-gate size_t io_len;
23987c478bd9Sstevel@tonic-gate u_offset_t io_off;
23997c478bd9Sstevel@tonic-gate u_offset_t pgoff;
24007c478bd9Sstevel@tonic-gate page_t *pp;
24017c478bd9Sstevel@tonic-gate
24027c478bd9Sstevel@tonic-gate pl[0] = NULL;
24037c478bd9Sstevel@tonic-gate
24047c478bd9Sstevel@tonic-gate /*
24057c478bd9Sstevel@tonic-gate * Figure out whether the page can be created, or must be
24067c478bd9Sstevel@tonic-gate * read from the disk
24077c478bd9Sstevel@tonic-gate */
24087c478bd9Sstevel@tonic-gate if (rw == S_CREATE) {
24097c478bd9Sstevel@tonic-gate if ((pp = page_create_va(vp, off,
24107c478bd9Sstevel@tonic-gate PAGESIZE, PG_WAIT, seg, addr)) == NULL) {
24117c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "ud_getpage_miss: page_create");
24127c478bd9Sstevel@tonic-gate return (EINVAL);
24137c478bd9Sstevel@tonic-gate }
24147c478bd9Sstevel@tonic-gate io_len = PAGESIZE;
24157c478bd9Sstevel@tonic-gate } else {
24167c478bd9Sstevel@tonic-gate pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
24177c478bd9Sstevel@tonic-gate &io_len, off, PAGESIZE, 0);
24187c478bd9Sstevel@tonic-gate
24197c478bd9Sstevel@tonic-gate /*
24207c478bd9Sstevel@tonic-gate * Some other thread has entered the page.
24217c478bd9Sstevel@tonic-gate * ud_getpage will retry page_lookup.
24227c478bd9Sstevel@tonic-gate */
24237c478bd9Sstevel@tonic-gate if (pp == NULL) {
24247c478bd9Sstevel@tonic-gate return (0);
24257c478bd9Sstevel@tonic-gate }
24267c478bd9Sstevel@tonic-gate
24277c478bd9Sstevel@tonic-gate /*
24287c478bd9Sstevel@tonic-gate * Fill the page with as much data as we can from the file.
24297c478bd9Sstevel@tonic-gate */
24307c478bd9Sstevel@tonic-gate err = ud_page_fill(ip, pp, off, B_READ, &pgoff);
24317c478bd9Sstevel@tonic-gate if (err) {
24327c478bd9Sstevel@tonic-gate pvn_read_done(pp, B_ERROR);
24337c478bd9Sstevel@tonic-gate return (err);
24347c478bd9Sstevel@tonic-gate }
24357c478bd9Sstevel@tonic-gate
24367c478bd9Sstevel@tonic-gate /*
24377c478bd9Sstevel@tonic-gate * XXX ??? ufs has io_len instead of pgoff below
24387c478bd9Sstevel@tonic-gate */
24397c478bd9Sstevel@tonic-gate ip->i_nextrio = off + ((pgoff + PAGESIZE - 1) & PAGEMASK);
24407c478bd9Sstevel@tonic-gate
24417c478bd9Sstevel@tonic-gate /*
24427c478bd9Sstevel@tonic-gate * If the file access is sequential, initiate read ahead
24437c478bd9Sstevel@tonic-gate * of the next cluster.
24447c478bd9Sstevel@tonic-gate */
24457c478bd9Sstevel@tonic-gate if (seq && ip->i_nextrio < ip->i_size) {
24467c478bd9Sstevel@tonic-gate ud_getpage_ra(vp, off, seg, addr);
24477c478bd9Sstevel@tonic-gate }
24487c478bd9Sstevel@tonic-gate }
24497c478bd9Sstevel@tonic-gate
24507c478bd9Sstevel@tonic-gate outmiss:
24517c478bd9Sstevel@tonic-gate pvn_plist_init(pp, pl, plsz, (offset_t)off, io_len, rw);
24527c478bd9Sstevel@tonic-gate return (err);
24537c478bd9Sstevel@tonic-gate }
24547c478bd9Sstevel@tonic-gate
24557c478bd9Sstevel@tonic-gate /* ARGSUSED */
24567c478bd9Sstevel@tonic-gate void
ud_getpage_ra(struct vnode * vp,u_offset_t off,struct seg * seg,caddr_t addr)24577c478bd9Sstevel@tonic-gate ud_getpage_ra(struct vnode *vp,
24587c478bd9Sstevel@tonic-gate u_offset_t off, struct seg *seg, caddr_t addr)
24597c478bd9Sstevel@tonic-gate {
24607c478bd9Sstevel@tonic-gate page_t *pp;
24617c478bd9Sstevel@tonic-gate size_t io_len;
24627c478bd9Sstevel@tonic-gate struct ud_inode *ip = VTOI(vp);
24637c478bd9Sstevel@tonic-gate u_offset_t io_off = ip->i_nextrio, pgoff;
24647c478bd9Sstevel@tonic-gate caddr_t addr2 = addr + (io_off - off);
24657c478bd9Sstevel@tonic-gate daddr_t bn;
24667c478bd9Sstevel@tonic-gate int32_t contig = 0;
24677c478bd9Sstevel@tonic-gate
24687c478bd9Sstevel@tonic-gate /*
24697c478bd9Sstevel@tonic-gate * Is this test needed?
24707c478bd9Sstevel@tonic-gate */
24717c478bd9Sstevel@tonic-gate
24727c478bd9Sstevel@tonic-gate if (addr2 >= seg->s_base + seg->s_size) {
24737c478bd9Sstevel@tonic-gate return;
24747c478bd9Sstevel@tonic-gate }
24757c478bd9Sstevel@tonic-gate
24767c478bd9Sstevel@tonic-gate contig = 0;
24777c478bd9Sstevel@tonic-gate if (ud_bmap_read(ip, io_off, &bn, &contig) != 0 || bn == UDF_HOLE) {
24787c478bd9Sstevel@tonic-gate return;
24797c478bd9Sstevel@tonic-gate }
24807c478bd9Sstevel@tonic-gate
24817c478bd9Sstevel@tonic-gate pp = pvn_read_kluster(vp, io_off, seg, addr2,
24827c478bd9Sstevel@tonic-gate &io_off, &io_len, io_off, PAGESIZE, 1);
24837c478bd9Sstevel@tonic-gate
24847c478bd9Sstevel@tonic-gate /*
24857c478bd9Sstevel@tonic-gate * Some other thread has entered the page.
24867c478bd9Sstevel@tonic-gate * So no read head done here (ie we will have to and wait
24877c478bd9Sstevel@tonic-gate * for the read when needed).
24887c478bd9Sstevel@tonic-gate */
24897c478bd9Sstevel@tonic-gate
24907c478bd9Sstevel@tonic-gate if (pp == NULL) {
24917c478bd9Sstevel@tonic-gate return;
24927c478bd9Sstevel@tonic-gate }
24937c478bd9Sstevel@tonic-gate
24947c478bd9Sstevel@tonic-gate (void) ud_page_fill(ip, pp, io_off, (B_READ|B_ASYNC), &pgoff);
24957c478bd9Sstevel@tonic-gate ip->i_nextrio = io_off + ((pgoff + PAGESIZE - 1) & PAGEMASK);
24967c478bd9Sstevel@tonic-gate }
24977c478bd9Sstevel@tonic-gate
24987c478bd9Sstevel@tonic-gate int
ud_page_fill(struct ud_inode * ip,page_t * pp,u_offset_t off,uint32_t bflgs,u_offset_t * pg_off)24997c478bd9Sstevel@tonic-gate ud_page_fill(struct ud_inode *ip, page_t *pp, u_offset_t off,
25007c478bd9Sstevel@tonic-gate uint32_t bflgs, u_offset_t *pg_off)
25017c478bd9Sstevel@tonic-gate {
25027c478bd9Sstevel@tonic-gate daddr_t bn;
25037c478bd9Sstevel@tonic-gate struct buf *bp;
25047c478bd9Sstevel@tonic-gate caddr_t kaddr, caddr;
25057c478bd9Sstevel@tonic-gate int32_t error = 0, contig = 0, multi_io = 0;
25067c478bd9Sstevel@tonic-gate int32_t lbsize = ip->i_udf->udf_lbsize;
25077c478bd9Sstevel@tonic-gate int32_t lbmask = ip->i_udf->udf_lbmask;
25087c478bd9Sstevel@tonic-gate uint64_t isize;
25097c478bd9Sstevel@tonic-gate
25107c478bd9Sstevel@tonic-gate isize = (ip->i_size + lbmask) & (~lbmask);
25117c478bd9Sstevel@tonic-gate if (ip->i_desc_type == ICB_FLAG_ONE_AD) {
25127c478bd9Sstevel@tonic-gate
25137c478bd9Sstevel@tonic-gate /*
25147c478bd9Sstevel@tonic-gate * Embedded file read file_entry
25157c478bd9Sstevel@tonic-gate * from buffer cache and copy the required
25167c478bd9Sstevel@tonic-gate * portions
25177c478bd9Sstevel@tonic-gate */
25187c478bd9Sstevel@tonic-gate bp = ud_bread(ip->i_dev,
25197c478bd9Sstevel@tonic-gate ip->i_icb_lbano << ip->i_udf->udf_l2d_shift, lbsize);
25207c478bd9Sstevel@tonic-gate if ((bp->b_error == 0) &&
25217c478bd9Sstevel@tonic-gate (bp->b_resid == 0)) {
25227c478bd9Sstevel@tonic-gate
25237c478bd9Sstevel@tonic-gate caddr = bp->b_un.b_addr + ip->i_data_off;
25247c478bd9Sstevel@tonic-gate
25257c478bd9Sstevel@tonic-gate /*
25267c478bd9Sstevel@tonic-gate * mapin to kvm
25277c478bd9Sstevel@tonic-gate */
25287c478bd9Sstevel@tonic-gate kaddr = (caddr_t)ppmapin(pp,
25297c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE, (caddr_t)-1);
25307c478bd9Sstevel@tonic-gate (void) kcopy(caddr, kaddr, ip->i_size);
25317c478bd9Sstevel@tonic-gate
25327c478bd9Sstevel@tonic-gate /*
25337c478bd9Sstevel@tonic-gate * mapout of kvm
25347c478bd9Sstevel@tonic-gate */
25357c478bd9Sstevel@tonic-gate ppmapout(kaddr);
25367c478bd9Sstevel@tonic-gate }
25377c478bd9Sstevel@tonic-gate brelse(bp);
25387c478bd9Sstevel@tonic-gate contig = ip->i_size;
25397c478bd9Sstevel@tonic-gate } else {
25407c478bd9Sstevel@tonic-gate
25417c478bd9Sstevel@tonic-gate /*
25427c478bd9Sstevel@tonic-gate * Get the continuous size and block number
25437c478bd9Sstevel@tonic-gate * at offset "off"
25447c478bd9Sstevel@tonic-gate */
25457c478bd9Sstevel@tonic-gate if (error = ud_bmap_read(ip, off, &bn, &contig))
25467c478bd9Sstevel@tonic-gate goto out;
25477c478bd9Sstevel@tonic-gate contig = MIN(contig, PAGESIZE);
25487c478bd9Sstevel@tonic-gate contig = (contig + lbmask) & (~lbmask);
25497c478bd9Sstevel@tonic-gate
25507c478bd9Sstevel@tonic-gate /*
25517c478bd9Sstevel@tonic-gate * Zero part of the page which we are not
25527c478bd9Sstevel@tonic-gate * going to read from the disk.
25537c478bd9Sstevel@tonic-gate */
25547c478bd9Sstevel@tonic-gate
25557c478bd9Sstevel@tonic-gate if (bn == UDF_HOLE) {
25567c478bd9Sstevel@tonic-gate
25577c478bd9Sstevel@tonic-gate /*
25587c478bd9Sstevel@tonic-gate * This is a HOLE. Just zero out
25597c478bd9Sstevel@tonic-gate * the page
25607c478bd9Sstevel@tonic-gate */
25617c478bd9Sstevel@tonic-gate if (((off + contig) == isize) ||
25627c478bd9Sstevel@tonic-gate (contig == PAGESIZE)) {
25637c478bd9Sstevel@tonic-gate pagezero(pp->p_prev, 0, PAGESIZE);
25647c478bd9Sstevel@tonic-gate goto out;
25657c478bd9Sstevel@tonic-gate }
25667c478bd9Sstevel@tonic-gate }
25677c478bd9Sstevel@tonic-gate
25687c478bd9Sstevel@tonic-gate if (contig < PAGESIZE) {
25697c478bd9Sstevel@tonic-gate uint64_t count;
25707c478bd9Sstevel@tonic-gate
25717c478bd9Sstevel@tonic-gate count = isize - off;
25727c478bd9Sstevel@tonic-gate if (contig != count) {
25737c478bd9Sstevel@tonic-gate multi_io = 1;
25747c478bd9Sstevel@tonic-gate contig = (int32_t)(MIN(count, PAGESIZE));
25757c478bd9Sstevel@tonic-gate } else {
25767c478bd9Sstevel@tonic-gate pagezero(pp->p_prev, contig, PAGESIZE - contig);
25777c478bd9Sstevel@tonic-gate }
25787c478bd9Sstevel@tonic-gate }
25797c478bd9Sstevel@tonic-gate
25807c478bd9Sstevel@tonic-gate /*
25817c478bd9Sstevel@tonic-gate * Get a bp and initialize it
25827c478bd9Sstevel@tonic-gate */
25837c478bd9Sstevel@tonic-gate bp = pageio_setup(pp, contig, ip->i_devvp, bflgs);
25847c478bd9Sstevel@tonic-gate ASSERT(bp != NULL);
25857c478bd9Sstevel@tonic-gate
25867c478bd9Sstevel@tonic-gate bp->b_edev = ip->i_dev;
25877c478bd9Sstevel@tonic-gate bp->b_dev = cmpdev(ip->i_dev);
25887c478bd9Sstevel@tonic-gate bp->b_blkno = bn;
25897c478bd9Sstevel@tonic-gate bp->b_un.b_addr = 0;
25907c478bd9Sstevel@tonic-gate bp->b_file = ip->i_vnode;
25917c478bd9Sstevel@tonic-gate
25927c478bd9Sstevel@tonic-gate /*
25937c478bd9Sstevel@tonic-gate * Start I/O
25947c478bd9Sstevel@tonic-gate */
25957c478bd9Sstevel@tonic-gate if (multi_io == 0) {
25967c478bd9Sstevel@tonic-gate
25977c478bd9Sstevel@tonic-gate /*
25987c478bd9Sstevel@tonic-gate * Single I/O is sufficient for this page
25997c478bd9Sstevel@tonic-gate */
26007c478bd9Sstevel@tonic-gate (void) bdev_strategy(bp);
26017c478bd9Sstevel@tonic-gate } else {
26027c478bd9Sstevel@tonic-gate
26037c478bd9Sstevel@tonic-gate /*
26047c478bd9Sstevel@tonic-gate * We need to do the I/O in
26057c478bd9Sstevel@tonic-gate * piece's
26067c478bd9Sstevel@tonic-gate */
26077c478bd9Sstevel@tonic-gate error = ud_multi_strat(ip, pp, bp, off);
26087c478bd9Sstevel@tonic-gate if (error != 0) {
26097c478bd9Sstevel@tonic-gate goto out;
26107c478bd9Sstevel@tonic-gate }
26117c478bd9Sstevel@tonic-gate }
26127c478bd9Sstevel@tonic-gate if ((bflgs & B_ASYNC) == 0) {
26137c478bd9Sstevel@tonic-gate
26147c478bd9Sstevel@tonic-gate /*
26157c478bd9Sstevel@tonic-gate * Wait for i/o to complete.
26167c478bd9Sstevel@tonic-gate */
26177c478bd9Sstevel@tonic-gate
26187c478bd9Sstevel@tonic-gate error = biowait(bp);
26197c478bd9Sstevel@tonic-gate pageio_done(bp);
26207c478bd9Sstevel@tonic-gate if (error) {
26217c478bd9Sstevel@tonic-gate goto out;
26227c478bd9Sstevel@tonic-gate }
26237c478bd9Sstevel@tonic-gate }
26247c478bd9Sstevel@tonic-gate }
26257c478bd9Sstevel@tonic-gate if ((off + contig) >= ip->i_size) {
26267c478bd9Sstevel@tonic-gate contig = ip->i_size - off;
26277c478bd9Sstevel@tonic-gate }
26287c478bd9Sstevel@tonic-gate
26297c478bd9Sstevel@tonic-gate out:
26307c478bd9Sstevel@tonic-gate *pg_off = contig;
26317c478bd9Sstevel@tonic-gate return (error);
26327c478bd9Sstevel@tonic-gate }
26337c478bd9Sstevel@tonic-gate
26347c478bd9Sstevel@tonic-gate int32_t
ud_putpages(struct vnode * vp,offset_t off,size_t len,int32_t flags,struct cred * cr)26357c478bd9Sstevel@tonic-gate ud_putpages(struct vnode *vp, offset_t off,
26367c478bd9Sstevel@tonic-gate size_t len, int32_t flags, struct cred *cr)
26377c478bd9Sstevel@tonic-gate {
26387c478bd9Sstevel@tonic-gate struct ud_inode *ip;
26397c478bd9Sstevel@tonic-gate page_t *pp;
26407c478bd9Sstevel@tonic-gate u_offset_t io_off;
26417c478bd9Sstevel@tonic-gate size_t io_len;
26427c478bd9Sstevel@tonic-gate u_offset_t eoff;
26437c478bd9Sstevel@tonic-gate int32_t err = 0;
26447c478bd9Sstevel@tonic-gate int32_t dolock;
26457c478bd9Sstevel@tonic-gate
26467c478bd9Sstevel@tonic-gate ud_printf("ud_putpages\n");
26477c478bd9Sstevel@tonic-gate
26487c478bd9Sstevel@tonic-gate if (vp->v_count == 0) {
26497c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "ud_putpages: bad v_count");
26507c478bd9Sstevel@tonic-gate return (EINVAL);
26517c478bd9Sstevel@tonic-gate }
26527c478bd9Sstevel@tonic-gate
26537c478bd9Sstevel@tonic-gate ip = VTOI(vp);
26547c478bd9Sstevel@tonic-gate
26557c478bd9Sstevel@tonic-gate /*
26567c478bd9Sstevel@tonic-gate * Acquire the readers/write inode lock before locking
26577c478bd9Sstevel@tonic-gate * any pages in this inode.
26587c478bd9Sstevel@tonic-gate * The inode lock is held during i/o.
26597c478bd9Sstevel@tonic-gate */
26607c478bd9Sstevel@tonic-gate if (len == 0) {
26617c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
26627c478bd9Sstevel@tonic-gate ip->i_delayoff = ip->i_delaylen = 0;
26637c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
26647c478bd9Sstevel@tonic-gate }
26657c478bd9Sstevel@tonic-gate #ifdef __lock_lint
26667c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
26677c478bd9Sstevel@tonic-gate #else
26687c478bd9Sstevel@tonic-gate dolock = (rw_owner(&ip->i_contents) != curthread);
26697c478bd9Sstevel@tonic-gate if (dolock) {
26707c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_READER);
26717c478bd9Sstevel@tonic-gate }
26727c478bd9Sstevel@tonic-gate #endif
26737c478bd9Sstevel@tonic-gate
26747c478bd9Sstevel@tonic-gate if (!vn_has_cached_data(vp)) {
26757c478bd9Sstevel@tonic-gate #ifdef __lock_lint
26767c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
26777c478bd9Sstevel@tonic-gate #else
26787c478bd9Sstevel@tonic-gate if (dolock) {
26797c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
26807c478bd9Sstevel@tonic-gate }
26817c478bd9Sstevel@tonic-gate #endif
26827c478bd9Sstevel@tonic-gate return (0);
26837c478bd9Sstevel@tonic-gate }
26847c478bd9Sstevel@tonic-gate
26857c478bd9Sstevel@tonic-gate if (len == 0) {
26867c478bd9Sstevel@tonic-gate /*
26877c478bd9Sstevel@tonic-gate * Search the entire vp list for pages >= off.
26887c478bd9Sstevel@tonic-gate */
26897c478bd9Sstevel@tonic-gate err = pvn_vplist_dirty(vp, (u_offset_t)off, ud_putapage,
26907c478bd9Sstevel@tonic-gate flags, cr);
26917c478bd9Sstevel@tonic-gate } else {
26927c478bd9Sstevel@tonic-gate /*
26937c478bd9Sstevel@tonic-gate * Loop over all offsets in the range looking for
26947c478bd9Sstevel@tonic-gate * pages to deal with.
26957c478bd9Sstevel@tonic-gate */
26967c478bd9Sstevel@tonic-gate if ((eoff = blkroundup(ip->i_udf, ip->i_size)) != 0) {
26977c478bd9Sstevel@tonic-gate eoff = MIN(off + len, eoff);
26987c478bd9Sstevel@tonic-gate } else {
26997c478bd9Sstevel@tonic-gate eoff = off + len;
27007c478bd9Sstevel@tonic-gate }
27017c478bd9Sstevel@tonic-gate
27027c478bd9Sstevel@tonic-gate for (io_off = off; io_off < eoff; io_off += io_len) {
27037c478bd9Sstevel@tonic-gate /*
27047c478bd9Sstevel@tonic-gate * If we are not invalidating, synchronously
27057c478bd9Sstevel@tonic-gate * freeing or writing pages, use the routine
27067c478bd9Sstevel@tonic-gate * page_lookup_nowait() to prevent reclaiming
27077c478bd9Sstevel@tonic-gate * them from the free list.
27087c478bd9Sstevel@tonic-gate */
27097c478bd9Sstevel@tonic-gate if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
27107c478bd9Sstevel@tonic-gate pp = page_lookup(vp, io_off,
27117c478bd9Sstevel@tonic-gate (flags & (B_INVAL | B_FREE)) ?
27127c478bd9Sstevel@tonic-gate SE_EXCL : SE_SHARED);
27137c478bd9Sstevel@tonic-gate } else {
27147c478bd9Sstevel@tonic-gate pp = page_lookup_nowait(vp, io_off,
27157c478bd9Sstevel@tonic-gate (flags & B_FREE) ? SE_EXCL : SE_SHARED);
27167c478bd9Sstevel@tonic-gate }
27177c478bd9Sstevel@tonic-gate
27187c478bd9Sstevel@tonic-gate if (pp == NULL || pvn_getdirty(pp, flags) == 0) {
27197c478bd9Sstevel@tonic-gate io_len = PAGESIZE;
27207c478bd9Sstevel@tonic-gate } else {
27217c478bd9Sstevel@tonic-gate
27227c478bd9Sstevel@tonic-gate err = ud_putapage(vp, pp,
27237c478bd9Sstevel@tonic-gate &io_off, &io_len, flags, cr);
27247c478bd9Sstevel@tonic-gate if (err != 0) {
27257c478bd9Sstevel@tonic-gate break;
27267c478bd9Sstevel@tonic-gate }
27277c478bd9Sstevel@tonic-gate /*
27287c478bd9Sstevel@tonic-gate * "io_off" and "io_len" are returned as
27297c478bd9Sstevel@tonic-gate * the range of pages we actually wrote.
27307c478bd9Sstevel@tonic-gate * This allows us to skip ahead more quickly
27317c478bd9Sstevel@tonic-gate * since several pages may've been dealt
27327c478bd9Sstevel@tonic-gate * with by this iteration of the loop.
27337c478bd9Sstevel@tonic-gate */
27347c478bd9Sstevel@tonic-gate }
27357c478bd9Sstevel@tonic-gate }
27367c478bd9Sstevel@tonic-gate }
27377c478bd9Sstevel@tonic-gate if (err == 0 && off == 0 && (len == 0 || len >= ip->i_size)) {
27387c478bd9Sstevel@tonic-gate /*
27397c478bd9Sstevel@tonic-gate * We have just sync'ed back all the pages on
27407c478bd9Sstevel@tonic-gate * the inode, turn off the IMODTIME flag.
27417c478bd9Sstevel@tonic-gate */
27427c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
27437c478bd9Sstevel@tonic-gate ip->i_flag &= ~IMODTIME;
27447c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
27457c478bd9Sstevel@tonic-gate }
27467c478bd9Sstevel@tonic-gate #ifdef __lock_lint
27477c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
27487c478bd9Sstevel@tonic-gate #else
27497c478bd9Sstevel@tonic-gate if (dolock) {
27507c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
27517c478bd9Sstevel@tonic-gate }
27527c478bd9Sstevel@tonic-gate #endif
27537c478bd9Sstevel@tonic-gate return (err);
27547c478bd9Sstevel@tonic-gate }
27557c478bd9Sstevel@tonic-gate
27567c478bd9Sstevel@tonic-gate /* ARGSUSED */
27577c478bd9Sstevel@tonic-gate int32_t
ud_putapage(struct vnode * vp,page_t * pp,u_offset_t * offp,size_t * lenp,int32_t flags,struct cred * cr)27587c478bd9Sstevel@tonic-gate ud_putapage(struct vnode *vp,
27597c478bd9Sstevel@tonic-gate page_t *pp, u_offset_t *offp,
27607c478bd9Sstevel@tonic-gate size_t *lenp, int32_t flags, struct cred *cr)
27617c478bd9Sstevel@tonic-gate {
27627c478bd9Sstevel@tonic-gate daddr_t bn;
27637c478bd9Sstevel@tonic-gate size_t io_len;
27647c478bd9Sstevel@tonic-gate struct ud_inode *ip;
27657c478bd9Sstevel@tonic-gate int32_t error = 0, contig, multi_io = 0;
27667c478bd9Sstevel@tonic-gate struct udf_vfs *udf_vfsp;
27677c478bd9Sstevel@tonic-gate u_offset_t off, io_off;
27687c478bd9Sstevel@tonic-gate caddr_t kaddr, caddr;
27697c478bd9Sstevel@tonic-gate struct buf *bp = NULL;
27707c478bd9Sstevel@tonic-gate int32_t lbmask;
27717c478bd9Sstevel@tonic-gate uint64_t isize;
2772ad9a7bd3SRichard Lowe uint16_t crc_len;
27737c478bd9Sstevel@tonic-gate struct file_entry *fe;
27747c478bd9Sstevel@tonic-gate
27757c478bd9Sstevel@tonic-gate ud_printf("ud_putapage\n");
27767c478bd9Sstevel@tonic-gate
27777c478bd9Sstevel@tonic-gate ip = VTOI(vp);
27787c478bd9Sstevel@tonic-gate ASSERT(ip);
27797c478bd9Sstevel@tonic-gate ASSERT(RW_LOCK_HELD(&ip->i_contents));
27807c478bd9Sstevel@tonic-gate lbmask = ip->i_udf->udf_lbmask;
27817c478bd9Sstevel@tonic-gate isize = (ip->i_size + lbmask) & (~lbmask);
27827c478bd9Sstevel@tonic-gate
27837c478bd9Sstevel@tonic-gate udf_vfsp = ip->i_udf;
27847c478bd9Sstevel@tonic-gate ASSERT(udf_vfsp->udf_flags & UDF_FL_RW);
27857c478bd9Sstevel@tonic-gate
27867c478bd9Sstevel@tonic-gate /*
27877c478bd9Sstevel@tonic-gate * If the modified time on the inode has not already been
27887c478bd9Sstevel@tonic-gate * set elsewhere (e.g. for write/setattr) we set the time now.
27897c478bd9Sstevel@tonic-gate * This gives us approximate modified times for mmap'ed files
27907c478bd9Sstevel@tonic-gate * which are modified via stores in the user address space.
27917c478bd9Sstevel@tonic-gate */
27927c478bd9Sstevel@tonic-gate if (((ip->i_flag & IMODTIME) == 0) || (flags & B_FORCE)) {
27937c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
27947c478bd9Sstevel@tonic-gate ip->i_flag |= IUPD;
27957c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(ip);
27967c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
27977c478bd9Sstevel@tonic-gate }
27987c478bd9Sstevel@tonic-gate
27997c478bd9Sstevel@tonic-gate
28007c478bd9Sstevel@tonic-gate /*
28017c478bd9Sstevel@tonic-gate * Align the request to a block boundry (for old file systems),
28027c478bd9Sstevel@tonic-gate * and go ask bmap() how contiguous things are for this file.
28037c478bd9Sstevel@tonic-gate */
28047c478bd9Sstevel@tonic-gate off = pp->p_offset & ~(offset_t)lbmask;
28057c478bd9Sstevel@tonic-gate /* block align it */
28067c478bd9Sstevel@tonic-gate
28077c478bd9Sstevel@tonic-gate
28087c478bd9Sstevel@tonic-gate if (ip->i_desc_type == ICB_FLAG_ONE_AD) {
28097c478bd9Sstevel@tonic-gate ASSERT(ip->i_size <= ip->i_max_emb);
28107c478bd9Sstevel@tonic-gate
28117c478bd9Sstevel@tonic-gate pp = pvn_write_kluster(vp, pp, &io_off,
28127c478bd9Sstevel@tonic-gate &io_len, off, PAGESIZE, flags);
28137c478bd9Sstevel@tonic-gate if (io_len == 0) {
28147c478bd9Sstevel@tonic-gate io_len = PAGESIZE;
28157c478bd9Sstevel@tonic-gate }
28167c478bd9Sstevel@tonic-gate
28177c478bd9Sstevel@tonic-gate bp = ud_bread(ip->i_dev,
28187c478bd9Sstevel@tonic-gate ip->i_icb_lbano << udf_vfsp->udf_l2d_shift,
28197c478bd9Sstevel@tonic-gate udf_vfsp->udf_lbsize);
28207c478bd9Sstevel@tonic-gate fe = (struct file_entry *)bp->b_un.b_addr;
28217c478bd9Sstevel@tonic-gate if ((bp->b_flags & B_ERROR) ||
28227c478bd9Sstevel@tonic-gate (ud_verify_tag_and_desc(&fe->fe_tag, UD_FILE_ENTRY,
28237c478bd9Sstevel@tonic-gate ip->i_icb_block,
28247c478bd9Sstevel@tonic-gate 1, udf_vfsp->udf_lbsize) != 0)) {
28257c478bd9Sstevel@tonic-gate if (pp != NULL)
28267c478bd9Sstevel@tonic-gate pvn_write_done(pp, B_ERROR | B_WRITE | flags);
28277c478bd9Sstevel@tonic-gate if (bp->b_flags & B_ERROR) {
28287c478bd9Sstevel@tonic-gate error = EIO;
28297c478bd9Sstevel@tonic-gate } else {
28307c478bd9Sstevel@tonic-gate error = EINVAL;
28317c478bd9Sstevel@tonic-gate }
28327c478bd9Sstevel@tonic-gate brelse(bp);
28337c478bd9Sstevel@tonic-gate return (error);
28347c478bd9Sstevel@tonic-gate }
28357c478bd9Sstevel@tonic-gate if ((bp->b_error == 0) &&
28367c478bd9Sstevel@tonic-gate (bp->b_resid == 0)) {
28377c478bd9Sstevel@tonic-gate
28387c478bd9Sstevel@tonic-gate caddr = bp->b_un.b_addr + ip->i_data_off;
28397c478bd9Sstevel@tonic-gate kaddr = (caddr_t)ppmapin(pp,
28407c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE, (caddr_t)-1);
28417c478bd9Sstevel@tonic-gate (void) kcopy(kaddr, caddr, ip->i_size);
28427c478bd9Sstevel@tonic-gate ppmapout(kaddr);
28437c478bd9Sstevel@tonic-gate }
2844ad9a7bd3SRichard Lowe crc_len = offsetof(struct file_entry, fe_spec) +
28457c478bd9Sstevel@tonic-gate SWAP_32(fe->fe_len_ear);
28467c478bd9Sstevel@tonic-gate crc_len += ip->i_size;
28477c478bd9Sstevel@tonic-gate ud_make_tag(ip->i_udf, &fe->fe_tag,
28487c478bd9Sstevel@tonic-gate UD_FILE_ENTRY, ip->i_icb_block, crc_len);
28497c478bd9Sstevel@tonic-gate
28507c478bd9Sstevel@tonic-gate bwrite(bp);
28517c478bd9Sstevel@tonic-gate
28527c478bd9Sstevel@tonic-gate if (flags & B_ASYNC) {
28537c478bd9Sstevel@tonic-gate pvn_write_done(pp, flags);
28547c478bd9Sstevel@tonic-gate }
28557c478bd9Sstevel@tonic-gate contig = ip->i_size;
28567c478bd9Sstevel@tonic-gate } else {
28577c478bd9Sstevel@tonic-gate
28587c478bd9Sstevel@tonic-gate if (error = ud_bmap_read(ip, off, &bn, &contig)) {
28597c478bd9Sstevel@tonic-gate goto out;
28607c478bd9Sstevel@tonic-gate }
28617c478bd9Sstevel@tonic-gate contig = MIN(contig, PAGESIZE);
28627c478bd9Sstevel@tonic-gate contig = (contig + lbmask) & (~lbmask);
28637c478bd9Sstevel@tonic-gate
28647c478bd9Sstevel@tonic-gate if (contig < PAGESIZE) {
28657c478bd9Sstevel@tonic-gate uint64_t count;
28667c478bd9Sstevel@tonic-gate
28677c478bd9Sstevel@tonic-gate count = isize - off;
28687c478bd9Sstevel@tonic-gate if (contig != count) {
28697c478bd9Sstevel@tonic-gate multi_io = 1;
28707c478bd9Sstevel@tonic-gate contig = (int32_t)(MIN(count, PAGESIZE));
28717c478bd9Sstevel@tonic-gate }
28727c478bd9Sstevel@tonic-gate }
28737c478bd9Sstevel@tonic-gate
28747c478bd9Sstevel@tonic-gate if ((off + contig) > isize) {
28757c478bd9Sstevel@tonic-gate contig = isize - off;
28767c478bd9Sstevel@tonic-gate }
28777c478bd9Sstevel@tonic-gate
28787c478bd9Sstevel@tonic-gate if (contig > PAGESIZE) {
28797c478bd9Sstevel@tonic-gate if (contig & PAGEOFFSET) {
28807c478bd9Sstevel@tonic-gate contig &= PAGEMASK;
28817c478bd9Sstevel@tonic-gate }
28827c478bd9Sstevel@tonic-gate }
28837c478bd9Sstevel@tonic-gate
28847c478bd9Sstevel@tonic-gate pp = pvn_write_kluster(vp, pp, &io_off,
28857c478bd9Sstevel@tonic-gate &io_len, off, contig, flags);
28867c478bd9Sstevel@tonic-gate if (io_len == 0) {
28877c478bd9Sstevel@tonic-gate io_len = PAGESIZE;
28887c478bd9Sstevel@tonic-gate }
28897c478bd9Sstevel@tonic-gate
28907c478bd9Sstevel@tonic-gate bp = pageio_setup(pp, contig, ip->i_devvp, B_WRITE | flags);
28917c478bd9Sstevel@tonic-gate ASSERT(bp != NULL);
28927c478bd9Sstevel@tonic-gate
28937c478bd9Sstevel@tonic-gate bp->b_edev = ip->i_dev;
28947c478bd9Sstevel@tonic-gate bp->b_dev = cmpdev(ip->i_dev);
28957c478bd9Sstevel@tonic-gate bp->b_blkno = bn;
28967c478bd9Sstevel@tonic-gate bp->b_un.b_addr = 0;
28977c478bd9Sstevel@tonic-gate bp->b_file = vp;
28987c478bd9Sstevel@tonic-gate bp->b_offset = (offset_t)off;
28997c478bd9Sstevel@tonic-gate
29007c478bd9Sstevel@tonic-gate
29017c478bd9Sstevel@tonic-gate /*
29027c478bd9Sstevel@tonic-gate * write throttle
29037c478bd9Sstevel@tonic-gate */
29047c478bd9Sstevel@tonic-gate ASSERT(bp->b_iodone == NULL);
29057c478bd9Sstevel@tonic-gate bp->b_iodone = ud_iodone;
29067c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
29077c478bd9Sstevel@tonic-gate ip->i_writes += bp->b_bcount;
29087c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
29097c478bd9Sstevel@tonic-gate
29107c478bd9Sstevel@tonic-gate if (multi_io == 0) {
29117c478bd9Sstevel@tonic-gate
29127c478bd9Sstevel@tonic-gate (void) bdev_strategy(bp);
29137c478bd9Sstevel@tonic-gate } else {
29147c478bd9Sstevel@tonic-gate error = ud_multi_strat(ip, pp, bp, off);
29157c478bd9Sstevel@tonic-gate if (error != 0) {
29167c478bd9Sstevel@tonic-gate goto out;
29177c478bd9Sstevel@tonic-gate }
29187c478bd9Sstevel@tonic-gate }
29197c478bd9Sstevel@tonic-gate
29207c478bd9Sstevel@tonic-gate if ((flags & B_ASYNC) == 0) {
29217c478bd9Sstevel@tonic-gate /*
29227c478bd9Sstevel@tonic-gate * Wait for i/o to complete.
29237c478bd9Sstevel@tonic-gate */
29247c478bd9Sstevel@tonic-gate error = biowait(bp);
29257c478bd9Sstevel@tonic-gate pageio_done(bp);
29267c478bd9Sstevel@tonic-gate }
29277c478bd9Sstevel@tonic-gate }
29287c478bd9Sstevel@tonic-gate
29297c478bd9Sstevel@tonic-gate if ((flags & B_ASYNC) == 0) {
29307c478bd9Sstevel@tonic-gate pvn_write_done(pp, ((error) ? B_ERROR : 0) | B_WRITE | flags);
29317c478bd9Sstevel@tonic-gate }
29327c478bd9Sstevel@tonic-gate
29337c478bd9Sstevel@tonic-gate pp = NULL;
29347c478bd9Sstevel@tonic-gate
29357c478bd9Sstevel@tonic-gate out:
29367c478bd9Sstevel@tonic-gate if (error != 0 && pp != NULL) {
29377c478bd9Sstevel@tonic-gate pvn_write_done(pp, B_ERROR | B_WRITE | flags);
29387c478bd9Sstevel@tonic-gate }
29397c478bd9Sstevel@tonic-gate
29407c478bd9Sstevel@tonic-gate if (offp) {
29417c478bd9Sstevel@tonic-gate *offp = io_off;
29427c478bd9Sstevel@tonic-gate }
29437c478bd9Sstevel@tonic-gate if (lenp) {
29447c478bd9Sstevel@tonic-gate *lenp = io_len;
29457c478bd9Sstevel@tonic-gate }
29467c478bd9Sstevel@tonic-gate
29477c478bd9Sstevel@tonic-gate return (error);
29487c478bd9Sstevel@tonic-gate }
29497c478bd9Sstevel@tonic-gate
29507c478bd9Sstevel@tonic-gate
29517c478bd9Sstevel@tonic-gate int32_t
ud_iodone(struct buf * bp)29527c478bd9Sstevel@tonic-gate ud_iodone(struct buf *bp)
29537c478bd9Sstevel@tonic-gate {
29547c478bd9Sstevel@tonic-gate struct ud_inode *ip;
29557c478bd9Sstevel@tonic-gate
29567c478bd9Sstevel@tonic-gate ASSERT((bp->b_pages->p_vnode != NULL) && !(bp->b_flags & B_READ));
29577c478bd9Sstevel@tonic-gate
29587c478bd9Sstevel@tonic-gate bp->b_iodone = NULL;
29597c478bd9Sstevel@tonic-gate
29607c478bd9Sstevel@tonic-gate ip = VTOI(bp->b_pages->p_vnode);
29617c478bd9Sstevel@tonic-gate
29627c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
29637c478bd9Sstevel@tonic-gate if (ip->i_writes >= ud_LW) {
29647c478bd9Sstevel@tonic-gate if ((ip->i_writes -= bp->b_bcount) <= ud_LW) {
29657c478bd9Sstevel@tonic-gate if (ud_WRITES) {
29667c478bd9Sstevel@tonic-gate cv_broadcast(&ip->i_wrcv); /* wake all up */
29677c478bd9Sstevel@tonic-gate }
29687c478bd9Sstevel@tonic-gate }
29697c478bd9Sstevel@tonic-gate } else {
29707c478bd9Sstevel@tonic-gate ip->i_writes -= bp->b_bcount;
29717c478bd9Sstevel@tonic-gate }
29727c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
29737c478bd9Sstevel@tonic-gate iodone(bp);
29747c478bd9Sstevel@tonic-gate return (0);
29757c478bd9Sstevel@tonic-gate }
29767c478bd9Sstevel@tonic-gate
29777c478bd9Sstevel@tonic-gate /* ARGSUSED3 */
29787c478bd9Sstevel@tonic-gate int32_t
ud_rdip(struct ud_inode * ip,struct uio * uio,int32_t ioflag,cred_t * cr)29797c478bd9Sstevel@tonic-gate ud_rdip(struct ud_inode *ip, struct uio *uio, int32_t ioflag, cred_t *cr)
29807c478bd9Sstevel@tonic-gate {
29817c478bd9Sstevel@tonic-gate struct vnode *vp;
29827c478bd9Sstevel@tonic-gate struct udf_vfs *udf_vfsp;
29837c478bd9Sstevel@tonic-gate krw_t rwtype;
29847c478bd9Sstevel@tonic-gate caddr_t base;
29857c478bd9Sstevel@tonic-gate uint32_t flags;
29867c478bd9Sstevel@tonic-gate int32_t error, n, on, mapon, dofree;
29877c478bd9Sstevel@tonic-gate u_offset_t off;
29887c478bd9Sstevel@tonic-gate long oresid = uio->uio_resid;
29897c478bd9Sstevel@tonic-gate
29907c478bd9Sstevel@tonic-gate ASSERT(RW_LOCK_HELD(&ip->i_contents));
29917c478bd9Sstevel@tonic-gate if ((ip->i_type != VREG) &&
29927c478bd9Sstevel@tonic-gate (ip->i_type != VDIR) &&
29937c478bd9Sstevel@tonic-gate (ip->i_type != VLNK)) {
29947c478bd9Sstevel@tonic-gate return (EIO);
29957c478bd9Sstevel@tonic-gate }
29967c478bd9Sstevel@tonic-gate
29977c478bd9Sstevel@tonic-gate if (uio->uio_loffset > MAXOFFSET_T) {
29987c478bd9Sstevel@tonic-gate return (0);
29997c478bd9Sstevel@tonic-gate }
30007c478bd9Sstevel@tonic-gate
30017c478bd9Sstevel@tonic-gate if ((uio->uio_loffset < (offset_t)0) ||
30027c478bd9Sstevel@tonic-gate ((uio->uio_loffset + uio->uio_resid) < 0)) {
30037c478bd9Sstevel@tonic-gate return (EINVAL);
30047c478bd9Sstevel@tonic-gate }
30057c478bd9Sstevel@tonic-gate if (uio->uio_resid == 0) {
30067c478bd9Sstevel@tonic-gate return (0);
30077c478bd9Sstevel@tonic-gate }
30087c478bd9Sstevel@tonic-gate
30097c478bd9Sstevel@tonic-gate vp = ITOV(ip);
30107c478bd9Sstevel@tonic-gate udf_vfsp = ip->i_udf;
30117c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
30127c478bd9Sstevel@tonic-gate ip->i_flag |= IACC;
30137c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
30147c478bd9Sstevel@tonic-gate
30157c478bd9Sstevel@tonic-gate rwtype = (rw_write_held(&ip->i_contents)?RW_WRITER:RW_READER);
30167c478bd9Sstevel@tonic-gate
30177c478bd9Sstevel@tonic-gate do {
30187c478bd9Sstevel@tonic-gate offset_t diff;
30197c478bd9Sstevel@tonic-gate u_offset_t uoff = uio->uio_loffset;
30207c478bd9Sstevel@tonic-gate off = uoff & (offset_t)MAXBMASK;
30217c478bd9Sstevel@tonic-gate mapon = (int)(uoff & (offset_t)MAXBOFFSET);
30227c478bd9Sstevel@tonic-gate on = (int)blkoff(udf_vfsp, uoff);
30237c478bd9Sstevel@tonic-gate n = (int)MIN(udf_vfsp->udf_lbsize - on, uio->uio_resid);
30247c478bd9Sstevel@tonic-gate
30257c478bd9Sstevel@tonic-gate diff = ip->i_size - uoff;
30267c478bd9Sstevel@tonic-gate
30277c478bd9Sstevel@tonic-gate if (diff <= (offset_t)0) {
30287c478bd9Sstevel@tonic-gate error = 0;
30297c478bd9Sstevel@tonic-gate goto out;
30307c478bd9Sstevel@tonic-gate }
30317c478bd9Sstevel@tonic-gate if (diff < (offset_t)n) {
30327c478bd9Sstevel@tonic-gate n = (int)diff;
30337c478bd9Sstevel@tonic-gate }
30347c478bd9Sstevel@tonic-gate dofree = ud_freebehind &&
30357c478bd9Sstevel@tonic-gate ip->i_nextr == (off & PAGEMASK) &&
30367c478bd9Sstevel@tonic-gate off > ud_smallfile;
30377c478bd9Sstevel@tonic-gate
30387c478bd9Sstevel@tonic-gate #ifndef __lock_lint
30397c478bd9Sstevel@tonic-gate if (rwtype == RW_READER) {
30407c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
30417c478bd9Sstevel@tonic-gate }
30427c478bd9Sstevel@tonic-gate #endif
30437c478bd9Sstevel@tonic-gate
30447c478bd9Sstevel@tonic-gate base = segmap_getmapflt(segkmap, vp, (off + mapon),
30457c478bd9Sstevel@tonic-gate (uint32_t)n, 1, S_READ);
30467c478bd9Sstevel@tonic-gate error = uiomove(base + mapon, (long)n, UIO_READ, uio);
30477c478bd9Sstevel@tonic-gate
30487c478bd9Sstevel@tonic-gate flags = 0;
30497c478bd9Sstevel@tonic-gate if (!error) {
30507c478bd9Sstevel@tonic-gate /*
30517c478bd9Sstevel@tonic-gate * If read a whole block, or read to eof,
30527c478bd9Sstevel@tonic-gate * won't need this buffer again soon.
30537c478bd9Sstevel@tonic-gate */
30547c478bd9Sstevel@tonic-gate if (n + on == MAXBSIZE && ud_freebehind && dofree &&
30557c478bd9Sstevel@tonic-gate freemem < lotsfree + pages_before_pager) {
30567c478bd9Sstevel@tonic-gate flags = SM_FREE | SM_DONTNEED |SM_ASYNC;
30577c478bd9Sstevel@tonic-gate }
30587c478bd9Sstevel@tonic-gate /*
30597c478bd9Sstevel@tonic-gate * In POSIX SYNC (FSYNC and FDSYNC) read mode,
30607c478bd9Sstevel@tonic-gate * we want to make sure that the page which has
30617c478bd9Sstevel@tonic-gate * been read, is written on disk if it is dirty.
30627c478bd9Sstevel@tonic-gate * And corresponding indirect blocks should also
30637c478bd9Sstevel@tonic-gate * be flushed out.
30647c478bd9Sstevel@tonic-gate */
30657c478bd9Sstevel@tonic-gate if ((ioflag & FRSYNC) && (ioflag & (FSYNC|FDSYNC))) {
30667c478bd9Sstevel@tonic-gate flags &= ~SM_ASYNC;
30677c478bd9Sstevel@tonic-gate flags |= SM_WRITE;
30687c478bd9Sstevel@tonic-gate }
30697c478bd9Sstevel@tonic-gate error = segmap_release(segkmap, base, flags);
30707c478bd9Sstevel@tonic-gate } else {
30717c478bd9Sstevel@tonic-gate (void) segmap_release(segkmap, base, flags);
30727c478bd9Sstevel@tonic-gate }
30737c478bd9Sstevel@tonic-gate
30747c478bd9Sstevel@tonic-gate #ifndef __lock_lint
30757c478bd9Sstevel@tonic-gate if (rwtype == RW_READER) {
30767c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, rwtype);
30777c478bd9Sstevel@tonic-gate }
30787c478bd9Sstevel@tonic-gate #endif
30797c478bd9Sstevel@tonic-gate } while (error == 0 && uio->uio_resid > 0 && n != 0);
30807c478bd9Sstevel@tonic-gate out:
30817c478bd9Sstevel@tonic-gate /*
30827c478bd9Sstevel@tonic-gate * Inode is updated according to this table if FRSYNC is set.
30837c478bd9Sstevel@tonic-gate *
30847c478bd9Sstevel@tonic-gate * FSYNC FDSYNC(posix.4)
30857c478bd9Sstevel@tonic-gate * --------------------------
30867c478bd9Sstevel@tonic-gate * always IATTCHG|IBDWRITE
30877c478bd9Sstevel@tonic-gate */
30887c478bd9Sstevel@tonic-gate if (ioflag & FRSYNC) {
30897c478bd9Sstevel@tonic-gate if ((ioflag & FSYNC) ||
30906f5f1c63SDonghai Qiao ((ioflag & FDSYNC) &&
30916f5f1c63SDonghai Qiao (ip->i_flag & (IATTCHG|IBDWRITE)))) {
30927c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
30937c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
30947c478bd9Sstevel@tonic-gate ud_iupdat(ip, 1);
30957c478bd9Sstevel@tonic-gate }
30967c478bd9Sstevel@tonic-gate }
30977c478bd9Sstevel@tonic-gate /*
30987c478bd9Sstevel@tonic-gate * If we've already done a partial read, terminate
30997c478bd9Sstevel@tonic-gate * the read but return no error.
31007c478bd9Sstevel@tonic-gate */
31017c478bd9Sstevel@tonic-gate if (oresid != uio->uio_resid) {
31027c478bd9Sstevel@tonic-gate error = 0;
31037c478bd9Sstevel@tonic-gate }
31047c478bd9Sstevel@tonic-gate ITIMES(ip);
31057c478bd9Sstevel@tonic-gate
31067c478bd9Sstevel@tonic-gate return (error);
31077c478bd9Sstevel@tonic-gate }
31087c478bd9Sstevel@tonic-gate
31097c478bd9Sstevel@tonic-gate int32_t
ud_wrip(struct ud_inode * ip,struct uio * uio,int ioflag,struct cred * cr)31107c478bd9Sstevel@tonic-gate ud_wrip(struct ud_inode *ip, struct uio *uio, int ioflag, struct cred *cr)
31117c478bd9Sstevel@tonic-gate {
31127c478bd9Sstevel@tonic-gate caddr_t base;
31137c478bd9Sstevel@tonic-gate struct vnode *vp;
31147c478bd9Sstevel@tonic-gate struct udf_vfs *udf_vfsp;
31157c478bd9Sstevel@tonic-gate uint32_t flags;
31167c478bd9Sstevel@tonic-gate int32_t error = 0, iupdat_flag, n, on, mapon, i_size_changed = 0;
31177c478bd9Sstevel@tonic-gate int32_t pagecreate, newpage;
31187c478bd9Sstevel@tonic-gate uint64_t old_i_size;
31197c478bd9Sstevel@tonic-gate u_offset_t off;
31207c478bd9Sstevel@tonic-gate long start_resid = uio->uio_resid, premove_resid;
31217c478bd9Sstevel@tonic-gate rlim64_t limit = uio->uio_limit;
31227c478bd9Sstevel@tonic-gate
31237c478bd9Sstevel@tonic-gate
31247c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&ip->i_contents));
31257c478bd9Sstevel@tonic-gate if ((ip->i_type != VREG) &&
31267c478bd9Sstevel@tonic-gate (ip->i_type != VDIR) &&
31277c478bd9Sstevel@tonic-gate (ip->i_type != VLNK)) {
31287c478bd9Sstevel@tonic-gate return (EIO);
31297c478bd9Sstevel@tonic-gate }
31307c478bd9Sstevel@tonic-gate
31317c478bd9Sstevel@tonic-gate if (uio->uio_loffset >= MAXOFFSET_T) {
31327c478bd9Sstevel@tonic-gate return (EFBIG);
31337c478bd9Sstevel@tonic-gate }
31347c478bd9Sstevel@tonic-gate /*
31357c478bd9Sstevel@tonic-gate * see udf_l_pathconf
31367c478bd9Sstevel@tonic-gate */
31377c478bd9Sstevel@tonic-gate if (limit > (((uint64_t)1 << 40) - 1)) {
31387c478bd9Sstevel@tonic-gate limit = ((uint64_t)1 << 40) - 1;
31397c478bd9Sstevel@tonic-gate }
31407c478bd9Sstevel@tonic-gate if (uio->uio_loffset >= limit) {
31417c478bd9Sstevel@tonic-gate proc_t *p = ttoproc(curthread);
31427c478bd9Sstevel@tonic-gate
31437c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock);
31447c478bd9Sstevel@tonic-gate (void) rctl_action(rctlproc_legacy[RLIMIT_FSIZE], p->p_rctls,
31457c478bd9Sstevel@tonic-gate p, RCA_UNSAFE_SIGINFO);
31467c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock);
31477c478bd9Sstevel@tonic-gate return (EFBIG);
31487c478bd9Sstevel@tonic-gate }
31497c478bd9Sstevel@tonic-gate if ((uio->uio_loffset < (offset_t)0) ||
31507c478bd9Sstevel@tonic-gate ((uio->uio_loffset + uio->uio_resid) < 0)) {
31517c478bd9Sstevel@tonic-gate return (EINVAL);
31527c478bd9Sstevel@tonic-gate }
31537c478bd9Sstevel@tonic-gate if (uio->uio_resid == 0) {
31547c478bd9Sstevel@tonic-gate return (0);
31557c478bd9Sstevel@tonic-gate }
31567c478bd9Sstevel@tonic-gate
31577c478bd9Sstevel@tonic-gate mutex_enter(&ip->i_tlock);
31587c478bd9Sstevel@tonic-gate ip->i_flag |= INOACC;
31597c478bd9Sstevel@tonic-gate
31607c478bd9Sstevel@tonic-gate if (ioflag & (FSYNC | FDSYNC)) {
31617c478bd9Sstevel@tonic-gate ip->i_flag |= ISYNC;
31627c478bd9Sstevel@tonic-gate iupdat_flag = 1;
31637c478bd9Sstevel@tonic-gate }
31647c478bd9Sstevel@tonic-gate mutex_exit(&ip->i_tlock);
31657c478bd9Sstevel@tonic-gate
31667c478bd9Sstevel@tonic-gate udf_vfsp = ip->i_udf;
31677c478bd9Sstevel@tonic-gate vp = ITOV(ip);
31687c478bd9Sstevel@tonic-gate
31697c478bd9Sstevel@tonic-gate do {
31707c478bd9Sstevel@tonic-gate u_offset_t uoff = uio->uio_loffset;
31717c478bd9Sstevel@tonic-gate off = uoff & (offset_t)MAXBMASK;
31727c478bd9Sstevel@tonic-gate mapon = (int)(uoff & (offset_t)MAXBOFFSET);
31737c478bd9Sstevel@tonic-gate on = (int)blkoff(udf_vfsp, uoff);
31747c478bd9Sstevel@tonic-gate n = (int)MIN(udf_vfsp->udf_lbsize - on, uio->uio_resid);
31757c478bd9Sstevel@tonic-gate
31767c478bd9Sstevel@tonic-gate if (ip->i_type == VREG && uoff + n >= limit) {
31777c478bd9Sstevel@tonic-gate if (uoff >= limit) {
31787c478bd9Sstevel@tonic-gate error = EFBIG;
31797c478bd9Sstevel@tonic-gate goto out;
31807c478bd9Sstevel@tonic-gate }
31817c478bd9Sstevel@tonic-gate n = (int)(limit - (rlim64_t)uoff);
31827c478bd9Sstevel@tonic-gate }
31837c478bd9Sstevel@tonic-gate if (uoff + n > ip->i_size) {
31847c478bd9Sstevel@tonic-gate /*
31857c478bd9Sstevel@tonic-gate * We are extending the length of the file.
31867c478bd9Sstevel@tonic-gate * bmap is used so that we are sure that
31877c478bd9Sstevel@tonic-gate * if we need to allocate new blocks, that it
31887c478bd9Sstevel@tonic-gate * is done here before we up the file size.
31897c478bd9Sstevel@tonic-gate */
31907c478bd9Sstevel@tonic-gate error = ud_bmap_write(ip, uoff,
31917c478bd9Sstevel@tonic-gate (int)(on + n), mapon == 0, cr);
31927c478bd9Sstevel@tonic-gate if (error) {
31937c478bd9Sstevel@tonic-gate break;
31947c478bd9Sstevel@tonic-gate }
31957c478bd9Sstevel@tonic-gate i_size_changed = 1;
31967c478bd9Sstevel@tonic-gate old_i_size = ip->i_size;
31977c478bd9Sstevel@tonic-gate ip->i_size = uoff + n;
31987c478bd9Sstevel@tonic-gate /*
31997c478bd9Sstevel@tonic-gate * If we are writing from the beginning of
32007c478bd9Sstevel@tonic-gate * the mapping, we can just create the
32017c478bd9Sstevel@tonic-gate * pages without having to read them.
32027c478bd9Sstevel@tonic-gate */
32037c478bd9Sstevel@tonic-gate pagecreate = (mapon == 0);
32047c478bd9Sstevel@tonic-gate } else if (n == MAXBSIZE) {
32057c478bd9Sstevel@tonic-gate /*
32067c478bd9Sstevel@tonic-gate * Going to do a whole mappings worth,
32077c478bd9Sstevel@tonic-gate * so we can just create the pages w/o
32087c478bd9Sstevel@tonic-gate * having to read them in. But before
32097c478bd9Sstevel@tonic-gate * we do that, we need to make sure any
32107c478bd9Sstevel@tonic-gate * needed blocks are allocated first.
32117c478bd9Sstevel@tonic-gate */
32127c478bd9Sstevel@tonic-gate error = ud_bmap_write(ip, uoff,
32137c478bd9Sstevel@tonic-gate (int)(on + n), 1, cr);
32147c478bd9Sstevel@tonic-gate if (error) {
32157c478bd9Sstevel@tonic-gate break;
32167c478bd9Sstevel@tonic-gate }
32177c478bd9Sstevel@tonic-gate pagecreate = 1;
32187c478bd9Sstevel@tonic-gate } else {
32197c478bd9Sstevel@tonic-gate pagecreate = 0;
32207c478bd9Sstevel@tonic-gate }
32217c478bd9Sstevel@tonic-gate
32227c478bd9Sstevel@tonic-gate rw_exit(&ip->i_contents);
32237c478bd9Sstevel@tonic-gate
32246f5f1c63SDonghai Qiao /*
32256f5f1c63SDonghai Qiao * Touch the page and fault it in if it is not in
32266f5f1c63SDonghai Qiao * core before segmap_getmapflt can lock it. This
32276f5f1c63SDonghai Qiao * is to avoid the deadlock if the buffer is mapped
32286f5f1c63SDonghai Qiao * to the same file through mmap which we want to
32296f5f1c63SDonghai Qiao * write to.
32306f5f1c63SDonghai Qiao */
32316f5f1c63SDonghai Qiao uio_prefaultpages((long)n, uio);
32326f5f1c63SDonghai Qiao
32337c478bd9Sstevel@tonic-gate base = segmap_getmapflt(segkmap, vp, (off + mapon),
32347c478bd9Sstevel@tonic-gate (uint32_t)n, !pagecreate, S_WRITE);
32357c478bd9Sstevel@tonic-gate
32367c478bd9Sstevel@tonic-gate /*
32377c478bd9Sstevel@tonic-gate * segmap_pagecreate() returns 1 if it calls
32387c478bd9Sstevel@tonic-gate * page_create_va() to allocate any pages.
32397c478bd9Sstevel@tonic-gate */
32407c478bd9Sstevel@tonic-gate newpage = 0;
32417c478bd9Sstevel@tonic-gate if (pagecreate) {
32427c478bd9Sstevel@tonic-gate newpage = segmap_pagecreate(segkmap, base,
32437c478bd9Sstevel@tonic-gate (size_t)n, 0);
32447c478bd9Sstevel@tonic-gate }
32457c478bd9Sstevel@tonic-gate
32467c478bd9Sstevel@tonic-gate premove_resid = uio->uio_resid;
32477c478bd9Sstevel@tonic-gate error = uiomove(base + mapon, (long)n, UIO_WRITE, uio);
32487c478bd9Sstevel@tonic-gate
32497c478bd9Sstevel@tonic-gate if (pagecreate &&
32507c478bd9Sstevel@tonic-gate uio->uio_loffset < roundup(off + mapon + n, PAGESIZE)) {
32517c478bd9Sstevel@tonic-gate /*
32527c478bd9Sstevel@tonic-gate * We created pages w/o initializing them completely,
32537c478bd9Sstevel@tonic-gate * thus we need to zero the part that wasn't set up.
32547c478bd9Sstevel@tonic-gate * This happens on most EOF write cases and if
32557c478bd9Sstevel@tonic-gate * we had some sort of error during the uiomove.
32567c478bd9Sstevel@tonic-gate */
32577c478bd9Sstevel@tonic-gate int nzero, nmoved;
32587c478bd9Sstevel@tonic-gate
32597c478bd9Sstevel@tonic-gate nmoved = (int)(uio->uio_loffset - (off + mapon));
32607c478bd9Sstevel@tonic-gate ASSERT(nmoved >= 0 && nmoved <= n);
32617c478bd9Sstevel@tonic-gate nzero = roundup(on + n, PAGESIZE) - nmoved;
32627c478bd9Sstevel@tonic-gate ASSERT(nzero > 0 && mapon + nmoved + nzero <= MAXBSIZE);
32637c478bd9Sstevel@tonic-gate (void) kzero(base + mapon + nmoved, (uint32_t)nzero);
32647c478bd9Sstevel@tonic-gate }
32657c478bd9Sstevel@tonic-gate
32667c478bd9Sstevel@tonic-gate /*
32677c478bd9Sstevel@tonic-gate * Unlock the pages allocated by page_create_va()
32687c478bd9Sstevel@tonic-gate * in segmap_pagecreate()
32697c478bd9Sstevel@tonic-gate */
32707c478bd9Sstevel@tonic-gate if (newpage) {
32717c478bd9Sstevel@tonic-gate segmap_pageunlock(segkmap, base, (size_t)n, S_WRITE);
32727c478bd9Sstevel@tonic-gate }
32737c478bd9Sstevel@tonic-gate
32747c478bd9Sstevel@tonic-gate if (error) {
32757c478bd9Sstevel@tonic-gate /*
32767c478bd9Sstevel@tonic-gate * If we failed on a write, we may have already
32777c478bd9Sstevel@tonic-gate * allocated file blocks as well as pages. It's
32787c478bd9Sstevel@tonic-gate * hard to undo the block allocation, but we must
32797c478bd9Sstevel@tonic-gate * be sure to invalidate any pages that may have
32807c478bd9Sstevel@tonic-gate * been allocated.
32817c478bd9Sstevel@tonic-gate */
32827c478bd9Sstevel@tonic-gate (void) segmap_release(segkmap, base, SM_INVAL);
32837c478bd9Sstevel@tonic-gate } else {
32847c478bd9Sstevel@tonic-gate flags = 0;
32857c478bd9Sstevel@tonic-gate /*
32867c478bd9Sstevel@tonic-gate * Force write back for synchronous write cases.
32877c478bd9Sstevel@tonic-gate */
32887c478bd9Sstevel@tonic-gate if ((ioflag & (FSYNC|FDSYNC)) || ip->i_type == VDIR) {
32897c478bd9Sstevel@tonic-gate /*
32907c478bd9Sstevel@tonic-gate * If the sticky bit is set but the
32917c478bd9Sstevel@tonic-gate * execute bit is not set, we do a
32927c478bd9Sstevel@tonic-gate * synchronous write back and free
32937c478bd9Sstevel@tonic-gate * the page when done. We set up swap
32947c478bd9Sstevel@tonic-gate * files to be handled this way to
32957c478bd9Sstevel@tonic-gate * prevent servers from keeping around
32967c478bd9Sstevel@tonic-gate * the client's swap pages too long.
32977c478bd9Sstevel@tonic-gate * XXX - there ought to be a better way.
32987c478bd9Sstevel@tonic-gate */
32997c478bd9Sstevel@tonic-gate if (IS_SWAPVP(vp)) {
33007c478bd9Sstevel@tonic-gate flags = SM_WRITE | SM_FREE |
33017c478bd9Sstevel@tonic-gate SM_DONTNEED;
33027c478bd9Sstevel@tonic-gate iupdat_flag = 0;
33037c478bd9Sstevel@tonic-gate } else {
33047c478bd9Sstevel@tonic-gate flags = SM_WRITE;
33057c478bd9Sstevel@tonic-gate }
33067c478bd9Sstevel@tonic-gate } else if (((mapon + n) == MAXBSIZE) ||
33077c478bd9Sstevel@tonic-gate IS_SWAPVP(vp)) {
33087c478bd9Sstevel@tonic-gate /*
33097c478bd9Sstevel@tonic-gate * Have written a whole block.
33107c478bd9Sstevel@tonic-gate * Start an asynchronous write and
33117c478bd9Sstevel@tonic-gate * mark the buffer to indicate that
33127c478bd9Sstevel@tonic-gate * it won't be needed again soon.
33137c478bd9Sstevel@tonic-gate */
33147c478bd9Sstevel@tonic-gate flags = SM_WRITE |SM_ASYNC | SM_DONTNEED;
33157c478bd9Sstevel@tonic-gate }
33167c478bd9Sstevel@tonic-gate error = segmap_release(segkmap, base, flags);
33177c478bd9Sstevel@tonic-gate
33187c478bd9Sstevel@tonic-gate /*
33197c478bd9Sstevel@tonic-gate * If the operation failed and is synchronous,
33207c478bd9Sstevel@tonic-gate * then we need to unwind what uiomove() last
33217c478bd9Sstevel@tonic-gate * did so we can potentially return an error to
33227c478bd9Sstevel@tonic-gate * the caller. If this write operation was
33237c478bd9Sstevel@tonic-gate * done in two pieces and the first succeeded,
33247c478bd9Sstevel@tonic-gate * then we won't return an error for the second
33257c478bd9Sstevel@tonic-gate * piece that failed. However, we only want to
33267c478bd9Sstevel@tonic-gate * return a resid value that reflects what was
33277c478bd9Sstevel@tonic-gate * really done.
33287c478bd9Sstevel@tonic-gate *
33297c478bd9Sstevel@tonic-gate * Failures for non-synchronous operations can
33307c478bd9Sstevel@tonic-gate * be ignored since the page subsystem will
33317c478bd9Sstevel@tonic-gate * retry the operation until it succeeds or the
33327c478bd9Sstevel@tonic-gate * file system is unmounted.
33337c478bd9Sstevel@tonic-gate */
33347c478bd9Sstevel@tonic-gate if (error) {
33357c478bd9Sstevel@tonic-gate if ((ioflag & (FSYNC | FDSYNC)) ||
33367c478bd9Sstevel@tonic-gate ip->i_type == VDIR) {
33377c478bd9Sstevel@tonic-gate uio->uio_resid = premove_resid;
33387c478bd9Sstevel@tonic-gate } else {
33397c478bd9Sstevel@tonic-gate error = 0;
33407c478bd9Sstevel@tonic-gate }
33417c478bd9Sstevel@tonic-gate }
33427c478bd9Sstevel@tonic-gate }
33437c478bd9Sstevel@tonic-gate
33447c478bd9Sstevel@tonic-gate /*
33457c478bd9Sstevel@tonic-gate * Re-acquire contents lock.
33467c478bd9Sstevel@tonic-gate */
33477c478bd9Sstevel@tonic-gate rw_enter(&ip->i_contents, RW_WRITER);
33487c478bd9Sstevel@tonic-gate /*
33497c478bd9Sstevel@tonic-gate * If the uiomove() failed or if a synchronous
33507c478bd9Sstevel@tonic-gate * page push failed, fix up i_size.
33517c478bd9Sstevel@tonic-gate */
33527c478bd9Sstevel@tonic-gate if (error) {
33537c478bd9Sstevel@tonic-gate if (i_size_changed) {
33547c478bd9Sstevel@tonic-gate /*
33557c478bd9Sstevel@tonic-gate * The uiomove failed, and we
33567c478bd9Sstevel@tonic-gate * allocated blocks,so get rid
33577c478bd9Sstevel@tonic-gate * of them.
33587c478bd9Sstevel@tonic-gate */
33597c478bd9Sstevel@tonic-gate (void) ud_itrunc(ip, old_i_size, 0, cr);
33607c478bd9Sstevel@tonic-gate }
33617c478bd9Sstevel@tonic-gate } else {
33627c478bd9Sstevel@tonic-gate /*
33637c478bd9Sstevel@tonic-gate * XXX - Can this be out of the loop?
33647c478bd9Sstevel@tonic-gate */
33657c478bd9Sstevel@tonic-gate ip->i_flag |= IUPD | ICHG;
33667c478bd9Sstevel@tonic-gate if (i_size_changed) {
33677c478bd9Sstevel@tonic-gate ip->i_flag |= IATTCHG;
33687c478bd9Sstevel@tonic-gate }
33697c478bd9Sstevel@tonic-gate if ((ip->i_perm & (IEXEC | (IEXEC >> 5) |
33707c478bd9Sstevel@tonic-gate (IEXEC >> 10))) != 0 &&
33717c478bd9Sstevel@tonic-gate (ip->i_char & (ISUID | ISGID)) != 0 &&
33727c478bd9Sstevel@tonic-gate secpolicy_vnode_setid_retain(cr,
33737c478bd9Sstevel@tonic-gate (ip->i_char & ISUID) != 0 && ip->i_uid == 0) != 0) {
33747c478bd9Sstevel@tonic-gate /*
33757c478bd9Sstevel@tonic-gate * Clear Set-UID & Set-GID bits on
33767c478bd9Sstevel@tonic-gate * successful write if not privileged
33777c478bd9Sstevel@tonic-gate * and at least one of the execute bits
33787c478bd9Sstevel@tonic-gate * is set. If we always clear Set-GID,
33797c478bd9Sstevel@tonic-gate * mandatory file and record locking is
33807c478bd9Sstevel@tonic-gate * unuseable.
33817c478bd9Sstevel@tonic-gate */
33827c478bd9Sstevel@tonic-gate ip->i_char &= ~(ISUID | ISGID);
33837c478bd9Sstevel@tonic-gate }
33847c478bd9Sstevel@tonic-gate }
33857c478bd9Sstevel@tonic-gate } while (error == 0 && uio->uio_resid > 0 && n != 0);
33867c478bd9Sstevel@tonic-gate
33877c478bd9Sstevel@tonic-gate out:
33887c478bd9Sstevel@tonic-gate /*
33897c478bd9Sstevel@tonic-gate * Inode is updated according to this table -
33907c478bd9Sstevel@tonic-gate *
33917c478bd9Sstevel@tonic-gate * FSYNC FDSYNC(posix.4)
33927c478bd9Sstevel@tonic-gate * --------------------------
33937c478bd9Sstevel@tonic-gate * always@ IATTCHG|IBDWRITE
33947c478bd9Sstevel@tonic-gate *
33957c478bd9Sstevel@tonic-gate * @ - If we are doing synchronous write the only time we should
33967c478bd9Sstevel@tonic-gate * not be sync'ing the ip here is if we have the stickyhack
33977c478bd9Sstevel@tonic-gate * activated, the file is marked with the sticky bit and
33987c478bd9Sstevel@tonic-gate * no exec bit, the file length has not been changed and
33997c478bd9Sstevel@tonic-gate * no new blocks have been allocated during this write.
34007c478bd9Sstevel@tonic-gate */
34017c478bd9Sstevel@tonic-gate if ((ip->i_flag & ISYNC) != 0) {
34027c478bd9Sstevel@tonic-gate /*
34037c478bd9Sstevel@tonic-gate * we have eliminated nosync
34047c478bd9Sstevel@tonic-gate */
34057c478bd9Sstevel@tonic-gate if ((ip->i_flag & (IATTCHG|IBDWRITE)) ||
34067c478bd9Sstevel@tonic-gate ((ioflag & FSYNC) && iupdat_flag)) {
34077c478bd9Sstevel@tonic-gate ud_iupdat(ip, 1);
34087c478bd9Sstevel@tonic-gate }
34097c478bd9Sstevel@tonic-gate }
34107c478bd9Sstevel@tonic-gate
34117c478bd9Sstevel@tonic-gate /*
34127c478bd9Sstevel@tonic-gate * If we've already done a partial-write, terminate
34137c478bd9Sstevel@tonic-gate * the write but return no error.
34147c478bd9Sstevel@tonic-gate */
34157c478bd9Sstevel@tonic-gate if (start_resid != uio->uio_resid) {
34167c478bd9Sstevel@tonic-gate error = 0;
34177c478bd9Sstevel@tonic-gate }
34187c478bd9Sstevel@tonic-gate ip->i_flag &= ~(INOACC | ISYNC);
34197c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(ip);
34207c478bd9Sstevel@tonic-gate
34217c478bd9Sstevel@tonic-gate return (error);
34227c478bd9Sstevel@tonic-gate }
34237c478bd9Sstevel@tonic-gate
34247c478bd9Sstevel@tonic-gate int32_t
ud_multi_strat(struct ud_inode * ip,page_t * pp,struct buf * bp,u_offset_t start)34257c478bd9Sstevel@tonic-gate ud_multi_strat(struct ud_inode *ip,
34267c478bd9Sstevel@tonic-gate page_t *pp, struct buf *bp, u_offset_t start)
34277c478bd9Sstevel@tonic-gate {
34287c478bd9Sstevel@tonic-gate daddr_t bn;
34297c478bd9Sstevel@tonic-gate int32_t error = 0, io_count, contig, alloc_sz, i;
34307c478bd9Sstevel@tonic-gate uint32_t io_off;
34317c478bd9Sstevel@tonic-gate mio_master_t *mm = NULL;
34327c478bd9Sstevel@tonic-gate mio_slave_t *ms = NULL;
34337c478bd9Sstevel@tonic-gate struct buf *rbp;
34347c478bd9Sstevel@tonic-gate
34357c478bd9Sstevel@tonic-gate ASSERT(!(start & PAGEOFFSET));
34367c478bd9Sstevel@tonic-gate
34377c478bd9Sstevel@tonic-gate /*
34387c478bd9Sstevel@tonic-gate * Figure out how many buffers to allocate
34397c478bd9Sstevel@tonic-gate */
34407c478bd9Sstevel@tonic-gate io_count = 0;
34417c478bd9Sstevel@tonic-gate for (io_off = 0; io_off < bp->b_bcount; io_off += contig) {
34427c478bd9Sstevel@tonic-gate contig = 0;
34437c478bd9Sstevel@tonic-gate if (error = ud_bmap_read(ip, (u_offset_t)(start + io_off),
34447c478bd9Sstevel@tonic-gate &bn, &contig)) {
34457c478bd9Sstevel@tonic-gate goto end;
34467c478bd9Sstevel@tonic-gate }
34477c478bd9Sstevel@tonic-gate if (contig == 0) {
34487c478bd9Sstevel@tonic-gate goto end;
34497c478bd9Sstevel@tonic-gate }
34507c478bd9Sstevel@tonic-gate contig = MIN(contig, PAGESIZE - io_off);
34517c478bd9Sstevel@tonic-gate if (bn != UDF_HOLE) {
34527c478bd9Sstevel@tonic-gate io_count ++;
34537c478bd9Sstevel@tonic-gate } else {
34547c478bd9Sstevel@tonic-gate /*
34557c478bd9Sstevel@tonic-gate * HOLE
34567c478bd9Sstevel@tonic-gate */
34577c478bd9Sstevel@tonic-gate if (bp->b_flags & B_READ) {
34587c478bd9Sstevel@tonic-gate
34597c478bd9Sstevel@tonic-gate /*
34607c478bd9Sstevel@tonic-gate * This is a hole and is read
34617c478bd9Sstevel@tonic-gate * it should be filled with 0's
34627c478bd9Sstevel@tonic-gate */
34637c478bd9Sstevel@tonic-gate pagezero(pp, io_off, contig);
34647c478bd9Sstevel@tonic-gate }
34657c478bd9Sstevel@tonic-gate }
34667c478bd9Sstevel@tonic-gate }
34677c478bd9Sstevel@tonic-gate
34687c478bd9Sstevel@tonic-gate
34697c478bd9Sstevel@tonic-gate if (io_count != 0) {
34707c478bd9Sstevel@tonic-gate
34717c478bd9Sstevel@tonic-gate /*
34727c478bd9Sstevel@tonic-gate * Allocate memory for all the
34737c478bd9Sstevel@tonic-gate * required number of buffers
34747c478bd9Sstevel@tonic-gate */
34757c478bd9Sstevel@tonic-gate alloc_sz = sizeof (mio_master_t) +
34767c478bd9Sstevel@tonic-gate (sizeof (mio_slave_t) * io_count);
34777c478bd9Sstevel@tonic-gate mm = (mio_master_t *)kmem_zalloc(alloc_sz, KM_SLEEP);
34787c478bd9Sstevel@tonic-gate if (mm == NULL) {
34797c478bd9Sstevel@tonic-gate error = ENOMEM;
34807c478bd9Sstevel@tonic-gate goto end;
34817c478bd9Sstevel@tonic-gate }
34827c478bd9Sstevel@tonic-gate
34837c478bd9Sstevel@tonic-gate /*
34847c478bd9Sstevel@tonic-gate * initialize master
34857c478bd9Sstevel@tonic-gate */
34867c478bd9Sstevel@tonic-gate mutex_init(&mm->mm_mutex, NULL, MUTEX_DEFAULT, NULL);
34877c478bd9Sstevel@tonic-gate mm->mm_size = alloc_sz;
34887c478bd9Sstevel@tonic-gate mm->mm_bp = bp;
34897c478bd9Sstevel@tonic-gate mm->mm_resid = 0;
34907c478bd9Sstevel@tonic-gate mm->mm_error = 0;
34917c478bd9Sstevel@tonic-gate mm->mm_index = master_index++;
34927c478bd9Sstevel@tonic-gate
34937c478bd9Sstevel@tonic-gate ms = (mio_slave_t *)(((caddr_t)mm) + sizeof (mio_master_t));
34947c478bd9Sstevel@tonic-gate
34957c478bd9Sstevel@tonic-gate /*
34967c478bd9Sstevel@tonic-gate * Initialize buffers
34977c478bd9Sstevel@tonic-gate */
34987c478bd9Sstevel@tonic-gate io_count = 0;
34997c478bd9Sstevel@tonic-gate for (io_off = 0; io_off < bp->b_bcount; io_off += contig) {
35007c478bd9Sstevel@tonic-gate contig = 0;
35017c478bd9Sstevel@tonic-gate if (error = ud_bmap_read(ip,
35027c478bd9Sstevel@tonic-gate (u_offset_t)(start + io_off),
35037c478bd9Sstevel@tonic-gate &bn, &contig)) {
35047c478bd9Sstevel@tonic-gate goto end;
35057c478bd9Sstevel@tonic-gate }
35067c478bd9Sstevel@tonic-gate ASSERT(contig);
35077c478bd9Sstevel@tonic-gate if ((io_off + contig) > bp->b_bcount) {
35087c478bd9Sstevel@tonic-gate contig = bp->b_bcount - io_off;
35097c478bd9Sstevel@tonic-gate }
35107c478bd9Sstevel@tonic-gate if (bn != UDF_HOLE) {
35117c478bd9Sstevel@tonic-gate /*
35127c478bd9Sstevel@tonic-gate * Clone the buffer
35137c478bd9Sstevel@tonic-gate * and prepare to start I/O
35147c478bd9Sstevel@tonic-gate */
35157c478bd9Sstevel@tonic-gate ms->ms_ptr = mm;
35167c478bd9Sstevel@tonic-gate bioinit(&ms->ms_buf);
35177c478bd9Sstevel@tonic-gate rbp = bioclone(bp, io_off, (size_t)contig,
35187c478bd9Sstevel@tonic-gate bp->b_edev, bn, ud_slave_done,
35197c478bd9Sstevel@tonic-gate &ms->ms_buf, KM_NOSLEEP);
35207c478bd9Sstevel@tonic-gate ASSERT(rbp == &ms->ms_buf);
35217c478bd9Sstevel@tonic-gate mm->mm_resid += contig;
35227c478bd9Sstevel@tonic-gate io_count++;
35237c478bd9Sstevel@tonic-gate ms ++;
35247c478bd9Sstevel@tonic-gate }
35257c478bd9Sstevel@tonic-gate }
35267c478bd9Sstevel@tonic-gate
35277c478bd9Sstevel@tonic-gate /*
35287c478bd9Sstevel@tonic-gate * Start I/O's
35297c478bd9Sstevel@tonic-gate */
35307c478bd9Sstevel@tonic-gate ms = (mio_slave_t *)(((caddr_t)mm) + sizeof (mio_master_t));
35317c478bd9Sstevel@tonic-gate for (i = 0; i < io_count; i++) {
35327c478bd9Sstevel@tonic-gate (void) bdev_strategy(&ms->ms_buf);
35337c478bd9Sstevel@tonic-gate ms ++;
35347c478bd9Sstevel@tonic-gate }
35357c478bd9Sstevel@tonic-gate }
35367c478bd9Sstevel@tonic-gate
35377c478bd9Sstevel@tonic-gate end:
35387c478bd9Sstevel@tonic-gate if (error != 0) {
35397c478bd9Sstevel@tonic-gate bp->b_flags |= B_ERROR;
35407c478bd9Sstevel@tonic-gate bp->b_error = error;
35417c478bd9Sstevel@tonic-gate if (mm != NULL) {
35427c478bd9Sstevel@tonic-gate mutex_destroy(&mm->mm_mutex);
35437c478bd9Sstevel@tonic-gate kmem_free(mm, mm->mm_size);
35447c478bd9Sstevel@tonic-gate }
35457c478bd9Sstevel@tonic-gate }
35467c478bd9Sstevel@tonic-gate return (error);
35477c478bd9Sstevel@tonic-gate }
35487c478bd9Sstevel@tonic-gate
35497c478bd9Sstevel@tonic-gate int32_t
ud_slave_done(struct buf * bp)35507c478bd9Sstevel@tonic-gate ud_slave_done(struct buf *bp)
35517c478bd9Sstevel@tonic-gate {
35527c478bd9Sstevel@tonic-gate mio_master_t *mm;
35537c478bd9Sstevel@tonic-gate int32_t resid;
35547c478bd9Sstevel@tonic-gate
35557c478bd9Sstevel@tonic-gate ASSERT(SEMA_HELD(&bp->b_sem));
35567c478bd9Sstevel@tonic-gate ASSERT((bp->b_flags & B_DONE) == 0);
35577c478bd9Sstevel@tonic-gate
35587c478bd9Sstevel@tonic-gate mm = ((mio_slave_t *)bp)->ms_ptr;
35597c478bd9Sstevel@tonic-gate
35607c478bd9Sstevel@tonic-gate /*
35617c478bd9Sstevel@tonic-gate * Propagate error and byte count info from slave struct to
35627c478bd9Sstevel@tonic-gate * the master struct
35637c478bd9Sstevel@tonic-gate */
35647c478bd9Sstevel@tonic-gate mutex_enter(&mm->mm_mutex);
35657c478bd9Sstevel@tonic-gate if (bp->b_flags & B_ERROR) {
35667c478bd9Sstevel@tonic-gate
35677c478bd9Sstevel@tonic-gate /*
35687c478bd9Sstevel@tonic-gate * If multiple slave buffers get
35697c478bd9Sstevel@tonic-gate * error we forget the old errors
35707c478bd9Sstevel@tonic-gate * this is ok because we any way
35717c478bd9Sstevel@tonic-gate * cannot return multiple errors
35727c478bd9Sstevel@tonic-gate */
35737c478bd9Sstevel@tonic-gate mm->mm_error = bp->b_error;
35747c478bd9Sstevel@tonic-gate }
35757c478bd9Sstevel@tonic-gate mm->mm_resid -= bp->b_bcount;
35767c478bd9Sstevel@tonic-gate resid = mm->mm_resid;
35777c478bd9Sstevel@tonic-gate mutex_exit(&mm->mm_mutex);
35787c478bd9Sstevel@tonic-gate
35797c478bd9Sstevel@tonic-gate /*
35807c478bd9Sstevel@tonic-gate * free up the resources allocated to cloned buffers.
35817c478bd9Sstevel@tonic-gate */
35827c478bd9Sstevel@tonic-gate bp_mapout(bp);
35837c478bd9Sstevel@tonic-gate biofini(bp);
35847c478bd9Sstevel@tonic-gate
35857c478bd9Sstevel@tonic-gate if (resid == 0) {
35867c478bd9Sstevel@tonic-gate
35877c478bd9Sstevel@tonic-gate /*
35887c478bd9Sstevel@tonic-gate * This is the last I/O operation
35897c478bd9Sstevel@tonic-gate * clean up and return the original buffer
35907c478bd9Sstevel@tonic-gate */
35917c478bd9Sstevel@tonic-gate if (mm->mm_error) {
35927c478bd9Sstevel@tonic-gate mm->mm_bp->b_flags |= B_ERROR;
35937c478bd9Sstevel@tonic-gate mm->mm_bp->b_error = mm->mm_error;
35947c478bd9Sstevel@tonic-gate }
35957c478bd9Sstevel@tonic-gate biodone(mm->mm_bp);
35967c478bd9Sstevel@tonic-gate mutex_destroy(&mm->mm_mutex);
35977c478bd9Sstevel@tonic-gate kmem_free(mm, mm->mm_size);
35987c478bd9Sstevel@tonic-gate }
35997c478bd9Sstevel@tonic-gate return (0);
36007c478bd9Sstevel@tonic-gate }
3601