3 * Copyright (C) 2002,2003 ReactOS Team
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; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: attrib.c,v 1.9 2004/01/28 20:53:06 ekohl Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: drivers/fs/ntfs/attrib.c
24 * PURPOSE: NTFS filesystem driver
25 * PROGRAMMER: Eric Kohl
26 * Updated by Valentin Verkhovsky 2003/09/12
29 /* INCLUDES *****************************************************************/
31 #include <ddk/ntddk.h>
40 /* FUNCTIONS ****************************************************************/
47 return(*run
& 0x0f) + ((*run
>> 4) & 0x0f) + 1;
54 UCHAR n1
= *run
& 0x0f;
55 UCHAR n2
= (*run
>> 4) & 0x0f;
56 LONGLONG lcn
= (n2
== 0) ? 0 : (CHAR
)(run
[n1
+ n2
]);
59 for (i
= n1
+n2
- 1; i
> n1
; i
--)
60 lcn
= (lcn
<< 8) + run
[i
];
73 for (i
= n
; i
> 0; i
--)
74 count
= (count
<< 8) + run
[i
];
80 FindRun (PNONRESIDENT_ATTRIBUTE NresAttr
,
87 ULONGLONG base
= NresAttr
->StartVcn
;
89 if (vcn
< NresAttr
->StartVcn
|| vcn
> NresAttr
->LastVcn
)
94 for (run
= (PUCHAR
)((ULONG
)NresAttr
+ NresAttr
->RunArrayOffset
);
95 *run
!= 0; run
+= RunLength(run
))
98 *count
= RunCount(run
);
100 if (base
<= vcn
&& vcn
< base
+ *count
)
102 *lcn
= (RunLCN(run
) == 0) ? 0 : *lcn
+ vcn
- base
;
103 *count
-= (ULONG
)(vcn
- base
);
118 NtfsDumpFileNameAttribute(PATTRIBUTE Attribute
)
120 PRESIDENT_ATTRIBUTE ResAttr
;
121 PFILENAME_ATTRIBUTE FileNameAttr
;
123 DbgPrint(" $FILE_NAME ");
125 ResAttr
= (PRESIDENT_ATTRIBUTE
)Attribute
;
126 // DbgPrint(" Length %lu Offset %hu ", ResAttr->ValueLength, ResAttr->ValueOffset);
128 FileNameAttr
= (PFILENAME_ATTRIBUTE
)((PVOID
)ResAttr
+ ResAttr
->ValueOffset
);
129 DbgPrint(" '%.*S' ", FileNameAttr
->NameLength
, FileNameAttr
->Name
);
134 NtfsDumpVolumeNameAttribute(PATTRIBUTE Attribute
)
136 PRESIDENT_ATTRIBUTE ResAttr
;
139 DbgPrint(" $VOLUME_NAME ");
141 ResAttr
= (PRESIDENT_ATTRIBUTE
)Attribute
;
142 // DbgPrint(" Length %lu Offset %hu ", ResAttr->ValueLength, ResAttr->ValueOffset);
144 VolumeName
= (PWCHAR
)((PVOID
)ResAttr
+ ResAttr
->ValueOffset
);
145 DbgPrint(" '%.*S' ", ResAttr
->ValueLength
/ sizeof(WCHAR
), VolumeName
);
150 NtfsDumpVolumeInformationAttribute(PATTRIBUTE Attribute
)
152 PRESIDENT_ATTRIBUTE ResAttr
;
153 PVOLINFO_ATTRIBUTE VolInfoAttr
;
155 DbgPrint(" $VOLUME_INFORMATION ");
157 ResAttr
= (PRESIDENT_ATTRIBUTE
)Attribute
;
158 // DbgPrint(" Length %lu Offset %hu ", ResAttr->ValueLength, ResAttr->ValueOffset);
160 VolInfoAttr
= (PVOLINFO_ATTRIBUTE
)((PVOID
)ResAttr
+ ResAttr
->ValueOffset
);
161 DbgPrint(" NTFS Version %u.%u Flags 0x%04hx ",
162 VolInfoAttr
->MajorVersion
,
163 VolInfoAttr
->MinorVersion
,
169 NtfsDumpAttribute (PATTRIBUTE Attribute
)
171 PNONRESIDENT_ATTRIBUTE NresAttr
;
177 switch (Attribute
->AttributeType
)
179 case AttributeFileName
:
180 NtfsDumpFileNameAttribute(Attribute
);
183 case AttributeStandardInformation
:
184 DbgPrint(" $STANDARD_INFORMATION ");
187 case AttributeAttributeList
:
188 DbgPrint(" $ATTRIBUTE_LIST ");
191 case AttributeObjectId
:
192 DbgPrint(" $OBJECT_ID ");
195 case AttributeSecurityDescriptor
:
196 DbgPrint(" $SECURITY_DESCRIPTOR ");
199 case AttributeVolumeName
:
200 NtfsDumpVolumeNameAttribute(Attribute
);
203 case AttributeVolumeInformation
:
204 NtfsDumpVolumeInformationAttribute(Attribute
);
209 //DataBuf = ExAllocatePool(NonPagedPool,AttributeLengthAllocated(Attribute));
212 case AttributeIndexRoot
:
213 DbgPrint(" $INDEX_ROOT ");
216 case AttributeIndexAllocation
:
217 DbgPrint(" $INDEX_ALLOCATION ");
220 case AttributeBitmap
:
221 DbgPrint(" $BITMAP ");
224 case AttributeReparsePoint
:
225 DbgPrint(" $REPARSE_POINT ");
228 case AttributeEAInformation
:
229 DbgPrint(" $EA_INFORMATION ");
236 case AttributePropertySet
:
237 DbgPrint(" $PROPERTY_SET ");
240 case AttributeLoggedUtilityStream
:
241 DbgPrint(" $LOGGED_UTILITY_STREAM ");
245 DbgPrint(" Attribute %lx ",
246 Attribute
->AttributeType
);
250 if (Attribute
->NameLength
!= 0)
252 Name
.Length
= Attribute
->NameLength
* sizeof(WCHAR
);
253 Name
.MaximumLength
= Name
.Length
;
254 Name
.Buffer
= (PWCHAR
)((ULONG
)Attribute
+ Attribute
->NameOffset
);
256 DbgPrint("'%wZ' ", &Name
);
260 Attribute
->Nonresident
? "non-resident" : "resident");
262 if (Attribute
->Nonresident
)
264 NresAttr
= (PNONRESIDENT_ATTRIBUTE
)Attribute
;
266 FindRun (NresAttr
,0,&lcn
, &runcount
);
268 DbgPrint (" AllocatedSize %I64u DataSize %I64u\n",
269 NresAttr
->AllocatedSize
, NresAttr
->DataSize
);
270 DbgPrint (" logical clusters: %I64u - %I64u\n",
271 lcn
, lcn
+ runcount
- 1);
277 NtfsDumpFileAttributes (PFILE_RECORD_HEADER FileRecord
)
279 PATTRIBUTE Attribute
;
281 Attribute
= (PATTRIBUTE
)((ULONG_PTR
)FileRecord
+ FileRecord
->AttributeOffset
);
282 while (Attribute
->AttributeType
!=-1)
284 NtfsDumpAttribute (Attribute
);
286 Attribute
= (PATTRIBUTE
)((ULONG_PTR
)Attribute
+ Attribute
->Length
);