/* mkfs.fat.c - utility to create FAT/MS-DOS filesystems
Copyright (C) 1991 Linus Torvalds <torvalds@klaava.helsinki.fi>
Copyright (C) 1992-1993 Remy Card <card@masi.ibp.fr>
Copyright (C) 1993-1994 David Hudson <dave@humbug.demon.co.uk>
Copyright (C) 1998 H. Peter Anvin <hpa@zytor.com>
Copyright (C) 1998-2005 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
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/>.
The complete text of the GNU General Public License
can be found in /usr/share/common-licenses/GPL-3 file.
*/
/* Description: Utility to allow an MS-DOS filesystem to be created
under Linux. A lot of the basic structure of this program has been
borrowed from Remy Card's "mke2fs" code.
As far as possible the aim here is to make the "mkfs.fat" command
look almost identical to the other Linux filesystem make utilties,
eg bad blocks are still specified as blocks, not sectors, but when
it comes down to it, DOS is tied to the idea of a sector (512 bytes
as a rule), and not the block. For example the boot block does not
occupy a full cluster.
Fixes/additions May 1998 by Roman Hodek
<Roman.Hodek@informatik.uni-erlangen.de>:
- Atari format support
- New options -A, -S, -C
- Support for filesystems > 2GB
- FAT32 support */
/* Include the header files */
#include "version.h"
#include <fcntl.h>
#include <linux/hdreg.h>
#include <sys/mount.h>
#include <linux/fs.h>
#include <linux/fd.h>
#include <endian.h>
#include <mntent.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <ctype.h>
#include <stdint.h>
#include <endian.h>
#include <asm/types.h>
/* In earlier versions, an own llseek() was used, but glibc lseek() is
* sufficient (or even better :) for 64 bit offsets in the meantime */
#define llseek lseek
/* Constant definitions */
#define TRUE 1 /* Boolean constants */
#define FALSE 0
#define TEST_BUFFER_BLOCKS 16
#define HARD_SECTOR_SIZE 512
#define SECTORS_PER_BLOCK ( BLOCK_SIZE / HARD_SECTOR_SIZE )
#define NO_NAME "NO NAME "
/* Macro definitions */
/* Report a failure message and return a failure error code */
#define die( str ) fatal_error( "%s: " str "\n" )
/* Mark a cluster in the FAT as bad */
#define mark_sector_bad( sector ) mark_FAT_sector( sector, FAT_BAD )
/* Compute ceil(a/b) */
static inline int cdiv(int a, int b)
{
return (a + b - 1) / b;
}
/* MS-DOS filesystem structures -- I included them here instead of
including linux/msdos_fs.h since that doesn't include some fields we
need */
#define ATTR_RO 1 /* read-only */
#define ATTR_HIDDEN 2 /* hidden */
#define ATTR_SYS 4 /* system */
#define ATTR_VOLUME 8 /* volume label */
#define ATTR_DIR 16 /* directory */
#define ATTR_ARCH 32 /* archived */
#define ATTR_NONE 0 /* no attribute bits */
#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
/* attribute bits that are copied "as is" */
/* FAT values */
#define FAT_EOF (atari_format ? 0x0fffffff : 0x0ffffff8)
#define FAT_BAD 0x0ffffff7
#define MSDOS_EXT_SIGN 0x29 /* extended boot sector signature */
#define MSDOS_FAT12_SIGN "FAT12 " /* FAT12 filesystem signature */
#define MSDOS_FAT16_SIGN "FAT16 " /* FAT16 filesystem signature */
#define MSDOS_FAT32_SIGN "FAT32 " /* FAT32 filesystem signature */
#define BOOT_SIGN 0xAA55 /* Boot sector magic number */
#define MAX_CLUST_12 ((1 << 12) - 16)
#define MAX_CLUST_16 ((1 << 16) - 16)
#define MIN_CLUST_32 65529
/* M$ says the high 4 bits of a FAT32 FAT entry are reserved and don't belong
* to the cluster number. So the max. cluster# is based on 2^28 */
#define MAX_CLUST_32 ((1 << 28) - 16)
#define FAT12_THRESHOLD 4085
#define OLDGEMDOS_MAX_SECTORS 32765
#define GEMDOS_MAX_SECTORS 65531
#define GEMDOS_MAX_SECTOR_SIZE (16*1024)
#define BOOTCODE_SIZE 448
#define BOOTCODE_FAT32_SIZE 420
/* __attribute__ ((packed)) is used on all structures to make gcc ignore any
* alignments */
struct msdos_volume_info {
__u8 drive_number; /* BIOS drive number */
__u8 RESERVED; /* Unused */
__u8 ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */
__u8 volume_id[4]; /* Volume ID number */
__u8 volume_label[11]; /* Volume label */
__u8 fs_type[8]; /* Typically FAT12 or FAT16 */
} __attribute__ ((packed));
struct msdos_boot_sector {
__u8 boot_jump[3]; /* Boot strap short or near jump */
__u8 system_id[8]; /* Name - can be used to special case
partition manager volumes */
__u8 sector_size[2]; /* bytes per logical sector */
__u8 cluster_size; /* sectors/cluster */
__u16 reserved; /* reserved sectors */
__u8 fats; /* number of FATs */
__u8 dir_entries[2]; /* root directory entries */
__u8 sectors[2]; /* number of sectors */
__u8 media; /* media code (unused) */
__u16 fat_length; /* sectors/FAT */
__u16 secs_track; /* sectors per track */
__u16 heads; /* number of heads */
__u32 hidden; /* hidden sectors (unused) */
__u32 total_sect; /* number of sectors (if sectors == 0) */
union {
struct {
struct msdos_volume_info vi;
__u8 boot_code[BOOTCODE_SIZE];
} __attribute__ ((packed)) _oldfat;
struct {
__u32 fat32_length; /* sectors/FAT */
__u16 flags; /* bit 8: fat mirroring, low 4: active fat */
__u8 version[2]; /* major, minor filesystem version */
__u32 root_cluster; /* first cluster in root directory */
__u16 info_sector; /* filesystem info sector */
__u16 backup_boot; /* backup boot sector */
__u16 reserved2[6]; /* Unused */
struct msdos_volume_info vi;
__u8 boot_code[BOOTCODE_FAT32_SIZE];
} __attribute__ ((packed)) _fat32;
} __attribute__ ((packed)) fstype;
__u16 boot_sign;
} __attribute__ ((packed));
#define fat32 fstype._fat32
#define oldfat fstype._oldfat
struct fat32_fsinfo {
__u32 reserved1; /* Nothing as far as I can tell */
__u32 signature; /* 0x61417272L */
__u32 free_clusters; /* Free cluster count. -1 if unknown */
__u32 next_cluster; /* Most recently allocated cluster.
* Unused under Linux. */
__u32 reserved2[4];
};
struct msdos_dir_entry {
char name[8], ext[3]; /* name and extension */
__u8 attr; /* attribute bits */
__u8 lcase; /* Case for base and extension */
__u8 ctime_ms; /* Creation time, milliseconds */
__u16 ctime; /* Creation time */
__u16 cdate; /* Creation date */
__u16 adate; /* Last access date */
__u16 starthi; /* high 16 bits of first cl. (FAT32) */
__u16 time, date, start; /* time, date and first cluster */
__u32 size; /* file size (in bytes) */
} __attribute__ ((packed));
/* The "boot code" we put into the filesystem... it writes a message and
tells the user to try again */
char dummy_boot_jump[3] = { 0xeb, 0x3c, 0x90 };
char dummy_boot_jump_m68k[2] = { 0x60, 0x1c };
#define MSG_OFFSET_OFFSET 3
char dummy_boot_code[BOOTCODE_SIZE] = "\x0e" /* push cs */
"\x1f" /* pop ds */
"\xbe\x5b\x7c" /* mov si, offset message_txt */
/* write_msg: */
"\xac" /* lodsb */
"\x22\xc0" /* and al, al */
"\x74\x0b" /*
没有合适的资源?快使用搜索试试~ 我知道了~
dosfstools-3.0.26
4星 · 超过85%的资源 需积分: 47 141 下载量 36 浏览量
2015-09-07
09:27:29
上传
评论
收藏 105KB TGZ 举报
温馨提示
共63个文件
c:11个
h:10个
8:6个
这是在ubuntu14.04系统上面测试通过的fsck.fat工具对应的源代码,加压以后进入dosfstools-3.0.26目录,直接make即可,生成的工具都在本目录下。
资源推荐
资源详情
资源评论
收起资源包目录
dosfstools-3.0.26.tgz (63个子文件)
dosfstools-3.0.26
debian
control 1KB
changelog 24KB
compat 2B
source
options 17B
format 12B
copyright 1KB
dosfstools.install 9B
dosfstools-udeb.install 42B
rules 640B
.gitignore 34B
COPYING 34KB
bin
Nindent 465B
manpages
bin
update-version.sh 1KB
de
fatlabel.de.8 2KB
mkfs.fat.de.8 8KB
fsck.fat.de.8 7KB
po4a.cfg 236B
po
de
fsck.fat.8.po 12KB
mkfs.fat.8.po 11KB
fatlabel.8.po 3KB
en
fsck.fat.8 7KB
mkfs.fat.8 8KB
fatlabel.8 2KB
pot
fatlabel.8.pot 3KB
fsck.fat.8.pot 12KB
mkfs.fat.8.pot 11KB
Makefile 1KB
ChangeLog 53KB
.pc
.version 2B
applied-patches 0B
.quilt_series 7B
.quilt_patches 15B
src
fsck.fat.h 7KB
io.h 2KB
version.h 1KB
fat.h 3KB
lfn.h 1KB
fat.c 16KB
file.h 2KB
file.c 7KB
common.c 3KB
common.h 2KB
io.c 6KB
boot.c 18KB
lfn.c 15KB
fsck.fat.c 6KB
charconv.h 173B
charconv.c 2KB
fatlabel.c 3KB
check.c 30KB
mkfs.fat.c 55KB
check.h 2KB
boot.h 1KB
doc
ChangeLog.dosfsck 413B
ChangeLog.mkdosfs 751B
ANNOUNCE.mkdosfs 1KB
README.dosfsck 2KB
ChangeLog.dosfstools-2.x 6KB
TODO.dosfstools-2.x 551B
README.mkdosfs 2KB
README.dosfstools-2.x 3KB
VERSION 7B
Makefile 5KB
共 63 条
- 1
baidu_31108809
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页