dosfstools
4.2
About: dosfstools are utilities to create, check and label (MS-DOS) FAT filesystems.
![]() ![]() |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "fsck.fat.h"
#include "io.h"
#include "boot.h"
#include "check.h"
#include "fat.h"
Go to the source code of this file.
Functions | |
void | get_fat (FAT_ENTRY *entry, void *fat, uint32_t cluster, DOS_FS *fs) |
void | release_fat (DOS_FS *fs) |
static void | fix_first_cluster (DOS_FS *fs, void *first_cluster) |
void | read_fat (DOS_FS *fs, int mode) |
void | set_fat (DOS_FS *fs, uint32_t cluster, int32_t new) |
int | bad_cluster (DOS_FS *fs, uint32_t cluster) |
uint32_t | next_cluster (DOS_FS *fs, uint32_t cluster) |
off_t | cluster_start (DOS_FS *fs, uint32_t cluster) |
void | set_owner (DOS_FS *fs, uint32_t cluster, DOS_FILE *owner) |
DOS_FILE * | get_owner (DOS_FS *fs, uint32_t cluster) |
void | fix_bad (DOS_FS *fs) |
void | reclaim_free (DOS_FS *fs) |
static void | tag_free (DOS_FS *fs, DOS_FILE *owner, uint32_t *num_refs, uint32_t start_cluster) |
void | reclaim_file (DOS_FS *fs) |
uint32_t | update_free (DOS_FS *fs) |
int bad_cluster | ( | DOS_FS * | fs, |
uint32_t | cluster | ||
) |
Definition at line 337 of file fat.c.
References DOS_FS::fat, FAT_IS_BAD, get_fat(), and FAT_ENTRY::value.
Referenced by check_file(), and test_file().
off_t cluster_start | ( | DOS_FS * | fs, |
uint32_t | cluster | ||
) |
Definition at line 368 of file fat.c.
References DOS_FS::cluster_size, and DOS_FS::data_start.
Referenced by alloc_rootdir_entry(), find_volume_de(), fix_bad(), scan_dir(), scan_free_entry(), and test_file().
void fix_bad | ( | DOS_FS * | fs | ) |
Definition at line 402 of file fat.c.
References DOS_FS::cluster_size, cluster_start(), DOS_FS::data_clusters, DOS_FS::fat, FAT_IS_BAD, fs_test(), get_fat(), get_owner(), set_fat(), FAT_ENTRY::value, and verbose.
Referenced by main().
|
static |
Definition at line 90 of file fat.c.
References DOS_FS::fat_bits, FAT_EXTD, fs_read(), and boot_sector::media.
Referenced by read_fat().
Fetch the FAT entry for a specified cluster.
[out] | entry | Cluster to which cluster of interest is linked |
[in] | fat | FAT table for the partition |
[in] | cluster | Cluster of interest |
[in] | fs | Information from the FAT boot sectors (bits per FAT entry) |
Definition at line 48 of file fat.c.
References DOS_FS::data_clusters, die(), fat, DOS_FS::fat_bits, FAT_ENTRY::reserved, and FAT_ENTRY::value.
Referenced by alloc_rootdir_entry(), bad_cluster(), check_dirty_bits(), check_file(), fix_bad(), next_cluster(), read_fat(), reclaim_file(), reclaim_free(), set_fat(), tag_free(), undelete(), and update_free().
Definition at line 394 of file fat.c.
References DOS_FS::cluster_owner.
Referenced by alloc_rootdir_entry(), check_file(), fix_bad(), reclaim_file(), reclaim_free(), tag_free(), test_file(), and update_free().
uint32_t next_cluster | ( | DOS_FS * | fs, |
uint32_t | cluster | ||
) |
Get the cluster to which the specified cluster is linked. If the linked cluster is marked bad, abort.
[in] | fs | Information about the filesystem |
[in] | cluster | Cluster to follow |
Definition at line 355 of file fat.c.
References die(), DOS_FS::fat, FAT_IS_BAD, FAT_IS_EOF, get_fat(), and FAT_ENTRY::value.
Referenced by alloc_rootdir_entry(), check_file(), find_volume_de(), reclaim_file(), scan_dir(), scan_free_entry(), tag_free(), test_file(), and truncate_file().
void read_fat | ( | DOS_FS * | fs, |
int | mode | ||
) |
Build a bookkeeping structure from the partition's FAT table. If the partition has multiple FATs and they don't agree, try to pick a winner, and queue a command to overwrite the loser. One error that is fixed here is a cluster that links to something out of range.
[in,out] | fs | Information about the filesystem |
[in] | mode | 0 - read-only, 1 - read-write (no repair), 2 - repair |
Definition at line 114 of file fat.c.
References alloc(), DOS_FS::cluster_owner, DOS_FS::data_clusters, die(), DOS_FS::fat, DOS_FS::fat_bits, FAT_EXTD, FAT_MIN_BAD, DOS_FS::fat_size, DOS_FS::fat_start, fat_table, fix_first_cluster(), fs_read(), fs_write(), get_choice(), get_fat(), DOS_FS::nfats, release_fat(), set_fat(), and FAT_ENTRY::value.
Referenced by handle_label(), and main().
void reclaim_file | ( | DOS_FS * | fs | ) |
Recover orphan chains to files, handling any cycles or cross-links.
[in,out] | fs | Information about the filesystem |
Definition at line 502 of file fat.c.
References alloc(), alloc_rootdir_entry(), DOS_FS::cluster_size, DOS_FS::data_clusters, die(), DOS_FS::fat, DOS_FS::fat_bits, FAT_IS_BAD, fs_write(), get_fat(), get_owner(), next_cluster(), set_fat(), DIR_ENT::size, DIR_ENT::start, DIR_ENT::starthi, tag_free(), FAT_ENTRY::value, and verbose.
Referenced by main().
void reclaim_free | ( | DOS_FS * | fs | ) |
Definition at line 420 of file fat.c.
References DOS_FS::cluster_size, DOS_FS::data_clusters, DOS_FS::fat, FAT_IS_BAD, get_fat(), get_owner(), set_fat(), FAT_ENTRY::value, and verbose.
Referenced by main().
void release_fat | ( | DOS_FS * | fs | ) |
Definition at line 80 of file fat.c.
References DOS_FS::cluster_owner, and DOS_FS::fat.
Referenced by handle_label(), main(), and read_fat().
void set_fat | ( | DOS_FS * | fs, |
uint32_t | cluster, | ||
int32_t | new | ||
) |
Update the FAT entry for a specified cluster (i.e., change the cluster it links to). Queue a command to write out this change.
[in,out] | fs | Information about the filesystem |
[in] | cluster | Cluster to change |
[in] | new | Cluster to link to Special values: 0 == free cluster -1 == end-of-chain -2 == bad cluster |
Definition at line 268 of file fat.c.
References DOS_FS::data_clusters, die(), DOS_FS::fat, FAT_BAD, DOS_FS::fat_bits, FAT_EOF, DOS_FS::fat_size, DOS_FS::fat_start, fs_write(), get_fat(), DOS_FS::nfats, FAT_ENTRY::reserved, and FAT_ENTRY::value.
Referenced by alloc_rootdir_entry(), check_file(), fix_bad(), read_fat(), reclaim_file(), reclaim_free(), tag_free(), test_file(), truncate_file(), and undelete().
Update internal bookkeeping to show that the specified cluster belongs to the specified dentry.
[in,out] | fs | Information about the filesystem |
[in] | cluster | Cluster being assigned |
[in] | owner | Information on dentry that owns this cluster (may be NULL) |
Definition at line 383 of file fat.c.
References DOS_FS::cluster_owner, and die().
Referenced by alloc_rootdir_entry(), check_file(), tag_free(), and test_file().
|
static |
Assign the specified owner to all orphan chains (except cycles). Break cross-links between orphan chains.
[in,out] | fs | Information about the filesystem |
[in] | owner | dentry to be assigned ownership of orphans |
[in,out] | num_refs | For each orphan cluster [index], how many clusters link to it. |
[in] | start_cluster | Where to start scanning for orphans |
Definition at line 454 of file fat.c.
References DOS_FS::data_clusters, DOS_FS::fat, FAT_IS_BAD, get_fat(), get_owner(), next_cluster(), set_fat(), set_owner(), and FAT_ENTRY::value.
Referenced by reclaim_file().
uint32_t update_free | ( | DOS_FS * | fs | ) |
Definition at line 601 of file fat.c.
References DOS_FS::data_clusters, DOS_FS::fat, FAT_IS_BAD, DOS_FS::free_clusters, fs_write(), DOS_FS::fsinfo_start, get_choice(), get_fat(), get_owner(), rw, FAT_ENTRY::value, and verbose.
Referenced by main().