]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/exfat/exfat_raw.h
exfat: redefine PBR as boot_sector
[mirror_ubuntu-jammy-kernel.git] / fs / exfat / exfat_raw.h
CommitLineData
1acf1a56
NJ
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#ifndef _EXFAT_RAW_H
7#define _EXFAT_RAW_H
8
9#include <linux/types.h>
10
181a9e80
TK
11#define BOOT_SIGNATURE 0xAA55
12#define EXBOOT_SIGNATURE 0xAA550000
1acf1a56
NJ
13
14#define EXFAT_MAX_FILE_LEN 255
15
16#define VOL_CLEAN 0x0000
17#define VOL_DIRTY 0x0002
18
19#define EXFAT_EOF_CLUSTER 0xFFFFFFFFu
20#define EXFAT_BAD_CLUSTER 0xFFFFFFF7u
21#define EXFAT_FREE_CLUSTER 0
22/* Cluster 0, 1 are reserved, the first cluster is 2 in the cluster heap. */
23#define EXFAT_RESERVED_CLUSTERS 2
24#define EXFAT_FIRST_CLUSTER 2
25#define EXFAT_DATA_CLUSTER_COUNT(sbi) \
26 ((sbi)->num_clusters - EXFAT_RESERVED_CLUSTERS)
27
28/* AllocationPossible and NoFatChain field in GeneralSecondaryFlags Field */
29#define ALLOC_FAT_CHAIN 0x01
30#define ALLOC_NO_FAT_CHAIN 0x03
31
32#define DENTRY_SIZE 32 /* directory entry size */
33#define DENTRY_SIZE_BITS 5
34/* exFAT allows 8388608(256MB) directory entries */
35#define MAX_EXFAT_DENTRIES 8388608
36
37/* dentry types */
38#define EXFAT_UNUSED 0x00 /* end of directory */
39#define EXFAT_DELETE (~0x80)
40#define IS_EXFAT_DELETED(x) ((x) < 0x80) /* deleted file (0x01~0x7F) */
41#define EXFAT_INVAL 0x80 /* invalid value */
42#define EXFAT_BITMAP 0x81 /* allocation bitmap */
43#define EXFAT_UPCASE 0x82 /* upcase table */
44#define EXFAT_VOLUME 0x83 /* volume label */
45#define EXFAT_FILE 0x85 /* file or dir */
46#define EXFAT_GUID 0xA0
47#define EXFAT_PADDING 0xA1
48#define EXFAT_ACLTAB 0xA2
49#define EXFAT_STREAM 0xC0 /* stream entry */
50#define EXFAT_NAME 0xC1 /* file name entry */
51#define EXFAT_ACL 0xC2 /* stream entry */
52
53#define IS_EXFAT_CRITICAL_PRI(x) (x < 0xA0)
54#define IS_EXFAT_BENIGN_PRI(x) (x < 0xC0)
55#define IS_EXFAT_CRITICAL_SEC(x) (x < 0xE0)
56
57/* checksum types */
58#define CS_DIR_ENTRY 0
181a9e80 59#define CS_BOOT_SECTOR 1
1acf1a56
NJ
60#define CS_DEFAULT 2
61
62/* file attributes */
63#define ATTR_READONLY 0x0001
64#define ATTR_HIDDEN 0x0002
65#define ATTR_SYSTEM 0x0004
66#define ATTR_VOLUME 0x0008
67#define ATTR_SUBDIR 0x0010
68#define ATTR_ARCHIVE 0x0020
69
70#define ATTR_RWMASK (ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME | \
71 ATTR_SUBDIR | ATTR_ARCHIVE)
72
181a9e80
TK
73#define BOOTSEC_JUMP_BOOT_LEN 3
74#define BOOTSEC_FS_NAME_LEN 8
75#define BOOTSEC_OLDBPB_LEN 53
1acf1a56
NJ
76
77#define EXFAT_FILE_NAME_LEN 15
78
181a9e80
TK
79/* EXFAT: Main and Backup Boot Sector (512 bytes) */
80struct boot_sector {
81 __u8 jmp_boot[BOOTSEC_JUMP_BOOT_LEN];
82 __u8 fs_name[BOOTSEC_FS_NAME_LEN];
83 __u8 must_be_zero[BOOTSEC_OLDBPB_LEN];
84 __le64 partition_offset;
85 __le64 vol_length;
86 __le32 fat_offset;
87 __le32 fat_length;
88 __le32 clu_offset;
89 __le32 clu_count;
90 __le32 root_cluster;
91 __le32 vol_serial;
92 __u8 fs_revision[2];
93 __le16 vol_flags;
94 __u8 sect_size_bits;
95 __u8 sect_per_clus_bits;
96 __u8 num_fats;
97 __u8 drv_sel;
98 __u8 percent_in_use;
99 __u8 reserved[7];
100 __u8 boot_code[390];
101 __le16 signature;
1acf1a56
NJ
102} __packed;
103
104struct exfat_dentry {
105 __u8 type;
106 union {
107 struct {
108 __u8 num_ext;
109 __le16 checksum;
110 __le16 attr;
111 __le16 reserved1;
112 __le16 create_time;
113 __le16 create_date;
114 __le16 modify_time;
115 __le16 modify_date;
116 __le16 access_time;
117 __le16 access_date;
ed0f84d3
TK
118 __u8 create_time_cs;
119 __u8 modify_time_cs;
1acf1a56
NJ
120 __u8 create_tz;
121 __u8 modify_tz;
122 __u8 access_tz;
123 __u8 reserved2[7];
124 } __packed file; /* file directory entry */
125 struct {
126 __u8 flags;
127 __u8 reserved1;
128 __u8 name_len;
129 __le16 name_hash;
130 __le16 reserved2;
131 __le64 valid_size;
132 __le32 reserved3;
133 __le32 start_clu;
134 __le64 size;
135 } __packed stream; /* stream extension directory entry */
136 struct {
137 __u8 flags;
138 __le16 unicode_0_14[EXFAT_FILE_NAME_LEN];
139 } __packed name; /* file name directory entry */
140 struct {
141 __u8 flags;
142 __u8 reserved[18];
143 __le32 start_clu;
144 __le64 size;
145 } __packed bitmap; /* allocation bitmap directory entry */
146 struct {
147 __u8 reserved1[3];
148 __le32 checksum;
149 __u8 reserved2[12];
150 __le32 start_clu;
151 __le64 size;
152 } __packed upcase; /* up-case table directory entry */
153 } __packed dentry;
154} __packed;
155
156#define EXFAT_TZ_VALID (1 << 7)
157
158/* Jan 1 GMT 00:00:00 1980 */
159#define EXFAT_MIN_TIMESTAMP_SECS 315532800LL
160/* Dec 31 GMT 23:59:59 2107 */
161#define EXFAT_MAX_TIMESTAMP_SECS 4354819199LL
162
163#endif /* !_EXFAT_RAW_H */