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