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 * ------------------------------------------------------------------------- */
16 * (C) Shao Miller, 2011
18 * Tests ntfssect.c functions
20 * With special thanks to Mark Roddy for his article:
21 * http://www.wd-3.com/archive/luserland.htm
33 /*** Function declarations */
34 static void show_usage(void);
35 static void show_last_err(void);
36 static void show_err(DWORD
);
38 /*** Struct/union definitions */
40 /*** Function definitions */
42 /** Program entry-point */
43 int main(int argc
, char ** argv
) {
46 S_NTFSSECT_VOLINFO vol_info
;
48 LARGE_INTEGER vcn
, lba
;
49 S_NTFSSECT_EXTENT extent
;
60 err
= NtfsSectGetVolumeInfoFromFileName(argv
[1], &vol_info
);
61 if (err
!= ERROR_SUCCESS
) {
66 "Volume has %d bytes per sector, %d sectors per cluster\n",
67 vol_info
.BytesPerSector
,
68 vol_info
.SectorsPerCluster
71 /* Open the file for reading */
81 if (file
== INVALID_HANDLE_VALUE
) {
90 NtfsSectGetFileVcnExtent(file
, &vcn
, &extent
) == ERROR_SUCCESS
;
93 len
= extent
.NextVcn
.QuadPart
- extent
.FirstVcn
.QuadPart
;
94 printf("Extent @ VCN #%lld,", extent
.FirstVcn
.QuadPart
);
95 printf(" %lld clusters long:\n", len
);
96 printf(" VCN #%lld -", extent
.FirstVcn
.QuadPart
);
97 printf(" #%lld\n", extent
.FirstVcn
.QuadPart
+ len
- 1);
98 printf(" LCN #%lld -", extent
.FirstLcn
.QuadPart
);
99 printf(" #%lld\n", extent
.FirstLcn
.QuadPart
+ len
- 1);
100 err
= NtfsSectLcnToLba(
105 if (err
== ERROR_SUCCESS
) {
106 printf(" LBA #%lld -", lba
.QuadPart
);
109 lba
.QuadPart
+ len
* vol_info
.SectorsPerCluster
120 CloseHandle(vol_info
.Handle
);
129 static void show_usage(void) {
130 static const char usage_text
[] = "\
131 File sector info . . . . . . . . . . . . . . . . . . . . Shao Miller, 2011\n\
133 Usage: NTFSTEST.EXE <filename>\n\
135 Attempts to dump cluster and sector info for <filename>.\n";
141 static void show_last_err(void) {
142 show_err(GetLastError());
146 /** Display an error */
147 static void show_err(DWORD err_code
) {
151 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
154 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
159 fprintf(stderr
, "Error: %s\n", buf
);