hfsplus

package
v1.0.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HFSPlusVersion uint32 = 0x0004 // 'H+' volumes are version 4 only
	HFSXVersion    uint32 = 0x0005 // 'HX' volumes start with version 5

	HFSPlusMountVersion uint32 = 0x31302E30 // '10.0' for Mac OS X
	HFSJMountVersion    uint32 = 0x4846534a // 'HFSJ' for journaled HFS+ on OS X
	FSKMountVersion     uint32 = 0x46534b21 // 'FSK!' for failed journal replay
	/*
	 * Indirect link files (hard links) have the following type/creator.
	 */
	HardLinkFileType = 0x686C6E6B // 'hlnk'
	HFSPlusCreator   = 0x6866732B //  'hfs+'
	/*
	 *	File type and creator for symbolic links
	 */
	SymLinkFileType uint32 = 0x736C6E6B // 'slnk'
	SymLinkCreator  uint32 = 0x72686170 // 'rhap'

	HFSMaxVolumeNameChars   = 27
	HFSMaxFileNameChars     = 31
	HFSPlusMaxFileNameChars = 255
)
View Source
const (
	/* Bits 0-6 are reserved (always cleared by MountVol call) */
	HFSVolumeHardwareLockBit     = 7  /* volume is locked by hardware */
	HFSVolumeUnmountedBit        = 8  /* volume was successfully unmounted */
	HFSVolumeSparedBlocksBit     = 9  /* volume has bad blocks spared */
	HFSVolumeNoCacheRequiredBit  = 10 /* don't cache volume blocks (i.e. RAM or ROM disk) */
	HFSBootVolumeInconsistentBit = 11 /* boot volume is inconsistent (System 7.6 and later) */
	HFSCatalogNodeIDsReusedBit   = 12
	HFSVolumeJournaledBit        = 13 /* this volume has a journal on it */
	HFSVolumeInconsistentBit     = 14 /* serious inconsistencies detected at runtime */
	HFSVolumeSoftwareLockBit     = 15 /* volume is locked by software */
	/*
	 * HFS only has 16 bits of attributes in the MDB, but HFS Plus has 32 bits.
	 * Therefore, bits 16-31 can only be used on HFS Plus.
	 */
	HFSUnusedNodeFixBit     = 31 /* Unused nodes in the Catalog B-tree have been zero-filled.  See Radar #6947811. */
	HFSContentProtectionBit = 30 /* Volume has per-file content protection */
	HFSExpandedTimesBit     = 29 /* Volume has expanded / non-MacOS native timestamps */

	/***  Keep these in sync with the bits above ! ****/
	HFSVolumeHardwareLockMask     = 0x00000080
	HFSVolumeUnmountedMask        = 0x00000100
	HFSVolumeSparedBlocksMask     = 0x00000200
	HFSVolumeNoCacheRequiredMask  = 0x00000400
	HFSBootVolumeInconsistentMask = 0x00000800
	HFSCatalogNodeIDsReusedMask   = 0x00001000
	HFSVolumeJournaledMask        = 0x00002000
	HFSVolumeInconsistentMask     = 0x00004000
	HFSVolumeSoftwareLockMask     = 0x00008000

	/* Bits 16-31 are allocated from high to low */
	HFSExpandedTimesMask     = 0x20000000
	HFSContentProtectionMask = 0x40000000
	HFSUnusedNodeFixMask     = 0x80000000

	HFSMDBAttributesMask = 0x8380
)

HFS and HFS Plus volume attribute bits

