X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/e5568f75972dfc723778653c11cb6b4dc825716a..ca66cea69e6e866fd781ae2260d9474bdd48f2ca:/bsd/hfs/hfs_catalog.h diff --git a/bsd/hfs/hfs_catalog.h b/bsd/hfs/hfs_catalog.h index 0f67eadf8..03c36567b 100644 --- a/bsd/hfs/hfs_catalog.h +++ b/bsd/hfs/hfs_catalog.h @@ -1,23 +1,29 @@ /* - * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2002-2007 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifndef __HFS_CATALOG__ #define __HFS_CATALOG__ @@ -26,9 +32,7 @@ #ifdef KERNEL #ifdef __APPLE_API_PRIVATE -#include #include -#include #include @@ -53,7 +57,7 @@ struct cat_desc { u_int8_t cd_flags; /* see below (8 bits) */ u_int8_t cd_encoding; /* name encoding */ int16_t cd_namelen; /* length of cnode name */ - char * cd_nameptr; /* pointer to cnode name */ + const u_int8_t * cd_nameptr; /* pointer to cnode name */ cnid_t cd_parentcnid; /* parent directory CNID */ u_long cd_hint; /* catalog file hint */ cnid_t cd_cnid; /* cnode id (for getattrlist) */ @@ -71,26 +75,39 @@ struct cat_desc { struct cat_attr { cnid_t ca_fileid; /* inode number (for stat) normally == cnid */ mode_t ca_mode; /* file access mode and type (16 bits) */ - nlink_t ca_nlink; /* file link count (16 bit integer) */ + u_int16_t ca_recflags; /* catalog record flags (16 bit integer) */ + u_int32_t ca_linkcount; /* real hard link count */ uid_t ca_uid; /* file owner */ gid_t ca_gid; /* file group */ - dev_t ca_rdev; /* device a special file represents */ + union { + dev_t cau_rdev; /* special file device (VBLK or VCHAR only) */ + u_int32_t cau_linkref; /* hardlink reference number */ + } ca_union1; time_t ca_atime; /* last access time */ + time_t ca_atimeondisk; /* access time value on disk */ time_t ca_mtime; /* last data modification time */ - int32_t ca_mtime_nsec; /* last data modification time nanosec */ time_t ca_ctime; /* last file status change */ time_t ca_itime; /* file initialization time */ time_t ca_btime; /* last backup time */ - u_long ca_flags; /* status flags (chflags) */ + u_int32_t ca_flags; /* status flags (chflags) */ + union { + u_int32_t cau_blocks; /* total file blocks used (rsrc + data) */ + u_int32_t cau_entries; /* total directory entries (valence) */ + } ca_union2; union { - u_int32_t cau_blocks; /* total file blocks used (rsrc + data) */ - u_int32_t cau_entries; /* total directory entries (valence) */ - } ca_union; + u_int32_t cau_dircount; /* count of sub dirs (for posix nlink) */ + u_int32_t cau_firstlink; /* first hardlink link (files only) */ + } ca_union3; u_int8_t ca_finderinfo[32]; /* Opaque Finder information */ }; + /* Aliases for common fields */ -#define ca_blocks ca_union.cau_blocks -#define ca_entries ca_union.cau_entries +#define ca_rdev ca_union1.cau_rdev +#define ca_linkref ca_union1.cau_linkref +#define ca_blocks ca_union2.cau_blocks +#define ca_entries ca_union2.cau_entries +#define ca_dircount ca_union3.cau_dircount +#define ca_firstlink ca_union3.cau_firstlink /* * Catalog Node Fork (runtime) @@ -98,7 +115,7 @@ struct cat_attr { * NOTE: this is not the same as a struct HFSPlusForkData */ struct cat_fork { - u_int64_t cf_size; /* fork's logical size in bytes */ + off_t cf_size; /* fork's logical size in bytes */ union { u_int32_t cfu_clump; /* fork's clump size in bytes (sys files only) */ u_int64_t cfu_bytesread; /* bytes read from this fork */ @@ -112,6 +129,34 @@ struct cat_fork { #define cf_bytesread cf_union.cfu_bytesread +/* + * Directory Hint + * Used to hold state across directory enumerations. + * + */ +struct directoryhint { + TAILQ_ENTRY(directoryhint) dh_link; /* chain */ + int dh_index; /* index into directory (zero relative) */ + u_int32_t dh_threadhint; /* node hint of a directory's thread record */ + u_int32_t dh_time; + struct cat_desc dh_desc; /* entry's descriptor */ +}; +typedef struct directoryhint directoryhint_t; + +/* + * HFS_MAXDIRHINTS cannot be larger than 63 without reducing + * HFS_INDEX_BITS, because given the 6-bit tag, at most 63 different + * tags can exist. When HFS_MAXDIRHINTS is larger than 63, the same + * list may contain dirhints of the same tag, and a staled dirhint may + * be returned. + */ +#define HFS_MAXDIRHINTS 32 +#define HFS_DIRHINT_TTL 45 + +#define HFS_INDEX_MASK 0x03ffffff +#define HFS_INDEX_BITS 26 + + /* * Catalog Node Entry * @@ -126,18 +171,33 @@ struct cat_entry { u_long ce_rsrcblks; }; -#define MAXCATENTRIES 8 +/* + * Starting in 10.5, hfs_vnop_readdirattr() only makes one + * call to cat_getentriesattr(). So we increased MAXCATENTRIES + * while keeping the total size of the CE LIST buffer <= 8K + * (which works out to be 60 entries per call). The 8K limit + * keeps the memory coming from a kalloc zone instead of + * valuable/fragment-able kernel map space. + */ +#define MAXCATENTRIES \ + (1 + (8192 - sizeof (struct cat_entrylist)) / sizeof (struct cat_entry)) + /* * Catalog Node Entry List * * A cat_entrylist is a list of Catalog Node Entries. */ struct cat_entrylist { - u_long maxentries; /* length of list */ - u_long realentries; /* valid entry count */ - struct cat_entry entry[MAXCATENTRIES]; /* array of entries */ + u_long maxentries; /* number of entries requested */ + u_long realentries; /* number of valid entries returned */ + u_long skipentries; /* number of entries skipped (reserved HFS+ files) */ + struct cat_entry entry[1]; /* array of entries */ }; +#define CE_LIST_SIZE(entries) \ + sizeof (*ce_list) + (((entries) - 1) * sizeof (struct cat_entry)) + + /* * Catalog Operations Hint * @@ -145,10 +205,10 @@ struct cat_entrylist { * upper 16 bits: count of B-tree delete operations * */ -#define CAT_DELETE 0x00020000 +#define CAT_DELETE 0x00010000 #define CAT_CREATE 0x00000002 -#define CAT_RENAME 0x00020002 -#define CAT_EXCHANGE 0x00020002 +#define CAT_RENAME 0x00010002 +#define CAT_EXCHANGE 0x00010002 typedef u_int32_t catops_t; @@ -160,6 +220,26 @@ typedef struct cat_cookie_t { char opaque[24]; } cat_cookie_t; +/* Universal catalog key */ +union CatalogKey { + HFSCatalogKey hfs; + HFSPlusCatalogKey hfsPlus; +}; +typedef union CatalogKey CatalogKey; + +/* Universal catalog data record */ +union CatalogRecord { + int16_t recordType; + HFSCatalogFolder hfsFolder; + HFSCatalogFile hfsFile; + HFSCatalogThread hfsThread; + HFSPlusCatalogFolder hfsPlusFolder; + HFSPlusCatalogFile hfsPlusFile; + HFSPlusCatalogThread hfsPlusThread; +}; +typedef union CatalogRecord CatalogRecord; + + /* * Catalog Interface * @@ -186,18 +266,23 @@ extern int cat_lookup ( struct hfsmount *hfsmp, int wantrsrc, struct cat_desc *outdescp, struct cat_attr *attrp, - struct cat_fork *forkp); + struct cat_fork *forkp, + cnid_t *desc_cnid); extern int cat_idlookup (struct hfsmount *hfsmp, cnid_t cnid, + int allow_system_files, struct cat_desc *outdescp, struct cat_attr *attrp, struct cat_fork *forkp); +extern int cat_findname (struct hfsmount *hfsmp, + cnid_t cnid, + struct cat_desc *outdescp); + extern int cat_getentriesattr( struct hfsmount *hfsmp, - struct cat_desc *prevdesc, - int index, + directoryhint_t *dirhint, struct cat_entrylist *ce_list); extern int cat_rename ( struct hfsmount * hfsmp, @@ -214,12 +299,12 @@ extern int cat_update ( struct hfsmount *hfsmp, extern int cat_getdirentries( struct hfsmount *hfsmp, - struct cat_desc *descp, int entrycnt, - struct uio *uio, - int *eofflag, - u_long *cookies, - int ncookies); + directoryhint_t *dirhint, + uio_t uio, + int extended, + int * items, + int * eofflag); extern int cat_insertfilethread ( struct hfsmount *hfsmp, @@ -240,6 +325,83 @@ extern int cat_binarykeycompare( HFSPlusCatalogKey *searchKey, HFSPlusCatalogKey *trialKey); +extern int CompareCatalogKeys( + HFSCatalogKey *searchKey, + HFSCatalogKey *trialKey); + +extern int CompareExtendedCatalogKeys( + HFSPlusCatalogKey *searchKey, + HFSPlusCatalogKey *trialKey); + +extern void cat_convertattr( + struct hfsmount *hfsmp, + CatalogRecord * recp, + struct cat_attr *attrp, + struct cat_fork *datafp, + struct cat_fork *rsrcfp); + +extern int cat_convertkey( + struct hfsmount *hfsmp, + CatalogKey *key, + CatalogRecord * recp, + struct cat_desc *descp); + +extern int cat_getkeyplusattr( + struct hfsmount *hfsmp, + cnid_t cnid, + CatalogKey *key, + struct cat_attr *attrp); + +/* Hard link functions. */ + +extern int cat_check_link_ancestry( + struct hfsmount *hfsmp, + cnid_t parentid, + cnid_t pointed_at_cnid); + +extern int cat_set_childlinkbit( + struct hfsmount *hfsmp, + cnid_t cnid); + +#define HFS_IGNORABLE_LINK 0x00000001 + +extern int cat_resolvelink( struct hfsmount *hfsmp, + u_long linkref, + int isdirlink, + struct HFSPlusCatalogFile *recp); + +extern int cat_createlink( struct hfsmount *hfsmp, + struct cat_desc *descp, + struct cat_attr *attr, + cnid_t nextlinkid, + cnid_t *linkfileid); + +/* Finder Info's file type and creator for directory hard link alias */ +enum { + kHFSAliasType = 0x66647270, /* 'fdrp' */ + kHFSAliasCreator = 0x4D414353 /* 'MACS' */ +}; + +extern int cat_deletelink( struct hfsmount *hfsmp, + struct cat_desc *descp); + +extern int cat_updatelink( struct hfsmount *hfsmp, + cnid_t linkfileid, + cnid_t prevlinkid, + cnid_t nextlinkid); + +extern int cat_lookuplink( struct hfsmount *hfsmp, + struct cat_desc *descp, + cnid_t *linkfileid, + cnid_t *prevlinkid, + cnid_t *nextlinkid); + +extern int cat_lookuplinkbyid( struct hfsmount *hfsmp, + cnid_t linkfileid, + cnid_t *prevlinkid, + cnid_t *nextlinkid); + + #endif /* __APPLE_API_PRIVATE */ #endif /* KERNEL */ #endif /* __HFS_CATALOG__ */