ntfs_vnops.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: ntfs_vnops.c,v 1.1.2.2 2002/12/29 19:56:19 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*
4 1.1.2.2 thorpej * Copyright (c) 1992, 1993
5 1.1.2.2 thorpej * The Regents of the University of California. All rights reserved.
6 1.1.2.2 thorpej *
7 1.1.2.2 thorpej * This code is derived from software contributed to Berkeley by
8 1.1.2.2 thorpej * John Heidemann of the UCLA Ficus project.
9 1.1.2.2 thorpej *
10 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.1.2.2 thorpej * are met:
13 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 thorpej * must display the following acknowledgement:
20 1.1.2.2 thorpej * This product includes software developed by the University of
21 1.1.2.2 thorpej * California, Berkeley and its contributors.
22 1.1.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
23 1.1.2.2 thorpej * may be used to endorse or promote products derived from this software
24 1.1.2.2 thorpej * without specific prior written permission.
25 1.1.2.2 thorpej *
26 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1.2.2 thorpej * SUCH DAMAGE.
37 1.1.2.2 thorpej *
38 1.1.2.2 thorpej * Id: ntfs_vnops.c,v 1.5 1999/05/12 09:43:06 semenu Exp
39 1.1.2.2 thorpej *
40 1.1.2.2 thorpej */
41 1.1.2.2 thorpej
42 1.1.2.2 thorpej #include <sys/cdefs.h>
43 1.1.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: ntfs_vnops.c,v 1.1.2.2 2002/12/29 19:56:19 thorpej Exp $");
44 1.1.2.2 thorpej
45 1.1.2.2 thorpej #include <sys/param.h>
46 1.1.2.2 thorpej #include <sys/systm.h>
47 1.1.2.2 thorpej #include <sys/kernel.h>
48 1.1.2.2 thorpej #include <sys/time.h>
49 1.1.2.2 thorpej #include <sys/stat.h>
50 1.1.2.2 thorpej #include <sys/vnode.h>
51 1.1.2.2 thorpej #include <sys/mount.h>
52 1.1.2.2 thorpej #include <sys/namei.h>
53 1.1.2.2 thorpej #include <sys/malloc.h>
54 1.1.2.2 thorpej #include <sys/buf.h>
55 1.1.2.2 thorpej #include <sys/dirent.h>
56 1.1.2.2 thorpej
57 1.1.2.2 thorpej #if !defined(__NetBSD__)
58 1.1.2.2 thorpej #include <vm/vm.h>
59 1.1.2.2 thorpej #endif
60 1.1.2.2 thorpej
61 1.1.2.2 thorpej #if defined(__FreeBSD__)
62 1.1.2.2 thorpej #include <vm/vnode_pager.h>
63 1.1.2.2 thorpej #endif
64 1.1.2.2 thorpej
65 1.1.2.2 thorpej #include <sys/sysctl.h>
66 1.1.2.2 thorpej
67 1.1.2.2 thorpej
68 1.1.2.2 thorpej /*#define NTFS_DEBUG 1*/
69 1.1.2.2 thorpej #include <fs/ntfs/ntfs.h>
70 1.1.2.2 thorpej #include <fs/ntfs/ntfs_inode.h>
71 1.1.2.2 thorpej #include <fs/ntfs/ntfs_subr.h>
72 1.1.2.2 thorpej #include <miscfs/specfs/specdev.h>
73 1.1.2.2 thorpej #include <miscfs/genfs/genfs.h>
74 1.1.2.2 thorpej
75 1.1.2.2 thorpej #include <sys/unistd.h> /* for pathconf(2) constants */
76 1.1.2.2 thorpej
77 1.1.2.2 thorpej static int ntfs_bypass __P((struct vop_generic_args *ap));
78 1.1.2.2 thorpej static int ntfs_read __P((struct vop_read_args *));
79 1.1.2.2 thorpej static int ntfs_write __P((struct vop_write_args *ap));
80 1.1.2.2 thorpej static int ntfs_getattr __P((struct vop_getattr_args *ap));
81 1.1.2.2 thorpej static int ntfs_inactive __P((struct vop_inactive_args *ap));
82 1.1.2.2 thorpej static int ntfs_print __P((struct vop_print_args *ap));
83 1.1.2.2 thorpej static int ntfs_reclaim __P((struct vop_reclaim_args *ap));
84 1.1.2.2 thorpej static int ntfs_strategy __P((struct vop_strategy_args *ap));
85 1.1.2.2 thorpej static int ntfs_access __P((struct vop_access_args *ap));
86 1.1.2.2 thorpej static int ntfs_open __P((struct vop_open_args *ap));
87 1.1.2.2 thorpej static int ntfs_close __P((struct vop_close_args *ap));
88 1.1.2.2 thorpej static int ntfs_readdir __P((struct vop_readdir_args *ap));
89 1.1.2.2 thorpej static int ntfs_lookup __P((struct vop_lookup_args *ap));
90 1.1.2.2 thorpej static int ntfs_bmap __P((struct vop_bmap_args *ap));
91 1.1.2.2 thorpej #if defined(__FreeBSD__)
92 1.1.2.2 thorpej static int ntfs_getpages __P((struct vop_getpages_args *ap));
93 1.1.2.2 thorpej static int ntfs_putpages __P((struct vop_putpages_args *));
94 1.1.2.2 thorpej static int ntfs_fsync __P((struct vop_fsync_args *ap));
95 1.1.2.2 thorpej #endif
96 1.1.2.2 thorpej static int ntfs_pathconf __P((void *));
97 1.1.2.2 thorpej
98 1.1.2.2 thorpej int ntfs_prtactive = 1; /* 1 => print out reclaim of active vnodes */
99 1.1.2.2 thorpej
100 1.1.2.2 thorpej #if defined(__FreeBSD__)
101 1.1.2.2 thorpej int
102 1.1.2.2 thorpej ntfs_getpages(ap)
103 1.1.2.2 thorpej struct vop_getpages_args *ap;
104 1.1.2.2 thorpej {
105 1.1.2.2 thorpej return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
106 1.1.2.2 thorpej ap->a_reqpage);
107 1.1.2.2 thorpej }
108 1.1.2.2 thorpej
109 1.1.2.2 thorpej int
110 1.1.2.2 thorpej ntfs_putpages(ap)
111 1.1.2.2 thorpej struct vop_putpages_args *ap;
112 1.1.2.2 thorpej {
113 1.1.2.2 thorpej return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
114 1.1.2.2 thorpej ap->a_sync, ap->a_rtvals);
115 1.1.2.2 thorpej }
116 1.1.2.2 thorpej #endif
117 1.1.2.2 thorpej
118 1.1.2.2 thorpej /*
119 1.1.2.2 thorpej * This is a noop, simply returning what one has been given.
120 1.1.2.2 thorpej */
121 1.1.2.2 thorpej int
122 1.1.2.2 thorpej ntfs_bmap(ap)
123 1.1.2.2 thorpej struct vop_bmap_args /* {
124 1.1.2.2 thorpej struct vnode *a_vp;
125 1.1.2.2 thorpej daddr_t a_bn;
126 1.1.2.2 thorpej struct vnode **a_vpp;
127 1.1.2.2 thorpej daddr_t *a_bnp;
128 1.1.2.2 thorpej int *a_runp;
129 1.1.2.2 thorpej int *a_runb;
130 1.1.2.2 thorpej } */ *ap;
131 1.1.2.2 thorpej {
132 1.1.2.2 thorpej dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
133 1.1.2.2 thorpej if (ap->a_vpp != NULL)
134 1.1.2.2 thorpej *ap->a_vpp = ap->a_vp;
135 1.1.2.2 thorpej if (ap->a_bnp != NULL)
136 1.1.2.2 thorpej *ap->a_bnp = ap->a_bn;
137 1.1.2.2 thorpej if (ap->a_runp != NULL)
138 1.1.2.2 thorpej *ap->a_runp = 0;
139 1.1.2.2 thorpej #if !defined(__NetBSD__)
140 1.1.2.2 thorpej if (ap->a_runb != NULL)
141 1.1.2.2 thorpej *ap->a_runb = 0;
142 1.1.2.2 thorpej #endif
143 1.1.2.2 thorpej return (0);
144 1.1.2.2 thorpej }
145 1.1.2.2 thorpej
146 1.1.2.2 thorpej static int
147 1.1.2.2 thorpej ntfs_read(ap)
148 1.1.2.2 thorpej struct vop_read_args /* {
149 1.1.2.2 thorpej struct vnode *a_vp;
150 1.1.2.2 thorpej struct uio *a_uio;
151 1.1.2.2 thorpej int a_ioflag;
152 1.1.2.2 thorpej struct ucred *a_cred;
153 1.1.2.2 thorpej } */ *ap;
154 1.1.2.2 thorpej {
155 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
156 1.1.2.2 thorpej struct fnode *fp = VTOF(vp);
157 1.1.2.2 thorpej struct ntnode *ip = FTONT(fp);
158 1.1.2.2 thorpej struct uio *uio = ap->a_uio;
159 1.1.2.2 thorpej struct ntfsmount *ntmp = ip->i_mp;
160 1.1.2.2 thorpej u_int64_t toread;
161 1.1.2.2 thorpej int error;
162 1.1.2.2 thorpej
163 1.1.2.2 thorpej dprintf(("ntfs_read: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
164 1.1.2.2 thorpej
165 1.1.2.2 thorpej dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
166 1.1.2.2 thorpej
167 1.1.2.2 thorpej /* don't allow reading after end of file */
168 1.1.2.2 thorpej if (uio->uio_offset > fp->f_size)
169 1.1.2.2 thorpej toread = 0;
170 1.1.2.2 thorpej else
171 1.1.2.2 thorpej toread = min( uio->uio_resid, fp->f_size - uio->uio_offset );
172 1.1.2.2 thorpej
173 1.1.2.2 thorpej dprintf((", toread: %d\n",(u_int32_t)toread));
174 1.1.2.2 thorpej
175 1.1.2.2 thorpej if (toread == 0)
176 1.1.2.2 thorpej return (0);
177 1.1.2.2 thorpej
178 1.1.2.2 thorpej error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
179 1.1.2.2 thorpej fp->f_attrname, uio->uio_offset, toread, NULL, uio);
180 1.1.2.2 thorpej if (error) {
181 1.1.2.2 thorpej printf("ntfs_read: ntfs_readattr failed: %d\n",error);
182 1.1.2.2 thorpej return (error);
183 1.1.2.2 thorpej }
184 1.1.2.2 thorpej
185 1.1.2.2 thorpej return (0);
186 1.1.2.2 thorpej }
187 1.1.2.2 thorpej
188 1.1.2.2 thorpej static int
189 1.1.2.2 thorpej ntfs_bypass(ap)
190 1.1.2.2 thorpej struct vop_generic_args /* {
191 1.1.2.2 thorpej struct vnodeop_desc *a_desc;
192 1.1.2.2 thorpej <other random data follows, presumably>
193 1.1.2.2 thorpej } */ *ap;
194 1.1.2.2 thorpej {
195 1.1.2.2 thorpej int error = ENOTTY;
196 1.1.2.2 thorpej dprintf(("ntfs_bypass: %s\n", ap->a_desc->vdesc_name));
197 1.1.2.2 thorpej return (error);
198 1.1.2.2 thorpej }
199 1.1.2.2 thorpej
200 1.1.2.2 thorpej
201 1.1.2.2 thorpej static int
202 1.1.2.2 thorpej ntfs_getattr(ap)
203 1.1.2.2 thorpej struct vop_getattr_args /* {
204 1.1.2.2 thorpej struct vnode *a_vp;
205 1.1.2.2 thorpej struct vattr *a_vap;
206 1.1.2.2 thorpej struct ucred *a_cred;
207 1.1.2.2 thorpej struct proc *a_p;
208 1.1.2.2 thorpej } */ *ap;
209 1.1.2.2 thorpej {
210 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
211 1.1.2.2 thorpej struct fnode *fp = VTOF(vp);
212 1.1.2.2 thorpej struct ntnode *ip = FTONT(fp);
213 1.1.2.2 thorpej struct vattr *vap = ap->a_vap;
214 1.1.2.2 thorpej
215 1.1.2.2 thorpej dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
216 1.1.2.2 thorpej
217 1.1.2.2 thorpej #if defined(__FreeBSD__)
218 1.1.2.2 thorpej vap->va_fsid = dev2udev(ip->i_dev);
219 1.1.2.2 thorpej #else /* NetBSD */
220 1.1.2.2 thorpej vap->va_fsid = ip->i_dev;
221 1.1.2.2 thorpej #endif
222 1.1.2.2 thorpej vap->va_fileid = ip->i_number;
223 1.1.2.2 thorpej vap->va_mode = ip->i_mp->ntm_mode;
224 1.1.2.2 thorpej vap->va_nlink = ip->i_nlink;
225 1.1.2.2 thorpej vap->va_uid = ip->i_mp->ntm_uid;
226 1.1.2.2 thorpej vap->va_gid = ip->i_mp->ntm_gid;
227 1.1.2.2 thorpej vap->va_rdev = 0; /* XXX UNODEV ? */
228 1.1.2.2 thorpej vap->va_size = fp->f_size;
229 1.1.2.2 thorpej vap->va_bytes = fp->f_allocated;
230 1.1.2.2 thorpej vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
231 1.1.2.2 thorpej vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
232 1.1.2.2 thorpej vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
233 1.1.2.2 thorpej vap->va_flags = ip->i_flag;
234 1.1.2.2 thorpej vap->va_gen = 0;
235 1.1.2.2 thorpej vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
236 1.1.2.2 thorpej vap->va_type = vp->v_type;
237 1.1.2.2 thorpej vap->va_filerev = 0;
238 1.1.2.2 thorpej return (0);
239 1.1.2.2 thorpej }
240 1.1.2.2 thorpej
241 1.1.2.2 thorpej
242 1.1.2.2 thorpej /*
243 1.1.2.2 thorpej * Last reference to an ntnode. If necessary, write or delete it.
244 1.1.2.2 thorpej */
245 1.1.2.2 thorpej int
246 1.1.2.2 thorpej ntfs_inactive(ap)
247 1.1.2.2 thorpej struct vop_inactive_args /* {
248 1.1.2.2 thorpej struct vnode *a_vp;
249 1.1.2.2 thorpej } */ *ap;
250 1.1.2.2 thorpej {
251 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
252 1.1.2.2 thorpej #ifdef NTFS_DEBUG
253 1.1.2.2 thorpej struct ntnode *ip = VTONT(vp);
254 1.1.2.2 thorpej #endif
255 1.1.2.2 thorpej
256 1.1.2.2 thorpej dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
257 1.1.2.2 thorpej
258 1.1.2.2 thorpej if (ntfs_prtactive && vp->v_usecount != 0)
259 1.1.2.2 thorpej vprint("ntfs_inactive: pushing active", vp);
260 1.1.2.2 thorpej
261 1.1.2.2 thorpej VOP__UNLOCK(vp, 0, ap->a_p);
262 1.1.2.2 thorpej
263 1.1.2.2 thorpej /* XXX since we don't support any filesystem changes
264 1.1.2.2 thorpej * right now, nothing more needs to be done
265 1.1.2.2 thorpej */
266 1.1.2.2 thorpej return (0);
267 1.1.2.2 thorpej }
268 1.1.2.2 thorpej
269 1.1.2.2 thorpej /*
270 1.1.2.2 thorpej * Reclaim an fnode/ntnode so that it can be used for other purposes.
271 1.1.2.2 thorpej */
272 1.1.2.2 thorpej int
273 1.1.2.2 thorpej ntfs_reclaim(ap)
274 1.1.2.2 thorpej struct vop_reclaim_args /* {
275 1.1.2.2 thorpej struct vnode *a_vp;
276 1.1.2.2 thorpej } */ *ap;
277 1.1.2.2 thorpej {
278 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
279 1.1.2.2 thorpej struct fnode *fp = VTOF(vp);
280 1.1.2.2 thorpej struct ntnode *ip = FTONT(fp);
281 1.1.2.2 thorpej int error;
282 1.1.2.2 thorpej
283 1.1.2.2 thorpej dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
284 1.1.2.2 thorpej
285 1.1.2.2 thorpej if (ntfs_prtactive && vp->v_usecount != 0)
286 1.1.2.2 thorpej vprint("ntfs_reclaim: pushing active", vp);
287 1.1.2.2 thorpej
288 1.1.2.2 thorpej if ((error = ntfs_ntget(ip)) != 0)
289 1.1.2.2 thorpej return (error);
290 1.1.2.2 thorpej
291 1.1.2.2 thorpej /* Purge old data structures associated with the inode. */
292 1.1.2.2 thorpej cache_purge(vp);
293 1.1.2.2 thorpej if (ip->i_devvp) {
294 1.1.2.2 thorpej vrele(ip->i_devvp);
295 1.1.2.2 thorpej ip->i_devvp = NULL;
296 1.1.2.2 thorpej }
297 1.1.2.2 thorpej
298 1.1.2.2 thorpej ntfs_frele(fp);
299 1.1.2.2 thorpej ntfs_ntput(ip);
300 1.1.2.2 thorpej vp->v_data = NULL;
301 1.1.2.2 thorpej
302 1.1.2.2 thorpej return (0);
303 1.1.2.2 thorpej }
304 1.1.2.2 thorpej
305 1.1.2.2 thorpej static int
306 1.1.2.2 thorpej ntfs_print(ap)
307 1.1.2.2 thorpej struct vop_print_args /* {
308 1.1.2.2 thorpej struct vnode *a_vp;
309 1.1.2.2 thorpej } */ *ap;
310 1.1.2.2 thorpej {
311 1.1.2.2 thorpej return (0);
312 1.1.2.2 thorpej }
313 1.1.2.2 thorpej
314 1.1.2.2 thorpej /*
315 1.1.2.2 thorpej * Calculate the logical to physical mapping if not done already,
316 1.1.2.2 thorpej * then call the device strategy routine.
317 1.1.2.2 thorpej */
318 1.1.2.2 thorpej int
319 1.1.2.2 thorpej ntfs_strategy(ap)
320 1.1.2.2 thorpej struct vop_strategy_args /* {
321 1.1.2.2 thorpej struct buf *a_bp;
322 1.1.2.2 thorpej } */ *ap;
323 1.1.2.2 thorpej {
324 1.1.2.2 thorpej struct buf *bp = ap->a_bp;
325 1.1.2.2 thorpej struct vnode *vp = bp->b_vp;
326 1.1.2.2 thorpej struct fnode *fp = VTOF(vp);
327 1.1.2.2 thorpej struct ntnode *ip = FTONT(fp);
328 1.1.2.2 thorpej struct ntfsmount *ntmp = ip->i_mp;
329 1.1.2.2 thorpej int error;
330 1.1.2.2 thorpej
331 1.1.2.2 thorpej #ifdef __FreeBSD__
332 1.1.2.2 thorpej dprintf(("ntfs_strategy: offset: %d, blkno: %d, lblkno: %d\n",
333 1.1.2.2 thorpej (u_int32_t)bp->b_offset,(u_int32_t)bp->b_blkno,
334 1.1.2.2 thorpej (u_int32_t)bp->b_lblkno));
335 1.1.2.2 thorpej #else
336 1.1.2.2 thorpej dprintf(("ntfs_strategy: blkno: %d, lblkno: %d\n",
337 1.1.2.2 thorpej (u_int32_t)bp->b_blkno,
338 1.1.2.2 thorpej (u_int32_t)bp->b_lblkno));
339 1.1.2.2 thorpej #endif
340 1.1.2.2 thorpej
341 1.1.2.2 thorpej dprintf(("strategy: bcount: %d flags: 0x%lx\n",
342 1.1.2.2 thorpej (u_int32_t)bp->b_bcount,bp->b_flags));
343 1.1.2.2 thorpej
344 1.1.2.2 thorpej if (bp->b_flags & B_READ) {
345 1.1.2.2 thorpej u_int32_t toread;
346 1.1.2.2 thorpej
347 1.1.2.2 thorpej if (ntfs_cntob(bp->b_blkno) >= fp->f_size) {
348 1.1.2.2 thorpej clrbuf(bp);
349 1.1.2.2 thorpej error = 0;
350 1.1.2.2 thorpej } else {
351 1.1.2.2 thorpej toread = min(bp->b_bcount,
352 1.1.2.2 thorpej fp->f_size-ntfs_cntob(bp->b_blkno));
353 1.1.2.2 thorpej dprintf(("ntfs_strategy: toread: %d, fsize: %d\n",
354 1.1.2.2 thorpej toread,(u_int32_t)fp->f_size));
355 1.1.2.2 thorpej
356 1.1.2.2 thorpej error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
357 1.1.2.2 thorpej fp->f_attrname, ntfs_cntob(bp->b_blkno),
358 1.1.2.2 thorpej toread, bp->b_data, NULL);
359 1.1.2.2 thorpej
360 1.1.2.2 thorpej if (error) {
361 1.1.2.2 thorpej printf("ntfs_strategy: ntfs_readattr failed\n");
362 1.1.2.2 thorpej bp->b_error = error;
363 1.1.2.2 thorpej bp->b_flags |= B_ERROR;
364 1.1.2.2 thorpej }
365 1.1.2.2 thorpej
366 1.1.2.2 thorpej bzero(bp->b_data + toread, bp->b_bcount - toread);
367 1.1.2.2 thorpej }
368 1.1.2.2 thorpej } else {
369 1.1.2.2 thorpej size_t tmp;
370 1.1.2.2 thorpej u_int32_t towrite;
371 1.1.2.2 thorpej
372 1.1.2.2 thorpej if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) {
373 1.1.2.2 thorpej printf("ntfs_strategy: CAN'T EXTEND FILE\n");
374 1.1.2.2 thorpej bp->b_error = error = EFBIG;
375 1.1.2.2 thorpej bp->b_flags |= B_ERROR;
376 1.1.2.2 thorpej } else {
377 1.1.2.2 thorpej towrite = min(bp->b_bcount,
378 1.1.2.2 thorpej fp->f_size-ntfs_cntob(bp->b_blkno));
379 1.1.2.2 thorpej dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n",
380 1.1.2.2 thorpej towrite,(u_int32_t)fp->f_size));
381 1.1.2.2 thorpej
382 1.1.2.2 thorpej error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
383 1.1.2.2 thorpej fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite,
384 1.1.2.2 thorpej bp->b_data, &tmp, NULL);
385 1.1.2.2 thorpej
386 1.1.2.2 thorpej if (error) {
387 1.1.2.2 thorpej printf("ntfs_strategy: ntfs_writeattr fail\n");
388 1.1.2.2 thorpej bp->b_error = error;
389 1.1.2.2 thorpej bp->b_flags |= B_ERROR;
390 1.1.2.2 thorpej }
391 1.1.2.2 thorpej }
392 1.1.2.2 thorpej }
393 1.1.2.2 thorpej biodone(bp);
394 1.1.2.2 thorpej return (error);
395 1.1.2.2 thorpej }
396 1.1.2.2 thorpej
397 1.1.2.2 thorpej static int
398 1.1.2.2 thorpej ntfs_write(ap)
399 1.1.2.2 thorpej struct vop_write_args /* {
400 1.1.2.2 thorpej struct vnode *a_vp;
401 1.1.2.2 thorpej struct uio *a_uio;
402 1.1.2.2 thorpej int a_ioflag;
403 1.1.2.2 thorpej struct ucred *a_cred;
404 1.1.2.2 thorpej } */ *ap;
405 1.1.2.2 thorpej {
406 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
407 1.1.2.2 thorpej struct fnode *fp = VTOF(vp);
408 1.1.2.2 thorpej struct ntnode *ip = FTONT(fp);
409 1.1.2.2 thorpej struct uio *uio = ap->a_uio;
410 1.1.2.2 thorpej struct ntfsmount *ntmp = ip->i_mp;
411 1.1.2.2 thorpej u_int64_t towrite;
412 1.1.2.2 thorpej size_t written;
413 1.1.2.2 thorpej int error;
414 1.1.2.2 thorpej
415 1.1.2.2 thorpej dprintf(("ntfs_write: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
416 1.1.2.2 thorpej dprintf(("ntfs_write: filesize: %d",(u_int32_t)fp->f_size));
417 1.1.2.2 thorpej
418 1.1.2.2 thorpej if (uio->uio_resid + uio->uio_offset > fp->f_size) {
419 1.1.2.2 thorpej printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
420 1.1.2.2 thorpej return (EFBIG);
421 1.1.2.2 thorpej }
422 1.1.2.2 thorpej
423 1.1.2.2 thorpej towrite = min(uio->uio_resid, fp->f_size - uio->uio_offset);
424 1.1.2.2 thorpej
425 1.1.2.2 thorpej dprintf((", towrite: %d\n",(u_int32_t)towrite));
426 1.1.2.2 thorpej
427 1.1.2.2 thorpej error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
428 1.1.2.2 thorpej fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
429 1.1.2.2 thorpej #ifdef NTFS_DEBUG
430 1.1.2.2 thorpej if (error)
431 1.1.2.2 thorpej printf("ntfs_write: ntfs_writeattr failed: %d\n", error);
432 1.1.2.2 thorpej #endif
433 1.1.2.2 thorpej
434 1.1.2.2 thorpej return (error);
435 1.1.2.2 thorpej }
436 1.1.2.2 thorpej
437 1.1.2.2 thorpej int
438 1.1.2.2 thorpej ntfs_access(ap)
439 1.1.2.2 thorpej struct vop_access_args /* {
440 1.1.2.2 thorpej struct vnode *a_vp;
441 1.1.2.2 thorpej int a_mode;
442 1.1.2.2 thorpej struct ucred *a_cred;
443 1.1.2.2 thorpej struct proc *a_p;
444 1.1.2.2 thorpej } */ *ap;
445 1.1.2.2 thorpej {
446 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
447 1.1.2.2 thorpej struct ntnode *ip = VTONT(vp);
448 1.1.2.2 thorpej struct ucred *cred = ap->a_cred;
449 1.1.2.2 thorpej mode_t mask, mode = ap->a_mode;
450 1.1.2.2 thorpej gid_t *gp;
451 1.1.2.2 thorpej int i;
452 1.1.2.2 thorpej #ifdef QUOTA
453 1.1.2.2 thorpej int error;
454 1.1.2.2 thorpej #endif
455 1.1.2.2 thorpej
456 1.1.2.2 thorpej dprintf(("ntfs_access: %d\n",ip->i_number));
457 1.1.2.2 thorpej
458 1.1.2.2 thorpej /*
459 1.1.2.2 thorpej * Disallow write attempts on read-only file systems;
460 1.1.2.2 thorpej * unless the file is a socket, fifo, or a block or
461 1.1.2.2 thorpej * character device resident on the file system.
462 1.1.2.2 thorpej */
463 1.1.2.2 thorpej if (mode & VWRITE) {
464 1.1.2.2 thorpej switch ((int)vp->v_type) {
465 1.1.2.2 thorpej case VDIR:
466 1.1.2.2 thorpej case VLNK:
467 1.1.2.2 thorpej case VREG:
468 1.1.2.2 thorpej if (vp->v_mount->mnt_flag & MNT_RDONLY)
469 1.1.2.2 thorpej return (EROFS);
470 1.1.2.2 thorpej #ifdef QUOTA
471 1.1.2.2 thorpej if (error = getinoquota(ip))
472 1.1.2.2 thorpej return (error);
473 1.1.2.2 thorpej #endif
474 1.1.2.2 thorpej break;
475 1.1.2.2 thorpej }
476 1.1.2.2 thorpej }
477 1.1.2.2 thorpej
478 1.1.2.2 thorpej /* Otherwise, user id 0 always gets access. */
479 1.1.2.2 thorpej if (cred->cr_uid == 0)
480 1.1.2.2 thorpej return (0);
481 1.1.2.2 thorpej
482 1.1.2.2 thorpej mask = 0;
483 1.1.2.2 thorpej
484 1.1.2.2 thorpej /* Otherwise, check the owner. */
485 1.1.2.2 thorpej if (cred->cr_uid == ip->i_mp->ntm_uid) {
486 1.1.2.2 thorpej if (mode & VEXEC)
487 1.1.2.2 thorpej mask |= S_IXUSR;
488 1.1.2.2 thorpej if (mode & VREAD)
489 1.1.2.2 thorpej mask |= S_IRUSR;
490 1.1.2.2 thorpej if (mode & VWRITE)
491 1.1.2.2 thorpej mask |= S_IWUSR;
492 1.1.2.2 thorpej return ((ip->i_mp->ntm_mode & mask) == mask ? 0 : EACCES);
493 1.1.2.2 thorpej }
494 1.1.2.2 thorpej
495 1.1.2.2 thorpej /* Otherwise, check the groups. */
496 1.1.2.2 thorpej for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
497 1.1.2.2 thorpej if (ip->i_mp->ntm_gid == *gp) {
498 1.1.2.2 thorpej if (mode & VEXEC)
499 1.1.2.2 thorpej mask |= S_IXGRP;
500 1.1.2.2 thorpej if (mode & VREAD)
501 1.1.2.2 thorpej mask |= S_IRGRP;
502 1.1.2.2 thorpej if (mode & VWRITE)
503 1.1.2.2 thorpej mask |= S_IWGRP;
504 1.1.2.2 thorpej return ((ip->i_mp->ntm_mode&mask) == mask ? 0 : EACCES);
505 1.1.2.2 thorpej }
506 1.1.2.2 thorpej
507 1.1.2.2 thorpej /* Otherwise, check everyone else. */
508 1.1.2.2 thorpej if (mode & VEXEC)
509 1.1.2.2 thorpej mask |= S_IXOTH;
510 1.1.2.2 thorpej if (mode & VREAD)
511 1.1.2.2 thorpej mask |= S_IROTH;
512 1.1.2.2 thorpej if (mode & VWRITE)
513 1.1.2.2 thorpej mask |= S_IWOTH;
514 1.1.2.2 thorpej return ((ip->i_mp->ntm_mode & mask) == mask ? 0 : EACCES);
515 1.1.2.2 thorpej }
516 1.1.2.2 thorpej
517 1.1.2.2 thorpej /*
518 1.1.2.2 thorpej * Open called.
519 1.1.2.2 thorpej *
520 1.1.2.2 thorpej * Nothing to do.
521 1.1.2.2 thorpej */
522 1.1.2.2 thorpej /* ARGSUSED */
523 1.1.2.2 thorpej static int
524 1.1.2.2 thorpej ntfs_open(ap)
525 1.1.2.2 thorpej struct vop_open_args /* {
526 1.1.2.2 thorpej struct vnode *a_vp;
527 1.1.2.2 thorpej int a_mode;
528 1.1.2.2 thorpej struct ucred *a_cred;
529 1.1.2.2 thorpej struct proc *a_p;
530 1.1.2.2 thorpej } */ *ap;
531 1.1.2.2 thorpej {
532 1.1.2.2 thorpej #if NTFS_DEBUG
533 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
534 1.1.2.2 thorpej struct ntnode *ip = VTONT(vp);
535 1.1.2.2 thorpej
536 1.1.2.2 thorpej printf("ntfs_open: %d\n",ip->i_number);
537 1.1.2.2 thorpej #endif
538 1.1.2.2 thorpej
539 1.1.2.2 thorpej /*
540 1.1.2.2 thorpej * Files marked append-only must be opened for appending.
541 1.1.2.2 thorpej */
542 1.1.2.2 thorpej
543 1.1.2.2 thorpej return (0);
544 1.1.2.2 thorpej }
545 1.1.2.2 thorpej
546 1.1.2.2 thorpej /*
547 1.1.2.2 thorpej * Close called.
548 1.1.2.2 thorpej *
549 1.1.2.2 thorpej * Update the times on the inode.
550 1.1.2.2 thorpej */
551 1.1.2.2 thorpej /* ARGSUSED */
552 1.1.2.2 thorpej static int
553 1.1.2.2 thorpej ntfs_close(ap)
554 1.1.2.2 thorpej struct vop_close_args /* {
555 1.1.2.2 thorpej struct vnode *a_vp;
556 1.1.2.2 thorpej int a_fflag;
557 1.1.2.2 thorpej struct ucred *a_cred;
558 1.1.2.2 thorpej struct proc *a_p;
559 1.1.2.2 thorpej } */ *ap;
560 1.1.2.2 thorpej {
561 1.1.2.2 thorpej #if NTFS_DEBUG
562 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
563 1.1.2.2 thorpej struct ntnode *ip = VTONT(vp);
564 1.1.2.2 thorpej
565 1.1.2.2 thorpej printf("ntfs_close: %d\n",ip->i_number);
566 1.1.2.2 thorpej #endif
567 1.1.2.2 thorpej
568 1.1.2.2 thorpej return (0);
569 1.1.2.2 thorpej }
570 1.1.2.2 thorpej
571 1.1.2.2 thorpej int
572 1.1.2.2 thorpej ntfs_readdir(ap)
573 1.1.2.2 thorpej struct vop_readdir_args /* {
574 1.1.2.2 thorpej struct vnode *a_vp;
575 1.1.2.2 thorpej struct uio *a_uio;
576 1.1.2.2 thorpej struct ucred *a_cred;
577 1.1.2.2 thorpej int *a_ncookies;
578 1.1.2.2 thorpej u_int **cookies;
579 1.1.2.2 thorpej } */ *ap;
580 1.1.2.2 thorpej {
581 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
582 1.1.2.2 thorpej struct fnode *fp = VTOF(vp);
583 1.1.2.2 thorpej struct ntnode *ip = FTONT(fp);
584 1.1.2.2 thorpej struct uio *uio = ap->a_uio;
585 1.1.2.2 thorpej struct ntfsmount *ntmp = ip->i_mp;
586 1.1.2.2 thorpej int i, error = 0;
587 1.1.2.2 thorpej u_int32_t faked = 0, num;
588 1.1.2.2 thorpej int ncookies = 0;
589 1.1.2.2 thorpej struct dirent *cde;
590 1.1.2.2 thorpej off_t off;
591 1.1.2.2 thorpej
592 1.1.2.2 thorpej dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
593 1.1.2.2 thorpej
594 1.1.2.2 thorpej off = uio->uio_offset;
595 1.1.2.2 thorpej
596 1.1.2.2 thorpej MALLOC(cde, struct dirent *, sizeof(struct dirent), M_TEMP, M_WAITOK);
597 1.1.2.2 thorpej
598 1.1.2.2 thorpej /* Simulate . in every dir except ROOT */
599 1.1.2.2 thorpej if (ip->i_number != NTFS_ROOTINO
600 1.1.2.2 thorpej && uio->uio_offset < sizeof(struct dirent)) {
601 1.1.2.2 thorpej cde->d_fileno = ip->i_number;
602 1.1.2.2 thorpej cde->d_reclen = sizeof(struct dirent);
603 1.1.2.2 thorpej cde->d_type = DT_DIR;
604 1.1.2.2 thorpej cde->d_namlen = 1;
605 1.1.2.2 thorpej strncpy(cde->d_name, ".", 2);
606 1.1.2.2 thorpej error = uiomove((void *)cde, sizeof(struct dirent), uio);
607 1.1.2.2 thorpej if (error)
608 1.1.2.2 thorpej goto out;
609 1.1.2.2 thorpej
610 1.1.2.2 thorpej ncookies++;
611 1.1.2.2 thorpej }
612 1.1.2.2 thorpej
613 1.1.2.2 thorpej /* Simulate .. in every dir including ROOT */
614 1.1.2.2 thorpej if (uio->uio_offset < 2 * sizeof(struct dirent)) {
615 1.1.2.2 thorpej cde->d_fileno = NTFS_ROOTINO; /* XXX */
616 1.1.2.2 thorpej cde->d_reclen = sizeof(struct dirent);
617 1.1.2.2 thorpej cde->d_type = DT_DIR;
618 1.1.2.2 thorpej cde->d_namlen = 2;
619 1.1.2.2 thorpej strncpy(cde->d_name, "..", 3);
620 1.1.2.2 thorpej
621 1.1.2.2 thorpej error = uiomove((void *) cde, sizeof(struct dirent), uio);
622 1.1.2.2 thorpej if (error)
623 1.1.2.2 thorpej goto out;
624 1.1.2.2 thorpej
625 1.1.2.2 thorpej ncookies++;
626 1.1.2.2 thorpej }
627 1.1.2.2 thorpej
628 1.1.2.2 thorpej faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
629 1.1.2.2 thorpej num = uio->uio_offset / sizeof(struct dirent) - faked;
630 1.1.2.2 thorpej
631 1.1.2.2 thorpej while (uio->uio_resid >= sizeof(struct dirent)) {
632 1.1.2.2 thorpej struct attr_indexentry *iep;
633 1.1.2.2 thorpej char *fname;
634 1.1.2.2 thorpej size_t remains;
635 1.1.2.2 thorpej int sz;
636 1.1.2.2 thorpej
637 1.1.2.2 thorpej error = ntfs_ntreaddir(ntmp, fp, num, &iep);
638 1.1.2.2 thorpej if (error)
639 1.1.2.2 thorpej goto out;
640 1.1.2.2 thorpej
641 1.1.2.2 thorpej if (NULL == iep)
642 1.1.2.2 thorpej break;
643 1.1.2.2 thorpej
644 1.1.2.2 thorpej for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
645 1.1.2.2 thorpej iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
646 1.1.2.2 thorpej {
647 1.1.2.2 thorpej if(!ntfs_isnamepermitted(ntmp,iep))
648 1.1.2.2 thorpej continue;
649 1.1.2.2 thorpej
650 1.1.2.2 thorpej remains = sizeof(cde->d_name) - 1;
651 1.1.2.2 thorpej fname = cde->d_name;
652 1.1.2.2 thorpej for(i=0; i<iep->ie_fnamelen; i++) {
653 1.1.2.2 thorpej sz = (*ntmp->ntm_wput)(fname, remains,
654 1.1.2.2 thorpej iep->ie_fname[i]);
655 1.1.2.2 thorpej fname += sz;
656 1.1.2.2 thorpej remains -= sz;
657 1.1.2.2 thorpej }
658 1.1.2.2 thorpej *fname = '\0';
659 1.1.2.2 thorpej dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
660 1.1.2.2 thorpej num, cde->d_name, iep->ie_fnametype,
661 1.1.2.2 thorpej iep->ie_flag));
662 1.1.2.2 thorpej cde->d_namlen = fname - (char *) cde->d_name;
663 1.1.2.2 thorpej cde->d_fileno = iep->ie_number;
664 1.1.2.2 thorpej cde->d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
665 1.1.2.2 thorpej cde->d_reclen = sizeof(struct dirent);
666 1.1.2.2 thorpej dprintf(("%s\n", (cde->d_type == DT_DIR) ? "dir":"reg"));
667 1.1.2.2 thorpej
668 1.1.2.2 thorpej error = uiomove((void *)cde, sizeof(struct dirent), uio);
669 1.1.2.2 thorpej if (error)
670 1.1.2.2 thorpej goto out;
671 1.1.2.2 thorpej
672 1.1.2.2 thorpej ncookies++;
673 1.1.2.2 thorpej num++;
674 1.1.2.2 thorpej }
675 1.1.2.2 thorpej }
676 1.1.2.2 thorpej
677 1.1.2.2 thorpej dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
678 1.1.2.2 thorpej ncookies,(u_int)(uio->uio_offset - off)));
679 1.1.2.2 thorpej dprintf(("ntfs_readdir: off: %d resid: %d\n",
680 1.1.2.2 thorpej (u_int32_t)uio->uio_offset,uio->uio_resid));
681 1.1.2.2 thorpej
682 1.1.2.2 thorpej if (!error && ap->a_ncookies != NULL) {
683 1.1.2.2 thorpej struct dirent* dpStart;
684 1.1.2.2 thorpej struct dirent* dp;
685 1.1.2.2 thorpej #if defined(__FreeBSD__)
686 1.1.2.2 thorpej u_long *cookies;
687 1.1.2.2 thorpej u_long *cookiep;
688 1.1.2.2 thorpej #else /* defined(__NetBSD__) */
689 1.1.2.2 thorpej off_t *cookies;
690 1.1.2.2 thorpej off_t *cookiep;
691 1.1.2.2 thorpej #endif
692 1.1.2.2 thorpej
693 1.1.2.2 thorpej printf("ntfs_readdir: %d cookies\n",ncookies);
694 1.1.2.2 thorpej if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
695 1.1.2.2 thorpej panic("ntfs_readdir: unexpected uio from NFS server");
696 1.1.2.2 thorpej dpStart = (struct dirent *)
697 1.1.2.2 thorpej ((caddr_t)uio->uio_iov->iov_base -
698 1.1.2.2 thorpej (uio->uio_offset - off));
699 1.1.2.2 thorpej #if defined(__FreeBSD__)
700 1.1.2.2 thorpej MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
701 1.1.2.2 thorpej M_TEMP, M_WAITOK);
702 1.1.2.2 thorpej #else /* defined(__NetBSD__) */
703 1.1.2.2 thorpej cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
704 1.1.2.2 thorpej #endif
705 1.1.2.2 thorpej for (dp = dpStart, cookiep = cookies, i=0;
706 1.1.2.2 thorpej i < ncookies;
707 1.1.2.2 thorpej dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
708 1.1.2.2 thorpej off += dp->d_reclen;
709 1.1.2.2 thorpej *cookiep++ = (u_int) off;
710 1.1.2.2 thorpej }
711 1.1.2.2 thorpej *ap->a_ncookies = ncookies;
712 1.1.2.2 thorpej *ap->a_cookies = cookies;
713 1.1.2.2 thorpej }
714 1.1.2.2 thorpej /*
715 1.1.2.2 thorpej if (ap->a_eofflag)
716 1.1.2.2 thorpej *ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
717 1.1.2.2 thorpej */
718 1.1.2.2 thorpej out:
719 1.1.2.2 thorpej FREE(cde, M_TEMP);
720 1.1.2.2 thorpej return (error);
721 1.1.2.2 thorpej }
722 1.1.2.2 thorpej
723 1.1.2.2 thorpej int
724 1.1.2.2 thorpej ntfs_lookup(ap)
725 1.1.2.2 thorpej struct vop_lookup_args /* {
726 1.1.2.2 thorpej struct vnode *a_dvp;
727 1.1.2.2 thorpej struct vnode **a_vpp;
728 1.1.2.2 thorpej struct componentname *a_cnp;
729 1.1.2.2 thorpej } */ *ap;
730 1.1.2.2 thorpej {
731 1.1.2.2 thorpej struct vnode *dvp = ap->a_dvp;
732 1.1.2.2 thorpej struct ntnode *dip = VTONT(dvp);
733 1.1.2.2 thorpej struct ntfsmount *ntmp = dip->i_mp;
734 1.1.2.2 thorpej struct componentname *cnp = ap->a_cnp;
735 1.1.2.2 thorpej struct ucred *cred = cnp->cn_cred;
736 1.1.2.2 thorpej int error;
737 1.1.2.2 thorpej int lockparent = cnp->cn_flags & LOCKPARENT;
738 1.1.2.2 thorpej #if NTFS_DEBUG
739 1.1.2.2 thorpej int wantparent = cnp->cn_flags & (LOCKPARENT|WANTPARENT);
740 1.1.2.2 thorpej #endif
741 1.1.2.2 thorpej dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d, lp: %d, wp: %d \n",
742 1.1.2.2 thorpej (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
743 1.1.2.2 thorpej dip->i_number, lockparent, wantparent));
744 1.1.2.2 thorpej
745 1.1.2.2 thorpej error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_proc);
746 1.1.2.2 thorpej if(error)
747 1.1.2.2 thorpej return (error);
748 1.1.2.2 thorpej
749 1.1.2.2 thorpej if ((cnp->cn_flags & ISLASTCN) &&
750 1.1.2.2 thorpej (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
751 1.1.2.2 thorpej (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
752 1.1.2.2 thorpej return (EROFS);
753 1.1.2.2 thorpej
754 1.1.2.2 thorpej #ifdef __NetBSD__
755 1.1.2.2 thorpej /*
756 1.1.2.2 thorpej * We now have a segment name to search for, and a directory
757 1.1.2.2 thorpej * to search.
758 1.1.2.2 thorpej *
759 1.1.2.2 thorpej * Before tediously performing a linear scan of the directory,
760 1.1.2.2 thorpej * check the name cache to see if the directory/name pair
761 1.1.2.2 thorpej * we are looking for is known already.
762 1.1.2.2 thorpej */
763 1.1.2.2 thorpej if ((error = cache_lookup(ap->a_dvp, ap->a_vpp, cnp)) >= 0)
764 1.1.2.2 thorpej return (error);
765 1.1.2.2 thorpej #endif
766 1.1.2.2 thorpej
767 1.1.2.2 thorpej if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
768 1.1.2.2 thorpej dprintf(("ntfs_lookup: faking . directory in %d\n",
769 1.1.2.2 thorpej dip->i_number));
770 1.1.2.2 thorpej
771 1.1.2.2 thorpej VREF(dvp);
772 1.1.2.2 thorpej *ap->a_vpp = dvp;
773 1.1.2.2 thorpej error = 0;
774 1.1.2.2 thorpej } else if (cnp->cn_flags & ISDOTDOT) {
775 1.1.2.2 thorpej struct ntvattr *vap;
776 1.1.2.2 thorpej
777 1.1.2.2 thorpej dprintf(("ntfs_lookup: faking .. directory in %d\n",
778 1.1.2.2 thorpej dip->i_number));
779 1.1.2.2 thorpej
780 1.1.2.2 thorpej error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
781 1.1.2.2 thorpej if(error)
782 1.1.2.2 thorpej return (error);
783 1.1.2.2 thorpej
784 1.1.2.2 thorpej VOP__UNLOCK(dvp,0,cnp->cn_proc);
785 1.1.2.2 thorpej cnp->cn_flags |= PDIRUNLOCK;
786 1.1.2.2 thorpej
787 1.1.2.2 thorpej dprintf(("ntfs_lookup: parentdir: %d\n",
788 1.1.2.2 thorpej vap->va_a_name->n_pnumber));
789 1.1.2.2 thorpej error = VFS_VGET(ntmp->ntm_mountp,
790 1.1.2.2 thorpej vap->va_a_name->n_pnumber,ap->a_vpp);
791 1.1.2.2 thorpej ntfs_ntvattrrele(vap);
792 1.1.2.2 thorpej if (error) {
793 1.1.2.2 thorpej if (VN_LOCK(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_proc)==0)
794 1.1.2.2 thorpej cnp->cn_flags &= ~PDIRUNLOCK;
795 1.1.2.2 thorpej return (error);
796 1.1.2.2 thorpej }
797 1.1.2.2 thorpej
798 1.1.2.2 thorpej if (lockparent && (cnp->cn_flags & ISLASTCN)) {
799 1.1.2.2 thorpej error = VN_LOCK(dvp, LK_EXCLUSIVE, cnp->cn_proc);
800 1.1.2.2 thorpej if (error) {
801 1.1.2.2 thorpej vput( *(ap->a_vpp) );
802 1.1.2.2 thorpej return (error);
803 1.1.2.2 thorpej }
804 1.1.2.2 thorpej cnp->cn_flags &= ~PDIRUNLOCK;
805 1.1.2.2 thorpej }
806 1.1.2.2 thorpej } else {
807 1.1.2.2 thorpej error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
808 1.1.2.2 thorpej if (error) {
809 1.1.2.2 thorpej dprintf(("ntfs_ntlookupfile: returned %d\n", error));
810 1.1.2.2 thorpej return (error);
811 1.1.2.2 thorpej }
812 1.1.2.2 thorpej
813 1.1.2.2 thorpej dprintf(("ntfs_lookup: found ino: %d\n",
814 1.1.2.2 thorpej VTONT(*ap->a_vpp)->i_number));
815 1.1.2.2 thorpej
816 1.1.2.2 thorpej if(!lockparent || !(cnp->cn_flags & ISLASTCN))
817 1.1.2.2 thorpej VOP__UNLOCK(dvp, 0, cnp->cn_proc);
818 1.1.2.2 thorpej }
819 1.1.2.2 thorpej
820 1.1.2.2 thorpej if (cnp->cn_flags & MAKEENTRY)
821 1.1.2.2 thorpej cache_enter(dvp, *ap->a_vpp, cnp);
822 1.1.2.2 thorpej
823 1.1.2.2 thorpej return (error);
824 1.1.2.2 thorpej }
825 1.1.2.2 thorpej
826 1.1.2.2 thorpej #if defined(__FreeBSD__)
827 1.1.2.2 thorpej /*
828 1.1.2.2 thorpej * Flush the blocks of a file to disk.
829 1.1.2.2 thorpej *
830 1.1.2.2 thorpej * This function is worthless for vnodes that represent directories. Maybe we
831 1.1.2.2 thorpej * could just do a sync if they try an fsync on a directory file.
832 1.1.2.2 thorpej */
833 1.1.2.2 thorpej static int
834 1.1.2.2 thorpej ntfs_fsync(ap)
835 1.1.2.2 thorpej struct vop_fsync_args /* {
836 1.1.2.2 thorpej struct vnode *a_vp;
837 1.1.2.2 thorpej struct ucred *a_cred;
838 1.1.2.2 thorpej int a_waitfor;
839 1.1.2.2 thorpej off_t offlo;
840 1.1.2.2 thorpej off_t offhi;
841 1.1.2.2 thorpej struct proc *a_p;
842 1.1.2.2 thorpej } */ *ap;
843 1.1.2.2 thorpej {
844 1.1.2.2 thorpej return (0);
845 1.1.2.2 thorpej }
846 1.1.2.2 thorpej #endif
847 1.1.2.2 thorpej
848 1.1.2.2 thorpej /*
849 1.1.2.2 thorpej * Return POSIX pathconf information applicable to NTFS filesystem
850 1.1.2.2 thorpej */
851 1.1.2.2 thorpej int
852 1.1.2.2 thorpej ntfs_pathconf(v)
853 1.1.2.2 thorpej void *v;
854 1.1.2.2 thorpej {
855 1.1.2.2 thorpej struct vop_pathconf_args /* {
856 1.1.2.2 thorpej struct vnode *a_vp;
857 1.1.2.2 thorpej int a_name;
858 1.1.2.2 thorpej register_t *a_retval;
859 1.1.2.2 thorpej } */ *ap = v;
860 1.1.2.2 thorpej
861 1.1.2.2 thorpej switch (ap->a_name) {
862 1.1.2.2 thorpej case _PC_LINK_MAX:
863 1.1.2.2 thorpej *ap->a_retval = 1;
864 1.1.2.2 thorpej return (0);
865 1.1.2.2 thorpej case _PC_NAME_MAX:
866 1.1.2.2 thorpej *ap->a_retval = NTFS_MAXFILENAME;
867 1.1.2.2 thorpej return (0);
868 1.1.2.2 thorpej case _PC_PATH_MAX:
869 1.1.2.2 thorpej *ap->a_retval = PATH_MAX;
870 1.1.2.2 thorpej return (0);
871 1.1.2.2 thorpej case _PC_CHOWN_RESTRICTED:
872 1.1.2.2 thorpej *ap->a_retval = 1;
873 1.1.2.2 thorpej return (0);
874 1.1.2.2 thorpej case _PC_NO_TRUNC:
875 1.1.2.2 thorpej *ap->a_retval = 0;
876 1.1.2.2 thorpej return (0);
877 1.1.2.2 thorpej case _PC_SYNC_IO:
878 1.1.2.2 thorpej *ap->a_retval = 1;
879 1.1.2.2 thorpej return (0);
880 1.1.2.2 thorpej case _PC_FILESIZEBITS:
881 1.1.2.2 thorpej *ap->a_retval = 64;
882 1.1.2.2 thorpej return (0);
883 1.1.2.2 thorpej default:
884 1.1.2.2 thorpej return (EINVAL);
885 1.1.2.2 thorpej }
886 1.1.2.2 thorpej /* NOTREACHED */
887 1.1.2.2 thorpej }
888 1.1.2.2 thorpej
889 1.1.2.2 thorpej /*
890 1.1.2.2 thorpej * Global vfs data structures
891 1.1.2.2 thorpej */
892 1.1.2.2 thorpej vop_t **ntfs_vnodeop_p;
893 1.1.2.2 thorpej #if defined(__FreeBSD__)
894 1.1.2.2 thorpej static
895 1.1.2.2 thorpej struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = {
896 1.1.2.2 thorpej { &vop_default_desc, (vop_t *)ntfs_bypass },
897 1.1.2.2 thorpej
898 1.1.2.2 thorpej { &vop_getattr_desc, (vop_t *)ntfs_getattr },
899 1.1.2.2 thorpej { &vop_inactive_desc, (vop_t *)ntfs_inactive },
900 1.1.2.2 thorpej { &vop_reclaim_desc, (vop_t *)ntfs_reclaim },
901 1.1.2.2 thorpej { &vop_print_desc, (vop_t *)ntfs_print },
902 1.1.2.2 thorpej { &vop_pathconf_desc, ntfs_pathconf },
903 1.1.2.2 thorpej
904 1.1.2.2 thorpej { &vop_islocked_desc, (vop_t *)vop_stdislocked },
905 1.1.2.2 thorpej { &vop_unlock_desc, (vop_t *)vop_stdunlock },
906 1.1.2.2 thorpej { &vop_lock_desc, (vop_t *)vop_stdlock },
907 1.1.2.2 thorpej { &vop_cachedlookup_desc, (vop_t *)ntfs_lookup },
908 1.1.2.2 thorpej { &vop_lookup_desc, (vop_t *)vfs_cache_lookup },
909 1.1.2.2 thorpej
910 1.1.2.2 thorpej { &vop_access_desc, (vop_t *)ntfs_access },
911 1.1.2.2 thorpej { &vop_close_desc, (vop_t *)ntfs_close },
912 1.1.2.2 thorpej { &vop_open_desc, (vop_t *)ntfs_open },
913 1.1.2.2 thorpej { &vop_readdir_desc, (vop_t *)ntfs_readdir },
914 1.1.2.2 thorpej { &vop_fsync_desc, (vop_t *)ntfs_fsync },
915 1.1.2.2 thorpej
916 1.1.2.2 thorpej { &vop_bmap_desc, (vop_t *)ntfs_bmap },
917 1.1.2.2 thorpej { &vop_getpages_desc, (vop_t *) ntfs_getpages },
918 1.1.2.2 thorpej { &vop_putpages_desc, (vop_t *) ntfs_putpages },
919 1.1.2.2 thorpej { &vop_strategy_desc, (vop_t *)ntfs_strategy },
920 1.1.2.2 thorpej { &vop_bwrite_desc, (vop_t *)vop_stdbwrite },
921 1.1.2.2 thorpej { &vop_read_desc, (vop_t *)ntfs_read },
922 1.1.2.2 thorpej { &vop_write_desc, (vop_t *)ntfs_write },
923 1.1.2.2 thorpej
924 1.1.2.2 thorpej { NULL, NULL }
925 1.1.2.2 thorpej };
926 1.1.2.2 thorpej
927 1.1.2.2 thorpej static
928 1.1.2.2 thorpej struct vnodeopv_desc ntfs_vnodeop_opv_desc =
929 1.1.2.2 thorpej { &ntfs_vnodeop_p, ntfs_vnodeop_entries };
930 1.1.2.2 thorpej
931 1.1.2.2 thorpej VNODEOP_SET(ntfs_vnodeop_opv_desc);
932 1.1.2.2 thorpej
933 1.1.2.2 thorpej #else /* !FreeBSD */
934 1.1.2.2 thorpej
935 1.1.2.2 thorpej const struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = {
936 1.1.2.2 thorpej { &vop_default_desc, (vop_t *) ntfs_bypass },
937 1.1.2.2 thorpej { &vop_lookup_desc, (vop_t *) ntfs_lookup }, /* lookup */
938 1.1.2.2 thorpej { &vop_create_desc, genfs_eopnotsupp }, /* create */
939 1.1.2.2 thorpej { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */
940 1.1.2.2 thorpej { &vop_open_desc, (vop_t *) ntfs_open }, /* open */
941 1.1.2.2 thorpej { &vop_close_desc,(vop_t *) ntfs_close }, /* close */
942 1.1.2.2 thorpej { &vop_access_desc, (vop_t *) ntfs_access }, /* access */
943 1.1.2.2 thorpej { &vop_getattr_desc, (vop_t *) ntfs_getattr }, /* getattr */
944 1.1.2.2 thorpej { &vop_setattr_desc, genfs_eopnotsupp }, /* setattr */
945 1.1.2.2 thorpej { &vop_read_desc, (vop_t *) ntfs_read }, /* read */
946 1.1.2.2 thorpej { &vop_write_desc, (vop_t *) ntfs_write }, /* write */
947 1.1.2.2 thorpej { &vop_lease_desc, genfs_lease_check }, /* lease */
948 1.1.2.2 thorpej { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
949 1.1.2.2 thorpej { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */
950 1.1.2.2 thorpej { &vop_poll_desc, genfs_poll }, /* poll */
951 1.1.2.2 thorpej { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
952 1.1.2.2 thorpej { &vop_revoke_desc, genfs_revoke }, /* revoke */
953 1.1.2.2 thorpej { &vop_mmap_desc, genfs_mmap }, /* mmap */
954 1.1.2.2 thorpej { &vop_fsync_desc, genfs_fsync }, /* fsync */
955 1.1.2.2 thorpej { &vop_seek_desc, genfs_seek }, /* seek */
956 1.1.2.2 thorpej { &vop_remove_desc, genfs_eopnotsupp }, /* remove */
957 1.1.2.2 thorpej { &vop_link_desc, genfs_eopnotsupp }, /* link */
958 1.1.2.2 thorpej { &vop_rename_desc, genfs_eopnotsupp }, /* rename */
959 1.1.2.2 thorpej { &vop_mkdir_desc, genfs_eopnotsupp }, /* mkdir */
960 1.1.2.2 thorpej { &vop_rmdir_desc, genfs_eopnotsupp }, /* rmdir */
961 1.1.2.2 thorpej { &vop_symlink_desc, genfs_eopnotsupp }, /* symlink */
962 1.1.2.2 thorpej { &vop_readdir_desc, (vop_t *) ntfs_readdir }, /* readdir */
963 1.1.2.2 thorpej { &vop_readlink_desc, genfs_eopnotsupp }, /* readlink */
964 1.1.2.2 thorpej { &vop_abortop_desc, genfs_abortop }, /* abortop */
965 1.1.2.2 thorpej { &vop_inactive_desc, (vop_t *) ntfs_inactive }, /* inactive */
966 1.1.2.2 thorpej { &vop_reclaim_desc, (vop_t *) ntfs_reclaim }, /* reclaim */
967 1.1.2.2 thorpej { &vop_lock_desc, genfs_lock }, /* lock */
968 1.1.2.2 thorpej { &vop_unlock_desc, genfs_unlock }, /* unlock */
969 1.1.2.2 thorpej { &vop_bmap_desc, (vop_t *) ntfs_bmap }, /* bmap */
970 1.1.2.2 thorpej { &vop_strategy_desc, (vop_t *) ntfs_strategy }, /* strategy */
971 1.1.2.2 thorpej { &vop_print_desc, (vop_t *) ntfs_print }, /* print */
972 1.1.2.2 thorpej { &vop_islocked_desc, genfs_islocked }, /* islocked */
973 1.1.2.2 thorpej { &vop_pathconf_desc, ntfs_pathconf }, /* pathconf */
974 1.1.2.2 thorpej { &vop_advlock_desc, genfs_nullop }, /* advlock */
975 1.1.2.2 thorpej { &vop_blkatoff_desc, genfs_eopnotsupp }, /* blkatoff */
976 1.1.2.2 thorpej { &vop_valloc_desc, genfs_eopnotsupp }, /* valloc */
977 1.1.2.2 thorpej { &vop_reallocblks_desc, genfs_eopnotsupp }, /* reallocblks */
978 1.1.2.2 thorpej { &vop_vfree_desc, genfs_eopnotsupp }, /* vfree */
979 1.1.2.2 thorpej { &vop_truncate_desc, genfs_eopnotsupp }, /* truncate */
980 1.1.2.2 thorpej { &vop_update_desc, genfs_eopnotsupp }, /* update */
981 1.1.2.2 thorpej { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
982 1.1.2.2 thorpej { &vop_getpages_desc, genfs_compat_getpages }, /* getpages */
983 1.1.2.2 thorpej { &vop_putpages_desc, genfs_putpages }, /* putpages */
984 1.1.2.2 thorpej { NULL, NULL }
985 1.1.2.2 thorpej };
986 1.1.2.2 thorpej const struct vnodeopv_desc ntfs_vnodeop_opv_desc =
987 1.1.2.2 thorpej { &ntfs_vnodeop_p, ntfs_vnodeop_entries };
988 1.1.2.2 thorpej
989 1.1.2.2 thorpej #endif
990