Lines Matching refs:fs
23 #include "fs.h"
28 static void fs_add_extent(struct fs *fs, struct extent *extent,
31 assert(fs);
38 extent->next = fs->extents;
39 fs->extents = extent;
42 struct extent *fs_find_extent(struct fs *fs, offset_t start, offset_t len,
52 assert(fs);
56 e = last ? last->next : fs->extents;
102 static void fs_set_fat(struct fs *fs, cluster_t cluster, fat_entry_t entry)
104 assert(fs);
106 fs->fat[cluster] = htole32(entry);
109 int fs_alloc_extent(struct fs *fs, struct extent *extent,
112 assert(fs);
126 clusters_needed = (len + fs->cluster_size - 1) / fs->cluster_size;
129 if (fs->next_cluster + clusters_needed > fs->num_clusters) {
135 start = fs->next_cluster;
136 fs->next_cluster += clusters_needed;
140 fs_set_fat(fs, start + i, start + i + 1);
142 fs_set_fat(fs, start + clusters_needed - 1, FAT_ENTRY_EOC);
146 fs_add_extent(fs,
148 fs->data_offset + (offset_t)(start - FAT_CLUSTER_ZERO)
149 * fs->cluster_size,
150 (offset_t)clusters_needed * fs->cluster_size,
156 int fs_init(struct fs *fs, uint16_t cluster_size, offset_t data_size,
168 assert(fs);
171 fs->cluster_size = cluster_size;
183 memset(&fs->boot, 0, sizeof(fs->boot));
184 bs = &fs->boot;
207 memset(&fs->info, 0, sizeof(fs->info));
208 is = &fs->info;
216 fs->num_clusters = FAT_CLUSTER_ZERO + data_clusters;
217 fs->next_cluster = FAT_CLUSTER_ZERO;
219 fs->fat_size = fat_sectors * sector_size;
220 fs->fat = malloc(fs->fat_size);
221 if (!fs->fat) {
226 memset(fs->fat, 0, fs->fat_size);
228 fs->data_offset = (reserved_sectors + fat_sectors) * sector_size;
230 fs->extents = NULL;
231 fs_add_extent(fs, &fs->boot_extent,
234 fs_add_extent(fs, &fs->info_extent,
237 fs_add_extent(fs, &fs->backup_boot_extent,
240 fs_add_extent(fs, &fs->fat_extent,
241 reserved_sectors * sector_size, fs->fat_size,
249 void fs_set_rootdir_start(struct fs *fs, cluster_t rootdir_start)
251 assert(fs);
253 fs->boot.rootdir_start = htole32(rootdir_start);
256 void fs_update_free_clusters(struct fs *fs)
258 assert(fs);
260 fs->info.free_clusters = htole32(fs->num_clusters - fs->next_cluster);