Loading...
Searching...
No Matches
fat.h
Go to the documentation of this file.
/*
libparted
Copyright (C) 1998-2001, 2007, 2009-2014, 2019-2023, 2026 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FAT_H_INCLUDED
#define FAT_H_INCLUDED
#include <parted/parted.h>
#include <parted/endian.h>
#include <parted/debug.h>
#if ENABLE_NLS
# include <libintl.h>
# define _(String) dgettext (PACKAGE, String)
#else
# define _(String) (String)
#endif /* ENABLE_NLS */
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUFFER_SIZE 1024 /* buffer size in sectors (512 bytes) */
typedef uint32_t FatCluster;
typedef int32_t FatFragment;
enum _FatType {
FAT_TYPE_FAT12,
FAT_TYPE_FAT16,
FAT_TYPE_FAT32
};
typedef enum _FatType FatType;
typedef struct _FatSpecific FatSpecific;
typedef struct _FatDirEntry FatDirEntry;
#include "bootsector.h"
#include "count.h"
struct _FatTable {
void* table;
FatCluster size;
int raw_size;
FatType fat_type;
FatCluster cluster_count;
FatCluster free_cluster_count;
FatCluster bad_cluster_count;
FatCluster last_alloc;
};
typedef struct _FatTable FatTable;
struct __attribute__ ((packed)) _FatDirEntry {
char name[8];
uint8_t extension[3];
uint8_t attributes;
uint8_t is_upper_case_name;
uint8_t creation_time_low; /* milliseconds */
uint16_t creation_time_high;
uint16_t creation_date;
uint16_t access_date;
uint16_t first_cluster_high; /* for FAT32 */
uint16_t time;
uint16_t date;
uint16_t first_cluster;
uint32_t length;
};
struct _FatSpecific {
FatBootSector *boot_sector; /* structure of boot sector */
FatInfoSector *info_sector; /* fat32-only information sector */
int logical_sector_size; /* illogical sector size :-) */
PedSector sector_count;
int sectors_per_track; /* BIOS CHS stuff (S) */
int heads; /* BIOS CHS stuff (H) */
int cluster_size;
PedSector cluster_sectors;
FatCluster cluster_count;
int dir_entries_per_cluster;
FatType fat_type;
int fat_table_count;
PedSector fat_sectors;
uint32_t serial_number;
PedSector info_sector_offset; /* FAT32 only */
PedSector fat_offset;
PedSector root_dir_offset; /* non-FAT32 */
PedSector cluster_offset;
PedSector boot_sector_backup_offset;
FatCluster root_cluster; /* FAT32 only */
int root_dir_entry_count; /* non-FAT32 */
PedSector root_dir_sector_count; /* non-FAT32 */
FatCluster total_dir_clusters;
FatTable* fat;
FatClusterInfo* cluster_info;
PedSector buffer_sectors;
char* buffer;
int frag_size;
PedSector frag_sectors;
FatFragment frag_count;
FatFragment buffer_frags;
FatFragment cluster_frags;
};
#define FAT_SPECIFIC(fs) ((FatSpecific*) fs->type_specific)
#define FAT_ROOT 0
#define DELETED_FLAG 0xe5
#define READONLY_ATTR 0x01
#define HIDDEN_ATTR 0x02
#define SYSTEM_ATTR 0x04
#define VOLUME_LABEL_ATTR 0x08
#define VFAT_ATTR 0x0f
#define DIRECTORY_ATTR 0x10
#define ARCH_ATTR 0x20
#define MAX_FAT12_CLUSTERS 4086
#define MAX_FAT16_CLUSTERS 65526
#define MAX_FAT32_CLUSTERS 2000000
#define FAT_ROOT_DIR_ENTRY_COUNT 512
extern PedFileSystemType fat16_type;
extern PedFileSystemType fat32_type;
extern void fat_print (const PedFileSystem* fs);
extern PedFileSystem* fat_alloc (const PedGeometry* geom);
extern void fat_free (PedFileSystem* fs);
extern int fat_alloc_buffers (PedFileSystem* fs);
extern int fat_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer);
#endif /* FAT_H_INCLUDED */
debug.h
length
uint32_t length
Definition dos.c:5
endian.h
bootsector.h
FatInfoSector
struct _FatInfoSector FatInfoSector
Definition bootsector.h:24
FatBootSector
struct _FatBootSector FatBootSector
Definition bootsector.h:23
count.h
FatClusterInfo
struct _FatClusterInfo FatClusterInfo
Definition count.h:24
fat32_type
PedFileSystemType fat32_type
Definition fat.c:138
fat16_type
PedFileSystemType fat16_type
Definition fat.c:132
fat_alloc
PedFileSystem * fat_alloc(const PedGeometry *geom)
Definition fat.c:27
FatTable
struct _FatTable FatTable
Definition fat.h:69
FatType
enum _FatType FatType
Definition fat.h:49
fat_alloc_buffers
int fat_alloc_buffers(PedFileSystem *fs)
Definition fat.c:59
_FatType
_FatType
Definition fat.h:44
FAT_TYPE_FAT16
@ FAT_TYPE_FAT16
Definition fat.h:46
FAT_TYPE_FAT32
@ FAT_TYPE_FAT32
Definition fat.h:47
FAT_TYPE_FAT12
@ FAT_TYPE_FAT12
Definition fat.h:45
fat_free
void fat_free(PedFileSystem *fs)
Definition fat.c:57
FatFragment
int32_t FatFragment
Definition fat.h:42
fat_resize
int fat_resize(PedFileSystem *fs, PedGeometry *geom, PedTimer *timer)
Definition resize.c:825
FatSpecific
struct _FatSpecific FatSpecific
Definition fat.h:51
fat_print
void fat_print(const PedFileSystem *fs)
FatCluster
uint32_t FatCluster
Definition fat.h:41
FatDirEntry
struct _FatDirEntry FatDirEntry
Definition fat.h:52
PedSector
long long PedSector
We can address 2^63 sectors.
Definition device.h:31
PedFileSystemType
struct _PedFileSystemType PedFileSystemType
Definition filesys.h:31
PedFileSystem
struct _PedFileSystem PedFileSystem
Definition filesys.h:30
PedGeometry
struct _PedGeometry PedGeometry
Definition geom.h:30
PedTimer
struct _PedTimer PedTimer
Definition timer.h:32
parted.h
name
char name[16]
Definition pc98.c:13
_FatSpecific
Definition fat.h:87
_FatSpecific::root_dir_sector_count
PedSector root_dir_sector_count
Definition fat.h:116
_FatSpecific::cluster_frags
FatFragment cluster_frags
Definition fat.h:129
_FatSpecific::buffer_frags
FatFragment buffer_frags
Definition fat.h:128
_FatSpecific::fat_table_count
int fat_table_count
Definition fat.h:103
_FatSpecific::serial_number
uint32_t serial_number
Definition fat.h:106
_FatSpecific::fat_sectors
PedSector fat_sectors
Definition fat.h:104
_FatSpecific::cluster_offset
PedSector cluster_offset
Definition fat.h:111
_FatSpecific::cluster_count
FatCluster cluster_count
Definition fat.h:99
_FatSpecific::buffer_sectors
PedSector buffer_sectors
Definition fat.h:122
_FatSpecific::heads
int heads
Definition fat.h:95
_FatSpecific::total_dir_clusters
FatCluster total_dir_clusters
Definition fat.h:117
_FatSpecific::fat_offset
PedSector fat_offset
Definition fat.h:109
_FatSpecific::sector_count
PedSector sector_count
Definition fat.h:92
_FatSpecific::info_sector_offset
PedSector info_sector_offset
Definition fat.h:108
_FatSpecific::dir_entries_per_cluster
int dir_entries_per_cluster
Definition fat.h:100
_FatSpecific::boot_sector
FatBootSector * boot_sector
Definition fat.h:88
_FatSpecific::info_sector
FatInfoSector * info_sector
Definition fat.h:89
_FatSpecific::boot_sector_backup_offset
PedSector boot_sector_backup_offset
Definition fat.h:112
_FatSpecific::frag_count
FatFragment frag_count
Definition fat.h:127
_FatSpecific::root_dir_entry_count
int root_dir_entry_count
Definition fat.h:115
_FatSpecific::cluster_size
int cluster_size
Definition fat.h:97
_FatSpecific::buffer
char * buffer
Definition fat.h:123
_FatSpecific::cluster_info
FatClusterInfo * cluster_info
Definition fat.h:120
_FatSpecific::logical_sector_size
int logical_sector_size
Definition fat.h:91
_FatSpecific::fat
FatTable * fat
Definition fat.h:119
_FatSpecific::fat_type
FatType fat_type
Definition fat.h:102
_FatSpecific::frag_size
int frag_size
Definition fat.h:125
_FatSpecific::root_dir_offset
PedSector root_dir_offset
Definition fat.h:110
_FatSpecific::cluster_sectors
PedSector cluster_sectors
Definition fat.h:98
_FatSpecific::root_cluster
FatCluster root_cluster
Definition fat.h:114
_FatSpecific::frag_sectors
PedSector frag_sectors
Definition fat.h:126
_FatSpecific::sectors_per_track
int sectors_per_track
Definition fat.h:94
_FatTable
Definition fat.h:57
_FatTable::bad_cluster_count
FatCluster bad_cluster_count
Definition fat.h:65
_FatTable::cluster_count
FatCluster cluster_count
Definition fat.h:63
_FatTable::table
void * table
Definition fat.h:58
_FatTable::size
FatCluster size
Definition fat.h:59
_FatTable::raw_size
int raw_size
Definition fat.h:60
_FatTable::last_alloc
FatCluster last_alloc
Definition fat.h:67
_FatTable::free_cluster_count
FatCluster free_cluster_count
Definition fat.h:64
_FatTable::fat_type
FatType fat_type
Definition fat.h:62