View Source
const (
	HFSExtentDensity     = 3
	HFSPlusExtentDensity = 8
)
View Source
const (
	HFSFileLockedBit  = 0x0000 /* file is locked and cannot be written to */
	HFSFileLockedMask = 0x0001

	HFSThreadExistsBit  = 0x0001 /* a file thread record exists for this file */
	HFSThreadExistsMask = 0x0002

	HFSHasAttributesBit  = 0x0002 /* object has extended attributes */
	HFSHasAttributesMask = 0x0004

	HFSHasSecurityBit  = 0x0003 /* object has security data (ACLs) */
	HFSHasSecurityMask = 0x0008

	HFSHasFolderCountBit  = 0x0004 /* only for HFSX, folder maintains a separate sub-folder count */
	HFSHasFolderCountMask = 0x0010 /* (sum of folder records and directory hard links) */

	HFSHasLinkChainBit  = 0x0005 /* has hardlink chain (inode or link) */
	HFSHasLinkChainMask = 0x0020

	HFSHasChildLinkBit  = 0x0006 /* folder has a child that's a dir link */
	HFSHasChildLinkMask = 0x0040

	HFSHasDateAddedBit  = 0x0007 /* File/Folder has the date-added stored in the finder info. */
	HFSHasDateAddedMask = 0x0080

	HFSFastDevPinnedBit  = 0x0008 /* this file has been pinned to the fast-device by the hot-file code on cooperative fusion */
	HFSFastDevPinnedMask = 0x0100

	HFSDoNotFastDevPinBit  = 0x0009 /* this file can not be pinned to the fast-device */
	HFSDoNotFastDevPinMask = 0x0200

	HFSFastDevCandidateBit  = 0x000a /* this item is a potential candidate for fast-dev pinning (as are any of its descendents */
	HFSFastDevCandidateMask = 0x0400

	HFSAutoCandidateBit  = 0x000b /* this item was automatically marked as a fast-dev candidate by the kernel */
	HFSAutoCandidateMask = 0x0800

	HFSCatExpandedTimesBit  = 0x000c /* this item has expanded timestamps */
	HFSCatExpandedTimesMask = 0x1000
)
View Source
const (
	/* Finder flags (finderFlags, fdFlags and frFlags) */
	IsOnDesk = 0x0001 /* Files and folders (System 6) */
	Color    = 0x000E /* Files and folders */
	IsShared = 0x0040 /* Files only (Applications only) If */
	/* clear, the application needs */
	/* to write to its resource fork, */
	/* and therefore cannot be shared */
	/* on a server */
	HasNoINITs = 0x0080 /* Files only (Extensions/Control */
	/* Panels only) */
	/* This file contains no INIT resource */
	HasBeenInited = 0x0100 /* Files only.  Clear if the file */
	/* contains desktop database resources */
	/* ('BNDL', 'FREF', 'open', 'kind'...) */
	/* that have not been added yet.  Set */
	/* only by the Finder. */
	/* Reserved for folders */
	HasCustomIcon = 0x0400 /* Files and folders */

	HasBundle = 0x2000 /* Files only */

)
View Source
const (
	HFSPlusAttrInlineData = 0x10 /* attributes whose data fits in a b-tree node */
	HFSPlusAttrForkData   = 0x20 /* extent based attributes (data lives in extents) */
	HFSPlusAttrExtents    = 0x30 /* overflow extents for large attributes */
)

#ifdef __APPLE_API_UNSTABLE

  • These are the types of records in the attribute B-tree. The values were
  • chosen so that they wouldn't conflict with the catalog record types.
View Source
const BTreeMaxKeyLength = 520

Variables

This section is empty.

Functions

This section is empty.

Types

type BSDInfo

type BSDInfo struct {
	OwnerID    uint32
	GroupID    uint32
	AdminFlags uint8
	OwnerFlags uint8
	FileMode   uint16
	// union {
	// UInt32  iNodeNum;
	// UInt32  linkCount;
	// UInt32  rawDevice;
	// } special;
	Special uint32
}

type BTHeaderAttributes added in v1.0.20

type BTHeaderAttributes uint32

Constants for BTHeaderRec attributes

const (
	BTBadCloseMask          BTHeaderAttributes = 0x00000001 /* reserved */
	BTBigKeysMask           BTHeaderAttributes = 0x00000002 /* key length field is 16 bits */
	BTVariableIndexKeysMask BTHeaderAttributes = 0x00000004 /* keys in index nodes are variable length */
)

type BTHeaderKeyCompareType added in v1.0.20

type BTHeaderKeyCompareType uint8

Catalog Key Name Comparison Type

