1 /*
2 libparted
3 Copyright (C) 1998-2001, 2007 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef FAT_H_INCLUDED
20 #define FAT_H_INCLUDED
21
22 #include <parted/parted.h>
23 #include <parted/endian.h>
24 #include <parted/debug.h>
25
26 #if ENABLE_NLS
27 # include <libintl.h>
28 # define _(String) dgettext (PACKAGE, String)
29 #else
30 # define _(String) (String)
31 #endif /* ENABLE_NLS */
32
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37
38 #define BUFFER_SIZE 1024 /* buffer size in sectors (512 bytes) */
39
40 typedef uint32_t FatCluster;
41 typedef int32_t FatFragment;
42
43 enum _FatType {
44 FAT_TYPE_FAT12,
45 FAT_TYPE_FAT16,
46 FAT_TYPE_FAT32
47 };
48 typedef enum _FatType FatType;
49
50 typedef struct _FatSpecific FatSpecific;
51 typedef struct _FatDirEntry FatDirEntry;
52
53 /* FIXME: YUCKY */
54 #include "table.h"
55 #include "bootsector.h"
56 #include "context.h"
57 #include "fatio.h"
58 #include "traverse.h"
59 #include "calc.h"
60 #include "count.h"
61 #include "clstdup.h"
62
63 #ifdef __sun
64 #define __attribute__(X) /*nothing*/
65 #endif /* __sun */
66
67 #ifdef __sun
68 #pragma pack(1)
69 #endif
70 struct __attribute__ ((packed)) _FatDirEntry {
71 char name[8];
72 uint8_t extension[3];
73 uint8_t attributes;
74 uint8_t is_upper_case_name;
75 uint8_t creation_time_low; /* milliseconds */
76 uint16_t creation_time_high;
77 uint16_t creation_date;
78 uint16_t access_date;
79 uint16_t first_cluster_high; /* for FAT32 */
80 uint16_t time;
81 uint16_t date;
82 uint16_t first_cluster;
83 uint32_t length;
84 };
85 #ifdef __sun
86 #pragma pack()
87 #endif
88
89 struct _FatSpecific {
90 FatBootSector boot_sector; /* structure of boot sector */
91 FatInfoSector info_sector; /* fat32-only information sector */
92
93 int logical_sector_size; /* illogical sector size :-) */
94 PedSector sector_count;
95
96 int sectors_per_track; /* BIOS CHS stuff (S) */
97 int heads; /* BIOS CHS stuff (H) */
98
99 int cluster_size;
100 PedSector cluster_sectors;
101 FatCluster cluster_count;
102 int dir_entries_per_cluster;
103
104 FatType fat_type;
105 int fat_table_count;
106 PedSector fat_sectors;
107
108 uint32_t serial_number;
109
110 PedSector info_sector_offset; /* FAT32 only */
111 PedSector fat_offset;
112 PedSector root_dir_offset; /* non-FAT32 */
113 PedSector cluster_offset;
114 PedSector boot_sector_backup_offset;
115
116 FatCluster root_cluster; /* FAT32 only */
117 int root_dir_entry_count; /* non-FAT32 */
118 PedSector root_dir_sector_count; /* non-FAT32 */
119 FatCluster total_dir_clusters;
120
121 FatTable* fat;
122 FatClusterInfo* cluster_info;
123
124 PedSector buffer_sectors;
125 char* buffer;
126
127 int frag_size;
128 PedSector frag_sectors;
129 FatFragment frag_count;
130 FatFragment buffer_frags;
131 FatFragment cluster_frags;
132 };
133
134 #define FAT_SPECIFIC(fs) ((FatSpecific*) fs->type_specific)
135
136 #define FAT_ROOT 0
137
138 #define DELETED_FLAG 0xe5
139
140 #define READONLY_ATTR 0x01
141 #define HIDDEN_ATTR 0x02
142 #define SYSTEM_ATTR 0x04
143 #define VOLUME_LABEL_ATTR 0x08
144 #define VFAT_ATTR 0x0f
145 #define DIRECTORY_ATTR 0x10
146 #define ARCH_ATTR 0x20
147
148 #define MAX_FAT12_CLUSTERS 4086
149 #define MAX_FAT16_CLUSTERS 65526
150 #define MAX_FAT32_CLUSTERS 2000000
151
152 #define FAT_ROOT_DIR_ENTRY_COUNT 512
153
154 extern PedFileSystemType fat16_type;
155 extern PedFileSystemType fat32_type;
156
157 extern void fat_print (const PedFileSystem* fs);
158
159 extern PedFileSystem* fat_alloc (const PedGeometry* geom);
160 extern void fat_free (PedFileSystem* fs);
161 extern int fat_alloc_buffers (PedFileSystem* fs);
162 extern void fat_free_buffers (PedFileSystem* fs);
163
164 extern int fat_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer);
165
166 extern int fat_set_frag_sectors (PedFileSystem* fs, PedSector frag_sectors);
167
168 #endif /* FAT_H_INCLUDED */