ReactOS 0.4.16-dev-205-g7b2bb7e
ntfsinfo.c File Reference
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
Include dependency graph for ntfsinfo.c:

Go to the source code of this file.

Classes

struct  NTFS_RECORD_HEADER
 
struct  _FILE_RECORD_HEADER
 
struct  NTFS_ATTR_RECORD
 

Macros

#define NRH_FILE_TYPE   0x454C4946
 
#define ATTRIBUTE_TYPE_DATA   0x80
 
#define ATTRIBUTE_TYPE_END   0xFFFFFFFF
 

Typedefs

typedef struct NTFS_RECORD_HEADERPNTFS_RECORD_HEADER
 
typedef struct _FILE_RECORD_HEADER FILE_RECORD_HEADER
 
typedef struct _FILE_RECORD_HEADERPFILE_RECORD_HEADER
 
typedef struct NTFS_ATTR_RECORDPNTFS_ATTR_RECORD
 

Functions

int __cdecl _tmain (int argc, const TCHAR *argv[])
 

Variables

static TCHARMetaDataFiles []
 

Macro Definition Documentation

◆ ATTRIBUTE_TYPE_DATA

#define ATTRIBUTE_TYPE_DATA   0x80

Definition at line 22 of file ntfsinfo.c.

◆ ATTRIBUTE_TYPE_END

#define ATTRIBUTE_TYPE_END   0xFFFFFFFF

Definition at line 23 of file ntfsinfo.c.

◆ NRH_FILE_TYPE

#define NRH_FILE_TYPE   0x454C4946

Definition at line 21 of file ntfsinfo.c.

Typedef Documentation

◆ FILE_RECORD_HEADER

◆ PFILE_RECORD_HEADER

◆ PNTFS_ATTR_RECORD

◆ PNTFS_RECORD_HEADER

Function Documentation

◆ _tmain()

int __cdecl _tmain ( int  argc,
const TCHAR argv[] 
)

Definition at line 89 of file ntfsinfo.c.

