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