2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 typedef uint32_t cluster_t;
25 typedef uint64_t sector_t;
26 typedef cluster_t fat_entry_t;
28 struct fat_boot_sector {
32 uint8_t sectors_per_cluster;
33 uint16_t reserved_sectors;
35 uint16_t rootdir_size;
38 uint16_t fat_sectors16;
39 uint16_t sectors_per_track;
41 uint32_t hidden_sectors;
43 uint32_t fat_sectors32;
46 cluster_t rootdir_start;
47 uint16_t fs_info_sector;
48 uint16_t backup_boot_sector;
49 uint8_t reserved1[12];
58 } __attribute__((__packed__));
60 #define FAT_MEDIA_DESC_FIXED 0xF8
62 #define FAT_PHYS_DRIVE_REMOVABLE 0x00
63 #define FAT_PHYS_DRIVE_FIXED 0x80
65 #define FAT_EXT_BOOT_SIG 0x29
67 extern const char FAT_BOOT_SIG[2];
69 extern const char FAT_INFO_SIG1[4];
70 extern const char FAT_INFO_SIG2[4];
71 #define FAT_INFO_SIG3 FAT_BOOT_SIG
73 struct fat_info_sector {
77 cluster_t free_clusters;
78 cluster_t last_cluster;
81 } __attribute__((__packed__));
84 struct fat_boot_sector boot;
85 struct fat_info_sector info;
86 } __attribute__((__packed__));
96 uint16_t first_cluster_hi;
99 uint16_t first_cluster_lo;
101 } __attribute__((__packed__));
103 #define FAT_ATTR_READONLY 0x01
104 #define FAT_ATTR_HIDDEN 0x02
105 #define FAT_ATTR_SYSTEM 0x04
106 #define FAT_ATTR_VOLLABEL 0x08
107 #define FAT_ATTR_SUBDIR 0x10
108 #define FAT_ATTR_ARCHIVE 0x20
109 #define FAT_ATTR_DEVICE 0x40
111 #define FAT_ENTRY_FREE 0x00000000
112 #define FAT_ENTRY_BAD 0x0FFFFFF7
113 #define FAT_ENTRY_EOC 0x0FFFFFF8
115 #define FAT_SECTOR_SIZE 512
116 #define FAT_CLUSTER_ZERO 2
117 #define FAT_ENTRIES_PER_SECTOR ((SECTOR_SIZE) / (sizeof(fat_entry_t)))
119 void fat_dirent_set_first_cluster(struct fat_dirent *de, cluster_t cluster);
120 void fat_dirent_set(struct fat_dirent *de,
121 char *name, uint8_t attr,
122 cluster_t first_cluster, uint32_t size);