const (
	HFSCaseFolding   BTHeaderKeyCompareType = 0xCF /* case folding (case-insensitive) */
	HFSBinaryCompare BTHeaderKeyCompareType = 0xBC /* binary compare (case-sensitive) */
)

type BTHeaderNode

type BTHeaderNode struct {
	Descriptor     BTNodeDescriptor
	Header         BTHeaderRec
	UserDataRecord [128]uint8
	Map            []uint8
	Offsets        [4]uint16
}

func (BTHeaderNode) HeaderOffset added in v1.0.20

func (hdr BTHeaderNode) HeaderOffset() uint16

func (BTHeaderNode) MapOffset added in v1.0.20

func (hdr BTHeaderNode) MapOffset() uint16

func (BTHeaderNode) OffsetsOffset added in v1.0.20

func (hdr BTHeaderNode) OffsetsOffset() uint16

func (BTHeaderNode) UserDataRecordsOffset added in v1.0.20

func (hdr BTHeaderNode) UserDataRecordsOffset() uint16

type BTHeaderRec

type BTHeaderRec struct {
	TreeDepth      uint16 //  maximum height (usually leaf nodes)
	RootNode       uint32 //  node number of root node
	LeafRecords    uint32 //  number of leaf records in all leaf nodes
	FirstLeafNode  uint32 // node number of first leaf node
	LastLeafNode   uint32 // node number of last leaf node
	NodeSize       uint16 // size of each node in bytes
	MaxKeyLength   uint16 // maximum key length
	TotalNodes     uint32 // total number of nodes in the tree
	FreeNodes      uint32 // number of unused (free) nodes in tree
	Reserved1      uint16
	ClumpSize      uint32
	BtreeType      BtreeType
	KeyCompareType BTHeaderKeyCompareType // Key string Comparison Type
	Attributes     BTHeaderAttributes     // persistent attributes about the tree
	Reserved3      [16]uint32
}

The first record of a B-tree header node

type BTNode

type BTNode struct {
	Descriptor BTNodeDescriptor
	Records    []BTRecord
	NodeSize   int // added: node size (in bytes) from the header record
}

type BTNodeDescriptor

type BTNodeDescriptor struct {
	FLink      uint32        // next node at this level
	BLink      uint32        // previous node at this level
	Kind       BTreeNodeKind //  kind of node (leaf, index, header, map)
	Height     uint8         // zero for header, map; child is one more than parent
	NumRecords uint16        // number of records in this node
	Reserved   uint16
}

type BTRecord

type BTRecord interface {
	Unmarshal(r io.Reader) error
	String() string
	Type() BTreeNodeKind
}

BTRecord represents a record in a B-tree node: CatalogRecord, FolderRecord, FileRecord

type BTree added in v1.0.20

type BTree struct {
	BTHeaderNode
	Root *BTNode
}

BTNode represents a B-tree node in the filesystem

type BTreeNodeKind added in v1.0.20

type BTreeNodeKind int8
const (
	BTLeafNodeKind   BTreeNodeKind = -1
	BTIndexNodeKind  BTreeNodeKind = 0
	BTHeaderNodeKind BTreeNodeKind = 1
	BTMapNodeKind    BTreeNodeKind = 2
)

func (BTreeNodeKind) String added in v1.0.20

func (kind BTreeNodeKind) String() string

type BtreeType added in v1.0.20

type BtreeType uint8
const (
	BtHFS      BtreeType = 0   // control file
	BtUser     BtreeType = 128 // user btree type starts from 128
	BtReserved BtreeType = 255 // reserved
)

type CatalogFlags added in v1.0.20

type CatalogFlags uint16

func (CatalogFlags) AutoCandidate added in v1.0.20

func (flags CatalogFlags) AutoCandidate() bool

func (CatalogFlags) CatExpandedTimes added in v1.0.20

func (flags CatalogFlags) CatExpandedTimes() bool

func (CatalogFlags) DoNotFastDevPin added in v1.0.20

func (flags CatalogFlags) DoNotFastDevPin() bool

func (CatalogFlags) FastDevCandidate added in v1.0.20

func (flags CatalogFlags) FastDevCandidate() bool

