📄 ntfs.h
字号:
/* * ntfs.h * * Copyright (C) 1995 Martin von L鰓is * Copyright (C) 1996 Regis Duchesne */#ifndef _NTFS_H#define _NTFS_H#include "ntfstypes.h"/* This is really unsigned long long. So we support only volumes up to 2 TB */typedef unsigned int ntfs_cluster_t;struct ntfs_inode;#ifdef __FreeBSD__#include <sys/queue.h>LIST_HEAD(ntfs_head,ntfs_inode);#endif/* which files should be returned from a director listing */enum ntfs_getdent_type{ ngt_dos, /* only short names, no hidden files */ ngt_nt, /* only long names, all-uppercase becomes all-lowercase, no hidden files */ ngt_posix, /* all names except hidden files */ ngt_full, /* all entries */};/* which character set is used for file names */enum ntfs_charset_type{ nct_utf8, nct_iso8859_1};typedef struct _ntfs_volume{ /* data read from the boot file */ int blocksize; int clusterfactor; int clustersize; int mft_recordsize; int mft_clusters_per_record; int index_recordsize; int index_clusters_per_record; int mft_cluster; /* data read from special files */ unsigned short *upcase; unsigned int upcase_length; unsigned char *mft; /* configuration provided by user */ ntfs_uid_t uid; ntfs_gid_t gid; ntmode_t umask; enum ntfs_charset_type nct; enum ntfs_getdent_type ngt; int partition_bias; /* for access to underlying device */ /* inodes we always hold onto */ struct ntfs_inode *mft_ino; union{ int fd; /* file descriptor for the tools */ void *sb; /* pointer to super block for the kernel */ }u;#ifdef __FreeBSD__ dev_t rdev; struct vnode *devvp; struct ntfs_head *inode_hash; /* not really a hash */#endif}ntfs_volume;#define NTFS_FD(vol) ((vol)->u.fd)/* Linux */#define NTFS_SB(vol) ((struct super_block*)(vol)->u.sb)#define NTFS_SB2VOL(sb) ((ntfs_volume*)(sb)->u.generic_sbp)#define NTFS_INO2VOL(ino) ((ntfs_volume*)((ino)->i_sb->u.generic_sbp))/* BSD */#define NTFS_MNT(vol) ((struct mount*)(vol)->u.sb)#define NTFS_MNT2VOL(sb) ((ntfs_volume*)(sb)->mnt_data)#define NTFS_V2INO(ino) ((ntfs_inode*)((ino)->v_data))typedef struct { ntfs_cluster_t cluster; ntfs_cluster_t len;}ntfs_runlist;typedef struct { int type; ntfs_u16 *name; int namelen; unsigned char header[0x40]; /* XXX */ union{ void *data; /* if resident */ struct { ntfs_runlist *runlist; int len; }r; }d;}ntfs_attribute;typedef struct ntfs_inode{ ntfs_volume *vol; int i_number; unsigned char* attr; /* array of the attributes */ int attr_count; /* size of attrs[] */ ntfs_attribute *attrs; int record_count; /* size of records[] */ /* array of the record numbers of the MFT whose attributes have been inserted in the inode */ int *records; union{ struct{ int recordsize; int clusters_per_record; }index; } u; #ifdef __FreeBSD__ struct vnode *vp; LIST_ENTRY(ntfs_inode) h_next;#endif}ntfs_inode;typedef struct { int recno; unsigned char* record;} ntfs_mft_record;typedef struct { int size; int count; ntfs_mft_record* records;} ntfs_disk_inode;typedef struct { ntfs_volume *vol; ntfs_inode *ino; int type; char *name; int mftno; int start_vcn;} ntfs_attrlist_item;/* Structure to define IO to user buffer. do_read means that the destination has to be written using fn_put, do_write means that the destination has to read using fn_get. So, do_read is from a user's point of view, while put and get are from the driver's point of view. The first argument is always the destination of the IO*/typedef struct ntfs_io{ int do_read; void (*fn_put)(struct ntfs_io* dest,void* buf,ntfs_size_t); void (*fn_get)(void* buf,struct ntfs_io* src,ntfs_size_t len); void *param;}ntfs_io;void ntfs_put(ntfs_io*,void*,ntfs_size_t);void ntfs_get(void*,ntfs_io*,ntfs_size_t);enum ntfs_iterate_e{BY_POSITION,BY_NAME,DIR_INSERT};/* not all fields are used for all operations */typedef struct ntfs_iterate_s{ enum ntfs_iterate_e type; ntfs_inode *dir; long long pos; char *result; ntfs_u16* name; int namelen; ntfs_inode* new;}ntfs_iterate_s;#define AT_STANDARD_INFORMATION 0x10#define AT_ATTRIBUTE_LIST 0x20#define AT_FILE_NAME 0x30#define AT_VOLUME_VERSION 0x40#define AT_SECURITY_DESCRIPTOR 0x50#define AT_VOLUME_NAME 0x60#define AT_VOLUME_INFORMATION 0x70#define AT_DATA 0x80#define AT_INDEX_ROOT 0x90#define AT_INDEX_ALLOCATION 0xA0#define AT_BITMAP 0xB0#define AT_SYMBOLIC_LINK 0xC0#define AT_EA_INFORMATION 0xD0#define AT_EA 0xE0/* The first 11 inodes correspond to special files */#define FILE_MFT 0#define FILE_MFTMIRR 1#define FILE_LOGFILE 2#define FILE_VOLUME 3#define FILE_ATTRDEF 4#define FILE_ROOT 5#define FILE_BITMAP 6#define FILE_BOOT 7#define FILE_BADCLUS 8#define FILE_QUOTA 9#define FILE_UPCASE 10extern ntfs_volume *the_vol;void print_time(ntfs_time64_t);/* Volume management */void ntfs_init_volume(ntfs_volume *vol,char *boot);int ntfs_load_special_files(ntfs_volume*);void ntfs_init_upcase(ntfs_inode *upcase);int ntfs_open_volume(char*, int, int, int);int ntfs_allocate_clusters(ntfs_volume* vol,int *start,int *count);int ntfs_deallocate_clusters(ntfs_volume* vol,int start,int count);/* MFT records */int ntfs_read_mft_record(ntfs_volume *vol,int mftno,char *buf);int ntfs_init_inode(ntfs_inode *ino,ntfs_volume* vol,int inum);void ntfs_clear_inode(ntfs_inode *ino);void ntfs_load_attributes(ntfs_inode* ino);int update_inode(ntfs_inode *ino);void ntfs_insert_fixups(unsigned char* record,int secsize);int ntfs_alloc_inode (ntfs_inode*,ntfs_inode*,char *,int);/* Attribute list */int ntfs_find_in_attr_list(ntfs_attrlist_item *,int );int ntfs_get_attr_size(ntfs_inode *ino,int attr,char*name);int ntfs_attr_is_resident(ntfs_inode *ino,int attr,char*name);ntfs_attribute* ntfs_find_attr(ntfs_inode *ino,int type,char *name);int ntfs_insert_attribute(ntfs_inode* ino,unsigned char* attr);int ntfs_create_attr(ntfs_inode *ino,int anum,char* aname,void *data,int dsize);int ntfs_allocate_attr_number(ntfs_inode *ino, int *result);/* attribute data */char *ntfs_get_attr(ntfs_inode *inode,int attr,char *name);int ntfs_read_attr(ntfs_inode *ino,int attr, char *name,int offset,ntfs_io *buf,int length);int ntfs_modify_attr(ntfs_inode *ino,int attr, char *name,int offset,ntfs_io *buf,int length);int ntfs_write_attr(ntfs_inode *ino,int attr, char *name,int offset,ntfs_io *buf,int l);int ntfs_readwrite_attr(ntfs_inode *ino,int attr, char *name,int offset,ntfs_io *dest,int length);int ntfs_resize_attr(ntfs_inode* ino,ntfs_attribute* attr,int newsize);/* block access */int decompress_run(unsigned char** data,int* length,int *cluster,int *ctype);int ntfs_vcn_to_lcn(ntfs_inode*,int);int ntfs_getput_clusters(ntfs_volume *vol,int start_cluster, ntfs_size_t start_offs, ntfs_size_t length,ntfs_io *dest);/* directory access */int ntfs_get_name(char*,char*);int ntfs_find_file(ntfs_inode* ino,char *name);int ntfs_getdir_byposition(ntfs_iterate_s*);int ntfs_getdir_byname(ntfs_iterate_s*);int ntfs_getdir_iterate(ntfs_iterate_s* walk,char* entry);int ntfs_getdir_unsorted(ntfs_inode *ino,ntfs_u32 *p_high,ntfs_u32* p_low, int(*cb)(ntfs_u8*,void*),void *param);int grep(int position,int length, unsigned char *string,int stringlen,int ignore_case);void dump(int position,int start,int length);void dump_inode(ntfs_inode *ino);void dump_decompress(ntfs_inode *ino,int run,int verbose);void dump_mem(unsigned char *buf,int start,int length);void dumpdir(ntfs_inode*);void dumpdir_record(ntfs_inode* ino,int nextblock);void list_attr_mem(char*);void list_attributes(int offset);ntfs_time64_t ntfs_now(void);ntfs_time_t ntfs_ntutc2unixutc(ntfs_time64_t);ntfs_time64_t ntfs_unixutc2ntutc(ntfs_time_t);void ntfs_uni2ascii(char*,char*,int);void ntfs_ascii2uni(short int*,char*,int);int ntfs_fixup_record(ntfs_volume*,char *record,char*magic,int size);int ntfs_check_index_record(ntfs_inode*,char *record);int ntfs_check_mft_record(ntfs_volume*,char *record);int ntfs_get_volumesize(ntfs_volume *);int ntfs_get_free_cluster_count(ntfs_inode *bitmap);int ntfs_get_free_inode_count(ntfs_volume *,char*mft);void* ntfs_memcpy(void*a,const void*b,ntfs_size_t);void ntfs_decompress(unsigned char*dst, unsigned char*src,ntfs_size_t len);/* Support */void ntfs_error(const char*, ...);void ntfs_debug(const char*,...);void *ntfs_malloc(int size);void ntfs_free(void*);int ntfs_uni_strncmp(short int* a,short int *b,int n);void uniprint(char *first,int length);void uniprint_lower(char *first,int length);int ntfs_strlen(char *s);int ntfs_ua_strncmp(short int* a,char* b,int n);void ntfs_bzero(void*,ntfs_size_t);int ntfs_encodeuni(ntfs_volume*,ntfs_u16*,int,char**,int*);int ntfs_decodeuni(ntfs_volume*,char*,int,ntfs_u16**,int*);/* Classical min and max macros still missing in standard headers... */#define min(a,b) ((a) <= (b) ? (a) : (b))#define max(a,b) ((a) >= (b) ? (a) : (b))#define RESIDENT(attr) (*((char*)(attr)+8)=='\0')#define COMPRESSED(attr) (*((char*)(attr)+0xC)!='\0')#define DATASIZE(attr) \ (RESIDENT(attr)?*(short*)((char*)(attr)+0x10):*(int*)((char*)(attr)+0x30))#define IS_MAGIC(a,b) (*(int*)(a)==*(int*)(b))#define IS_MFT_RECORD(a) IS_MAGIC((a),"FILE")#define IS_NTFS_VOLUME(a) IS_MAGIC((a)+3,"NTFS")#define IS_INDEX_RECORD(a) IS_MAGIC((a),"INDX")/* 'NTFS' in little endian */#define NTFS_SUPER_MAGIC 0x5346544E#endif/* * Local variables: * c-file-style: "linux" * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -