1*db7aa982Smpi /* $OpenBSD: ntfs_subr.c,v 1.51 2020/02/27 09:10:31 mpi Exp $ */ 226f3deacStedu /* $NetBSD: ntfs_subr.c,v 1.4 2003/04/10 21:37:32 jdolecek Exp $ */ 326f3deacStedu 426f3deacStedu /*- 526f3deacStedu * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org) 626f3deacStedu * All rights reserved. 726f3deacStedu * 826f3deacStedu * Redistribution and use in source and binary forms, with or without 926f3deacStedu * modification, are permitted provided that the following conditions 1026f3deacStedu * are met: 1126f3deacStedu * 1. Redistributions of source code must retain the above copyright 1226f3deacStedu * notice, this list of conditions and the following disclaimer. 1326f3deacStedu * 2. Redistributions in binary form must reproduce the above copyright 1426f3deacStedu * notice, this list of conditions and the following disclaimer in the 1526f3deacStedu * documentation and/or other materials provided with the distribution. 1626f3deacStedu * 1726f3deacStedu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1826f3deacStedu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1926f3deacStedu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2026f3deacStedu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2126f3deacStedu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2226f3deacStedu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2326f3deacStedu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2426f3deacStedu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2526f3deacStedu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2626f3deacStedu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2726f3deacStedu * SUCH DAMAGE. 2826f3deacStedu * 2926f3deacStedu * Id: ntfs_subr.c,v 1.4 1999/05/12 09:43:01 semenu Exp 3026f3deacStedu */ 3126f3deacStedu 3226f3deacStedu #include <sys/param.h> 3326f3deacStedu #include <sys/systm.h> 3426f3deacStedu #include <sys/namei.h> 3526f3deacStedu #include <sys/kernel.h> 3626f3deacStedu #include <sys/vnode.h> 370ae9dfeaStedu #include <sys/lock.h> 3826f3deacStedu #include <sys/mount.h> 3926f3deacStedu #include <sys/buf.h> 4026f3deacStedu #include <sys/malloc.h> 41c74ceabfSoga #include <sys/rwlock.h> 42544451c3Sderaadt #include <sys/specdev.h> 4326f3deacStedu 4426f3deacStedu /* #define NTFS_DEBUG 1 */ 4526f3deacStedu #include <ntfs/ntfs.h> 4626f3deacStedu #include <ntfs/ntfsmount.h> 4726f3deacStedu #include <ntfs/ntfs_inode.h> 4826f3deacStedu #include <ntfs/ntfs_vfsops.h> 4926f3deacStedu #include <ntfs/ntfs_subr.h> 5026f3deacStedu #include <ntfs/ntfs_compr.h> 5126f3deacStedu #include <ntfs/ntfs_ihash.h> 5226f3deacStedu 5326f3deacStedu #if defined(NTFS_DEBUG) 5426f3deacStedu int ntfs_debug = NTFS_DEBUG; 5526f3deacStedu #endif 5626f3deacStedu 5726f3deacStedu /* Local struct used in ntfs_ntlookupfile() */ 5826f3deacStedu struct ntfs_lookup_ctx { 5926f3deacStedu u_int32_t aoff; 6026f3deacStedu u_int32_t rdsize; 6126f3deacStedu cn_t cn; 6226f3deacStedu struct ntfs_lookup_ctx *prev; 6326f3deacStedu }; 6426f3deacStedu 6505c5dae5Sjsing int ntfs_ntlookupattr(struct ntfsmount *, const char *, int, int *, char **); 6605c5dae5Sjsing int ntfs_findvattr(struct ntfsmount *, struct ntnode *, struct ntvattr **, struct ntvattr **, u_int32_t, const char *, size_t, cn_t); 6705c5dae5Sjsing int ntfs_uastricmp(struct ntfsmount *, const wchar *, size_t, const char *, size_t); 6805c5dae5Sjsing int ntfs_uastrcmp(struct ntfsmount *, const wchar *, size_t, const char *, size_t); 6926f3deacStedu 70274476fcStedu /* table for mapping Unicode chars into uppercase; it's filled upon first 71274476fcStedu * ntfs mount, freed upon last ntfs umount */ 7226f3deacStedu static wchar *ntfs_toupper_tab; 7326f3deacStedu #define NTFS_U28(ch) ((((ch) & 0xE0) == 0) ? '_' : (ch) & 0xFF) 7426f3deacStedu #define NTFS_TOUPPER(ch) (ntfs_toupper_tab[(unsigned char)(ch)]) 75274476fcStedu struct rwlock ntfs_toupper_lock = RWLOCK_INITIALIZER("ntfs_toupper"); 76274476fcStedu static signed int ntfs_toupper_usecount; 7726f3deacStedu 7826f3deacStedu /* support macro for ntfs_ntvattrget() */ 7926f3deacStedu #define NTFS_AALPCMP(aalp,type,name,namelen) ( \ 8026f3deacStedu (aalp->al_type == type) && (aalp->al_namelen == namelen) && \ 8126f3deacStedu !ntfs_uastrcmp(ntmp, aalp->al_name,aalp->al_namelen,name,namelen) ) 8226f3deacStedu 8326f3deacStedu /* 8426f3deacStedu * 8526f3deacStedu */ 8626f3deacStedu int 871cc0505dSjsing ntfs_ntvattrrele(struct ntvattr *vap) 8826f3deacStedu { 89f2997212Sjsing DPRINTF("ntfs_ntvattrrele: ino: %u, type: 0x%x\n", 90a1ea65c6Sjsing vap->va_ip->i_number, vap->va_type); 9126f3deacStedu 9226f3deacStedu ntfs_ntrele(vap->va_ip); 9326f3deacStedu 9426f3deacStedu return (0); 9526f3deacStedu } 9626f3deacStedu 9726f3deacStedu /* 9826f3deacStedu * find the attribute in the ntnode 9926f3deacStedu */ 10005c5dae5Sjsing int 1011cc0505dSjsing ntfs_findvattr(struct ntfsmount *ntmp, struct ntnode *ip, 1021cc0505dSjsing struct ntvattr **lvapp, struct ntvattr **vapp, u_int32_t type, 1031cc0505dSjsing const char *name, size_t namelen, cn_t vcn) 10426f3deacStedu { 10526f3deacStedu int error; 10626f3deacStedu struct ntvattr *vap; 10726f3deacStedu 10826f3deacStedu if((ip->i_flag & IN_LOADED) == 0) { 109f2997212Sjsing DPRINTF("ntfs_findvattr: node not loaded, ino: %u\n", 110a1ea65c6Sjsing ip->i_number); 11126f3deacStedu error = ntfs_loadntnode(ntmp,ip); 11226f3deacStedu if (error) { 11326f3deacStedu printf("ntfs_findvattr: FAILED TO LOAD INO: %d\n", 11426f3deacStedu ip->i_number); 11526f3deacStedu return (error); 11626f3deacStedu } 1178fc6378aSjsing } else { 1188fc6378aSjsing /* Update LRU loaded list. */ 1198fc6378aSjsing TAILQ_REMOVE(&ntmp->ntm_ntnodeq, ip, i_loaded); 1208fc6378aSjsing TAILQ_INSERT_HEAD(&ntmp->ntm_ntnodeq, ip, i_loaded); 12126f3deacStedu } 12226f3deacStedu 12326f3deacStedu *lvapp = NULL; 12426f3deacStedu *vapp = NULL; 1251573508eSmiod LIST_FOREACH(vap, &ip->i_valist, va_list) { 126f2997212Sjsing DDPRINTF("ntfs_findvattr: type: 0x%x, vcn: %llu - %llu\n", 127f2997212Sjsing vap->va_type, vap->va_vcnstart, vap->va_vcnend); 12826f3deacStedu if ((vap->va_type == type) && 12926f3deacStedu (vap->va_vcnstart <= vcn) && (vap->va_vcnend >= vcn) && 13026f3deacStedu (vap->va_namelen == namelen) && 13126f3deacStedu (strncmp(name, vap->va_name, namelen) == 0)) { 13226f3deacStedu *vapp = vap; 13326f3deacStedu ntfs_ntref(vap->va_ip); 13426f3deacStedu return (0); 13526f3deacStedu } 13626f3deacStedu if (vap->va_type == NTFS_A_ATTRLIST) 13726f3deacStedu *lvapp = vap; 13826f3deacStedu } 13926f3deacStedu 14026f3deacStedu return (-1); 14126f3deacStedu } 14226f3deacStedu 14326f3deacStedu /* 14426f3deacStedu * Search attribute specified in ntnode (load ntnode if necessary). 14526f3deacStedu * If not found but ATTR_A_ATTRLIST present, read it in and search through. 146cec6d865Smiod * VOP_VGET node needed, and lookup through its ntnode (load if necessary). 14726f3deacStedu * 14826f3deacStedu * ntnode should be locked 14926f3deacStedu */ 15026f3deacStedu int 1511cc0505dSjsing ntfs_ntvattrget(struct ntfsmount *ntmp, struct ntnode *ip, u_int32_t type, 1521cc0505dSjsing const char *name, cn_t vcn, struct ntvattr **vapp) 15326f3deacStedu { 15426f3deacStedu struct ntvattr *lvap = NULL; 15526f3deacStedu struct attr_attrlist *aalp; 15626f3deacStedu struct attr_attrlist *nextaalp; 15726f3deacStedu struct vnode *newvp; 15826f3deacStedu struct ntnode *newip; 15926f3deacStedu caddr_t alpool; 16026f3deacStedu size_t namelen, len; 16126f3deacStedu int error; 16226f3deacStedu 16326f3deacStedu *vapp = NULL; 16426f3deacStedu 16526f3deacStedu if (name) { 166f2997212Sjsing DPRINTF("ntfs_ntvattrget: ino: %u, type: 0x%x, name: %s, " 167f2997212Sjsing "vcn: %llu\n", ip->i_number, type, name, vcn); 16826f3deacStedu namelen = strlen(name); 16926f3deacStedu } else { 170f2997212Sjsing DPRINTF("ntfs_ntvattrget: ino: %u, type: 0x%x, vcn: %llu\n", 171f2997212Sjsing ip->i_number, type, vcn); 17226f3deacStedu name = ""; 17326f3deacStedu namelen = 0; 17426f3deacStedu } 17526f3deacStedu 17626f3deacStedu error = ntfs_findvattr(ntmp, ip, &lvap, vapp, type, name, namelen, vcn); 17726f3deacStedu if (error >= 0) 17826f3deacStedu return (error); 17926f3deacStedu 18026f3deacStedu if (!lvap) { 181f2997212Sjsing DPRINTF("ntfs_ntvattrget: UNEXISTED ATTRIBUTE: ino: %u, " 182f2997212Sjsing "type: 0x%x, name: %s, vcn: %llu\n", ip->i_number, type, 183f2997212Sjsing name, vcn); 18426f3deacStedu return (ENOENT); 18526f3deacStedu } 18626f3deacStedu /* Scan $ATTRIBUTE_LIST for requested attribute */ 18726f3deacStedu len = lvap->va_datalen; 188c6c302e5Stedu alpool = malloc(len, M_TEMP, M_WAITOK); 18926f3deacStedu error = ntfs_readntvattr_plain(ntmp, ip, lvap, 0, len, alpool, &len, 19026f3deacStedu NULL); 19126f3deacStedu if (error) 19226f3deacStedu goto out; 19326f3deacStedu 19426f3deacStedu aalp = (struct attr_attrlist *) alpool; 19526f3deacStedu nextaalp = NULL; 19626f3deacStedu 19726f3deacStedu for(; len > 0; aalp = nextaalp) { 198f2997212Sjsing DPRINTF("ntfs_ntvattrget: attrlist: ino: %u, attr: 0x%x, " 199f2997212Sjsing "vcn: %llu\n", aalp->al_inumber, aalp->al_type, 200f2997212Sjsing aalp->al_vcnstart); 20126f3deacStedu 20226f3deacStedu if (len > aalp->reclen) { 20326f3deacStedu nextaalp = NTFS_NEXTREC(aalp, struct attr_attrlist *); 20426f3deacStedu } else { 20526f3deacStedu nextaalp = NULL; 20626f3deacStedu } 20726f3deacStedu len -= aalp->reclen; 20826f3deacStedu 20926f3deacStedu if (!NTFS_AALPCMP(aalp, type, name, namelen) || 21026f3deacStedu (nextaalp && (nextaalp->al_vcnstart <= vcn) && 21126f3deacStedu NTFS_AALPCMP(nextaalp, type, name, namelen))) 21226f3deacStedu continue; 21326f3deacStedu 214f2997212Sjsing DPRINTF("ntfs_ntvattrget: attribute in ino: %u\n", 215a1ea65c6Sjsing aalp->al_inumber); 21626f3deacStedu 21726f3deacStedu /* this is not a main record, so we can't use just plain 21826f3deacStedu vget() */ 21926f3deacStedu error = ntfs_vgetex(ntmp->ntm_mountp, aalp->al_inumber, 22026f3deacStedu NTFS_A_DATA, NULL, LK_EXCLUSIVE, 221*db7aa982Smpi VG_EXT, &newvp); 22226f3deacStedu if (error) { 22326f3deacStedu printf("ntfs_ntvattrget: CAN'T VGET INO: %d\n", 22426f3deacStedu aalp->al_inumber); 22526f3deacStedu goto out; 22626f3deacStedu } 22726f3deacStedu newip = VTONT(newvp); 22826f3deacStedu /* XXX have to lock ntnode */ 22926f3deacStedu error = ntfs_findvattr(ntmp, newip, &lvap, vapp, 23026f3deacStedu type, name, namelen, vcn); 23126f3deacStedu vput(newvp); 23226f3deacStedu if (error == 0) 23326f3deacStedu goto out; 23426f3deacStedu printf("ntfs_ntvattrget: ATTRLIST ERROR.\n"); 23526f3deacStedu break; 23626f3deacStedu } 23726f3deacStedu error = ENOENT; 23826f3deacStedu 239f2997212Sjsing DPRINTF("ntfs_ntvattrget: UNEXISTED ATTRIBUTE: ino: %u, type: 0x%x, " 240f2997212Sjsing "name: %.*s, vcn: %llu\n", ip->i_number, type, 241f2997212Sjsing (unsigned int)namelen, name, vcn); 24226f3deacStedu out: 243825c4e6aStedu free(alpool, M_TEMP, 0); 24426f3deacStedu return (error); 24526f3deacStedu } 24626f3deacStedu 24726f3deacStedu /* 24826f3deacStedu * Read ntnode from disk, make ntvattr list. 24926f3deacStedu * 25026f3deacStedu * ntnode should be locked 25126f3deacStedu */ 25226f3deacStedu int 2531cc0505dSjsing ntfs_loadntnode(struct ntfsmount *ntmp, struct ntnode *ip) 25426f3deacStedu { 2558fc6378aSjsing struct ntnode *oip; 2568fc6378aSjsing struct ntvattr *vap; 25726f3deacStedu struct filerec *mfrp; 2588fc6378aSjsing struct attr *ap; 2591abdbfdeSderaadt daddr_t bn; 26026f3deacStedu int error,off; 26126f3deacStedu 262f2997212Sjsing DPRINTF("ntfs_loadntnode: loading ino: %u\n", ip->i_number); 26326f3deacStedu 2648fc6378aSjsing KASSERT((ip->i_flag & IN_LOADED) == 0); 2658fc6378aSjsing 2668fc6378aSjsing if (ntmp->ntm_ntnodes >= LOADED_NTNODE_HI) { 2678fc6378aSjsing oip = TAILQ_LAST(&ntmp->ntm_ntnodeq, ntnodeq); 2688fc6378aSjsing TAILQ_REMOVE(&ntmp->ntm_ntnodeq, oip, i_loaded); 2698fc6378aSjsing ntmp->ntm_ntnodes--; 2708fc6378aSjsing 271f2997212Sjsing DPRINTF("ntfs_loadntnode: unloading ino: %u\n", oip->i_number); 2728fc6378aSjsing 2738fc6378aSjsing KASSERT((oip->i_flag & IN_LOADED)); 2748fc6378aSjsing oip->i_flag &= ~IN_LOADED; 2758fc6378aSjsing while ((vap = LIST_FIRST(&oip->i_valist)) != NULL) { 2768fc6378aSjsing LIST_REMOVE(vap, va_list); 2778fc6378aSjsing ntfs_freentvattr(vap); 2788fc6378aSjsing } 2798fc6378aSjsing } 2808fc6378aSjsing 281c6c302e5Stedu mfrp = malloc(ntfs_bntob(ntmp->ntm_bpmftrec), M_TEMP, M_WAITOK); 28226f3deacStedu 28326f3deacStedu if (ip->i_number < NTFS_SYSNODESNUM) { 28426f3deacStedu struct buf *bp; 28526f3deacStedu 286a1ea65c6Sjsing DPRINTF("ntfs_loadntnode: read system node\n"); 28726f3deacStedu 28826f3deacStedu bn = ntfs_cntobn(ntmp->ntm_mftcn) + 28926f3deacStedu ntmp->ntm_bpmftrec * ip->i_number; 29026f3deacStedu 29193f62a9eStedu error = bread(ntmp->ntm_devvp, bn, 29293f62a9eStedu ntfs_bntob(ntmp->ntm_bpmftrec), &bp); 29326f3deacStedu if (error) { 29426f3deacStedu printf("ntfs_loadntnode: BREAD FAILED\n"); 29526f3deacStedu brelse(bp); 29626f3deacStedu goto out; 29726f3deacStedu } 29826f3deacStedu memcpy(mfrp, bp->b_data, ntfs_bntob(ntmp->ntm_bpmftrec)); 299c6c302e5Stedu brelse(bp); 30026f3deacStedu } else { 30126f3deacStedu struct vnode *vp; 30226f3deacStedu 30326f3deacStedu vp = ntmp->ntm_sysvn[NTFS_MFTINO]; 30426f3deacStedu error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL, 30526f3deacStedu ip->i_number * ntfs_bntob(ntmp->ntm_bpmftrec), 30626f3deacStedu ntfs_bntob(ntmp->ntm_bpmftrec), mfrp, NULL); 30726f3deacStedu if (error) { 30826f3deacStedu printf("ntfs_loadntnode: ntfs_readattr failed\n"); 30926f3deacStedu goto out; 31026f3deacStedu } 31126f3deacStedu } 31226f3deacStedu 31326f3deacStedu /* Check if magic and fixups are correct */ 31426f3deacStedu error = ntfs_procfixups(ntmp, NTFS_FILEMAGIC, (caddr_t)mfrp, 31526f3deacStedu ntfs_bntob(ntmp->ntm_bpmftrec)); 31626f3deacStedu if (error) { 31726f3deacStedu printf("ntfs_loadntnode: BAD MFT RECORD %d\n", 31826f3deacStedu (u_int32_t) ip->i_number); 31926f3deacStedu goto out; 32026f3deacStedu } 32126f3deacStedu 322f2997212Sjsing DPRINTF("ntfs_loadntnode: load attrs for ino: %u\n", ip->i_number); 32326f3deacStedu off = mfrp->fr_attroff; 32426f3deacStedu ap = (struct attr *) ((caddr_t)mfrp + off); 32526f3deacStedu 32626f3deacStedu LIST_INIT(&ip->i_valist); 32726f3deacStedu 32826f3deacStedu while (ap->a_hdr.a_type != -1) { 3298fc6378aSjsing error = ntfs_attrtontvattr(ntmp, &vap, ap); 33026f3deacStedu if (error) 33126f3deacStedu break; 3328fc6378aSjsing vap->va_ip = ip; 33326f3deacStedu 3348fc6378aSjsing LIST_INSERT_HEAD(&ip->i_valist, vap, va_list); 33526f3deacStedu 33626f3deacStedu off += ap->a_hdr.reclen; 33726f3deacStedu ap = (struct attr *) ((caddr_t)mfrp + off); 33826f3deacStedu } 33926f3deacStedu if (error) { 34026f3deacStedu printf("ntfs_loadntnode: failed to load attr ino: %d\n", 34126f3deacStedu ip->i_number); 34226f3deacStedu goto out; 34326f3deacStedu } 34426f3deacStedu 34526f3deacStedu ip->i_mainrec = mfrp->fr_mainrec; 34626f3deacStedu ip->i_nlink = mfrp->fr_nlink; 34726f3deacStedu ip->i_frflag = mfrp->fr_flags; 34826f3deacStedu 34926f3deacStedu ip->i_flag |= IN_LOADED; 35026f3deacStedu 3518fc6378aSjsing /* Add to loaded list. */ 3528fc6378aSjsing TAILQ_INSERT_HEAD(&ntmp->ntm_ntnodeq, ip, i_loaded); 3538fc6378aSjsing ntmp->ntm_ntnodes++; 3548fc6378aSjsing 35526f3deacStedu out: 356825c4e6aStedu free(mfrp, M_TEMP, 0); 35726f3deacStedu return (error); 35826f3deacStedu } 35926f3deacStedu 36026f3deacStedu /* 36126f3deacStedu * Routine locks ntnode and increase usecount, just opposite of 36226f3deacStedu * ntfs_ntput(). 36326f3deacStedu */ 36426f3deacStedu int 365*db7aa982Smpi ntfs_ntget(struct ntnode *ip) 36626f3deacStedu { 367f2997212Sjsing DPRINTF("ntfs_ntget: get ntnode %u: %p, usecount: %d\n", 368a1ea65c6Sjsing ip->i_number, ip, ip->i_usecount); 36926f3deacStedu 37026f3deacStedu ip->i_usecount++; 3712752fedbSpedro 372c74ceabfSoga rw_enter_write(&ip->i_lock); 37326f3deacStedu 37426f3deacStedu return 0; 37526f3deacStedu } 37626f3deacStedu 37726f3deacStedu /* 37826f3deacStedu * Routine search ntnode in hash, if found: lock, inc usecount and return. 37926f3deacStedu * If not in hash allocate structure for ntnode, prefill it, lock, 38026f3deacStedu * inc count and return. 38126f3deacStedu * 38226f3deacStedu * ntnode returned locked 38326f3deacStedu */ 38426f3deacStedu int 385*db7aa982Smpi ntfs_ntlookup(struct ntfsmount *ntmp, ntfsino_t ino, struct ntnode **ipp) 38626f3deacStedu { 38726f3deacStedu struct ntnode *ip; 38826f3deacStedu 389f2997212Sjsing DPRINTF("ntfs_ntlookup: looking for ntnode %u\n", ino); 39026f3deacStedu 39126f3deacStedu do { 39226f3deacStedu if ((ip = ntfs_nthashlookup(ntmp->ntm_dev, ino)) != NULL) { 393*db7aa982Smpi ntfs_ntget(ip); 394f2997212Sjsing DPRINTF("ntfs_ntlookup: ntnode %u: %p, usecount: %d\n", 395a1ea65c6Sjsing ino, ip, ip->i_usecount); 39626f3deacStedu *ipp = ip; 39726f3deacStedu return (0); 39826f3deacStedu } 399c74ceabfSoga } while (rw_enter(&ntfs_hashlock, RW_WRITE | RW_SLEEPFAIL)); 40026f3deacStedu 401c86f0003Skrw ip = malloc(sizeof(*ip), M_NTFSNTNODE, M_WAITOK | M_ZERO); 402f2997212Sjsing DDPRINTF("ntfs_ntlookup: allocating ntnode: %u: %p\n", ino, ip); 40326f3deacStedu 40426f3deacStedu /* Generic initialization */ 40526f3deacStedu ip->i_devvp = ntmp->ntm_devvp; 40626f3deacStedu ip->i_dev = ntmp->ntm_dev; 40726f3deacStedu ip->i_number = ino; 40826f3deacStedu ip->i_mp = ntmp; 40926f3deacStedu 41026f3deacStedu LIST_INIT(&ip->i_fnlist); 411627b2c48Sthib vref(ip->i_devvp); 41226f3deacStedu 41326f3deacStedu /* init lock and lock the newborn ntnode */ 414c74ceabfSoga rw_init(&ip->i_lock, "ntnode"); 415*db7aa982Smpi ntfs_ntget(ip); 41626f3deacStedu 41726f3deacStedu ntfs_nthashins(ip); 41826f3deacStedu 419c74ceabfSoga rw_exit(&ntfs_hashlock); 42026f3deacStedu 42126f3deacStedu *ipp = ip; 42226f3deacStedu 423f2997212Sjsing DPRINTF("ntfs_ntlookup: ntnode %u: %p, usecount: %d\n", 424a1ea65c6Sjsing ino, ip, ip->i_usecount); 42526f3deacStedu 42626f3deacStedu return (0); 42726f3deacStedu } 42826f3deacStedu 42926f3deacStedu /* 43026f3deacStedu * Decrement usecount of ntnode and unlock it, if usecount reach zero, 43126f3deacStedu * deallocate ntnode. 43226f3deacStedu * 43326f3deacStedu * ntnode should be locked on entry, and unlocked on return. 43426f3deacStedu */ 43526f3deacStedu void 436*db7aa982Smpi ntfs_ntput(struct ntnode *ip) 43726f3deacStedu { 4388fc6378aSjsing struct ntfsmount *ntmp = ip->i_mp; 43926f3deacStedu struct ntvattr *vap; 44026f3deacStedu 441f2997212Sjsing DPRINTF("ntfs_ntput: rele ntnode %u: %p, usecount: %d\n", 442a1ea65c6Sjsing ip->i_number, ip, ip->i_usecount); 44326f3deacStedu 44426f3deacStedu ip->i_usecount--; 44526f3deacStedu 44626f3deacStedu #ifdef DIAGNOSTIC 44726f3deacStedu if (ip->i_usecount < 0) { 44826f3deacStedu panic("ntfs_ntput: ino: %d usecount: %d ", 44926f3deacStedu ip->i_number,ip->i_usecount); 45026f3deacStedu } 45126f3deacStedu #endif 45226f3deacStedu 4539b32ea3cSpat if (ip->i_usecount > 0) { 454c74ceabfSoga rw_exit_write(&ip->i_lock); 4559b32ea3cSpat return; 4569b32ea3cSpat } 45726f3deacStedu 458f2997212Sjsing DPRINTF("ntfs_ntput: deallocating ntnode: %u\n", ip->i_number); 45926f3deacStedu 4609b32ea3cSpat if (LIST_FIRST(&ip->i_fnlist)) 46126f3deacStedu panic("ntfs_ntput: ntnode has fnodes"); 46226f3deacStedu 46326f3deacStedu ntfs_nthashrem(ip); 46426f3deacStedu 4658fc6378aSjsing /* Remove from loaded list. */ 4668fc6378aSjsing if (ip->i_flag & IN_LOADED) { 4678fc6378aSjsing TAILQ_REMOVE(&ntmp->ntm_ntnodeq, ip, i_loaded); 4688fc6378aSjsing ntmp->ntm_ntnodes--; 4698fc6378aSjsing } 4708fc6378aSjsing 4719b32ea3cSpat while ((vap = LIST_FIRST(&ip->i_valist)) != NULL) { 47226f3deacStedu LIST_REMOVE(vap, va_list); 47326f3deacStedu ntfs_freentvattr(vap); 47426f3deacStedu } 4759b32ea3cSpat 4769b32ea3cSpat vrele(ip->i_devvp); 477825c4e6aStedu free(ip, M_NTFSNTNODE, 0); 47826f3deacStedu } 47926f3deacStedu 48026f3deacStedu /* 48126f3deacStedu * increment usecount of ntnode 48226f3deacStedu */ 48326f3deacStedu void 4841cc0505dSjsing ntfs_ntref(struct ntnode *ip) 48526f3deacStedu { 48626f3deacStedu ip->i_usecount++; 48726f3deacStedu 488f2997212Sjsing DPRINTF("ntfs_ntref: ino %u, usecount: %d\n", 489a1ea65c6Sjsing ip->i_number, ip->i_usecount); 49026f3deacStedu } 49126f3deacStedu 49226f3deacStedu /* 49326f3deacStedu * Decrement usecount of ntnode. 49426f3deacStedu */ 49526f3deacStedu void 4961cc0505dSjsing ntfs_ntrele(struct ntnode *ip) 49726f3deacStedu { 498f2997212Sjsing DPRINTF("ntfs_ntrele: rele ntnode %u: %p, usecount: %d\n", 499a1ea65c6Sjsing ip->i_number, ip, ip->i_usecount); 50026f3deacStedu 50126f3deacStedu ip->i_usecount--; 50226f3deacStedu 50326f3deacStedu if (ip->i_usecount < 0) 50426f3deacStedu panic("ntfs_ntrele: ino: %d usecount: %d ", 50526f3deacStedu ip->i_number,ip->i_usecount); 50626f3deacStedu } 50726f3deacStedu 50826f3deacStedu /* 50926f3deacStedu * Deallocate all memory allocated for ntvattr 51026f3deacStedu */ 51126f3deacStedu void 5121cc0505dSjsing ntfs_freentvattr(struct ntvattr *vap) 51326f3deacStedu { 51426f3deacStedu if (vap->va_flag & NTFS_AF_INRUN) { 51526f3deacStedu if (vap->va_vruncn) 516825c4e6aStedu free(vap->va_vruncn, M_NTFSRUN, 0); 51726f3deacStedu if (vap->va_vruncl) 518825c4e6aStedu free(vap->va_vruncl, M_NTFSRUN, 0); 51926f3deacStedu } else { 52026f3deacStedu if (vap->va_datap) 521825c4e6aStedu free(vap->va_datap, M_NTFSRDATA, 0); 52226f3deacStedu } 523825c4e6aStedu free(vap, M_NTFSNTVATTR, 0); 52426f3deacStedu } 52526f3deacStedu 52626f3deacStedu /* 52726f3deacStedu * Convert disk image of attribute into ntvattr structure, 52826f3deacStedu * runs are expanded also. 52926f3deacStedu */ 53026f3deacStedu int 5311cc0505dSjsing ntfs_attrtontvattr(struct ntfsmount *ntmp, struct ntvattr **rvapp, 53226f3deacStedu struct attr *rap) 53326f3deacStedu { 53426f3deacStedu int error, i; 53526f3deacStedu struct ntvattr *vap; 53626f3deacStedu 53726f3deacStedu error = 0; 53826f3deacStedu *rvapp = NULL; 53926f3deacStedu 540c86f0003Skrw vap = malloc(sizeof(*vap), M_NTFSNTVATTR, M_WAITOK | M_ZERO); 54126f3deacStedu vap->va_ip = NULL; 54226f3deacStedu vap->va_flag = rap->a_hdr.a_flag; 54326f3deacStedu vap->va_type = rap->a_hdr.a_type; 54426f3deacStedu vap->va_compression = rap->a_hdr.a_compression; 54526f3deacStedu vap->va_index = rap->a_hdr.a_index; 54626f3deacStedu 547f2997212Sjsing DDPRINTF("type: 0x%x, index: %u", vap->va_type, vap->va_index); 54826f3deacStedu 54926f3deacStedu vap->va_namelen = rap->a_hdr.a_namelen; 55026f3deacStedu if (rap->a_hdr.a_namelen) { 55126f3deacStedu wchar *unp = (wchar *) ((caddr_t) rap + rap->a_hdr.a_nameoff); 552a1ea65c6Sjsing DDPRINTF(", name:["); 55326f3deacStedu for (i = 0; i < vap->va_namelen; i++) { 55426f3deacStedu vap->va_name[i] = unp[i]; 555a1ea65c6Sjsing DDPRINTF("%c", vap->va_name[i]); 55626f3deacStedu } 557a1ea65c6Sjsing DDPRINTF("]"); 55826f3deacStedu } 55926f3deacStedu if (vap->va_flag & NTFS_AF_INRUN) { 560a1ea65c6Sjsing DDPRINTF(", nonres."); 56126f3deacStedu vap->va_datalen = rap->a_nr.a_datalen; 56226f3deacStedu vap->va_allocated = rap->a_nr.a_allocated; 56326f3deacStedu vap->va_vcnstart = rap->a_nr.a_vcnstart; 56426f3deacStedu vap->va_vcnend = rap->a_nr.a_vcnend; 56526f3deacStedu vap->va_compressalg = rap->a_nr.a_compressalg; 56626f3deacStedu error = ntfs_runtovrun(&(vap->va_vruncn), &(vap->va_vruncl), 56726f3deacStedu &(vap->va_vruncnt), 56826f3deacStedu (caddr_t) rap + rap->a_nr.a_dataoff); 56926f3deacStedu } else { 57026f3deacStedu vap->va_compressalg = 0; 571a1ea65c6Sjsing DDPRINTF(", res."); 57226f3deacStedu vap->va_datalen = rap->a_r.a_datalen; 57326f3deacStedu vap->va_allocated = rap->a_r.a_datalen; 57426f3deacStedu vap->va_vcnstart = 0; 57526f3deacStedu vap->va_vcnend = ntfs_btocn(vap->va_allocated); 576c6c302e5Stedu vap->va_datap = malloc(vap->va_datalen, M_NTFSRDATA, M_WAITOK); 57726f3deacStedu memcpy(vap->va_datap, (caddr_t) rap + rap->a_r.a_dataoff, 57826f3deacStedu rap->a_r.a_datalen); 57926f3deacStedu } 5805adbeedcSjsing DDPRINTF(", len: %llu", vap->va_datalen); 58126f3deacStedu 58226f3deacStedu if (error) 583825c4e6aStedu free(vap, M_NTFSNTVATTR, 0); 58426f3deacStedu else 58526f3deacStedu *rvapp = vap; 58626f3deacStedu 587a1ea65c6Sjsing DDPRINTF("\n"); 58826f3deacStedu 58926f3deacStedu return (error); 59026f3deacStedu } 59126f3deacStedu 59226f3deacStedu /* 59326f3deacStedu * Expand run into more utilizable and more memory eating format. 59426f3deacStedu */ 59526f3deacStedu int 5961cc0505dSjsing ntfs_runtovrun(cn_t **rcnp, cn_t **rclp, u_long *rcntp, u_int8_t *run) 59726f3deacStedu { 59826f3deacStedu u_int32_t off; 59926f3deacStedu u_int32_t sz, i; 60026f3deacStedu cn_t *cn; 60126f3deacStedu cn_t *cl; 60226f3deacStedu u_long cnt; 60326f3deacStedu cn_t prev; 60426f3deacStedu cn_t tmp; 60526f3deacStedu 60626f3deacStedu off = 0; 60726f3deacStedu cnt = 0; 60826f3deacStedu while (run[off]) { 60926f3deacStedu off += (run[off] & 0xF) + ((run[off] >> 4) & 0xF) + 1; 61026f3deacStedu cnt++; 61126f3deacStedu } 612540e394aSdoug cn = mallocarray(cnt, sizeof(cn_t), M_NTFSRUN, M_WAITOK); 613540e394aSdoug cl = mallocarray(cnt, sizeof(cn_t), M_NTFSRUN, M_WAITOK); 61426f3deacStedu 61526f3deacStedu off = 0; 61626f3deacStedu cnt = 0; 61726f3deacStedu prev = 0; 61826f3deacStedu while (run[off]) { 61926f3deacStedu 62026f3deacStedu sz = run[off++]; 62126f3deacStedu cl[cnt] = 0; 62226f3deacStedu 62326f3deacStedu for (i = 0; i < (sz & 0xF); i++) 62426f3deacStedu cl[cnt] += (u_int32_t) run[off++] << (i << 3); 62526f3deacStedu 62626f3deacStedu sz >>= 4; 62726f3deacStedu if (run[off + sz - 1] & 0x80) { 62826f3deacStedu tmp = ((u_int64_t) - 1) << (sz << 3); 62926f3deacStedu for (i = 0; i < sz; i++) 63026f3deacStedu tmp |= (u_int64_t) run[off++] << (i << 3); 63126f3deacStedu } else { 63226f3deacStedu tmp = 0; 63326f3deacStedu for (i = 0; i < sz; i++) 63426f3deacStedu tmp |= (u_int64_t) run[off++] << (i << 3); 63526f3deacStedu } 63626f3deacStedu if (tmp) 63726f3deacStedu prev = cn[cnt] = prev + tmp; 63826f3deacStedu else 63926f3deacStedu cn[cnt] = tmp; 64026f3deacStedu 64126f3deacStedu cnt++; 64226f3deacStedu } 64326f3deacStedu *rcnp = cn; 64426f3deacStedu *rclp = cl; 64526f3deacStedu *rcntp = cnt; 64626f3deacStedu return (0); 64726f3deacStedu } 64826f3deacStedu 64926f3deacStedu /* 65026f3deacStedu * Compare unicode and ascii string case insens. 65126f3deacStedu */ 65205c5dae5Sjsing int 6531cc0505dSjsing ntfs_uastricmp(struct ntfsmount *ntmp, const wchar *ustr, size_t ustrlen, 6541cc0505dSjsing const char *astr, size_t astrlen) 65526f3deacStedu { 65626f3deacStedu size_t i; 65726f3deacStedu int res; 65826f3deacStedu const char *astrend = astr + astrlen; 65926f3deacStedu 66026f3deacStedu for (i = 0; i < ustrlen && astr < astrend; i++) { 66126f3deacStedu res = (*ntmp->ntm_wcmp)(NTFS_TOUPPER(ustr[i]), 66226f3deacStedu NTFS_TOUPPER((*ntmp->ntm_wget)(&astr)) ); 66326f3deacStedu if (res) 66426f3deacStedu return res; 66526f3deacStedu } 66626f3deacStedu 66726f3deacStedu if (i == ustrlen && astr == astrend) 66826f3deacStedu return 0; 66926f3deacStedu else if (i == ustrlen) 67026f3deacStedu return -1; 67126f3deacStedu else 67226f3deacStedu return 1; 67326f3deacStedu } 67426f3deacStedu 67526f3deacStedu /* 67626f3deacStedu * Compare unicode and ascii string case sens. 67726f3deacStedu */ 67805c5dae5Sjsing int 6791cc0505dSjsing ntfs_uastrcmp(struct ntfsmount *ntmp, const wchar *ustr, size_t ustrlen, 6801cc0505dSjsing const char *astr, size_t astrlen) 68126f3deacStedu { 68226f3deacStedu size_t i; 68326f3deacStedu int res; 68426f3deacStedu const char *astrend = astr + astrlen; 68526f3deacStedu 68626f3deacStedu for (i = 0; (i < ustrlen) && (astr < astrend); i++) { 68726f3deacStedu res = (*ntmp->ntm_wcmp)(ustr[i], (*ntmp->ntm_wget)(&astr)); 68826f3deacStedu if (res) 68926f3deacStedu return res; 69026f3deacStedu } 69126f3deacStedu 69226f3deacStedu if (i == ustrlen && astr == astrend) 69326f3deacStedu return 0; 69426f3deacStedu else if (i == ustrlen) 69526f3deacStedu return -1; 69626f3deacStedu else 69726f3deacStedu return 1; 69826f3deacStedu } 69926f3deacStedu 70026f3deacStedu /* 70126f3deacStedu * Search fnode in ntnode, if not found allocate and preinitialize. 70226f3deacStedu * 70326f3deacStedu * ntnode should be locked on entry. 70426f3deacStedu */ 70526f3deacStedu int 7061cc0505dSjsing ntfs_fget(struct ntfsmount *ntmp, struct ntnode *ip, int attrtype, 7071cc0505dSjsing char *attrname, struct fnode **fpp) 70826f3deacStedu { 70926f3deacStedu struct fnode *fp; 71026f3deacStedu 711f2997212Sjsing DPRINTF("ntfs_fget: ino: %u, attrtype: 0x%x, attrname: %s\n", 712a1ea65c6Sjsing ip->i_number, attrtype, attrname ? attrname : ""); 71326f3deacStedu *fpp = NULL; 7141573508eSmiod LIST_FOREACH(fp, &ip->i_fnlist, f_fnlist) { 715f2997212Sjsing DPRINTF("ntfs_fget: fnode: attrtype: %u, attrname: %s\n", 716a1ea65c6Sjsing fp->f_attrtype, fp->f_attrname ? fp->f_attrname : ""); 71726f3deacStedu 71826f3deacStedu if ((attrtype == fp->f_attrtype) && 71926f3deacStedu ((!attrname && !fp->f_attrname) || 72026f3deacStedu (attrname && fp->f_attrname && 72126f3deacStedu !strcmp(attrname,fp->f_attrname)))){ 722a1ea65c6Sjsing DPRINTF("ntfs_fget: found existed: %p\n", fp); 72326f3deacStedu *fpp = fp; 72426f3deacStedu } 72526f3deacStedu } 72626f3deacStedu 72726f3deacStedu if (*fpp) 72826f3deacStedu return (0); 72926f3deacStedu 730c86f0003Skrw fp = malloc(sizeof(*fp), M_NTFSFNODE, M_WAITOK | M_ZERO); 731a1ea65c6Sjsing DPRINTF("ntfs_fget: allocating fnode: %p\n", fp); 73226f3deacStedu 73326f3deacStedu fp->f_ip = ip; 73426f3deacStedu fp->f_attrname = attrname; 73526f3deacStedu if (fp->f_attrname) fp->f_flag |= FN_AATTRNAME; 73626f3deacStedu fp->f_attrtype = attrtype; 73726f3deacStedu 73826f3deacStedu ntfs_ntref(ip); 73926f3deacStedu 74026f3deacStedu LIST_INSERT_HEAD(&ip->i_fnlist, fp, f_fnlist); 74126f3deacStedu 74226f3deacStedu *fpp = fp; 74326f3deacStedu 74426f3deacStedu return (0); 74526f3deacStedu } 74626f3deacStedu 74726f3deacStedu /* 74826f3deacStedu * Deallocate fnode, remove it from ntnode's fnode list. 74926f3deacStedu * 75026f3deacStedu * ntnode should be locked. 75126f3deacStedu */ 75226f3deacStedu void 7531cc0505dSjsing ntfs_frele(struct fnode *fp) 75426f3deacStedu { 75526f3deacStedu struct ntnode *ip = FTONT(fp); 75626f3deacStedu 757f2997212Sjsing DPRINTF("ntfs_frele: fnode: %p for %u: %p\n", fp, ip->i_number, ip); 75826f3deacStedu 759a1ea65c6Sjsing DPRINTF("ntfs_frele: deallocating fnode\n"); 76026f3deacStedu LIST_REMOVE(fp,f_fnlist); 76126f3deacStedu if (fp->f_flag & FN_AATTRNAME) 762825c4e6aStedu free(fp->f_attrname, M_TEMP, 0); 76326f3deacStedu if (fp->f_dirblbuf) 764825c4e6aStedu free(fp->f_dirblbuf, M_NTFSDIR, 0); 765825c4e6aStedu free(fp, M_NTFSFNODE, 0); 76626f3deacStedu ntfs_ntrele(ip); 76726f3deacStedu } 76826f3deacStedu 76926f3deacStedu /* 77026f3deacStedu * Lookup attribute name in format: [[:$ATTR_TYPE]:$ATTR_NAME], 77126f3deacStedu * $ATTR_TYPE is searched in attrdefs read from $AttrDefs. 77226f3deacStedu * If $ATTR_TYPE not specified, ATTR_A_DATA assumed. 77326f3deacStedu */ 77405c5dae5Sjsing int 7751cc0505dSjsing ntfs_ntlookupattr(struct ntfsmount *ntmp, const char *name, int namelen, 7761cc0505dSjsing int *attrtype, char **attrname) 77726f3deacStedu { 77826f3deacStedu const char *sys; 77926f3deacStedu size_t syslen, i; 78026f3deacStedu struct ntvattrdef *adp; 78126f3deacStedu 78226f3deacStedu if (namelen == 0) 78326f3deacStedu return (0); 78426f3deacStedu 78526f3deacStedu if (name[0] == '$') { 78626f3deacStedu sys = name; 78726f3deacStedu for (syslen = 0; syslen < namelen; syslen++) { 78826f3deacStedu if(sys[syslen] == ':') { 78926f3deacStedu name++; 79026f3deacStedu namelen--; 79126f3deacStedu break; 79226f3deacStedu } 79326f3deacStedu } 79426f3deacStedu name += syslen; 79526f3deacStedu namelen -= syslen; 79626f3deacStedu 79726f3deacStedu adp = ntmp->ntm_ad; 79826f3deacStedu for (i = 0; i < ntmp->ntm_adnum; i++, adp++){ 79926f3deacStedu if (syslen != adp->ad_namelen || 80026f3deacStedu strncmp(sys, adp->ad_name, syslen) != 0) 80126f3deacStedu continue; 80226f3deacStedu 80326f3deacStedu *attrtype = adp->ad_type; 80426f3deacStedu goto out; 80526f3deacStedu } 80626f3deacStedu return (ENOENT); 80726f3deacStedu } 80826f3deacStedu 80926f3deacStedu out: 81026f3deacStedu if (namelen) { 811c6c302e5Stedu *attrname = malloc(namelen + 1, M_TEMP, M_WAITOK); 812c6c302e5Stedu memcpy(*attrname, name, namelen); 81326f3deacStedu (*attrname)[namelen] = '\0'; 81426f3deacStedu *attrtype = NTFS_A_DATA; 81526f3deacStedu } 81626f3deacStedu 81726f3deacStedu return (0); 81826f3deacStedu } 81926f3deacStedu 82026f3deacStedu /* 8211cc0505dSjsing * Lookup specified node for filename, matching cnp, return fnode filled. 82226f3deacStedu */ 82326f3deacStedu int 8241cc0505dSjsing ntfs_ntlookupfile(struct ntfsmount *ntmp, struct vnode *vp, 825*db7aa982Smpi struct componentname *cnp, struct vnode **vpp) 82626f3deacStedu { 82726f3deacStedu struct fnode *fp = VTOF(vp); 82826f3deacStedu struct ntnode *ip = FTONT(fp); 8296f6d0059Sjsing struct ntvattr *vap = NULL; /* Root attribute */ 83026f3deacStedu cn_t cn = 0; /* VCN in current attribute */ 8316f6d0059Sjsing caddr_t rdbuf = NULL; /* Buffer to read directory's blocks */ 83226f3deacStedu u_int32_t blsize; 83326f3deacStedu u_int32_t rdsize; /* Length of data to read from current block */ 83426f3deacStedu struct attr_indexentry *iep; 83526f3deacStedu int error, res, anamelen, fnamelen; 83626f3deacStedu const char *fname,*aname; 83726f3deacStedu u_int32_t aoff; 83826f3deacStedu int attrtype = NTFS_A_DATA; 83926f3deacStedu char *attrname = NULL; 84026f3deacStedu struct fnode *nfp; 84126f3deacStedu struct vnode *nvp; 84226f3deacStedu enum vtype f_type; 84326f3deacStedu int fullscan = 0; 84426f3deacStedu struct ntfs_lookup_ctx *lookup_ctx = NULL, *tctx; 84526f3deacStedu 846*db7aa982Smpi error = ntfs_ntget(ip); 84726f3deacStedu if (error) 84826f3deacStedu return (error); 84926f3deacStedu 85026f3deacStedu error = ntfs_ntvattrget(ntmp, ip, NTFS_A_INDXROOT, "$I30", 0, &vap); 8516f6d0059Sjsing if (error || (vap->va_flag & NTFS_AF_INRUN)) { 8526f6d0059Sjsing error = ENOTDIR; 8536f6d0059Sjsing goto fail; 8546f6d0059Sjsing } 85526f3deacStedu 85626f3deacStedu /* 85726f3deacStedu * Divide file name into: foofilefoofilefoofile[:attrspec] 85826f3deacStedu * Store like this: fname:fnamelen [aname:anamelen] 85926f3deacStedu */ 86026f3deacStedu fname = cnp->cn_nameptr; 86126f3deacStedu aname = NULL; 86226f3deacStedu anamelen = 0; 86326f3deacStedu for (fnamelen = 0; fnamelen < cnp->cn_namelen; fnamelen++) 86426f3deacStedu if(fname[fnamelen] == ':') { 86526f3deacStedu aname = fname + fnamelen + 1; 86626f3deacStedu anamelen = cnp->cn_namelen - fnamelen - 1; 867a1ea65c6Sjsing DPRINTF("ntfs_ntlookupfile: %s (%d), attr: %s (%d)\n", 868a1ea65c6Sjsing fname, fnamelen, aname, anamelen); 86926f3deacStedu break; 87026f3deacStedu } 87126f3deacStedu 87226f3deacStedu blsize = vap->va_a_iroot->ir_size; 873f2997212Sjsing DPRINTF("ntfs_ntlookupfile: blksz: %u\n", blsize); 87426f3deacStedu 875c6c302e5Stedu rdbuf = malloc(blsize, M_TEMP, M_WAITOK); 87626f3deacStedu 87726f3deacStedu loop: 87826f3deacStedu rdsize = vap->va_datalen; 879f2997212Sjsing DPRINTF("ntfs_ntlookupfile: rdsz: %u\n", rdsize); 88026f3deacStedu 88126f3deacStedu error = ntfs_readattr(ntmp, ip, NTFS_A_INDXROOT, "$I30", 88226f3deacStedu 0, rdsize, rdbuf, NULL); 88326f3deacStedu if (error) 88426f3deacStedu goto fail; 88526f3deacStedu 88626f3deacStedu aoff = sizeof(struct attr_indexroot); 88726f3deacStedu 88826f3deacStedu do { 88926f3deacStedu iep = (struct attr_indexentry *) (rdbuf + aoff); 89026f3deacStedu 89126f3deacStedu for (; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (rdsize > aoff); 89226f3deacStedu aoff += iep->reclen, 89326f3deacStedu iep = (struct attr_indexentry *) (rdbuf + aoff)) 89426f3deacStedu { 895f2997212Sjsing DDPRINTF("scan: %u, %u\n", iep->ie_number, 896f2997212Sjsing iep->ie_fnametype); 89726f3deacStedu 89826f3deacStedu /* check the name - the case-insensitive check 89926f3deacStedu * has to come first, to break from this for loop 90026f3deacStedu * if needed, so we can dive correctly */ 90126f3deacStedu res = ntfs_uastricmp(ntmp, iep->ie_fname, 90226f3deacStedu iep->ie_fnamelen, fname, fnamelen); 90326f3deacStedu if (!fullscan) { 90426f3deacStedu if (res > 0) break; 90526f3deacStedu if (res < 0) continue; 90626f3deacStedu } 90726f3deacStedu 90826f3deacStedu if (iep->ie_fnametype == 0 || 90926f3deacStedu !(ntmp->ntm_flag & NTFS_MFLAG_CASEINS)) 91026f3deacStedu { 91126f3deacStedu res = ntfs_uastrcmp(ntmp, iep->ie_fname, 91226f3deacStedu iep->ie_fnamelen, fname, fnamelen); 91326f3deacStedu if (res != 0 && !fullscan) continue; 91426f3deacStedu } 91526f3deacStedu 91626f3deacStedu /* if we perform full scan, the file does not match 91726f3deacStedu * and this is subnode, dive */ 91826f3deacStedu if (fullscan && res != 0) { 91926f3deacStedu if (iep->ie_flag & NTFS_IEFLAG_SUBNODE) { 920e8821f89Shshoexer tctx = malloc(sizeof(struct ntfs_lookup_ctx), 92126f3deacStedu M_TEMP, M_WAITOK); 92226f3deacStedu tctx->aoff = aoff + iep->reclen; 92326f3deacStedu tctx->rdsize = rdsize; 92426f3deacStedu tctx->cn = cn; 92526f3deacStedu tctx->prev = lookup_ctx; 92626f3deacStedu lookup_ctx = tctx; 92726f3deacStedu break; 92826f3deacStedu } else 92926f3deacStedu continue; 93026f3deacStedu } 93126f3deacStedu 93226f3deacStedu if (aname) { 93326f3deacStedu error = ntfs_ntlookupattr(ntmp, 93426f3deacStedu aname, anamelen, 93526f3deacStedu &attrtype, &attrname); 93626f3deacStedu if (error) 93726f3deacStedu goto fail; 93826f3deacStedu } 93926f3deacStedu 94026f3deacStedu /* Check if we've found ourselves */ 94126f3deacStedu if ((iep->ie_number == ip->i_number) && 94226f3deacStedu (attrtype == fp->f_attrtype) && 94326f3deacStedu ((!attrname && !fp->f_attrname) || 94426f3deacStedu (attrname && fp->f_attrname && 94526f3deacStedu !strcmp(attrname, fp->f_attrname)))) 94626f3deacStedu { 947627b2c48Sthib vref(vp); 94826f3deacStedu *vpp = vp; 94926f3deacStedu error = 0; 95026f3deacStedu goto fail; 95126f3deacStedu } 95226f3deacStedu 95326f3deacStedu /* free the buffer returned by ntfs_ntlookupattr() */ 95426f3deacStedu if (attrname) { 955825c4e6aStedu free(attrname, M_TEMP, 0); 95626f3deacStedu attrname = NULL; 95726f3deacStedu } 95826f3deacStedu 95926f3deacStedu /* vget node, but don't load it */ 96026f3deacStedu error = ntfs_vgetex(ntmp->ntm_mountp, 96126f3deacStedu iep->ie_number, attrtype, attrname, 96226f3deacStedu LK_EXCLUSIVE, VG_DONTLOADIN | VG_DONTVALIDFN, 963*db7aa982Smpi &nvp); 96426f3deacStedu if (error) 96526f3deacStedu goto fail; 96626f3deacStedu 96726f3deacStedu nfp = VTOF(nvp); 96826f3deacStedu 96926f3deacStedu if (nfp->f_flag & FN_VALID) { 97026f3deacStedu *vpp = nvp; 97126f3deacStedu goto fail; 97226f3deacStedu } 97326f3deacStedu 97426f3deacStedu nfp->f_fflag = iep->ie_fflag; 97526f3deacStedu nfp->f_pnumber = iep->ie_fpnumber; 97626f3deacStedu nfp->f_times = iep->ie_ftimes; 97726f3deacStedu 97826f3deacStedu if((nfp->f_fflag & NTFS_FFLAG_DIR) && 97926f3deacStedu (nfp->f_attrtype == NTFS_A_DATA) && 98026f3deacStedu (nfp->f_attrname == NULL)) 98126f3deacStedu f_type = VDIR; 98226f3deacStedu else 98326f3deacStedu f_type = VREG; 98426f3deacStedu 98526f3deacStedu nvp->v_type = f_type; 98626f3deacStedu 98726f3deacStedu if ((nfp->f_attrtype == NTFS_A_DATA) && 98826f3deacStedu (nfp->f_attrname == NULL)) 98926f3deacStedu { 99026f3deacStedu /* Opening default attribute */ 99126f3deacStedu nfp->f_size = iep->ie_fsize; 99226f3deacStedu nfp->f_allocated = iep->ie_fallocated; 99326f3deacStedu nfp->f_flag |= FN_PRELOADED; 99426f3deacStedu } else { 99526f3deacStedu error = ntfs_filesize(ntmp, nfp, 99626f3deacStedu &nfp->f_size, &nfp->f_allocated); 99726f3deacStedu if (error) { 99826f3deacStedu vput(nvp); 99926f3deacStedu goto fail; 100026f3deacStedu } 100126f3deacStedu } 100226f3deacStedu 100326f3deacStedu nfp->f_flag &= ~FN_VALID; 100426f3deacStedu *vpp = nvp; 100526f3deacStedu goto fail; 100626f3deacStedu } 100726f3deacStedu 100826f3deacStedu /* Dive if possible */ 100926f3deacStedu if (iep->ie_flag & NTFS_IEFLAG_SUBNODE) { 1010a1ea65c6Sjsing DPRINTF("ntfs_ntlookupfile: diving\n"); 101126f3deacStedu 101226f3deacStedu cn = *(cn_t *) (rdbuf + aoff + 101326f3deacStedu iep->reclen - sizeof(cn_t)); 101426f3deacStedu rdsize = blsize; 101526f3deacStedu 101626f3deacStedu error = ntfs_readattr(ntmp, ip, NTFS_A_INDX, "$I30", 101726f3deacStedu ntfs_cntob(cn), rdsize, rdbuf, NULL); 101826f3deacStedu if (error) 101926f3deacStedu goto fail; 102026f3deacStedu 102126f3deacStedu error = ntfs_procfixups(ntmp, NTFS_INDXMAGIC, 102226f3deacStedu rdbuf, rdsize); 102326f3deacStedu if (error) 102426f3deacStedu goto fail; 102526f3deacStedu 102626f3deacStedu aoff = (((struct attr_indexalloc *) rdbuf)->ia_hdrsize + 102726f3deacStedu 0x18); 102826f3deacStedu } else if (fullscan && lookup_ctx) { 102926f3deacStedu cn = lookup_ctx->cn; 103026f3deacStedu aoff = lookup_ctx->aoff; 103126f3deacStedu rdsize = lookup_ctx->rdsize; 103226f3deacStedu 103326f3deacStedu error = ntfs_readattr(ntmp, ip, 103426f3deacStedu (cn == 0) ? NTFS_A_INDXROOT : NTFS_A_INDX, 103526f3deacStedu "$I30", ntfs_cntob(cn), rdsize, rdbuf, NULL); 103626f3deacStedu if (error) 103726f3deacStedu goto fail; 103826f3deacStedu 103926f3deacStedu if (cn != 0) { 104026f3deacStedu error = ntfs_procfixups(ntmp, NTFS_INDXMAGIC, 104126f3deacStedu rdbuf, rdsize); 104226f3deacStedu if (error) 104326f3deacStedu goto fail; 104426f3deacStedu } 104526f3deacStedu 104626f3deacStedu tctx = lookup_ctx; 104726f3deacStedu lookup_ctx = lookup_ctx->prev; 1048825c4e6aStedu free(tctx, M_TEMP, 0); 104926f3deacStedu } else { 1050a1ea65c6Sjsing DPRINTF("ntfs_ntlookupfile: nowhere to dive :-(\n"); 105126f3deacStedu error = ENOENT; 105226f3deacStedu break; 105326f3deacStedu } 105426f3deacStedu } while (1); 105526f3deacStedu 1056b0d9a5a6Snatano if (error == ENOENT) { 105726f3deacStedu /* perform full scan if no entry was found */ 1058b0d9a5a6Snatano if (!fullscan) { 105926f3deacStedu fullscan = 1; 106026f3deacStedu cn = 0; /* need zero, used by lookup_ctx */ 106126f3deacStedu 1062a1ea65c6Sjsing DDPRINTF("ntfs_ntlookupfile: fullscan performed for: %.*s\n", 1063f2997212Sjsing (unsigned int)fnamelen, fname); 106426f3deacStedu goto loop; 106526f3deacStedu } 106626f3deacStedu 1067b0d9a5a6Snatano if ((cnp->cn_flags & ISLASTCN) && 1068b0d9a5a6Snatano (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)) 1069b0d9a5a6Snatano error = EJUSTRETURN; 1070b0d9a5a6Snatano } 1071b0d9a5a6Snatano 1072a1ea65c6Sjsing DPRINTF("finish\n"); 107326f3deacStedu 107426f3deacStedu fail: 10756f6d0059Sjsing if (vap) 10766f6d0059Sjsing ntfs_ntvattrrele(vap); 10776f6d0059Sjsing if (rdbuf) 1078825c4e6aStedu free(rdbuf, M_TEMP, 0); 107926f3deacStedu if (attrname) 1080825c4e6aStedu free(attrname, M_TEMP, 0); 108126f3deacStedu if (lookup_ctx) { 108226f3deacStedu while(lookup_ctx) { 108326f3deacStedu tctx = lookup_ctx; 108426f3deacStedu lookup_ctx = lookup_ctx->prev; 1085825c4e6aStedu free(tctx, M_TEMP, 0); 108626f3deacStedu } 108726f3deacStedu } 1088*db7aa982Smpi ntfs_ntput(ip); 108926f3deacStedu return (error); 109026f3deacStedu } 109126f3deacStedu 109226f3deacStedu /* 109326f3deacStedu * Check if name type is permitted to show. 109426f3deacStedu */ 109526f3deacStedu int 10961cc0505dSjsing ntfs_isnamepermitted(struct ntfsmount *ntmp, struct attr_indexentry *iep) 109726f3deacStedu { 109826f3deacStedu if (ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES) 109926f3deacStedu return 1; 110026f3deacStedu 110126f3deacStedu switch (iep->ie_fnametype) { 110226f3deacStedu case 2: 1103a1ea65c6Sjsing DDPRINTF("ntfs_isnamepermitted: skipped DOS name\n"); 110426f3deacStedu return 0; 110526f3deacStedu case 0: case 1: case 3: 110626f3deacStedu return 1; 110726f3deacStedu default: 110826f3deacStedu printf("ntfs_isnamepermitted: " \ 110926f3deacStedu "WARNING! Unknown file name type: %d\n", 111026f3deacStedu iep->ie_fnametype); 111126f3deacStedu break; 111226f3deacStedu } 111326f3deacStedu return 0; 111426f3deacStedu } 111526f3deacStedu 111626f3deacStedu /* 111726f3deacStedu * Read ntfs dir like stream of attr_indexentry, not like btree of them. 111826f3deacStedu * This is done by scanning $BITMAP:$I30 for busy clusters and reading them. 111926f3deacStedu * Of course $INDEX_ROOT:$I30 is read before. Last read values are stored in 112026f3deacStedu * fnode, so we can skip toward record number num almost immediately. 112126f3deacStedu * Anyway this is rather slow routine. The problem is that we don't know 112226f3deacStedu * how many records are there in $INDEX_ALLOCATION:$I30 block. 112326f3deacStedu */ 112426f3deacStedu int 11251cc0505dSjsing ntfs_ntreaddir(struct ntfsmount *ntmp, struct fnode *fp, u_int32_t num, 11261cc0505dSjsing struct attr_indexentry **riepp, struct proc *p) 112726f3deacStedu { 112826f3deacStedu struct ntnode *ip = FTONT(fp); 112926f3deacStedu struct ntvattr *vap = NULL; /* IndexRoot attribute */ 113026f3deacStedu struct ntvattr *bmvap = NULL; /* BitMap attribute */ 113126f3deacStedu struct ntvattr *iavap = NULL; /* IndexAllocation attribute */ 113226f3deacStedu caddr_t rdbuf; /* Buffer to read directory's blocks */ 11336978a3abSbrad u_int8_t *bmp = NULL; /* Bitmap */ 113426f3deacStedu u_int32_t blsize; /* Index allocation size (2048) */ 113526f3deacStedu u_int32_t rdsize; /* Length of data to read */ 113626f3deacStedu u_int32_t attrnum; /* Current attribute type */ 113726f3deacStedu u_int32_t cpbl = 1; /* Clusters per directory block */ 113826f3deacStedu u_int32_t blnum; 113926f3deacStedu struct attr_indexentry *iep; 114026f3deacStedu int error = ENOENT; 114126f3deacStedu u_int32_t aoff, cnum; 114226f3deacStedu 1143f2997212Sjsing DPRINTF("ntfs_ntreaddir: read ino: %u, num: %u\n", ip->i_number, num); 1144*db7aa982Smpi error = ntfs_ntget(ip); 114526f3deacStedu if (error) 114626f3deacStedu return (error); 114726f3deacStedu 114826f3deacStedu error = ntfs_ntvattrget(ntmp, ip, NTFS_A_INDXROOT, "$I30", 0, &vap); 11496f6d0059Sjsing if (error) { 11506f6d0059Sjsing error = ENOTDIR; 11516f6d0059Sjsing goto fail; 11526f6d0059Sjsing } 115326f3deacStedu 115426f3deacStedu if (fp->f_dirblbuf == NULL) { 115526f3deacStedu fp->f_dirblsz = vap->va_a_iroot->ir_size; 1156c6c302e5Stedu fp->f_dirblbuf = malloc(MAX(vap->va_datalen,fp->f_dirblsz), 1157c6c302e5Stedu M_NTFSDIR, M_WAITOK); 115826f3deacStedu } 115926f3deacStedu 116026f3deacStedu blsize = fp->f_dirblsz; 116126f3deacStedu rdbuf = fp->f_dirblbuf; 116226f3deacStedu 1163f2997212Sjsing DPRINTF("ntfs_ntreaddir: rdbuf: %p, blsize: %u\n", rdbuf, blsize); 116426f3deacStedu 116526f3deacStedu if (vap->va_a_iroot->ir_flag & NTFS_IRFLAG_INDXALLOC) { 116626f3deacStedu error = ntfs_ntvattrget(ntmp, ip, NTFS_A_INDXBITMAP, "$I30", 116726f3deacStedu 0, &bmvap); 116826f3deacStedu if (error) { 116926f3deacStedu error = ENOTDIR; 117026f3deacStedu goto fail; 117126f3deacStedu } 1172c6c302e5Stedu bmp = malloc(bmvap->va_datalen, M_TEMP, M_WAITOK); 117326f3deacStedu error = ntfs_readattr(ntmp, ip, NTFS_A_INDXBITMAP, "$I30", 0, 117426f3deacStedu bmvap->va_datalen, bmp, NULL); 117526f3deacStedu if (error) 117626f3deacStedu goto fail; 117726f3deacStedu 117826f3deacStedu error = ntfs_ntvattrget(ntmp, ip, NTFS_A_INDX, "$I30", 117926f3deacStedu 0, &iavap); 118026f3deacStedu if (error) { 118126f3deacStedu error = ENOTDIR; 118226f3deacStedu goto fail; 118326f3deacStedu } 118426f3deacStedu cpbl = ntfs_btocn(blsize + ntfs_cntob(1) - 1); 11855adbeedcSjsing DPRINTF("ntfs_ntreaddir: indexalloc: %llu, cpbl: %u\n", 1186a1ea65c6Sjsing iavap->va_datalen, cpbl); 118726f3deacStedu } else { 1188a1ea65c6Sjsing DPRINTF("ntfs_ntreadidir: w/o BitMap and IndexAllocation\n"); 118926f3deacStedu iavap = bmvap = NULL; 119026f3deacStedu bmp = NULL; 119126f3deacStedu } 119226f3deacStedu 119326f3deacStedu /* Try use previous values */ 119426f3deacStedu if ((fp->f_lastdnum < num) && (fp->f_lastdnum != 0)) { 119526f3deacStedu attrnum = fp->f_lastdattr; 119626f3deacStedu aoff = fp->f_lastdoff; 119726f3deacStedu blnum = fp->f_lastdblnum; 119826f3deacStedu cnum = fp->f_lastdnum; 119926f3deacStedu } else { 120026f3deacStedu attrnum = NTFS_A_INDXROOT; 120126f3deacStedu aoff = sizeof(struct attr_indexroot); 120226f3deacStedu blnum = 0; 120326f3deacStedu cnum = 0; 120426f3deacStedu } 120526f3deacStedu 120626f3deacStedu do { 1207f2997212Sjsing DPRINTF("ntfs_ntreaddir: scan: 0x%x, %u, %u, %u, %u\n", 1208f2997212Sjsing attrnum, blnum, cnum, num, aoff); 120926f3deacStedu rdsize = (attrnum == NTFS_A_INDXROOT) ? vap->va_datalen : blsize; 121026f3deacStedu error = ntfs_readattr(ntmp, ip, attrnum, "$I30", 121126f3deacStedu ntfs_cntob(blnum * cpbl), rdsize, rdbuf, NULL); 121226f3deacStedu if (error) 121326f3deacStedu goto fail; 121426f3deacStedu 121526f3deacStedu if (attrnum == NTFS_A_INDX) { 121626f3deacStedu error = ntfs_procfixups(ntmp, NTFS_INDXMAGIC, 121726f3deacStedu rdbuf, rdsize); 121826f3deacStedu if (error) 121926f3deacStedu goto fail; 122026f3deacStedu } 122126f3deacStedu if (aoff == 0) 122226f3deacStedu aoff = (attrnum == NTFS_A_INDX) ? 122326f3deacStedu (0x18 + ((struct attr_indexalloc *) rdbuf)->ia_hdrsize) : 122426f3deacStedu sizeof(struct attr_indexroot); 122526f3deacStedu 122626f3deacStedu iep = (struct attr_indexentry *) (rdbuf + aoff); 122726f3deacStedu for (; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (rdsize > aoff); 122826f3deacStedu aoff += iep->reclen, 122926f3deacStedu iep = (struct attr_indexentry *) (rdbuf + aoff)) 123026f3deacStedu { 123126f3deacStedu if (!ntfs_isnamepermitted(ntmp, iep)) continue; 123226f3deacStedu 123326f3deacStedu if (cnum >= num) { 123426f3deacStedu fp->f_lastdnum = cnum; 123526f3deacStedu fp->f_lastdoff = aoff; 123626f3deacStedu fp->f_lastdblnum = blnum; 123726f3deacStedu fp->f_lastdattr = attrnum; 123826f3deacStedu 123926f3deacStedu *riepp = iep; 124026f3deacStedu 124126f3deacStedu error = 0; 124226f3deacStedu goto fail; 124326f3deacStedu } 124426f3deacStedu cnum++; 124526f3deacStedu } 124626f3deacStedu 124726f3deacStedu if (iavap) { 124826f3deacStedu if (attrnum == NTFS_A_INDXROOT) 124926f3deacStedu blnum = 0; 125026f3deacStedu else 125126f3deacStedu blnum++; 125226f3deacStedu 125326f3deacStedu while (ntfs_cntob(blnum * cpbl) < iavap->va_datalen) { 12546978a3abSbrad if (bmp[blnum >> 3] & (1 << (blnum & 7))) 125526f3deacStedu break; 125626f3deacStedu blnum++; 125726f3deacStedu } 125826f3deacStedu 125926f3deacStedu attrnum = NTFS_A_INDX; 126026f3deacStedu aoff = 0; 126126f3deacStedu if (ntfs_cntob(blnum * cpbl) >= iavap->va_datalen) 126226f3deacStedu break; 1263f2997212Sjsing DPRINTF("ntfs_ntreaddir: blnum: %u\n", blnum); 126426f3deacStedu } 126526f3deacStedu } while (iavap); 126626f3deacStedu 126726f3deacStedu *riepp = NULL; 126826f3deacStedu fp->f_lastdnum = 0; 126926f3deacStedu 127026f3deacStedu fail: 127126f3deacStedu if (vap) 127226f3deacStedu ntfs_ntvattrrele(vap); 127326f3deacStedu if (bmvap) 127426f3deacStedu ntfs_ntvattrrele(bmvap); 127526f3deacStedu if (iavap) 127626f3deacStedu ntfs_ntvattrrele(iavap); 127726f3deacStedu if (bmp) 1278825c4e6aStedu free(bmp, M_TEMP, 0); 1279*db7aa982Smpi ntfs_ntput(ip); 12801ad3841aSjasper 128126f3deacStedu return (error); 128226f3deacStedu } 128326f3deacStedu 128426f3deacStedu /* 128526f3deacStedu * Convert NTFS times that are in 100 ns units and begins from 128626f3deacStedu * 1601 Jan 1 into unix times. 128726f3deacStedu */ 128826f3deacStedu struct timespec 12891cc0505dSjsing ntfs_nttimetounix(u_int64_t nt) 129026f3deacStedu { 129126f3deacStedu struct timespec t; 129226f3deacStedu 129326f3deacStedu /* WindowNT times are in 100 ns and from 1601 Jan 1 */ 129426f3deacStedu t.tv_nsec = (nt % (1000 * 1000 * 10)) * 100; 129526f3deacStedu t.tv_sec = nt / (1000 * 1000 * 10) - 129626f3deacStedu 369LL * 365LL * 24LL * 60LL * 60LL - 129726f3deacStedu 89LL * 1LL * 24LL * 60LL * 60LL; 129826f3deacStedu return (t); 129926f3deacStedu } 130026f3deacStedu 130126f3deacStedu /* 130226f3deacStedu * Get file sizes from corresponding attribute. 130326f3deacStedu * 130426f3deacStedu * ntnode under fnode should be locked. 130526f3deacStedu */ 130626f3deacStedu int 13071cc0505dSjsing ntfs_filesize(struct ntfsmount *ntmp, struct fnode *fp, u_int64_t *size, 130826f3deacStedu u_int64_t *bytes) 130926f3deacStedu { 131026f3deacStedu struct ntvattr *vap; 131126f3deacStedu struct ntnode *ip = FTONT(fp); 131226f3deacStedu u_int64_t sz, bn; 131326f3deacStedu int error; 131426f3deacStedu 1315f2997212Sjsing DPRINTF("ntfs_filesize: ino: %u\n", ip->i_number); 131626f3deacStedu 131726f3deacStedu error = ntfs_ntvattrget(ntmp, ip, 131826f3deacStedu fp->f_attrtype, fp->f_attrname, 0, &vap); 131926f3deacStedu if (error) 132026f3deacStedu return (error); 132126f3deacStedu 132226f3deacStedu bn = vap->va_allocated; 132326f3deacStedu sz = vap->va_datalen; 132426f3deacStedu 1325f2997212Sjsing DPRINTF("ntfs_filesize: %llu bytes (%llu bytes allocated)\n", sz, bn); 132626f3deacStedu 132726f3deacStedu if (size) 132826f3deacStedu *size = sz; 132926f3deacStedu if (bytes) 133026f3deacStedu *bytes = bn; 133126f3deacStedu 133226f3deacStedu ntfs_ntvattrrele(vap); 133326f3deacStedu 133426f3deacStedu return (0); 133526f3deacStedu } 133626f3deacStedu 133726f3deacStedu /* 1338835c1779Sbrad * This is one of the read routines. 133926f3deacStedu * 134026f3deacStedu * ntnode should be locked. 134126f3deacStedu */ 134226f3deacStedu int 13431cc0505dSjsing ntfs_readntvattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, 13441cc0505dSjsing struct ntvattr *vap, off_t roff, size_t rsize, void *rdata, size_t *initp, 134526f3deacStedu struct uio *uio) 134626f3deacStedu { 134726f3deacStedu int error = 0; 1348ac80acddSjsing off_t off; 134926f3deacStedu 135026f3deacStedu *initp = 0; 135126f3deacStedu if (vap->va_flag & NTFS_AF_INRUN) { 135226f3deacStedu int cnt; 1353f05ab2cdSstefan cn_t ccn, ccl, cn, cl; 135426f3deacStedu caddr_t data = rdata; 135526f3deacStedu struct buf *bp; 1356f05ab2cdSstefan size_t left, tocopy; 135726f3deacStedu 1358a1ea65c6Sjsing DDPRINTF("ntfs_readntvattr_plain: data in run: %lu chains\n", 1359a1ea65c6Sjsing vap->va_vruncnt); 136026f3deacStedu 136126f3deacStedu off = roff; 136226f3deacStedu left = rsize; 136326f3deacStedu ccl = 0; 136426f3deacStedu ccn = 0; 136526f3deacStedu cnt = 0; 136626f3deacStedu while (left && (cnt < vap->va_vruncnt)) { 136726f3deacStedu ccn = vap->va_vruncn[cnt]; 136826f3deacStedu ccl = vap->va_vruncl[cnt]; 136926f3deacStedu 1370f05ab2cdSstefan DDPRINTF("ntfs_readntvattr_plain: left %zu, " 1371f2997212Sjsing "cn: 0x%llx, cl: %llu, off: %lld\n", 1372f2997212Sjsing left, ccn, ccl, off); 137326f3deacStedu 137426f3deacStedu if (ntfs_cntob(ccl) < off) { 137526f3deacStedu off -= ntfs_cntob(ccl); 137626f3deacStedu cnt++; 137726f3deacStedu continue; 137826f3deacStedu } 137926f3deacStedu if (ccn || ip->i_number == NTFS_BOOTINO) { 138026f3deacStedu ccl -= ntfs_btocn(off); 138126f3deacStedu cn = ccn + ntfs_btocn(off); 138226f3deacStedu off = ntfs_btocnoff(off); 138326f3deacStedu 138426f3deacStedu while (left && ccl) { 138526f3deacStedu /* 1386835c1779Sbrad * Always read single clusters at a 1387835c1779Sbrad * time - we need to avoid reading 1388835c1779Sbrad * differently-sized blocks at the 1389835c1779Sbrad * same disk offsets to avoid 1390835c1779Sbrad * confusing the buffer cache. 139126f3deacStedu */ 1392835c1779Sbrad tocopy = MIN(left, 1393835c1779Sbrad ntfs_cntob(1) - off); 1394835c1779Sbrad cl = ntfs_btocl(tocopy + off); 1395835c1779Sbrad KASSERT(cl == 1 && 1396835c1779Sbrad tocopy <= ntfs_cntob(1)); 139726f3deacStedu 1398a1ea65c6Sjsing DDPRINTF("ntfs_readntvattr_plain: " 1399f2997212Sjsing "read: cn: 0x%llx cl: %llu, " 1400f05ab2cdSstefan "off: %lld, len: %zu, " 1401f05ab2cdSstefan "left: %zu\n", 1402f2997212Sjsing cn, cl, off, tocopy, left); 140326f3deacStedu error = bread(ntmp->ntm_devvp, 140426f3deacStedu ntfs_cntobn(cn), 140526f3deacStedu ntfs_cntob(cl), 140693f62a9eStedu &bp); 140726f3deacStedu if (error) { 140826f3deacStedu brelse(bp); 140926f3deacStedu return (error); 141026f3deacStedu } 141126f3deacStedu if (uio) { 1412f05ab2cdSstefan error = uiomove(bp->b_data + off, 141326f3deacStedu tocopy, uio); 1414fca26c8fSmiod if (error != 0) 1415fca26c8fSmiod break; 141626f3deacStedu } else { 141726f3deacStedu memcpy(data, bp->b_data + off, 141826f3deacStedu tocopy); 141926f3deacStedu } 142026f3deacStedu brelse(bp); 142126f3deacStedu data = data + tocopy; 142226f3deacStedu *initp += tocopy; 142326f3deacStedu off = 0; 142426f3deacStedu left -= tocopy; 142526f3deacStedu cn += cl; 142626f3deacStedu ccl -= cl; 142726f3deacStedu } 142826f3deacStedu } else { 1429835c1779Sbrad tocopy = MIN(left, ntfs_cntob(ccl) - off); 1430a1ea65c6Sjsing DDPRINTF("ntfs_readntvattr_plain: hole: " 1431f2997212Sjsing "ccn: 0x%llx ccl: %llu, off: %lld, " 1432f05ab2cdSstefan "len: %zu, left: %zu\n", 1433f2997212Sjsing ccn, ccl, off, tocopy, left); 143426f3deacStedu left -= tocopy; 143526f3deacStedu off = 0; 143626f3deacStedu if (uio) { 143726f3deacStedu size_t remains = tocopy; 1438fca26c8fSmiod for(; remains; remains--) { 143968343589Smiod error = uiomove("", 1, uio); 1440fca26c8fSmiod if (error != 0) 1441fca26c8fSmiod break; 1442fca26c8fSmiod } 144326f3deacStedu } else 144426f3deacStedu bzero(data, tocopy); 144526f3deacStedu data = data + tocopy; 144626f3deacStedu } 144726f3deacStedu cnt++; 1448fca26c8fSmiod if (error != 0) 1449fca26c8fSmiod break; 145026f3deacStedu } 1451fca26c8fSmiod if (left && error == 0) { 145226f3deacStedu printf("ntfs_readntvattr_plain: POSSIBLE RUN ERROR\n"); 145326f3deacStedu error = E2BIG; 145426f3deacStedu } 145526f3deacStedu } else { 1456a1ea65c6Sjsing DDPRINTF("ntfs_readnvattr_plain: data is in mft record\n"); 145726f3deacStedu if (uio) 1458f05ab2cdSstefan error = uiomove(vap->va_datap + roff, rsize, uio); 145926f3deacStedu else 146026f3deacStedu memcpy(rdata, vap->va_datap + roff, rsize); 146126f3deacStedu *initp += rsize; 146226f3deacStedu } 146326f3deacStedu 146426f3deacStedu return (error); 146526f3deacStedu } 146626f3deacStedu 146726f3deacStedu /* 146826f3deacStedu * This is one of read routines. 146926f3deacStedu */ 147026f3deacStedu int 14711cc0505dSjsing ntfs_readattr_plain(struct ntfsmount *ntmp, struct ntnode *ip, 14721cc0505dSjsing u_int32_t attrnum, char *attrname, off_t roff, size_t rsize, void *rdata, 14731cc0505dSjsing size_t *initp, struct uio *uio) 147426f3deacStedu { 147526f3deacStedu size_t init; 147626f3deacStedu int error = 0; 1477f05ab2cdSstefan off_t off = roff; 1478f05ab2cdSstefan size_t left = rsize, toread; 147926f3deacStedu caddr_t data = rdata; 148026f3deacStedu struct ntvattr *vap; 148126f3deacStedu *initp = 0; 148226f3deacStedu 148326f3deacStedu while (left) { 148426f3deacStedu error = ntfs_ntvattrget(ntmp, ip, attrnum, attrname, 148526f3deacStedu ntfs_btocn(off), &vap); 148626f3deacStedu if (error) 148726f3deacStedu return (error); 1488835c1779Sbrad toread = MIN(left, ntfs_cntob(vap->va_vcnend + 1) - off); 1489f05ab2cdSstefan DDPRINTF("ntfs_readattr_plain: o: %lld, s: %zu " 1490f2997212Sjsing "(%llu - %llu)\n", off, toread, 1491f2997212Sjsing vap->va_vcnstart, vap->va_vcnend); 149226f3deacStedu error = ntfs_readntvattr_plain(ntmp, ip, vap, 149326f3deacStedu off - ntfs_cntob(vap->va_vcnstart), 149426f3deacStedu toread, data, &init, uio); 149526f3deacStedu if (error) { 1496f05ab2cdSstefan printf("ntfs_readattr_plain: ntfs_readntvattr_plain " 1497f05ab2cdSstefan "failed: o: %lld, s: %zu\n", off, toread); 1498f05ab2cdSstefan printf("ntfs_readattr_plain: attrib: %llu - %llu\n", 1499f05ab2cdSstefan vap->va_vcnstart, vap->va_vcnend); 150026f3deacStedu ntfs_ntvattrrele(vap); 150126f3deacStedu break; 150226f3deacStedu } 150326f3deacStedu ntfs_ntvattrrele(vap); 150426f3deacStedu left -= toread; 150526f3deacStedu off += toread; 150626f3deacStedu data = data + toread; 150726f3deacStedu *initp += init; 150826f3deacStedu } 150926f3deacStedu 151026f3deacStedu return (error); 151126f3deacStedu } 151226f3deacStedu 151326f3deacStedu /* 151426f3deacStedu * This is one of read routines. 151526f3deacStedu */ 151626f3deacStedu int 15171cc0505dSjsing ntfs_readattr(struct ntfsmount *ntmp, struct ntnode *ip, u_int32_t attrnum, 15181cc0505dSjsing char *attrname, off_t roff, size_t rsize, void *rdata, struct uio *uio) 151926f3deacStedu { 152026f3deacStedu int error = 0; 152126f3deacStedu struct ntvattr *vap; 152226f3deacStedu size_t init; 152326f3deacStedu 1524f2997212Sjsing DDPRINTF("ntfs_readattr: reading %u: 0x%x, from %lld size %zu bytes\n", 1525f2997212Sjsing ip->i_number, attrnum, roff, rsize); 152626f3deacStedu 152726f3deacStedu error = ntfs_ntvattrget(ntmp, ip, attrnum, attrname, 0, &vap); 152826f3deacStedu if (error) 152926f3deacStedu return (error); 153026f3deacStedu 153126f3deacStedu if ((roff > vap->va_datalen) || 153226f3deacStedu (roff + rsize > vap->va_datalen)) { 15335adbeedcSjsing printf("ntfs_readattr: offset too big: %lld (%lld) > %llu\n", 1534f2997212Sjsing roff, roff + rsize, vap->va_datalen); 153526f3deacStedu ntfs_ntvattrrele(vap); 153626f3deacStedu return (E2BIG); 153726f3deacStedu } 153826f3deacStedu if (vap->va_compression && vap->va_compressalg) { 153926f3deacStedu u_int8_t *cup; 154026f3deacStedu u_int8_t *uup; 1541f05ab2cdSstefan off_t off = roff; 154226f3deacStedu caddr_t data = rdata; 154326f3deacStedu cn_t cn; 1544f05ab2cdSstefan size_t left = rsize, tocopy; 154526f3deacStedu 1546f2997212Sjsing DDPRINTF("ntfs_ntreadattr: compression: %u\n", 1547a1ea65c6Sjsing vap->va_compressalg); 154826f3deacStedu 1549e8821f89Shshoexer cup = malloc(ntfs_cntob(NTFS_COMPUNIT_CL), M_NTFSDECOMP, 1550e8821f89Shshoexer M_WAITOK); 1551e8821f89Shshoexer uup = malloc(ntfs_cntob(NTFS_COMPUNIT_CL), M_NTFSDECOMP, 1552e8821f89Shshoexer M_WAITOK); 155326f3deacStedu 155426f3deacStedu cn = (ntfs_btocn(roff)) & (~(NTFS_COMPUNIT_CL - 1)); 155526f3deacStedu off = roff - ntfs_cntob(cn); 155626f3deacStedu 155726f3deacStedu while (left) { 155826f3deacStedu error = ntfs_readattr_plain(ntmp, ip, attrnum, 155926f3deacStedu attrname, ntfs_cntob(cn), 156026f3deacStedu ntfs_cntob(NTFS_COMPUNIT_CL), 156126f3deacStedu cup, &init, NULL); 156226f3deacStedu if (error) 156326f3deacStedu break; 156426f3deacStedu 1565835c1779Sbrad tocopy = MIN(left, ntfs_cntob(NTFS_COMPUNIT_CL) - off); 156626f3deacStedu 156726f3deacStedu if (init == ntfs_cntob(NTFS_COMPUNIT_CL)) { 156826f3deacStedu if (uio) 1569f05ab2cdSstefan error = uiomove(cup + off, tocopy, uio); 157026f3deacStedu else 157126f3deacStedu memcpy(data, cup + off, tocopy); 157226f3deacStedu } else if (init == 0) { 157326f3deacStedu if (uio) { 157426f3deacStedu size_t remains = tocopy; 1575fca26c8fSmiod for(; remains; remains--) { 157668343589Smiod error = uiomove("", 1, uio); 1577fca26c8fSmiod if (error != 0) 1578fca26c8fSmiod break; 1579fca26c8fSmiod } 158026f3deacStedu } 158126f3deacStedu else 158226f3deacStedu bzero(data, tocopy); 158326f3deacStedu } else { 158426f3deacStedu error = ntfs_uncompunit(ntmp, uup, cup); 158526f3deacStedu if (error) 158626f3deacStedu break; 158726f3deacStedu if (uio) 1588f05ab2cdSstefan error = uiomove(uup + off, tocopy, uio); 158926f3deacStedu else 159026f3deacStedu memcpy(data, uup + off, tocopy); 159126f3deacStedu } 1592fca26c8fSmiod if (error) 1593fca26c8fSmiod break; 159426f3deacStedu 159526f3deacStedu left -= tocopy; 159626f3deacStedu data = data + tocopy; 159726f3deacStedu off += tocopy - ntfs_cntob(NTFS_COMPUNIT_CL); 159826f3deacStedu cn += NTFS_COMPUNIT_CL; 159926f3deacStedu } 160026f3deacStedu 1601825c4e6aStedu free(uup, M_NTFSDECOMP, 0); 1602825c4e6aStedu free(cup, M_NTFSDECOMP, 0); 160326f3deacStedu } else 160426f3deacStedu error = ntfs_readattr_plain(ntmp, ip, attrnum, attrname, 160526f3deacStedu roff, rsize, rdata, &init, uio); 160626f3deacStedu ntfs_ntvattrrele(vap); 160726f3deacStedu return (error); 160826f3deacStedu } 160926f3deacStedu 161026f3deacStedu #if UNUSED_CODE 161126f3deacStedu int 16121cc0505dSjsing ntfs_parserun(cn_t *cn, cn_t *cl, u_int8_t *run, u_long len, u_long *off) 161326f3deacStedu { 161426f3deacStedu u_int8_t sz; 161526f3deacStedu int i; 161626f3deacStedu 161726f3deacStedu if (NULL == run) { 161826f3deacStedu printf("ntfs_parsetun: run == NULL\n"); 161926f3deacStedu return (EINVAL); 162026f3deacStedu } 162126f3deacStedu sz = run[(*off)++]; 162226f3deacStedu if (0 == sz) { 162326f3deacStedu printf("ntfs_parserun: trying to go out of run\n"); 162426f3deacStedu return (E2BIG); 162526f3deacStedu } 162626f3deacStedu *cl = 0; 162726f3deacStedu if ((sz & 0xF) > 8 || (*off) + (sz & 0xF) > len) { 162826f3deacStedu printf("ntfs_parserun: " \ 162926f3deacStedu "bad run: length too big: sz: 0x%02x (%ld < %ld + sz)\n", 163026f3deacStedu sz, len, *off); 163126f3deacStedu return (EINVAL); 163226f3deacStedu } 163326f3deacStedu for (i = 0; i < (sz & 0xF); i++) 163426f3deacStedu *cl += (u_int32_t) run[(*off)++] << (i << 3); 163526f3deacStedu 163626f3deacStedu sz >>= 4; 163726f3deacStedu if ((sz & 0xF) > 8 || (*off) + (sz & 0xF) > len) { 163826f3deacStedu printf("ntfs_parserun: " \ 163926f3deacStedu "bad run: length too big: sz: 0x%02x (%ld < %ld + sz)\n", 164026f3deacStedu sz, len, *off); 164126f3deacStedu return (EINVAL); 164226f3deacStedu } 164326f3deacStedu for (i = 0; i < (sz & 0xF); i++) 164426f3deacStedu *cn += (u_int32_t) run[(*off)++] << (i << 3); 164526f3deacStedu 164626f3deacStedu return (0); 164726f3deacStedu } 164826f3deacStedu #endif 164926f3deacStedu 165026f3deacStedu /* 165126f3deacStedu * Process fixup routine on given buffer. 165226f3deacStedu */ 165326f3deacStedu int 16541cc0505dSjsing ntfs_procfixups(struct ntfsmount *ntmp, u_int32_t magic, caddr_t buf, 165526f3deacStedu size_t len) 165626f3deacStedu { 165726f3deacStedu struct fixuphdr *fhp = (struct fixuphdr *) buf; 165826f3deacStedu int i; 165926f3deacStedu u_int16_t fixup; 166026f3deacStedu u_int16_t *fxp; 166126f3deacStedu u_int16_t *cfxp; 166226f3deacStedu 166326f3deacStedu if (fhp->fh_magic != magic) { 166426f3deacStedu printf("ntfs_procfixups: magic doesn't match: %08x != %08x\n", 166526f3deacStedu fhp->fh_magic, magic); 166626f3deacStedu return (EINVAL); 166726f3deacStedu } 166826f3deacStedu if ((fhp->fh_fnum - 1) * ntmp->ntm_bps != len) { 166926f3deacStedu printf("ntfs_procfixups: " \ 167026f3deacStedu "bad fixups number: %d for %ld bytes block\n", 167126f3deacStedu fhp->fh_fnum, (long)len); /* XXX printf kludge */ 167226f3deacStedu return (EINVAL); 167326f3deacStedu } 167426f3deacStedu if (fhp->fh_foff >= ntmp->ntm_spc * ntmp->ntm_mftrecsz * ntmp->ntm_bps) { 167526f3deacStedu printf("ntfs_procfixups: invalid offset: %x", fhp->fh_foff); 167626f3deacStedu return (EINVAL); 167726f3deacStedu } 167826f3deacStedu fxp = (u_int16_t *) (buf + fhp->fh_foff); 167926f3deacStedu cfxp = (u_int16_t *) (buf + ntmp->ntm_bps - 2); 168026f3deacStedu fixup = *fxp++; 168126f3deacStedu for (i = 1; i < fhp->fh_fnum; i++, fxp++) { 168226f3deacStedu if (*cfxp != fixup) { 168326f3deacStedu printf("ntfs_procfixups: fixup %d doesn't match\n", i); 168426f3deacStedu return (EINVAL); 168526f3deacStedu } 168626f3deacStedu *cfxp = *fxp; 1687835c1779Sbrad cfxp = (u_int16_t *)((caddr_t)cfxp + ntmp->ntm_bps); 168826f3deacStedu } 168926f3deacStedu return (0); 169026f3deacStedu } 169126f3deacStedu 169226f3deacStedu #if UNUSED_CODE 169326f3deacStedu int 16941cc0505dSjsing ntfs_runtocn(cn_t *cn, struct ntfsmount *ntmp, u_int8_t *run, u_long len, 169526f3deacStedu cn_t vcn) 169626f3deacStedu { 169726f3deacStedu cn_t ccn = 0; 169826f3deacStedu cn_t ccl = 0; 169926f3deacStedu u_long off = 0; 170026f3deacStedu int error = 0; 170126f3deacStedu 170226f3deacStedu #if NTFS_DEBUG 170326f3deacStedu int i; 1704846c180eSbrad printf("ntfs_runtocn: run: %p, %ld bytes, vcn:%ld\n", 170526f3deacStedu run, len, (u_long) vcn); 170626f3deacStedu printf("ntfs_runtocn: run: "); 170726f3deacStedu for (i = 0; i < len; i++) 170826f3deacStedu printf("0x%02x ", run[i]); 170926f3deacStedu printf("\n"); 171026f3deacStedu #endif 171126f3deacStedu 171226f3deacStedu if (NULL == run) { 171326f3deacStedu printf("ntfs_runtocn: run == NULL\n"); 171426f3deacStedu return (EINVAL); 171526f3deacStedu } 171626f3deacStedu do { 171726f3deacStedu if (run[off] == 0) { 171826f3deacStedu printf("ntfs_runtocn: vcn too big\n"); 171926f3deacStedu return (E2BIG); 172026f3deacStedu } 172126f3deacStedu vcn -= ccl; 172226f3deacStedu error = ntfs_parserun(&ccn, &ccl, run, len, &off); 172326f3deacStedu if (error) { 172426f3deacStedu printf("ntfs_runtocn: ntfs_parserun failed\n"); 172526f3deacStedu return (error); 172626f3deacStedu } 172726f3deacStedu } while (ccl <= vcn); 172826f3deacStedu *cn = ccn + vcn; 172926f3deacStedu return (0); 173026f3deacStedu } 173126f3deacStedu #endif 173226f3deacStedu 173326f3deacStedu /* 1734274476fcStedu * if the ntfs_toupper_tab[] is filled already, just raise use count; 1735274476fcStedu * otherwise read the data from the filesystem we are currently mounting 173626f3deacStedu */ 173726f3deacStedu int 17381cc0505dSjsing ntfs_toupper_use(struct mount *mp, struct ntfsmount *ntmp, struct proc *p) 173926f3deacStedu { 174026f3deacStedu int error = 0; 174126f3deacStedu struct vnode *vp; 174226f3deacStedu 1743274476fcStedu /* get exclusive access */ 1744274476fcStedu rw_enter_write(&ntfs_toupper_lock); 1745274476fcStedu 174626f3deacStedu /* only read the translation data from a file if it hasn't been 174726f3deacStedu * read already */ 174826f3deacStedu if (ntfs_toupper_tab) 174926f3deacStedu goto out; 175026f3deacStedu 175126f3deacStedu /* 175226f3deacStedu * Read in Unicode lowercase -> uppercase translation file. 175326f3deacStedu * XXX for now, just the first 256 entries are used anyway, 175426f3deacStedu * so don't bother reading more 175526f3deacStedu */ 1756265a1ec5Sdhill ntfs_toupper_tab = malloc(256 * 256 * sizeof(wchar), M_NTFSRDATA, 1757274476fcStedu M_WAITOK); 175826f3deacStedu 175926f3deacStedu if ((error = VFS_VGET(mp, NTFS_UPCASEINO, &vp))) 176026f3deacStedu goto out; 1761274476fcStedu error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL, 1762274476fcStedu 0, 256*256*sizeof(wchar), (char *) ntfs_toupper_tab, 1763274476fcStedu NULL); 176426f3deacStedu vput(vp); 176526f3deacStedu 1766274476fcStedu out: 1767274476fcStedu ntfs_toupper_usecount++; 1768274476fcStedu rw_exit_write(&ntfs_toupper_lock); 1769274476fcStedu return (error); 1770e7116e76Stedu } 1771e7116e76Stedu 1772274476fcStedu /* 1773274476fcStedu * lower the use count and if it reaches zero, free the memory 1774274476fcStedu * tied by toupper table 1775274476fcStedu */ 1776274476fcStedu void 17771cc0505dSjsing ntfs_toupper_unuse(struct proc *p) 1778274476fcStedu { 1779274476fcStedu /* get exclusive access */ 1780274476fcStedu rw_enter_write(&ntfs_toupper_lock); 1781e7116e76Stedu 1782274476fcStedu ntfs_toupper_usecount--; 1783274476fcStedu if (ntfs_toupper_usecount == 0) { 1784825c4e6aStedu free(ntfs_toupper_tab, M_NTFSRDATA, 0); 1785274476fcStedu ntfs_toupper_tab = NULL; 1786274476fcStedu } 1787274476fcStedu #ifdef DIAGNOSTIC 1788274476fcStedu else if (ntfs_toupper_usecount < 0) { 1789274476fcStedu panic("ntfs_toupper_unuse(): use count negative: %d", 1790274476fcStedu ntfs_toupper_usecount); 1791274476fcStedu } 1792274476fcStedu #endif 1793274476fcStedu 1794274476fcStedu /* release the lock */ 1795274476fcStedu rw_exit_write(&ntfs_toupper_lock); 179626f3deacStedu } 1797