func (CatalogFlags) FastDevPinned added in v1.0.20

func (flags CatalogFlags) FastDevPinned() bool

func (CatalogFlags) FileLocked added in v1.0.20

func (flags CatalogFlags) FileLocked() bool

func (CatalogFlags) HasAttributes added in v1.0.20

func (flags CatalogFlags) HasAttributes() bool
func (flags CatalogFlags) HasChildLink() bool

func (CatalogFlags) HasDateAdded added in v1.0.20

func (flags CatalogFlags) HasDateAdded() bool

func (CatalogFlags) HasFolderCount added in v1.0.20

func (flags CatalogFlags) HasFolderCount() bool

func (CatalogFlags) HasLinkChain added in v1.0.20

func (flags CatalogFlags) HasLinkChain() bool

func (CatalogFlags) HasSecurity added in v1.0.20

func (flags CatalogFlags) HasSecurity() bool

func (CatalogFlags) String added in v1.0.20

func (flags CatalogFlags) String() string

func (CatalogFlags) ThreadExists added in v1.0.20

func (flags CatalogFlags) ThreadExists() bool

type CatalogKey

type CatalogKey struct {
	KeyLength uint16
	ParentID  CatalogNodeID
	NodeName  UniStr255
}

type CatalogNodeID

type CatalogNodeID uint32
const (
	HFSRootParentID           CatalogNodeID = 1  // Parent ID of the root folder
	HFSRootFolderID           CatalogNodeID = 2  // Folder ID of the root folder
	HFSExtentsFileID          CatalogNodeID = 3  // File ID of the extents file
	HFSCatalogFileID          CatalogNodeID = 4  // File ID of the catalog file
	HFSBadBlockFileID         CatalogNodeID = 5  // File ID of the bad allocation block file
	HFSAllocationFileID       CatalogNodeID = 6  // File ID of the allocation file (HFS Plus only)
	HFSStartupFileID          CatalogNodeID = 7  // File ID of the startup file (HFS Plus only)
	HFSAttributesFileID       CatalogNodeID = 8  // File ID of the attribute file (HFS Plus only)
	HFSAttributeDataFileID    CatalogNodeID = 13 // Used in Mac OS X runtime for extent based attributes. (never stored on disk)
	HFSRepairCatalogFileID    CatalogNodeID = 14 // Used when rebuilding Catalog B-tree
	HFSBogusExtentFileID      CatalogNodeID = 15 // Used for exchanging extents in extents file
	HFSFirstUserCatalogNodeID CatalogNodeID = 16
)

func (CatalogNodeID) String added in v1.0.20

func (id CatalogNodeID) String() string

type CatalogRecord

type CatalogRecord struct {
	Key      CatalogKey
	Link     uint32
	ChildPos int64
	Child    BTNode
}

func (*CatalogRecord) String added in v1.0.20

func (cr *CatalogRecord) String() string

func (*CatalogRecord) Type added in v1.0.20

func (cr *CatalogRecord) Type() BTreeNodeKind

func (*CatalogRecord) Unmarshal added in v1.0.20

func (cr *CatalogRecord) Unmarshal(r io.Reader) error

type ExtendedFinderFlags added in v1.0.20

type ExtendedFinderFlags uint16
const (
	ExtendedFlagsAreInvalid    ExtendedFinderFlags = 0x8000 // The other extended flags should be ignored
	ExtendedFlagHasCustomBadge ExtendedFinderFlags = 0x0100 // The file or folder has a badge resource
	ExtendedFlagHasRoutingInfo ExtendedFinderFlags = 0x0004 // The file contains routing info resource
)

type ExtendedFolderInfo

type ExtendedFolderInfo struct {
	ScrollPosition      Point // Scroll position (for icon views)
	Reserved1           int32
	ExtendedFinderFlags ExtendedFinderFlags
	Reserved2           int16
	PutAwayFolderID     int32
}

type ExtentDescriptor

type ExtentDescriptor struct {
	StartBlock uint32
	BlockCount uint32
}

type FileBlock added in v1.0.20

type FileBlock struct {
	Data  []byte
	Slack []byte
}

