]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfs_catalog.h
xnu-3247.1.106.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_catalog.h
index 2eaf3811f447b6f7747c209a896ecb852296105d..a4719ea41bf13cb8d5df7c6d0869254f71ffecec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2002-2014 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -63,9 +63,18 @@ struct cat_desc {
        const u_int8_t * cd_nameptr; /* pointer to cnode name */
 };
 
-/* cd_flags */
+/* cd_flags
+ *
+ * CD_EOF is used by hfs_vnop_readdir / cat_getdirentries to indicate EOF was
+ * encountered during a directory enumeration.  When this flag is observed
+ * on the next call to hfs_vnop_readdir it tells the caller that there's no
+ * need to descend into the catalog as EOF was encountered during the last call.
+ * This flag should only be set on the descriptor embedded in the directoryhint. 
+ */
+
 #define        CD_HASBUF       0x01    /* allocated filename buffer */
 #define CD_DECOMPOSED  0x02    /* name is fully decomposed */
+#define CD_EOF         0x04    /* see above */
 #define        CD_ISMETA       0x40    /* describes a metadata file */
 #define        CD_ISDIR        0x80    /* describes a directory */
 
@@ -98,7 +107,17 @@ struct cat_attr {
            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 */
+       union {
+               u_int8_t        ca_finderinfo[32]; /* Opaque Finder information */
+               struct {
+                       FndrFileInfo                                    ca_finderfileinfo;
+                       struct FndrExtendedFileInfo     ca_finderextendedfileinfo;
+               };
+               struct {
+                       FndrDirInfo                                     ca_finderdirinfo;
+                       struct FndrExtendedDirInfo              ca_finderextendeddirinfo;
+               };
+       };
 };
 
 /* Aliases for common fields */
@@ -129,11 +148,18 @@ struct cat_fork {
        u_int32_t      cf_vblocks;     /* virtual (unalloated) blocks */
        u_int32_t      cf_blocks;      /* total blocks used by this fork */
        struct HFSPlusExtentDescriptor  cf_extents[8];  /* initial set of extents */
+
+       /*
+        * NOTE: If you change this structure, make sure you change you change
+        * hfs_fork_copy.
+        */
 };
 
 #define cf_clump       cf_union.cfu_clump
 #define cf_bytesread   cf_union.cfu_bytesread
 
+void hfs_fork_copy(struct cat_fork *dst, const struct cat_fork *src,
+                                  HFSPlusExtentDescriptor *extents);
 
 /*
  * Directory Hint
@@ -203,6 +229,50 @@ struct cat_entrylist {
 #define CE_LIST_SIZE(entries)  \
        sizeof (*ce_list) + (((entries) - 1) * sizeof (struct cat_entry))
 
+struct hfsmount;
+
+/*
+ * Catalog FileID/CNID Acquisition / Lookup 
+ *
+ * Some use-cases require that we find a valid CNID
+ * before we may be ready to enter the item into the namespace.
+ * In order to resolve this, we support a hashtable attached to
+ * the mount that is secured by the catalog lock.  
+ * 
+ * Finding the next valid CNID is easy if the wraparound bit is
+ * not set -- you just pull from the hfsmp next pointer.  
+ * If it is set then you must find a free entry in the catalog
+ * and also query the hashtable to see if the item is free or not.
+ * 
+ * If you want to request a CNID before there is a backing item
+ * in the catalog, you must find one that is valid, then insert
+ * it into the hash table until such time that the item is
+ * inserted into the catalog.  After successful catalog insertion,
+ * you must remove the item from the hashtable.
+ */
+
+typedef struct cat_preflightid {
+       cnid_t fileid;
+       LIST_ENTRY(cat_preflightid) id_hash;
+} cat_preflightid_t;
+
+extern int cat_remove_idhash (cat_preflightid_t *preflight);
+extern int cat_insert_idhash (struct hfsmount *hfsmp, cat_preflightid_t *preflight);
+extern int cat_check_idhash (struct hfsmount *hfsmp, cnid_t test_fileid);
+
+/* initialize the id look up hashtable during mount */
+extern void hfs_idhash_init (struct hfsmount *hfsmp);
+
+/* release the id lookup hashtable during unmount */
+extern void hfs_idhash_destroy (struct hfsmount *hfsmp);
+
+/* Get a new CNID for use */
+extern int cat_acquire_cnid (struct hfsmount *hfsmp, cnid_t *new_cnid);
+
+
+/* default size of ID hash is 64 entries */
+#define HFS_IDHASH_DEFAULT 64
+
 
 /*
  * Catalog Operations Hint
@@ -249,6 +319,11 @@ union CatalogRecord {
 };
 typedef union CatalogRecord  CatalogRecord;
 
+/* Constants for HFS fork types */
+enum {
+       kHFSDataForkType = 0x0,         /* data fork */
+       kHFSResourceForkType = 0xff     /* resource fork */
+};
 
 /*
  * Catalog Interface
@@ -258,11 +333,11 @@ typedef union CatalogRecord  CatalogRecord;
  * (please don't go around it)
  */
 