90{
91 TCHAR VolumeName[] = _T("\\\\.\\C:");
95 ULONGLONG VolumeSize;
96 ULONGLONG MftClusters;
97 UINT File = 0;
99
100 if (argc > 1)
101 {
102 TCHAR Letter = argv[1][0];
103
104 if ((Letter >= 'A' && Letter <= 'Z') ||
105 (Letter >= 'a' && Letter <= 'z'))
106 {
107 VolumeName[4] = Letter;
108 }
109 }
110
113 {
114 _ftprintf(stderr, _T("Failed opening the volume '%s' (%lx)\n"), VolumeName, GetLastError());
115 return 1;
116 }
117
119 {
120 _ftprintf(stderr, _T("Failed requesting volume '%s' data (%lx)\n"), VolumeName, GetLastError());
122 return 1;
123 }
124
125 if (LengthReturned < sizeof(VolumeInfo))
126 {
127 _ftprintf(stderr, _T("Failed reading volume '%s' data (%lx)\n"), VolumeName, GetLastError());
129 return 1;
130 }
131
132 _tprintf(_T("Volume Size\n-----------\n"));
133 VolumeSize = VolumeInfo.TotalClusters.QuadPart * VolumeInfo.BytesPerCluster;
134 _tprintf(_T("Volume size\t\t: %I64u MB\n"), VolumeSize >> 20);
135 _tprintf(_T("Total sectors\t\t: %I64u\n"), VolumeInfo.NumberSectors.QuadPart);
136 _tprintf(_T("Total clusters\t\t: %I64u\n"), VolumeInfo.TotalClusters.QuadPart);
137 _tprintf(_T("Free clusters\t\t: %I64u\n"), VolumeInfo.FreeClusters.QuadPart);
138 _tprintf(_T("Free space\t\t: %I64u MB (%I64u%% of drive)\n"), (VolumeInfo.FreeClusters.QuadPart * VolumeInfo.BytesPerCluster) >> 20, (VolumeInfo.FreeClusters.QuadPart * 100) / VolumeInfo.TotalClusters.QuadPart);
139
140 _tprintf(_T("\nAllocation Size\n---------------\n"));
141 _tprintf(_T("Bytes per sector\t: %lu\n"), VolumeInfo.BytesPerSector);
142 _tprintf(_T("Bytes per cluster\t: %lu\n"), VolumeInfo.BytesPerCluster);
143 _tprintf(_T("Bytes per MFT record:\t: %lu\n"), VolumeInfo.BytesPerFileRecordSegment);
144 _tprintf(_T("Clusters per MFT record\t: %lu\n"), VolumeInfo.ClustersPerFileRecordSegment);
145
146 _tprintf(_T("\nMFT Information\n---------------\n"));
147 _tprintf(_T("MFT size\t\t: %I64u MB (%I64u%% of drive)\n"), VolumeInfo.MftValidDataLength.QuadPart >> 20, (VolumeInfo.MftValidDataLength.QuadPart * 100) / VolumeSize);
148 _tprintf(_T("MFT start cluster\t: %I64u\n"), VolumeInfo.MftStartLcn.QuadPart);
149 _tprintf(_T("MFT zone clusters\t: %I64u - %I64u\n"), VolumeInfo.MftZoneStart.QuadPart, VolumeInfo.MftZoneEnd.QuadPart);
150 MftClusters = VolumeInfo.MftZoneEnd.QuadPart - VolumeInfo.MftZoneStart.QuadPart;
151 _tprintf(_T("MFT zone size\t\t: %I64u MB (%I64u%% of drive)\n"), (MftClusters * VolumeInfo.BytesPerCluster) >> 20, (MftClusters * 100) / VolumeInfo.TotalClusters.QuadPart);
152 _tprintf(_T("MFT mirror start\t: %I64u\n"), VolumeInfo.Mft2StartLcn.QuadPart);
153
154 _tprintf(_T("\nMeta-Data files\n---------------\n"));
155 OutputBuffer = HeapAlloc(GetProcessHeap(), 0, VolumeInfo.BytesPerFileRecordSegment + sizeof(NTFS_FILE_RECORD_OUTPUT_BUFFER));
156 while (MetaDataFiles[File] != NULL)
157 {
159 PFILE_RECORD_HEADER FileRecord;
160 PNTFS_ATTR_RECORD Attribute;
161 ULONGLONG Size = 0;
162
163 if (File == 5)
164 {
165 ++File;
166 continue;
167 }
168
169 InputBuffer.FileReferenceNumber.QuadPart = File;
171 OutputBuffer, VolumeInfo.BytesPerFileRecordSegment + sizeof(NTFS_FILE_RECORD_OUTPUT_BUFFER),
173 {
174 ++File;
175 continue;
176 }
177
178 if (OutputBuffer->FileReferenceNumber.QuadPart != File)
179 {
180 ++File;
181 continue;
182 }
183
184 FileRecord = (PFILE_RECORD_HEADER)OutputBuffer->FileRecordBuffer;
185 if (FileRecord->Ntfs.Type != NRH_FILE_TYPE)
186 {
187 ++File;
188 continue;
189 }
190
191 Attribute = (PNTFS_ATTR_RECORD)((ULONG_PTR)FileRecord + FileRecord->AttributeOffset);
192 while (Attribute < (PNTFS_ATTR_RECORD)((ULONG_PTR)FileRecord + FileRecord->BytesInUse) &&
193 Attribute->Type != ATTRIBUTE_TYPE_END)
194 {
195 if (Attribute->Type == ATTRIBUTE_TYPE_DATA)
196 {
197 Size = (Attribute->IsNonResident) ? Attribute->NonResident.AllocatedSize : Attribute->Resident.ValueLength;
198 break;
199 }
200
201 Attribute = (PNTFS_ATTR_RECORD)((ULONG_PTR)Attribute + Attribute->Length);
202 }
203
204 _tprintf(_T("%s%I64u bytes\n"), MetaDataFiles[File], Size);
205
206 ++File;
207 }
208
211 return 0;
212}
WCHAR Letter
static int argc
Definition: ServiceArgs.c:12
Definition: File.h:16
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define GENERIC_READ
Definition: compat.h:135
#define HeapFree(x, y, z)
Definition: compat.h:735
#define FILE_SHARE_READ
Definition: compat.h:136
#define ULONG_PTR
Definition: config.h:101
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING VolumeName
Definition: fltkernel.h:1117
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FILE_INFORMATION_CLASS _Out_opt_ PULONG LengthReturned
Definition: fltkernel.h:1308
_Must_inspect_result_ _Out_ PHANDLE VolumeHandle
Definition: fltkernel.h:2283
#define stderr
Definition: stdio.h:100
#define _ftprintf
Definition: tchar.h:518
#define _tprintf
Definition: tchar.h:506
if(dx< 0)
Definition: linetemp.h:194
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
struct NTFS_ATTR_RECORD * PNTFS_ATTR_RECORD
#define NRH_FILE_TYPE
Definition: ntfsinfo.c:21
static TCHAR * MetaDataFiles[]
Definition: ntfsinfo.c:71
struct _FILE_RECORD_HEADER * PFILE_RECORD_HEADER
#define ATTRIBUTE_TYPE_DATA
Definition: ntfsinfo.c:22
#define ATTRIBUTE_TYPE_END
Definition: ntfsinfo.c:23
#define FSCTL_GET_NTFS_VOLUME_DATA
Definition: ntifs_ex.h:261
#define FSCTL_GET_NTFS_FILE_RECORD
Definition: ntifs_ex.h:262
struct NTFS_ATTR_RECORD::@169::@171 Resident
ULONG Length
Definition: ntfs.h:127
UCHAR IsNonResident
Definition: ntfs.h:128
ULONG Type
Definition: ntfs.h:126
struct NTFS_ATTR_RECORD::@169::@172 NonResident
NTFS_RECORD_HEADER Ntfs
Definition: ntfs.h:252
USHORT AttributeOffset
Definition: ntfs.h:255
ULONG BytesInUse
Definition: ntfs.h:257
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint64_t ULONGLONG
Definition: typedefs.h:67
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateFile
Definition: winbase.h:3773
char TCHAR
Definition: xmlstorage.h:189

Variable Documentation

◆ MetaDataFiles

TCHAR* MetaDataFiles[]
static
Initial value:
= {
_T("$MFT\t\t"),
_T("$MFTMirr\t"),
_T("$LogFile\t"),
_T("$Volume\t\t"),
_T("$AttrDef\t"),
_T("."),
_T("$Bitmap\t\t"),
_T("$Boot\t\t"),
_T("$BadClus\t"),
_T("$Quota\t\t"),
_T("$UpCase\t\t"),
_T("$Extended\t"),
}

Definition at line 71 of file ntfsinfo.c.

Referenced by _tmain().