Skip to content

Commit ec95cd1

Browse files
committed
hfs/hfsplus: move on-disk layout declarations into hfs_common.h
Currently, HFS declares on-disk layout's metadata structures in fs/hfs/hfs.h and HFS+ declares it in fs/hfsplus/hfsplus_raw.h. However, HFS and HFS+ on-disk layouts have some similarity and overlapping in declarations. As a result, fs/hfs/hfs.h and fs/hfsplus/hfsplus_raw.h contain multiple duplicated declarations. Moreover, both HFS and HFS+ drivers contain completely similar implemented functionality in multiple places. This patch is moving the on-disk layout declarations from fs/hfs/hfs.h and fs/hfsplus/hfsplus_raw.h into include/linux/hfs_common.h with the goal to exclude the duplication in declarations. Also, this patch prepares the basis for creating a hfslib that can aggregate common functionality without necessity to duplicate the same code in HFS and HFS+ drivers. Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com> cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> cc: Yangtao Li <frank.li@vivo.com> cc: linux-fsdevel@vger.kernel.org Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
1 parent 3f04ee2 commit ec95cd1

7 files changed

Lines changed: 645 additions & 717 deletions

File tree

fs/hfs/btree.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -129,45 +129,3 @@ extern int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd);
129129
extern int hfs_brec_find(struct hfs_find_data *fd);
130130
extern int hfs_brec_read(struct hfs_find_data *fd, void *rec, u32 rec_len);
131131
extern int hfs_brec_goto(struct hfs_find_data *fd, int cnt);
132-
133-
134-
struct hfs_bnode_desc {
135-
__be32 next; /* (V) Number of the next node at this level */
136-
__be32 prev; /* (V) Number of the prev node at this level */
137-
u8 type; /* (F) The type of node */
138-
u8 height; /* (F) The level of this node (leaves=1) */
139-
__be16 num_recs; /* (V) The number of records in this node */
140-
u16 reserved;
141-
} __packed;
142-
143-
#define HFS_NODE_INDEX 0x00 /* An internal (index) node */
144-
#define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
145-
#define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
146-
#define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
147-
148-
struct hfs_btree_header_rec {
149-
__be16 depth; /* (V) The number of levels in this B-tree */
150-
__be32 root; /* (V) The node number of the root node */
151-
__be32 leaf_count; /* (V) The number of leaf records */
152-
__be32 leaf_head; /* (V) The number of the first leaf node */
153-
__be32 leaf_tail; /* (V) The number of the last leaf node */
154-
__be16 node_size; /* (F) The number of bytes in a node (=512) */
155-
__be16 max_key_len; /* (F) The length of a key in an index node */
156-
__be32 node_count; /* (V) The total number of nodes */
157-
__be32 free_nodes; /* (V) The number of unused nodes */
158-
u16 reserved1;
159-
__be32 clump_size; /* (F) clump size. not usually used. */
160-
u8 btree_type; /* (F) BTree type */
161-
u8 reserved2;
162-
__be32 attributes; /* (F) attributes */
163-
u32 reserved3[16];
164-
} __packed;
165-
166-
#define BTREE_ATTR_BADCLOSE 0x00000001 /* b-tree not closed properly. not
167-
used by hfsplus. */
168-
#define HFS_TREE_BIGKEYS 0x00000002 /* key length is u16 instead of u8.
169-
used by hfsplus. */
170-
#define HFS_TREE_VARIDXKEYS 0x00000004 /* variable key length instead of
171-
max key length. use din catalog
172-
b-tree but not in extents
173-
b-tree (hfsplus). */

fs/hfs/hfs.h

Lines changed: 1 addition & 268 deletions
Original file line numberDiff line numberDiff line change
@@ -9,274 +9,7 @@
99
#ifndef _HFS_H
1010
#define _HFS_H
1111

