1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/* -------------------------------------------------------------------------- *
*
* Copyright 2011 Shao Miller - All Rights Reserved
*
* 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, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ------------------------------------------------------------------------- */
#ifndef M_NTFSSECT_H_
/****
* ntfssect.h
*
* Fetch NTFS file cluster & sector information via Windows
*
* With special thanks to Mark Roddy for his article:
* http://www.wd-3.com/archive/luserland.htm
*/
/*** Macros */
#define M_NTFSSECT_H_
#define M_NTFSSECT_API
/*** Object types */
/* An "extent;" a contiguous range of file data */
typedef struct S_NTFSSECT_EXTENT_ S_NTFSSECT_EXTENT;
/* Volume info relevant to file cluster & sector info */
typedef struct S_NTFSSECT_VOLINFO_ S_NTFSSECT_VOLINFO;
/* Stores function pointers to some Windows functions */
typedef struct S_NTFSSECT_XPFUNCS_ S_NTFSSECT_XPFUNCS;
/*** Function types */
/* The function type for Kernel32.dll's GetDiskFreeSpace() */
typedef BOOL WINAPI F_KERNEL32_GETDISKFREESPACE(
LPCTSTR,
LPDWORD,
LPDWORD,
LPDWORD,
LPDWORD
);
/* The function type for Kernel32.dll's GetVolumePathName() */
typedef BOOL WINAPI F_KERNEL32_GETVOLUMEPATHNAME(LPCTSTR, LPCTSTR, DWORD);
/*** Function declarations */
/**
* Fetch the extent containing a particular VCN
*
* @v File
* @v Vcn
* @v Extent
* @ret DWORD
*/
DWORD M_NTFSSECT_API NtfsSectGetFileVcnExtent(
HANDLE File,
LARGE_INTEGER * Vcn,
S_NTFSSECT_EXTENT * Extent
);
/**
* Populate a volume info object
*
* @v VolumeName
* @v VolumeInfo
* @ret DWORD
*/
DWORD M_NTFSSECT_API NtfsSectGetVolumeInfo(
CHAR * VolumeName,
S_NTFSSECT_VOLINFO * VolumeInfo
);
/**
* Populate a volume info object
*
* @v FileName
* @v VolumeInfo
* @ret DWORD
*/
DWORD M_NTFSSECT_API NtfsSectGetVolumeInfoFromFileName(
CHAR * FileName,
S_NTFSSECT_VOLINFO * VolumeInfo
);
/**
* Convert a volume LCN to an absolute disk LBA
*
* @v VolumeInfo
* @v Lcn
* @v Lba
* @ret DWORD
*/
DWORD M_NTFSSECT_API NtfsSectLcnToLba(
const S_NTFSSECT_VOLINFO * VolumeInfo,
const LARGE_INTEGER * Lcn,
LARGE_INTEGER * Lba
);
/**
* Load some helper XP functions
*
* @v XpFuncs
* @ret DWORD
*/
DWORD M_NTFSSECT_API NtfsSectLoadXpFuncs(S_NTFSSECT_XPFUNCS * XpFuncs);
/**
* Unload some helper XP functions
*
* @v XpFuncs
* @ret DWORD
*/
VOID M_NTFSSECT_API NtfsSectUnloadXpFuncs(S_NTFSSECT_XPFUNCS * XpFuncs);
/*** Object declarations */
/**
* The last error message set by one of our functions.
* Obviously not per-thread
*/
extern CHAR * NtfsSectLastErrorMessage;
/*** Struct/union definitions */
struct S_NTFSSECT_EXTENT_ {
LARGE_INTEGER FirstVcn;
LARGE_INTEGER NextVcn;
LARGE_INTEGER FirstLcn;
};
struct S_NTFSSECT_VOLINFO_ {
DWORD Size;
HANDLE Handle;
DWORD BytesPerSector;
DWORD SectorsPerCluster;
LARGE_INTEGER PartitionLba;
};
struct S_NTFSSECT_XPFUNCS_ {
DWORD Size;
HMODULE Kernel32;
F_KERNEL32_GETVOLUMEPATHNAME * GetVolumePathName;
F_KERNEL32_GETDISKFREESPACE * GetDiskFreeSpace;
};
#endif /* M_NTFSSECT_H_ */
|