#ifndef __HFS_CATALOG__
#define __HFS_CATALOG__
#include <sys/appleapiopts.h>
#ifdef KERNEL
#ifdef __APPLE_API_PRIVATE
#include <sys/vnode.h>
#include <hfs/hfs_format.h>
typedef u_int32_t cnid_t;
struct cat_desc {
u_int8_t cd_flags;
u_int8_t cd_encoding;
int16_t cd_namelen;
cnid_t cd_parentcnid;
u_int32_t cd_hint;
cnid_t cd_cnid;
const u_int8_t * cd_nameptr;
};
#define CD_HASBUF 0x01
#define CD_DECOMPOSED 0x02
#define CD_EOF 0x04
#define CD_ISMETA 0x40
#define CD_ISDIR 0x80
struct cat_attr {
cnid_t ca_fileid;
mode_t ca_mode;
u_int16_t ca_recflags;
u_int32_t ca_linkcount;
uid_t ca_uid;
gid_t ca_gid;
union {
dev_t cau_rdev;
u_int32_t cau_linkref;
} ca_union1;
time_t ca_atime;
time_t ca_atimeondisk;
time_t ca_mtime;
time_t ca_ctime;
time_t ca_itime;
time_t ca_btime;
u_int32_t ca_flags;
union {
u_int32_t cau_blocks;
u_int32_t cau_entries;
} ca_union2;
union {
u_int32_t cau_dircount;
u_int32_t cau_firstlink;
} ca_union3;
u_int8_t ca_finderinfo[32];
};
#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
struct cat_fork {
off_t cf_size;
off_t cf_new_size;
union {
u_int32_t cfu_clump;
u_int64_t cfu_bytesread;
} cf_union;
u_int32_t cf_vblocks;
u_int32_t cf_blocks;
struct HFSPlusExtentDescriptor cf_extents[8];
};
#define cf_clump cf_union.cfu_clump
#define cf_bytesread cf_union.cfu_bytesread
struct directoryhint {
TAILQ_ENTRY(directoryhint) dh_link;
int dh_index;
u_int32_t dh_threadhint;
u_int32_t dh_time;
struct cat_desc dh_desc;
};
typedef struct directoryhint directoryhint_t;
#define HFS_MAXDIRHINTS 32
#define HFS_DIRHINT_TTL 45
#define HFS_INDEX_MASK 0x03ffffff
#define HFS_INDEX_BITS 26
struct cat_entry {
struct cat_desc ce_desc;
struct cat_attr ce_attr;
off_t ce_datasize;
off_t ce_rsrcsize;
u_int32_t ce_datablks;
u_int32_t ce_rsrcblks;
};
#define MAXCATENTRIES \
(1 + (8192 - sizeof (struct cat_entrylist)) / sizeof (struct cat_entry))
struct cat_entrylist {
u_int32_t maxentries;
u_int32_t realentries;
u_int32_t skipentries;
struct cat_entry entry[1];
};
#define CE_LIST_SIZE(entries) \
sizeof (*ce_list) + (((entries) - 1) * sizeof (struct cat_entry))
#define CAT_DELETE 0x00010000
#define CAT_CREATE 0x00000002
#define CAT_RENAME 0x00010002
#define CAT_EXCHANGE 0x00010002
typedef u_int32_t catops_t;
typedef struct cat_cookie_t {
#if defined(__LP64__)
char opaque[40];
#else
char opaque[24];
#endif
} cat_cookie_t;
union CatalogKey {
HFSCatalogKey hfs;
HFSPlusCatalogKey hfsPlus;
};
typedef union CatalogKey CatalogKey;
union CatalogRecord {
int16_t recordType;
HFSCatalogFolder hfsFolder;
HFSCatalogFile hfsFile;
HFSCatalogThread hfsThread;
HFSPlusCatalogFolder hfsPlusFolder;
HFSPlusCatalogFile hfsPlusFile;
HFSPlusCatalogThread hfsPlusThread;
};
typedef union CatalogRecord CatalogRecord;
enum {
kHFSDataForkType = 0x0,
kHFSResourceForkType = 0xff
};
struct hfsmount;
extern void cat_releasedesc(struct cat_desc *descp);
extern int cat_create ( struct hfsmount *hfsmp,
struct cat_desc *descp,
struct cat_attr *attrp,
struct cat_desc *out_descp);
extern int cat_delete ( struct hfsmount *hfsmp,
struct cat_desc *descp,
struct cat_attr *attrp);
extern int cat_lookup ( struct hfsmount *hfsmp,
struct cat_desc *descp,
int wantrsrc,
struct cat_desc *outdescp,
struct cat_attr *attrp,
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,
directoryhint_t *dirhint,
struct cat_entrylist *ce_list);
extern int cat_rename ( struct hfsmount * hfsmp,
struct cat_desc * from_cdp,
struct cat_desc * todir_cdp,
struct cat_desc * to_cdp,
struct cat_desc * cdp);
extern int cat_update ( struct hfsmount *hfsmp,
struct cat_desc *descp,
struct cat_attr *attrp,
struct cat_fork *dataforkp,
struct cat_fork *rsrcforkp);
extern int cat_getdirentries(
struct hfsmount *hfsmp,
u_int32_t entrycnt,
directoryhint_t *dirhint,
uio_t uio,
int extended,
int * items,
int * eofflag);
extern int cat_insertfilethread (
struct hfsmount *hfsmp,
struct cat_desc *descp);
extern int cat_preflight(
struct hfsmount *hfsmp,
catops_t ops,
cat_cookie_t *cookie,
struct proc *p);
extern void cat_postflight(
struct hfsmount *hfsmp,
cat_cookie_t *cookie,
struct proc *p);
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);
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_int32_t 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);
enum {
kHFSAliasType = 0x66647270,
kHFSAliasCreator = 0x4D414353
};
extern int cat_deletelink( struct hfsmount *hfsmp,
struct cat_desc *descp);
extern int cat_update_siblinglinks( 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_lookup_siblinglinks( struct hfsmount *hfsmp,
cnid_t linkfileid,
cnid_t *prevlinkid,
cnid_t *nextlinkid);
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
#endif
#endif