-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk.h
More file actions
132 lines (112 loc) · 3.24 KB
/
disk.h
File metadata and controls
132 lines (112 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2025, Hongzhen Luo
*/
/*
* numbfs disk layout definitions
*
* This header defines the on-disk structures and constants for the NUMBFS filesystem.
* It includes:
* - Magic number and basic constants (block size, root inode, etc.)
* - Superblock structure (filesystem metadata and bitmaps location)
* - Inode structure (file metadata and data block pointers)
* - Directory entry structure (file name and inode number mapping)
* - Extended attribute entry structure (key-value storage)
* - Compile-time checks for structure sizes
*
* All structures are designed to be packed and aligned to avoid padding.
* The superblock is located at block offset 1 (after the reserved boot block).
*/
#ifndef __NUMBFS_DISK_H
#define __NUMBFS_DISK_H
#include <linux/types.h>
#include <linux/build_bug.h>
#define NUMBFS_MAGIC 0x4E554D42 /* "NUMB" */
#define NUMBFS_BYTES_PER_BLOCK 512
/* the first block is reserved */
#define NUMBFS_SUPER_OFFSET NUMBFS_BYTES_PER_BLOCK
#define NUMBFS_HOLE (-32)
/* root inode number */
#define NUMBFS_ROOT_NID 0
#define NUMBFS_NUM_DATA_ENTRY 10
#define NUMBFS_MAX_PATH_LEN 60
#define NUMBFS_MAX_ATTR 32
/* 128-byte on-disk numbfs superblock, 64 bytes should be enough, but... */
struct numbfs_super_block {
__le32 s_magic;
/* feature bits */
__le32 s_feature;
/* block addr of inode bitmap */
__le32 s_ibitmap_start;
/* block addr of inode zone */
__le32 s_inode_start;
/* block addr of block bitmap */
__le32 s_bbitmap_start;
/* block addr of data start */
__le32 s_data_start;
/* total num of inodes */
__le32 s_total_inodes;
/* num of free inodes */
__le32 s_free_inodes;
/* num of total data blocks */
__le32 s_data_blocks;
/* num of free data blocks */
__le32 s_free_blocks;
/* reserved */
__u8 s_reserved[88];
};
/* 64-byte on-disk numbfs inode */
struct numbfs_inode {
__le16 i_ino;
__le16 i_nlink;
__le16 i_uid;
__le16 i_gid;
__le32 i_mode;
__le32 i_size;
/* start block addr of xattrs */
__le32 i_xattr_start;
/* number of xattrs */
__u8 i_xattr_count;
__u8 reserved2[3]; /* padding */
/* block addr of data blocks */
__le32 i_data[10];
};
/* 64-byte on-disk numbfs dirent */
struct numbfs_dirent {
__u8 name_len;
__u8 type;
char name[NUMBFS_MAX_PATH_LEN];
__le16 ino;
};
struct numbfs_timestamps {
__le64 t_atime;
__le64 t_mtime;
__le64 t_ctime;
__u8 reserved[8];
};
/* xattr name indexes */
#define NUMBFS_XATTR_INDEX_USER 1
#define NUMBFS_XATTR_INDEX_TRUSTED 2
#define NUMBFS_XATTR_MAXNAME 16
#define NUMBFS_XATTR_MAXVALUE 32
/* on-disk xattr entry */
struct numbfs_xattr_entry {
__u8 e_valid;
__u8 e_type;
__u8 e_nlen;
__u8 e_vlen;
__u8 e_name[NUMBFS_XATTR_MAXNAME];
__u8 e_value[NUMBFS_XATTR_MAXVALUE];
};
#define NUMBFS_XATTR_MAX_ENTRY \
((NUMBFS_BYTES_PER_BLOCK - sizeof(struct numbfs_timestamps)) / sizeof(struct numbfs_xattr_entry))
#define NUMBFS_XATTR_ENTRY_START (sizeof(struct numbfs_timestamps))
/* check the on-disk layout at compile time */
static inline void numbfs_check_ondisk(void)
{
BUILD_BUG_ON(sizeof(struct numbfs_super_block) != 128);
BUILD_BUG_ON(sizeof(struct numbfs_inode) != 64);
BUILD_BUG_ON(sizeof(struct numbfs_dirent) != 64);
BUILD_BUG_ON(sizeof(struct numbfs_timestamps) != 32);
}
#endif