type FileData added in v1.0.20

type FileData struct {
	Block FileBlock
}

type FileRecord added in v1.0.20

type FileRecord struct {
	Key      CatalogKey
	FileInfo HFSPlusCatalogFile
	FileData FileData
	// contains filtered or unexported fields
}

func (*FileRecord) Path added in v1.0.24

func (fr *FileRecord) Path() string

func (*FileRecord) Reader added in v1.0.20

func (fr *FileRecord) Reader() io.Reader

func (*FileRecord) String added in v1.0.20

func (fr *FileRecord) String() string

func (*FileRecord) Type added in v1.0.20

func (fr *FileRecord) Type() BTreeNodeKind

func (*FileRecord) Unmarshal added in v1.0.20

func (fr *FileRecord) Unmarshal(r io.Reader) error

type FinderFileInfo added in v1.0.20

type FinderFileInfo struct {
	FileType    OSType // The type of the file
	FileCreator OSType // The file's creator
	FinderFlags uint16
	Location    Point // File's location in the folder.
	Opaque      uint16
}

type FinderOpaqueInfo added in v1.0.20

type FinderOpaqueInfo struct {
	Opaque [16]int8
}

type FolderInfo

type FolderInfo struct {
	WindowBounds Rect // The position and dimension of the folder's window
	FinderFlags  uint16
	Location     Point // Folder's location in the parent folder. If set to {0, 0}, the Finder will place the item automatically
	Opaque       uint16
}

type FolderRecord added in v1.0.20

type FolderRecord struct {
	Key        CatalogKey
	FolderInfo HFSPlusCatalogFolder
	SubDir     []BTRecord // folders and files
}

func (*FolderRecord) String added in v1.0.20

func (fdr *FolderRecord) String() string

func (*FolderRecord) Type added in v1.0.20

func (fdr *FolderRecord) Type() BTreeNodeKind

func (*FolderRecord) Unmarshal added in v1.0.20

func (fdr *FolderRecord) Unmarshal(r io.Reader) error

type ForkData

type ForkData struct {
	LogicalSize uint64
	ClumpSize   uint32
	TotalBlocks uint32
	Extents     ExtentRecord
}

type FourCharCode

type FourCharCode uint32

type HFSPlus

type HFSPlus struct {
	// contains filtered or unexported fields
}

HFSPlus represents a mounted HFS+ filesystem

func New

func New(device io.ReaderAt) (*HFSPlus, error)

New creates a new HFSPlus instance from a device

func Open

func Open(filename string) (*HFSPlus, error)

Open creates a new HFSPlus instance from a file path

func (*HFSPlus) Close

func (fs *HFSPlus) Close() error

Close releases any resources associated with the filesystem

func (*HFSPlus) Files added in v1.0.20

func (fs *HFSPlus) Files() ([]*FileRecord, error)

type HFSPlusCatalogFile added in v1.0.20

type HFSPlusCatalogFile struct {
	RecordType       RecordType // == HFSPlusFileRecord
	Flags            CatalogFlags
	Reserved1        uint32 // reserved - initialized as zero
	FileID           CatalogNodeID
	CreateDate       hfsTime
	ContentModDate   hfsTime
	AttributeModDate hfsTime
	AccessDate       hfsTime
	BackupDate       hfsTime
	BSDInfo          BSDInfo
	UserInfo         FinderFileInfo
	FinderInfo       FinderOpaqueInfo
	TextEncoding     uint32
	Reserved2        uint32 // reserved - initialized as zero
	DataFork         ForkData
	ResourceFork     ForkData
}

HFSPlusCatalogFile is a HFS Plus catalog file record - 248 bytes

type HFSPlusCatalogFolder added in v1.0.20

type HFSPlusCatalogFolder struct {
	RecordType       RecordType
	Flags            CatalogFlags
	Valence          uint32
	FolderID         CatalogNodeID
	CreateDate       hfsTime
	ContentModDate   hfsTime
	AttributeModDate hfsTime
	AccessDate       hfsTime
	BackupDate       hfsTime
	BSDInfo          BSDInfo
	UserInfo         FolderInfo
	FinderInfo       FinderOpaqueInfo
	TextEncoding     uint32 // hint for name conversions
	FolderCount      uint32 // number of enclosed folders, active when HasFolderCount is set
}

