dosfstools  4.2
About: dosfstools are utilities to create, check and label (MS-DOS) FAT filesystems.
  Fossies Dox: dosfstools-4.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

check.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <ctype.h>
#include <wctype.h>
#include "common.h"
#include "fsck.fat.h"
#include "io.h"
#include "fat.h"
#include "file.h"
#include "lfn.h"
#include "check.h"
#include "boot.h"
#include "charconv.h"
Include dependency graph for check.c:

Go to the source code of this file.


#define PATH_NAME_MAX   1023
#define FSTART(p, fs)
#define MODIFY(p, i, v)
#define MODIFY_START(p, v, fs)


static char * path_name (DOS_FILE *file)
static char * file_stat (DOS_FILE *file)
static int bad_name (DOS_FILE *file)
static void lfn_remove (off_t from, off_t to)
static void drop_file (DOS_FS *fs, DOS_FILE *file)
static void truncate_file (DOS_FS *fs, DOS_FILE *file, uint32_t clusters)
static void auto_rename (DOS_FILE *file)
static void rename_file (DOS_FILE *file)
static uint32_t scan_free_entry (DOS_FS *fs, DOS_FILE *this)
static int handle_dot (DOS_FS *fs, DOS_FILE *file, int dotdot)
static int check_file (DOS_FS *fs, DOS_FILE *file)
static int check_files (DOS_FS *fs, DOS_FILE *start)
static int check_dir (DOS_FS *fs, DOS_FILE **root, int dots)
static void test_file (DOS_FS *fs, DOS_FILE *file, int read_test)
static void undelete (DOS_FS *fs, DOS_FILE *file)
static void new_dir (void)
static void add_file (DOS_FS *fs, DOS_FILE ***chain, DOS_FILE *parent, off_t offset, FDSC **cp)
static int subdirs (DOS_FS *fs, DOS_FILE *parent, FDSC **cp)
static int scan_dir (DOS_FS *fs, DOS_FILE *this, FDSC **cp)
int scan_root (DOS_FS *fs)
static char print_fat_dirty_state (void)
void check_dirty_bits (DOS_FS *fs)
static void get_new_label (char doslabel[12])
static int check_boot_label (DOS_FS *fs)
void check_label (DOS_FS *fs)


static DOS_FILEroot
static const char * month_str []

Macro Definition Documentation


#define FSTART (   p,
((uint32_t)le16toh(p->dir_ent.start) | \
(fs->fat_bits == 32 ? (uint32_t)le16toh(p->dir_ent.starthi) << 16 : 0))

Definition at line 54 of file check.c.


#define MODIFY (   p,
do { \
if (p->offset) { \
p->dir_ent.i = v; \
fs_write(p->offset+offsetof(DIR_ENT,i), \
sizeof(p->dir_ent.i),&p->dir_ent.i); \
} \
} while(0)

Definition at line 58 of file check.c.


#define MODIFY_START (   p,
do { \
uint32_t __v = (v); \
if (!p->offset) { \
/* writing to fake entry for FAT32 root dir */ \
if (!__v) die("Oops, deleting FAT32 root dir!"); \
fs->root_cluster = __v; \
p->dir_ent.start = htole16(__v&0xffff); \
p->dir_ent.starthi = htole16(__v>>16); \
__v = htole32(__v); \
fs_write(offsetof(struct boot_sector,root_cluster), \
sizeof(((struct boot_sector *)0)->root_cluster), \
&__v); \
} \
else { \
MODIFY(p,start,htole16((__v)&0xffff)); \
if (fs->fat_bits == 32) \
MODIFY(p,starthi,htole16((__v)>>16)); \
} \
} while(0)
void die(const char *msg,...)
Definition: common.c:53

Definition at line 67 of file check.c.


#define PATH_NAME_MAX   1023

Definition at line 49 of file check.c.

Function Documentation

◆ add_file()

