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

📄 disktype.h

📁 linux下自动mount各种即插即用设备的一个小程序源码 文件包含内容: /vold.h /vold.c /split.h /split.c /disktype-6/disktype.c
💻 H
字号:
/* * disktype.h * Common header file. * * 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.  */#ifndef _DISKTYPE_H#define _DISKTYPE_H//#define DEBUG/* global includes */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <fcntl.h>#include <uuid/uuid.h>/* string macro */#define _T(text)	strdup(text)/* constants */#define FLAG_IN_DISKLABEL (0x0001)/* types */typedef unsigned char	U8;typedef signed char	S8;typedef unsigned short	U16;typedef signed short	S16;typedef unsigned int	U32;typedef signed int	S32;/* Figure out how to support 64-bit datatypes - taken from SDL*/#if !defined(__STRICT_ANSI__)#if defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__DECC)#define DT_HAS_64BIT_TYPE	long long#elif defined(_MSC_VER) /* VC++ */#define DT_HAS_64BIT_TYPE	__int64#endif#endif /* !__STRICT_ANSI__ *//* The 64-bit datatype isn't supported on all platforms */#ifdef DT_HAS_64BIT_TYPE#ifndef H_MMBASICtypedef unsigned DT_HAS_64BIT_TYPE U64;#endiftypedef DT_HAS_64BIT_TYPE S64;#else/* This is really just a hack to prevent the compiler from complaining */typedef struct {	U32 hi;	U32 lo;} U64, S64;#endif/* Make sure the types really have the right sizes */#define DT_COMPILE_TIME_ASSERT(name, x)               \       typedef int DT_dummy_ ## name[(x) * 2 - 1]DT_COMPILE_TIME_ASSERT(uint8, sizeof(U8) == 1);DT_COMPILE_TIME_ASSERT(sint8, sizeof(S8) == 1);DT_COMPILE_TIME_ASSERT(uint16, sizeof(U16) == 2);DT_COMPILE_TIME_ASSERT(sint16, sizeof(S16) == 2);DT_COMPILE_TIME_ASSERT(uint32, sizeof(U32) == 4);DT_COMPILE_TIME_ASSERT(sint32, sizeof(S32) == 4);DT_COMPILE_TIME_ASSERT(uint64, sizeof(U64) == 8);DT_COMPILE_TIME_ASSERT(sint64, sizeof(S64) == 8);/* Return values for detectors *//* yes: the fs was detected, no: it was not detected, -1: internal error */#define DT_YES	1#define DT_NO	0#define	DT_ERROR	-1/* Detector Flags */#define DFLAG_DIF	1#define DFLAG_BC	2#define DFLAG_PT	4#define DFLAG_FS	8#define DFLAG_FF	16#define DFLAG_ALL	31/* Filetypes */enum {	DT_FILE = 0,	DT_BLOCK,	DT_CHAR,	DT_DIR,	DT_FIFO,	DT_SOCKET,	DT_SPECIAL};/* Partition maps, filesystems and stuff */enum {  DT_NOTHING = 0,  /* DT_INFO_TYPES */  DT_BOOTCODE,  DT_PARTMAP,  DT_FS,  DT_OTHER,    /* boot code */  DT_LINUX_LOADER,  DT_BSD_LOADER,  DT_LOADER_RESERVED0,  DT_LOADER_RESERVED1,  DT_LOADER_RESERVED2,  /* partition maps */  DT_BSD_DISKLABEL,  DT_SOLARIS_DISKLABEL,  DT_SOLARIS_VTOC,  DT_AMIGA_PARTMAP,  DT_ATARI_PARTMAP,  DT_DOS_PARTMAP,  DT_PARTMAP_RESERVED0,  DT_PARTMAP_RESERVED1,  DT_PARTMAP_RESERVED2,  DT_PARTMAP_RESERVED3,  DT_PARTMAP_RESERVED4,  /* filesystems / partitions */  DT_AMIGA_FS,  DT_APPLE_VOLUME,  DT_FAT,  DT_NTFS,  DT_HPFS,  DT_UDF,  DT_ISO,  DT_EXT23,  DT_REISER,  DT_LINUX_RAID,  DT_LINUX_LVM,  DT_LINUX_SWAP,  DT_LINUX_MISC,  DT_JFS,  DT_XFS,  DT_UFS,  DT_SYSV,  DT_QNX,  DT_BFS,  DT_FS_RESERVED0,  DT_FS_RESERVED1,  DT_FS_RESERVED2,  DT_FS_RESERVED3,  DT_FS_RESERVED4,  DT_FS_RESERVED5,  DT_FS_RESERVED6,  DT_FS_RESERVED7,  DT_FS_RESERVED8,  DT_FS_RESERVED9,  /* other: disk image formats, file formats, blank disks */  DT_VHD,  DT_CDIMAGE,  DT_UDIF,  DT_ARCHIVE,  DT_COMPRESSED,  DT_BLANK,  DT_OTHER_RESERVED0,  DT_OTHER_RESERVED1,  DT_OTHER_RESERVED2,  DT_OTHER_RESERVED3,  DT_OTHER_RESERVED4,  DT_OTHER_RESERVED5,  DT_OTHER_RESERVED6,  DT_OTHER_RESERVED7,  DT_OTHER_RESERVED8,  DT_OTHER_RESERVED9};typedef struct _dt_bootcode {  U8	type;				/* Disktype enum for this bootcode */  char*	loader;				/* string containing the loader name i.e. "LILO" */  U8	loader_version;		/* loader version if any, 0 else  */  U8	loader_subversion;	/* loader subversion if any, 0 else */  char*	loader_version_string;	/* text string containing additional information on loader */  U8	loader_bootdrive;	/* bootdrive set in loader (supported only for grub) */  void* data;				/* ?? (unused) */} DT_BootCode;typedef struct _dt_fs {  U16	type;				/* Disktype enum for this fs */  U8	type_version;		/* Version of this fs, 0 if fs has no version */  U8	type_subversion;	/* Subversion if any, 0 else */  char*	type_version_name;	/* A string containing the fs description */  char* type_name;			/* linux fs name compatible to /proc/filesystems */  char*	volume_name;		/* Volume label */  U64	volume_size;		/* size in bytes */  U64	volume_blocks;  U32	volume_blocksize;  uuid_t	uuid;} DT_Filesystem;typedef struct _dt_partmap_entry {  U8	type;				/* Disktype enum for this partition map */  U8	num;				/* Partition number */  U8	part_type;			/* Partition type (0x83 for linux) */  char*	part_type_name;		/* string containing part type */  U8	bootable;			/* 1 if partition has the boot flag */  U64	start;				/* sector where partition starts */  U64	size;				/* partition size */} DT_PartitionMap;typedef struct _dt_other {  U8	type;  DT_BootCode*	bootcode;  DT_PartitionMap*	partmap;  DT_Filesystem*	fs;  struct _dt_other*	other;} DT_Other;typedef struct _dt_info {	U8	type;	DT_BootCode	bootcode;	DT_PartitionMap	partmap;	DT_Filesystem	fs;	DT_Other	other;	struct _dt_info*	next;} DT_Info;typedef struct source {	U8 type;	U64 size;	int size_known;	void *cache_head;	int sequential;	U64 seq_pos;	int blocksize;	struct source *foundation;	int fd;				/* file descriptor */	int source_open;	/* 1 if file descriptor is valid (means source is open) */	int (*analyze)(struct source* s, DT_Info* info);	int (*open)(struct source* s, char* filename);	U64 (*read_bytes)(struct source* s, U64 pos, U64 len, void* buf);	int (*read_block)(struct source* s, U64 pos, void* buf);	void (*close)(struct source* s);} SOURCE;typedef struct section {	U64	pos,	size;	int	flags;	int detectorflags;	SOURCE	*source;} SECTION;/*	function for the user: returns 0 if detection was succesful 	info has to point to a valid DT_Info struct. filename is analyzed	with the given or'd flags(DT_BOOTCODE, DT_PARTMAP, DT_FS, DT_OTHER).	flags tells us what we should test for */ DT_Info* DT_detect(char* filename, int flags);/*	first of all we need to analyze the hardware (file, char device, block device etc.)	returns a SOURCE struct we can work with */SOURCE* dt_analyze_source(char* filename);/*	Use the SOURCE to detect for filesystems etc */DT_Info* dt_detect_source(SOURCE* s, char* filename, int flags);DT_Info* dt_detect(SECTION* s);void stop_detect(void);DT_Info* new_DT_Info();void remove_DT_Info(DT_Info* info);DT_Info* remove_single_DT_Info(DT_Info* info);/* cdaccess.c */int analyze_cdaccess(int fd, SOURCE* s, int level);/* lib.c */void dt_getfilesize(int f, SOURCE* s);/* buffer functions */U64 get_buffer(SECTION *section, U64 pos, U64 len, void **buf);U64 get_buffer_real(SOURCE *s, U64 pos, U64 len, void *inbuf, void **outbuf);void close_source(SOURCE *s);/* output functions */void print_line(int level, const char *fmt, ...);void start_line(const char *fmt, ...);void continue_line(const char *fmt, ...);void finish_line(int level);/* formatting functions */void format_blocky_size(char *buf, U64 count, U32 blocksize,                        const char *blockname, const char *append);void format_size(char *buf, U64 size);void format_size_verbose(char *buf, U64 size);/* OLD: void format_size(char *buf, U64 size, U32 mult); */void format_ascii(void *from, char *to);void format_unicode(void *from, char *to);void format_uuid(void *from, char *to, char* type, int version);/* endian-aware data access */U16 get_be_short(void *from);U32 get_be_long(void *from);U64 get_be_quad(void *from);U16 get_le_short(void *from);U32 get_le_long(void *from);U64 get_le_quad(void *from);U16 get_ve_short(int endianness, void *from);U32 get_ve_long(int endianness, void *from);U64 get_ve_quad(int endianness, void *from);const char * get_ve_name(int endianness);/* more data access */void get_string(void *from, int len, char *to);void get_pstring(void *from, char *to);void get_padded_string(void *from, int len, char pad, char *to);int find_memory(void *haystack, int haystack_len,		void *needle, int needle_len);/* error functions */#ifdef DEBUG#define DBG(msg, arg...)	debugmessage(__FUNCTION__, __LINE__, msg, ## arg)void debugmessage(char* function, int line, const char* msg, ...);#else#define DBG(msg, arg...)	#endifvoid error(const char *msg, ...);void errore(const char *msg, ...);void bailout(const char *msg, ...);void bailoute(const char *msg, ...);#endif /* _DISKTYPE_H */

⌨️ 快捷键说明

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