12-
/* offsets to various blocks */
13-
#define HFS_DD_BLK 0 /* Driver Descriptor block */
14-
#define HFS_PMAP_BLK 1 /* First block of partition map */
15-
#define HFS_MDB_BLK 2 /* Block (w/i partition) of MDB */
16-
17-
/* magic numbers for various disk blocks */
18-
#define HFS_DRVR_DESC_MAGIC 0x4552 /* "ER": driver descriptor map */
19-
#define HFS_OLD_PMAP_MAGIC 0x5453 /* "TS": old-type partition map */
20-
#define HFS_NEW_PMAP_MAGIC 0x504D /* "PM": new-type partition map */
21-
#define HFS_SUPER_MAGIC 0x4244 /* "BD": HFS MDB (super block) */
22-
#define HFS_MFS_SUPER_MAGIC 0xD2D7 /* MFS MDB (super block) */
23-
24-
/* various FIXED size parameters */
25-
#define HFS_SECTOR_SIZE 512 /* size of an HFS sector */
26-
#define HFS_SECTOR_SIZE_BITS 9 /* log_2(HFS_SECTOR_SIZE) */
27-
#define HFS_NAMELEN 31 /* maximum length of an HFS filename */
28-
#define HFS_MAX_NAMELEN 128
29-
#define HFS_MAX_VALENCE 32767U
30-
31-
/* Meanings of the drAtrb field of the MDB,
32-
* Reference: _Inside Macintosh: Files_ p. 2-61
33-
*/
34-
#define HFS_SB_ATTRIB_HLOCK (1 << 7)
35-
#define HFS_SB_ATTRIB_UNMNT (1 << 8)
36-
#define HFS_SB_ATTRIB_SPARED (1 << 9)
37-
#define HFS_SB_ATTRIB_INCNSTNT (1 << 11)
38-
#define HFS_SB_ATTRIB_SLOCK (1 << 15)
39-
40-
/* Some special File ID numbers */
41-
#define HFS_POR_CNID 1 /* Parent Of the Root */
42-
#define HFS_ROOT_CNID 2 /* ROOT directory */
43-
#define HFS_EXT_CNID 3 /* EXTents B-tree */
44-
#define HFS_CAT_CNID 4 /* CATalog B-tree */
45-
#define HFS_BAD_CNID 5 /* BAD blocks file */
46-
#define HFS_ALLOC_CNID 6 /* ALLOCation file (HFS+) */
47-
#define HFS_START_CNID 7 /* STARTup file (HFS+) */
48-
#define HFS_ATTR_CNID 8 /* ATTRibutes file (HFS+) */
49-
#define HFS_EXCH_CNID 15 /* ExchangeFiles temp id */
50-
#define HFS_FIRSTUSER_CNID 16
51-
52-
/* values for hfs_cat_rec.cdrType */
53-
#define HFS_CDR_DIR 0x01 /* folder (directory) */
54-
#define HFS_CDR_FIL 0x02 /* file */
55-
#define HFS_CDR_THD 0x03 /* folder (directory) thread */
56-
#define HFS_CDR_FTH 0x04 /* file thread */
57-
58-
/* legal values for hfs_ext_key.FkType and hfs_file.fork */
59-
#define HFS_FK_DATA 0x00
60-
#define HFS_FK_RSRC 0xFF
61-
62-
/* bits in hfs_fil_entry.Flags */
63-
#define HFS_FIL_LOCK 0x01 /* locked */
64-
#define HFS_FIL_THD 0x02 /* file thread */
65-
#define HFS_FIL_DOPEN 0x04 /* data fork open */
66-
#define HFS_FIL_ROPEN 0x08 /* resource fork open */
67-
#define HFS_FIL_DIR 0x10 /* directory (always clear) */
68-
#define HFS_FIL_NOCOPY 0x40 /* copy-protected file */
69-
#define HFS_FIL_USED 0x80 /* open */
70-
71-
/* bits in hfs_dir_entry.Flags. dirflags is 16 bits. */
72-
#define HFS_DIR_LOCK 0x01 /* locked */
73-
#define HFS_DIR_THD 0x02 /* directory thread */
74-
#define HFS_DIR_INEXPFOLDER 0x04 /* in a shared area */
75-
#define HFS_DIR_MOUNTED 0x08 /* mounted */
76-
#define HFS_DIR_DIR 0x10 /* directory (always set) */
77-
#define HFS_DIR_EXPFOLDER 0x20 /* share point */
78-
79-
/* bits hfs_finfo.fdFlags */
80-
#define HFS_FLG_INITED 0x0100
81-
#define HFS_FLG_LOCKED 0x1000
82-
#define HFS_FLG_INVISIBLE 0x4000
83-
84-
/*======== HFS structures as they appear on the disk ========*/
85-
86-
/* Pascal-style string of up to 31 characters */
87-
struct hfs_name {
88-
u8 len;
89-
u8 name[HFS_NAMELEN];
90-
} __packed;
91-
92-
struct hfs_point {
93-
__be16 v;
94-
__be16 h;
95-
} __packed;
96-
97-
struct hfs_rect {
98-
__be16 top;
99-
__be16 left;
100-
__be16 bottom;
101-
__be16 right;
102-
} __packed;
103-
104-
struct hfs_finfo {
105-
__be32 fdType;
106-
__be32 fdCreator;
107-
__be16 fdFlags;
108-
struct hfs_point fdLocation;
109-
__be16 fdFldr;
110-
} __packed;
111-
112-
struct hfs_fxinfo {
113-
__be16 fdIconID;
114-
u8 fdUnused[8];
115-
__be16 fdComment;
116-
__be32 fdPutAway;
117-
} __packed;
118-
119-
struct hfs_dinfo {
120-
struct hfs_rect frRect;
121-
__be16 frFlags;
122-
struct hfs_point frLocation;
123-
__be16 frView;
124-
} __packed;
125-
126-
struct hfs_dxinfo {
127-
struct hfs_point frScroll;
128-
__be32 frOpenChain;
129-
__be16 frUnused;
130-
__be16 frComment;
131-
__be32 frPutAway;
132-
} __packed;
133-
134-
union hfs_finder_info {
135-
struct {
136-
struct hfs_finfo finfo;
137-
struct hfs_fxinfo fxinfo;
138-
} file;
139-
struct {
140-
struct hfs_dinfo dinfo;
141-
struct hfs_dxinfo dxinfo;
142-
} dir;
143-
} __packed;
144-
145-
/* Cast to a pointer to a generic bkey */
146-
#define HFS_BKEY(X) (((void)((X)->KeyLen)), ((struct hfs_bkey *)(X)))
147-
148-
/* The key used in the catalog b-tree: */
149-
struct hfs_cat_key {
150-
u8 key_len; /* number of bytes in the key */
151-
u8 reserved; /* padding */
152-
__be32 ParID; /* CNID of the parent dir */
153-
struct hfs_name CName; /* The filename of the entry */
154-
} __packed;
155-
156-
/* The key used in the extents b-tree: */
157-
struct hfs_ext_key {
158-
u8 key_len; /* number of bytes in the key */
159-
u8 FkType; /* HFS_FK_{DATA,RSRC} */
160-
__be32 FNum; /* The File ID of the file */
161-
__be16 FABN; /* allocation blocks number*/
162-
} __packed;
163-
164-
typedef union hfs_btree_key {
165-
u8 key_len; /* number of bytes in the key */
166-
struct hfs_cat_key cat;
167-
struct hfs_ext_key ext;
168-
} hfs_btree_key;
169-
170-
#define HFS_MAX_CAT_KEYLEN (sizeof(struct hfs_cat_key) - sizeof(u8))
171-
#define HFS_MAX_EXT_KEYLEN (sizeof(struct hfs_ext_key) - sizeof(u8))
172-
173-
typedef union hfs_btree_key btree_key;
174-
175-
struct hfs_extent {
176-
__be16 block;
177-
__be16 count;
178-
};
179-
typedef struct hfs_extent hfs_extent_rec[3];
180-
181-
/* The catalog record for a file */
182-
struct hfs_cat_file {
183-
s8 type; /* The type of entry */
184-
u8 reserved;
185-
u8 Flags; /* Flags such as read-only */
186-
s8 Typ; /* file version number = 0 */
187-
struct hfs_finfo UsrWds; /* data used by the Finder */
188-
__be32 FlNum; /* The CNID */
189-
__be16 StBlk; /* obsolete */
190-
__be32 LgLen; /* The logical EOF of the data fork*/
191-
__be32 PyLen; /* The physical EOF of the data fork */
192-
__be16 RStBlk; /* obsolete */
193-
__be32 RLgLen; /* The logical EOF of the rsrc fork */
194-
__be32 RPyLen; /* The physical EOF of the rsrc fork */
195-
__be32 CrDat; /* The creation date */
196-
__be32 MdDat; /* The modified date */
197-
__be32 BkDat; /* The last backup date */
198-
struct hfs_fxinfo FndrInfo; /* more data for the Finder */
199-
__be16 ClpSize; /* number of bytes to allocate
200-
when extending files */
201-
hfs_extent_rec ExtRec; /* first extent record
202-
for the data fork */
203-
hfs_extent_rec RExtRec; /* first extent record
204-
for the resource fork */
205-
u32 Resrv; /* reserved by Apple */
206-
} __packed;
207-
208-
/* the catalog record for a directory */
209-
struct hfs_cat_dir {
210-
s8 type; /* The type of entry */
211-
u8 reserved;
212-
__be16 Flags; /* flags */
213-
__be16 Val; /* Valence: number of files and
214-
dirs in the directory */
215-
__be32 DirID; /* The CNID */
216-
__be32 CrDat; /* The creation date */
217-
__be32 MdDat; /* The modification date */
218-
__be32 BkDat; /* The last backup date */
219-
struct hfs_dinfo UsrInfo; /* data used by the Finder */
220-
struct hfs_dxinfo FndrInfo; /* more data used by Finder */
221-
u8 Resrv[16]; /* reserved by Apple */
222-
} __packed;
223-
224-
/* the catalog record for a thread */
225-
struct hfs_cat_thread {
226-
s8 type; /* The type of entry */
227-
u8 reserved[9]; /* reserved by Apple */
228-
__be32 ParID; /* CNID of parent directory */
229-
struct hfs_name CName; /* The name of this entry */
230-
} __packed;
231-
232-
/* A catalog tree record */
233-
typedef union hfs_cat_rec {
234-
s8 type; /* The type of entry */
235-
struct hfs_cat_file file;
236-
struct hfs_cat_dir dir;
237-
struct hfs_cat_thread thread;
238-
} hfs_cat_rec;
239-
240-
struct hfs_mdb {
241-
__be16 drSigWord; /* Signature word indicating fs type */
242-
__be32 drCrDate; /* fs creation date/time */
243-
__be32 drLsMod; /* fs modification date/time */
244-
__be16 drAtrb; /* fs attributes */
245-
__be16 drNmFls; /* number of files in root directory */
246-
__be16 drVBMSt; /* location (in 512-byte blocks)
247-
of the volume bitmap */
248-
__be16 drAllocPtr; /* location (in allocation blocks)
249-
to begin next allocation search */
250-
__be16 drNmAlBlks; /* number of allocation blocks */
251-
__be32 drAlBlkSiz; /* bytes in an allocation block */
252-
__be32 drClpSiz; /* clumpsize, the number of bytes to
253-
allocate when extending a file */
254-
__be16 drAlBlSt; /* location (in 512-byte blocks)
255-
of the first allocation block */
256-
__be32 drNxtCNID; /* CNID to assign to the next
257-
file or directory created */
258-
__be16 drFreeBks; /* number of free allocation blocks */
259-
u8 drVN[28]; /* the volume label */
260-
__be32 drVolBkUp; /* fs backup date/time */
261-
__be16 drVSeqNum; /* backup sequence number */
262-
__be32 drWrCnt; /* fs write count */
263-
__be32 drXTClpSiz; /* clumpsize for the extents B-tree */
264-
__be32 drCTClpSiz; /* clumpsize for the catalog B-tree */
265-
__be16 drNmRtDirs; /* number of directories in
266-
the root directory */
267-
__be32 drFilCnt; /* number of files in the fs */
268-
__be32 drDirCnt; /* number of directories in the fs */
269-
u8 drFndrInfo[32]; /* data used by the Finder */
270-
__be16 drEmbedSigWord; /* embedded volume signature */
271-
__be32 drEmbedExtent; /* starting block number (xdrStABN)
272-
and number of allocation blocks
273-
(xdrNumABlks) occupied by embedded
274-
volume */
275-
__be32 drXTFlSize; /* bytes in the extents B-tree */
276-
hfs_extent_rec drXTExtRec; /* extents B-tree's first 3 extents */
277-
__be32 drCTFlSize; /* bytes in the catalog B-tree */
278-
hfs_extent_rec drCTExtRec; /* catalog B-tree's first 3 extents */
279-
} __packed;
12+
#include <linux/hfs_common.h>
28013

28114
/*======== Data structures kept in memory ========*/
28215

fs/hfs/hfs_fs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <asm/byteorder.h>
2020
#include <linux/uaccess.h>
21-
#include <linux/hfs_common.h>
2221

2322
#include "hfs.h"
2423

fs/hfsplus/hfsplus_fs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <linux/buffer_head.h>
1717
#include <linux/blkdev.h>
1818
#include <linux/fs_context.h>
19-
#include <linux/hfs_common.h>
2019
#include "hfsplus_raw.h"
2120

2221
/* Runtime config options */

0 commit comments

Comments
 (0)