-struct hfsmount;
 
 extern void cat_releasedesc(struct cat_desc *descp);
 
 extern int cat_create (        struct hfsmount *hfsmp,
+                       cnid_t new_fileid,
                        struct cat_desc *descp,
                        struct cat_attr *attrp,
                        struct cat_desc *out_descp);
@@ -274,6 +349,7 @@ extern int cat_delete (     struct hfsmount *hfsmp,
 extern int cat_lookup (        struct hfsmount *hfsmp,
                        struct cat_desc *descp,
                        int wantrsrc,
+                       int force_casesensitive_lookup,
                        struct cat_desc *outdescp,
                        struct cat_attr *attrp,
                        struct cat_fork *forkp,
@@ -282,6 +358,7 @@ extern int cat_lookup (     struct hfsmount *hfsmp,
 extern int cat_idlookup (struct hfsmount *hfsmp,
                        cnid_t cnid,
                        int allow_system_files,
+                       int wantrsrc,
                        struct cat_desc *outdescp,
                        struct cat_attr *attrp,
                        struct cat_fork *forkp);
@@ -293,7 +370,8 @@ extern int cat_findname (struct hfsmount *hfsmp,
 extern int cat_getentriesattr(
                        struct hfsmount *hfsmp,
                        directoryhint_t *dirhint,
-                       struct cat_entrylist *ce_list);
+                       struct cat_entrylist *ce_list, 
+                       int *reachedeof);
 
 extern int cat_rename (        struct hfsmount * hfsmp,
                        struct cat_desc * from_cdp,
@@ -304,12 +382,12 @@ extern int cat_rename (   struct hfsmount * hfsmp,
 extern int cat_update (        struct hfsmount *hfsmp,
                        struct cat_desc *descp,
                        struct cat_attr *attrp,
-                       struct cat_fork *dataforkp,
-                       struct cat_fork *rsrcforkp);
+                       const struct cat_fork *dataforkp,
+                       const struct cat_fork *rsrcforkp);
 
 extern int cat_getdirentries(
                        struct hfsmount *hfsmp,
-                       int entrycnt,
+                       u_int32_t entrycnt,
                        directoryhint_t *dirhint,
                        uio_t uio,
                        int extended,
@@ -395,7 +473,7 @@ enum {
 extern int cat_deletelink( struct hfsmount *hfsmp,
                            struct cat_desc *descp);
 
-extern int cat_updatelink( struct hfsmount *hfsmp,
+extern int cat_update_siblinglinks( struct hfsmount *hfsmp,
                            cnid_t linkfileid,
                            cnid_t prevlinkid,
                            cnid_t nextlinkid);
@@ -406,11 +484,28 @@ extern int cat_lookuplink( struct hfsmount *hfsmp,
                            cnid_t *prevlinkid,
                            cnid_t *nextlinkid);
 
-extern int cat_lookuplinkbyid( struct hfsmount *hfsmp,
+extern int cat_lookup_siblinglinks( struct hfsmount *hfsmp,
                                cnid_t linkfileid,
                                cnid_t *prevlinkid,
                                cnid_t *nextlinkid);
 
+extern int cat_lookup_lastlink( struct hfsmount *hfsmp,
+                               cnid_t startid,
+                               cnid_t *nextlinkid,
+                                                          struct cat_desc *cdesc);
+
+extern int cat_lookup_dirlink(struct hfsmount *hfsmp, 
+                            cnid_t dirlink_id, 
+                            u_int8_t forktype, 
+                            struct cat_desc *outdescp, 
+                            struct cat_attr *attrp, 
+                            struct cat_fork *forkp);
+
+extern int cat_update_dirlink(struct hfsmount *hfsmp, 
+                             u_int8_t forktype, 
+                             struct cat_desc *descp, 
+                             struct cat_attr *attrp, 
+                             struct cat_fork *rsrcforkp);
 
 #endif /* __APPLE_API_PRIVATE */
 #endif /* KERNEL */