static void add_file ( DOS_FS fs,
DOS_FILE ***  chain,
DOS_FILE parent,
off_t  offset,
FDSC **  cp 

Create a description for a referenced dentry and insert it in our dentry tree. Then, go check the dentry's cluster chain for bad clusters and cluster loops.

[in,out]fsInformation about the filesystem
[in]parentInformation about parent directory of this file NULL == no parent ('file' is root directory)
[in]offsetPartition-relative byte offset of directory entry of interest 0 == Root directory

Definition at line 901 of file check.c.

References DIR_ENT::attr, ATTR_DIR, die(), fdt_none, fdt_undelete, file_modify(), file_name(), file_type(), fs_read(), fs_write(), IS_FREE, lfn_add_slot(), lfn_check_orphaned(), lfn_get(), list, mem_queue, MSDOS_NAME, n_files, DIR_ENT::name, _dos_file::next, path_name(), qalloc(), DOS_FS::root_cluster, DIR_ENT::start, DIR_ENT::starthi, test, test_file(), undelete(), and VFAT_LN_ATTR.

Referenced by scan_dir(), and scan_root().

◆ auto_rename()

◆ bad_name()

static int bad_name ( DOS_FILE file)

◆ check_boot_label()

◆ check_dir()

static int check_dir ( DOS_FS fs,
DOS_FILE **  root,
int  dots 

◆ check_dirty_bits()

◆ check_file()

◆ check_files()

static int check_files ( DOS_FS fs,
DOS_FILE start 

Definition at line 646 of file check.c.

References check_file(), and _dos_file::next.

Referenced by scan_dir(), and scan_root().

◆ check_label()

◆ drop_file()

static void drop_file ( DOS_FS fs,
DOS_FILE file 

Definition at line 227 of file check.c.

References DELETED_FLAG, _dos_file::lfn, _dos_file::lfn_offset, lfn_remove(), MODIFY, n_files, and _dos_file::offset.

Referenced by check_dir(), and handle_dot().

◆ file_stat()

static char* file_stat ( DOS_FILE file)

Definition at line 120 of file check.c.

References DIR_ENT::date, _dos_file::dir_ent, month_str, DIR_ENT::size, and DIR_ENT::time.

Referenced by check_dir().

◆ get_new_label()

static void get_new_label ( char  doslabel[12])

◆ handle_dot()

◆ lfn_remove()

static void lfn_remove ( off_t  from,
off_t  to 

Definition at line 211 of file check.c.

References DELETED_FLAG, fs_write(), and DIR_ENT::name.

Referenced by auto_rename(), drop_file(), and rename_file().

◆ new_dir()

static void new_dir ( void  )

Definition at line 883 of file check.c.

References lfn_reset().

Referenced by scan_dir(), and scan_root().

◆ path_name()

static char* path_name ( DOS_FILE file)

Construct a full path (starting with '/') for the specified dentry, relative to the partition. All components are "long" names where possible.

[in]fileInformation about dentry (file or directory) of interest

return Pointer to static string containing file's full path

Definition at line 96 of file check.c.

References die(), _dos_file::dir_ent, file_name(), _dos_file::lfn, DIR_ENT::name, _dos_file::parent, and PATH_NAME_MAX.

Referenced by add_file(), check_dir(), check_file(), handle_dot(), and test_file().

◆ print_fat_dirty_state()

static char print_fat_dirty_state ( void  )

Definition at line 1054 of file check.c.

References get_choice().

Referenced by check_dirty_bits().

◆ rename_file()

◆ scan_dir()

◆ scan_free_entry()

static uint32_t scan_free_entry ( DOS_FS fs,
DOS_FILE this 

Definition at line 339 of file check.c.

References DOS_FS::cluster_size, cluster_start(), fs_read(), FSTART, IS_FREE, DIR_ENT::name, and next_cluster().

Referenced by handle_dot().

◆ scan_root()

int scan_root ( DOS_FS fs)

Scan all directory and file information for errors.

[in,out]fsInformation about the filesystem
0 Success
1 Error

Definition at line 1032 of file check.c.

References add_file(), check_dir(), check_files(), fp_root, lfn_check_orphaned(), new_dir(), root, DOS_FS::root_cluster, DOS_FS::root_entries, DOS_FS::root_start, and subdirs().

Referenced by main().

◆ subdirs()

static int subdirs ( DOS_FS fs,
DOS_FILE parent,
FDSC **  cp 

Recursively scan subdirectories of the specified parent directory.

[in,out]fsInformation about the filesystem
[in]parentIdentifies the directory to scan
0 Success
1 Error

Definition at line 1013 of file check.c.

References DIR_ENT::attr, ATTR_DIR, _dos_file::dir_ent, file_cd(), _dos_file::first, IS_FREE, DIR_ENT::name, _dos_file::next, root, and scan_dir().

Referenced by scan_dir(), and scan_root().

◆ test_file()

static void test_file ( DOS_FS fs,
DOS_FILE file,
int  read_test 

Check a dentry's cluster chain for bad clusters. If requested, we verify readability and mark unreadable clusters as bad.

[in,out]fsInformation about the filesystem
[in]filedentry to check
[in]read_testNonzero == verify that dentry's clusters can be read

Definition at line 789 of file check.c.

References bad_cluster(), DOS_FS::cluster_size, cluster_start(), DOS_FS::data_clusters, die(), fs_test(), FSTART, get_owner(), MODIFY_START, next_cluster(), _dos_file::offset, path_name(), set_fat(), and set_owner().

Referenced by add_file().

◆ truncate_file()

static void truncate_file ( DOS_FS fs,
DOS_FILE file,
uint32_t  clusters 

Definition at line 237 of file check.c.

References FSTART, MODIFY_START, next_cluster(), and set_fat().

Referenced by check_dir(), and check_file().

◆ undelete()

static void undelete ( DOS_FS fs,
DOS_FILE file 

Variable Documentation

◆ month_str

const char* month_str[]
Initial value:
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }

Definition at line 117 of file check.c.

Referenced by file_stat().

◆ root

DOS_FILE* root

Definition at line 51 of file check.c.

Referenced by alloc_rootdir_entry(), auto_rename(), check_dir(), qalloc(), qfree(), scan_root(), and subdirs().