3 Copyright (C) 1998-2000, 2007, 2009-2010 Free Software Foundation,
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
35 fat_read_fragments (PedFileSystem* fs, char* buf, FatFragment frag,
38 FatSpecific* fs_info = FAT_SPECIFIC (fs);
39 PedSector sector = fat_frag_to_sector (fs, frag);
40 PedSector sector_count = count * fs_info->frag_sectors;
42 PED_ASSERT (frag >= 0 && frag < fs_info->frag_count, return 0);
44 return ped_geometry_read (fs->geom, buf, sector, sector_count);
48 fat_read_fragment (PedFileSystem* fs, char* buf, FatFragment frag)
50 return fat_read_fragments (fs, buf, frag, 1);
54 fat_write_fragments (PedFileSystem* fs, char* buf, FatFragment frag,
57 FatSpecific* fs_info = FAT_SPECIFIC (fs);
58 PedSector sector = fat_frag_to_sector (fs, frag);
59 PedSector sector_count = count * fs_info->frag_sectors;
61 PED_ASSERT (frag >= 0 && frag < fs_info->frag_count, return 0);
63 return ped_geometry_write (fs->geom, buf, sector, sector_count);
67 fat_write_fragment (PedFileSystem* fs, char* buf, FatFragment frag)
69 return fat_write_fragments (fs, buf, frag, 1);
73 fat_write_sync_fragments (PedFileSystem* fs, char* buf, FatFragment frag,
76 if (!fat_write_fragments (fs, buf, frag, count))
78 if (!ped_geometry_sync (fs->geom))
84 fat_write_sync_fragment (PedFileSystem* fs, char* buf, FatFragment frag)
86 return fat_write_sync_fragments (fs, buf, frag, 1);
90 fat_read_clusters (PedFileSystem* fs, char *buf, FatCluster cluster,
93 FatSpecific* fs_info = FAT_SPECIFIC (fs);
94 PedSector sector = fat_cluster_to_sector (fs, cluster);
95 PedSector sector_count = count * fs_info->cluster_sectors;
97 PED_ASSERT (cluster >= 2
98 && cluster + count - 1 < fs_info->cluster_count + 2,
101 return ped_geometry_read (fs->geom, buf, sector, sector_count);
105 fat_read_cluster (PedFileSystem* fs, char *buf, FatCluster cluster)
107 return fat_read_clusters (fs, buf, cluster, 1);
111 fat_write_clusters (PedFileSystem* fs, char *buf, FatCluster cluster,
114 FatSpecific* fs_info = FAT_SPECIFIC (fs);
115 PedSector sector = fat_cluster_to_sector (fs, cluster);
116 PedSector sector_count = count * fs_info->cluster_sectors;
118 PED_ASSERT (cluster >= 2
119 && cluster + count - 1 < fs_info->cluster_count + 2,
122 return ped_geometry_write (fs->geom, buf, sector, sector_count);
126 fat_write_cluster (PedFileSystem* fs, char *buf, FatCluster cluster)
128 return fat_write_clusters (fs, buf, cluster, 1);
132 fat_write_sync_clusters (PedFileSystem* fs, char *buf, FatCluster cluster,
135 if (!fat_write_clusters (fs, buf, cluster, count))
137 if (!ped_geometry_sync (fs->geom))
143 fat_write_sync_cluster (PedFileSystem* fs, char *buf, FatCluster cluster)
145 if (!fat_write_cluster (fs, buf, cluster))
147 if (!ped_geometry_sync (fs->geom))
152 #endif /* !DISCOVER_ONLY */