HFSPlusCatalogFolder is a HFS Plus catalog folder record - 88 bytes

type HFSPlusCatalogThread added in v1.0.20

type HFSPlusCatalogThread struct {
	RecordType RecordType    //  == HFSPlusFolderThreadRecord or HFSPlusFileThreadRecord
	Reserved   int16         // reserved - initialized as zero
	ParentID   CatalogNodeID // parent ID for this catalog node
	NodeName   UniStr255     // name of this catalog node (variable length)
}

HFSPlusCatalogThread is a HFS Plus catalog thread record -- 264 bytes

type OSType

type OSType FourCharCode

type Point

type Point struct {
	V int16
	H int16
}

type RecordType added in v1.0.20

type RecordType int16
const (
	/* HFS Catalog Records */
	HFSFolderRecord       RecordType = 0x0100
	HFSFileRecord         RecordType = 0x0200
	HFSFolderThreadRecord RecordType = 0x0300
	HFSFileThreadRecord   RecordType = 0x0400

	/* HFS Plus Catalog Records */
	HFSPlusFolderRecord       RecordType = 0x0001
	HFSPlusFileRecord         RecordType = 0x0002
	HFSPlusFolderThreadRecord RecordType = 0x0003
	HFSPlusFileThreadRecord   RecordType = 0x0004
)

func (RecordType) String added in v1.0.20

func (rt RecordType) String() string

type Rect

type Rect struct {
	Top    int16
	Left   int16
	Bottom int16
	Right  int16
}

type Signature added in v1.0.20

type Signature uint16
const (
	HFSSigWord     Signature = 0x4244 // "BD"
	HFSPlusSigWord Signature = 0x482B // "H+"
	HFSXSigWord    Signature = 0x4858 // "HX"
)

func (Signature) String added in v1.0.20

func (s Signature) String() string

type ThreadKey added in v1.0.20

type ThreadKey struct {
	KeyLength uint16
	ParentID  CatalogNodeID
	Reserved  uint16
}

type ThreadRecord added in v1.0.20

type ThreadRecord struct {
	Key ThreadKey
	HFSPlusCatalogThread
}

func (*ThreadRecord) String added in v1.0.20

func (thread *ThreadRecord) String() string

func (*ThreadRecord) Type added in v1.0.20

func (thread *ThreadRecord) Type() BTreeNodeKind

func (*ThreadRecord) Unmarshal added in v1.0.20

func (t *ThreadRecord) Unmarshal(r io.Reader) error

type UniStr255

type UniStr255 struct {
	Length  uint16
	UniChar []uint16
}

func UniStr255FromString

func UniStr255FromString(s string) UniStr255

UniStr255FromString creates a UniStr255 from a Go string

func (*UniStr255) String added in v1.0.20

func (us *UniStr255) String() string

type VolumeHeader

type VolumeHeader struct {
	Signature          Signature // 'H+' or 'HX'
	Version            uint16    // 4 for HFS+ and 5 for HFSX
	Attributes         hfsAttributes
	LastMountedVersion [4]byte
	JournalInfoBlock   uint32
	CreateDate         hfsTime
	ModifyDate         hfsTime
	BackupDate         hfsTime
	CheckedDate        hfsTime
	FileCount          uint32
	FolderCount        uint32
	BlockSize          uint32
	TotalBlocks        uint32
	FreeBlocks         uint32
	NextAllocation     uint32
	RsrcClumpSize      uint32
	DataClumpSize      uint32
	NextCatalogID      CatalogNodeID
	WriteCount         uint32
	EncodingsBitmap    uint64
	FinderInfo         [8]uint32
	AllocationFile     ForkData
	ExtentsFile        ForkData
	CatalogFile        ForkData
	AttributesFile     ForkData
	StartupFile        ForkData
	// contains filtered or unexported fields
}

func (*VolumeHeader) String

func (hdr *VolumeHeader) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL