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