1 /* -------------------------------------------------------------------------- *
3 * Copyright 2011 Shao Miller - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ------------------------------------------------------------------------- */
17 * Fetch NTFS file cluster & sector information via Windows
19 * With special thanks to Mark Roddy for his article:
20 * http://www.wd-3.com/archive/luserland.htm
25 #define M_NTFSSECT_API
29 /* An "extent;" a contiguous range of file data */
30 typedef struct S_NTFSSECT_EXTENT_ S_NTFSSECT_EXTENT;
32 /* Volume info relevant to file cluster & sector info */
33 typedef struct S_NTFSSECT_VOLINFO_ S_NTFSSECT_VOLINFO;
35 /* Stores function pointers to some Windows functions */
36 typedef struct S_NTFSSECT_XPFUNCS_ S_NTFSSECT_XPFUNCS;
38 /*** Function types */
40 /* The function type for Kernel32.dll's GetDiskFreeSpace() */
41 typedef BOOL WINAPI F_KERNEL32_GETDISKFREESPACE(
49 /* The function type for Kernel32.dll's GetVolumePathName() */
50 typedef BOOL WINAPI F_KERNEL32_GETVOLUMEPATHNAME(LPCTSTR, LPCTSTR, DWORD);
52 /*** Function declarations */
55 * Fetch the extent containing a particular VCN
62 DWORD M_NTFSSECT_API NtfsSectGetFileVcnExtent(
65 S_NTFSSECT_EXTENT * Extent
69 * Populate a volume info object
75 DWORD M_NTFSSECT_API NtfsSectGetVolumeInfo(
77 S_NTFSSECT_VOLINFO * VolumeInfo
81 * Populate a volume info object
87 DWORD M_NTFSSECT_API NtfsSectGetVolumeInfoFromFileName(
89 S_NTFSSECT_VOLINFO * VolumeInfo
93 * Convert a volume LCN to an absolute disk LBA
100 DWORD M_NTFSSECT_API NtfsSectLcnToLba(
101 const S_NTFSSECT_VOLINFO * VolumeInfo,
102 const LARGE_INTEGER * Lcn,
107 * Load some helper XP functions
112 DWORD M_NTFSSECT_API NtfsSectLoadXpFuncs(S_NTFSSECT_XPFUNCS * XpFuncs);
115 * Unload some helper XP functions
120 VOID M_NTFSSECT_API NtfsSectUnloadXpFuncs(S_NTFSSECT_XPFUNCS * XpFuncs);
122 /*** Object declarations */
125 * The last error message set by one of our functions.
126 * Obviously not per-thread
128 extern CHAR * NtfsSectLastErrorMessage;
130 /*** Struct/union definitions */
131 struct S_NTFSSECT_EXTENT_ {
132 LARGE_INTEGER FirstVcn;
133 LARGE_INTEGER NextVcn;
134 LARGE_INTEGER FirstLcn;
137 struct S_NTFSSECT_VOLINFO_ {
140 DWORD BytesPerSector;
141 DWORD SectorsPerCluster;
142 LARGE_INTEGER PartitionLba;
145 struct S_NTFSSECT_XPFUNCS_ {
148 F_KERNEL32_GETVOLUMEPATHNAME * GetVolumePathName;
149 F_KERNEL32_GETDISKFREESPACE * GetDiskFreeSpace;
152 #endif /* M_NTFSSECT_H_ */