⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dos.c

📁 linux下自动mount各种即插即用设备的一个小程序源码 文件包含内容: /vold.h /vold.c /split.h /split.c /disktype-6/disktype.c
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * dos.c * Detection of DOS parition maps and file systems * * Copyright (c) 2003 Christoph Pfisterer * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.  */#include "detect.h"/* * DOS partition types * * Taken from fdisk/i386_sys_types.c and fdisk/common.h of * util-linux 2.11n (as packaged by Debian), Feb 08, 2003. */struct systypes {	unsigned char type;	char *name;};struct systypes i386_sys_types[] = {	                                   { 0x00, "Empty" },	                                   { 0x01, "FAT12" },	                                   { 0x02, "XENIX root" },	                                   { 0x03, "XENIX usr" },	                                   { 0x04, "FAT16 <32M" },	                                   { 0x05, "Extended" },	                                   { 0x06, "FAT16" },	                                   { 0x07, "HPFS/NTFS" },	                                   { 0x08, "AIX" },	                                   { 0x09, "AIX bootable" },	                                   { 0x0a, "OS/2 Boot Manager" },	                                   { 0x0b, "Win95 FAT32" },	                                   { 0x0c, "Win95 FAT32 (LBA)" },	                                   { 0x0e, "Win95 FAT16 (LBA)" },	                                   { 0x0f, "Win95 Ext'd (LBA)" },	                                   { 0x10, "OPUS" },	                                   { 0x11, "Hidden FAT12" },	                                   { 0x12, "Compaq diagnostics" },	                                   { 0x14, "Hidden FAT16 <32M" },	                                   { 0x16, "Hidden FAT16" },	                                   { 0x17, "Hidden HPFS/NTFS" },	                                   { 0x18, "AST SmartSleep" },	                                   { 0x1b, "Hidden Win95 FAT32" },	                                   { 0x1c, "Hidden Win95 FAT32 (LBA)" },	                                   { 0x1e, "Hidden Win95 FAT16 (LBA)" },	                                   { 0x24, "NEC DOS" },	                                   { 0x39, "Plan 9" },	                                   { 0x3c, "PartitionMagic recovery" },	                                   { 0x40, "Venix 80286" },	                                   { 0x41, "PPC PReP Boot" },	                                   { 0x42, "SFS" },	                                   { 0x4d, "QNX4.x" },	                                   { 0x4e, "QNX4.x 2nd part" },	                                   { 0x4f, "QNX4.x 3rd part" },	                                   { 0x50, "OnTrack DM" },	                                   { 0x51, "OnTrack DM6 Aux1" },	                                   { 0x52, "CP/M" },	                                   { 0x53, "OnTrack DM6 Aux3" },	                                   { 0x54, "OnTrackDM6" },	                                   { 0x55, "EZ-Drive" },	                                   { 0x56, "Golden Bow" },	                                   { 0x5c, "Priam Edisk" },	                                   { 0x61, "SpeedStor" },	                                   { 0x63, "GNU HURD or SysV" },	                                   { 0x64, "Novell Netware 286" },	                                   { 0x65, "Novell Netware 386" },	                                   { 0x70, "DiskSecure Multi-Boot" },	                                   { 0x75, "PC/IX" },	                                   { 0x78, "XOSL" },	                                   { 0x80, "Old Minix" },	                                   { 0x81, "Minix / old Linux" },	                                   { 0x82, "Linux swap / Solaris" },	                                   { 0x83, "Linux" },	                                   { 0x84, "OS/2 hidden C: drive" },	                                   { 0x85, "Linux extended" },	                                   { 0x86, "NTFS volume set" },	                                   { 0x87, "NTFS volume set" },	                                   { 0x8e, "Linux LVM" },	                                   { 0x93, "Amoeba" },	                                   { 0x94, "Amoeba BBT" },	                                   { 0x9f, "BSD/OS" },	                                   { 0xa0, "IBM Thinkpad hibernation" },	                                   { 0xa5, "FreeBSD" },	                                   { 0xa6, "OpenBSD" },	                                   { 0xa7, "NeXTSTEP" },	                                   { 0xa9, "NetBSD" },	                                   { 0xb7, "BSDI fs" },	                                   { 0xb8, "BSDI swap" },	                                   { 0xbb, "Boot Wizard hidden" },	                                   { 0xc1, "DRDOS/sec (FAT-12)" },	                                   { 0xc4, "DRDOS/sec (FAT-16 < 32M)" },	                                   { 0xc6, "DRDOS/sec (FAT-16)" },	                                   { 0xc7, "Syrinx" },	                                   { 0xda, "Non-FS data" },	                                   { 0xdb, "CP/M / CTOS / ..." },	                                   { 0xde, "Dell Utility" },	                                   { 0xdf, "BootIt" },	                                   { 0xe1, "DOS access" },	                                   { 0xe3, "DOS R/O" },	                                   { 0xe4, "SpeedStor" },	                                   { 0xeb, "BeOS fs" },	                                   { 0xee, "EFI GPT" },	                                   { 0xef, "EFI (FAT-12/16/32)" },	                                   { 0xf0, "Linux/PA-RISC boot" },	                                   { 0xf1, "SpeedStor" },	                                   { 0xf4, "SpeedStor" },	                                   { 0xf2, "DOS secondary" },	                                   { 0xfd, "Linux raid autodetect" },	                                   { 0xfe, "LANstep" },	                                   { 0xff, "BBT" },	                                   { 0, 0 }                                   };static char * get_name_for_type(int type) {	int i;	for (i = 0; i386_sys_types[i].name; i++)		if (i386_sys_types[i].type == type)			return i386_sys_types[i].name;	return _T("Unknown");}/* * DOS-style partition map / MBR */int detect_dos_partmap(SECTION *section, DT_Info* info) {	unsigned char *buf;	int i, off, used, type, types[4], bootflags[4];	U32 start, size, starts[4], sizes[4];	int extpartnum = 5;	SECTION rs;	/* char s[256], append[64]; */	/* partition maps only occur at the start of a device */	if (section->pos != 0)		return DT_NO;	if (get_buffer(section, 0, 512, (void **)&buf) < 512)		return DT_NO;	/* check signature */	if (buf[510] != 0x55 || buf[511] != 0xAA)		return DT_NO;	/* get entries and check */	used = 0;	for (off = 446, i = 0; i < 4; i++, off += 16) {		/* get data */		bootflags[i] = buf[off];		types[i] = buf[off + 4];		starts[i] = get_le_long(buf + off + 8);		sizes[i] = get_le_long(buf + off + 12);		/* bootable flag: either on or off */		if (bootflags[i] != 0x00 && bootflags[i] != 0x80)			return DT_NO;		/* size non-zero -> entry in use */		if (starts[i] && sizes[i])			used = 1;	}	if (!used)		return DT_NO;	DBG("Is DOS Partition. * NOT implemented* returning DT_NO");	return DT_NO;		/* parse the data for real */	/* print_line(level, "DOS partition map"); */	for (i = 0; i < 4; i++) {		start = starts[i];		size = sizes[i];		type = types[i];		if (start == 0 || size == 0)			continue;		/* sprintf(append, " from %lu", start);		if (bootflags[i] == 0x80)		  strcat(append, ", bootable"); */		info->partmap.type = DT_DOS_PARTMAP;		info->partmap.part_type = type;		info->partmap.part_type_name = get_name_for_type(type);		info->partmap.bootable = (bootflags[i] == 0x80);		info->partmap.start = start;		info->partmap.size = size * 512;		/*format_blocky_size(s, size, 512, "sectors", append);		print_line(level, "Partition %d: %s",		    i+1, s);		print_line(level + 1, "Type 0x%02X (%s)", type, get_name_for_type(type)); */		info->next = new_DT_Info();		if (type == 0x05 || type == 0x0f || type == 0x85) {			/* extended partition - shortcut :-) */			detect_dos_partmap_ext(section, start, info->next, &extpartnum);		} else {			/* recurse for content detection */			rs.source = section->source;			rs.pos = section->pos + (U64)start * 512;			rs.size = (U64)size * 512;			rs.flags = 0;			info->next = dt_detect(&rs);		}	}		if(info->partmap.type == DT_DOS_PARTMAP)		return DT_YES;	return DT_NO;}int detect_dos_partmap_ext(SECTION *section, U64 extbase, DT_Info* info, int *extpartnum) {	unsigned char *buf;	U64 tablebase, nexttablebase;	int i, off, type, types[4];	U32 start, size, starts[4], sizes[4];	SECTION rs;	/* char s[256], append[64]; */	for (tablebase = extbase; tablebase; tablebase = nexttablebase) {		/* read sector from linked list */		if (get_buffer(section, tablebase << 9, 512, (void **)&buf) < 512)			return DT_NO;		/* check signature */		if (buf[510] != 0x55 || buf[511] != 0xAA) {			info->partmap.type = DT_DOS_PARTMAP;			info->partmap.part_type_name = _T("Signature missing");			/* print_line(level, "Signature missing"); */						/* return yes or no?? unsure */			return DT_NO;		}		/* get entries */		for (off = 446, i = 0; i < 4; i++, off += 16) {			types[i] = buf[off + 4];			starts[i] = get_le_long(buf + off + 8);			sizes[i] = get_le_long(buf + off + 12);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -