1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
6 /*************************************************************************
7 *
8 * File: sys_spec_lib.h
9 *
10 * Module: UDF File System Driver (Kernel mode execution only)
11 *
12 * Description:
13 *   The main include file for the UDF file system driver.
14 *
15 * Author: Alter
16 *
17 *************************************************************************/
18 
19 #ifndef _UDF_SYS_SPEC_LIB__H_
20 #define _UDF_SYS_SPEC_LIB__H_
21 
22 typedef struct _UDF_PH_CALL_CONTEXT {
23     KEVENT          event;
24     IO_STATUS_BLOCK IosbToUse;
25 } UDF_PH_CALL_CONTEXT, *PUDF_PH_CALL_CONTEXT;
26 
27 #ifdef _BROWSE_UDF_
28 
29 // convert UDF timestamp to NT time
30 LONGLONG UDFTimeToNT(IN PUDF_TIME_STAMP UdfTime);
31 // translate UDF file attributes to NT ones
32 ULONG    UDFAttributesToNT(IN PDIR_INDEX_ITEM FileDirNdx,
33                            IN tag* FileEntry);
34 // translate NT file attributes to UDF ones
35 VOID     UDFAttributesToUDF(IN PDIR_INDEX_ITEM FileDirNdx,
36                             IN tag* FileEntry,
37                             IN ULONG NTAttr);
38 // translate all file information to NT
39 NTSTATUS UDFFileDirInfoToNT(IN PVCB Vcb,
40                             IN PDIR_INDEX_ITEM FileDirNdx,
41                             OUT PFILE_BOTH_DIR_INFORMATION NTFileInfo);
42 // convert NT time to UDF timestamp
43 VOID     UDFTimeToUDF(IN LONGLONG NtTime,
44                       OUT PUDF_TIME_STAMP UdfTime);
45 // change xxxTime field(s) in (Ext)FileEntry
46 VOID     UDFSetFileXTime(IN PUDF_FILE_INFO FileInfo,
47                          IN LONGLONG* CrtTime,
48                          IN LONGLONG* AccTime,
49                          IN LONGLONG* AttrTime,
50                          IN LONGLONG* ChgTime);
51 // get xxxTime field(s) in (Ext)FileEntry
52 VOID     UDFGetFileXTime(IN PUDF_FILE_INFO FileInfo,
53                          OUT LONGLONG* CrtTime,
54                          OUT LONGLONG* AccTime,
55                          OUT LONGLONG* AttrTime,
56                          OUT LONGLONG* ChgTime);
57 //
58 #define UDFUpdateAccessTime(Vcb, FileInfo)             \
59 if(Vcb->CompatFlags & UDF_VCB_IC_UPDATE_ACCESS_TIME) {       \
60     LONGLONG NtTime;                                   \
61     KeQuerySystemTime((PLARGE_INTEGER)&NtTime);            \
62     UDFSetFileXTime(FileInfo, NULL, &NtTime, NULL, NULL);  \
63 }
64 //
65 #define UDFUpdateModifyTime(Vcb, FileInfo)             \
66 if(Vcb->CompatFlags & UDF_VCB_IC_UPDATE_MODIFY_TIME) {       \
67     LONGLONG NtTime;                                   \
68     ULONG Attr;                                        \
69     PDIR_INDEX_ITEM DirNdx;                            \
70     KeQuerySystemTime((PLARGE_INTEGER)&NtTime);               \
71     UDFSetFileXTime(FileInfo, NULL, &NtTime, NULL, &NtTime);  \
72     DirNdx = UDFDirIndex(UDFGetDirIndexByFileInfo(FileInfo), (FileInfo)->Index); \
73     Attr = UDFAttributesToNT(DirNdx, (FileInfo)->Dloc->FileEntry); \
74     if(!(Attr & FILE_ATTRIBUTE_ARCHIVE))                            \
75         UDFAttributesToUDF(DirNdx, (FileInfo)->Dloc->FileEntry, Attr); \
76 }
77 //
78 #define UDFUpdateAttrTime(Vcb, FileInfo)               \
79 if(Vcb->CompatFlags & UDF_VCB_IC_UPDATE_ATTR_TIME) {         \
80     LONGLONG NtTime;                                   \
81     KeQuerySystemTime((PLARGE_INTEGER)&NtTime);               \
82     UDFSetFileXTime(FileInfo, NULL, &NtTime, &NtTime, NULL);  \
83 }
84 //
85 #define UDFUpdateCreateTime(Vcb, FileInfo)             \
86 {                                                      \
87     LONGLONG NtTime;                                   \
88     KeQuerySystemTime((PLARGE_INTEGER)&NtTime);               \
89     UDFSetFileXTime(FileInfo, &NtTime, &NtTime, &NtTime, &NtTime);  \
90 }
91 
92 void
93 __fastcall
94 UDFDOSNameOsNative(
95     IN OUT PUNICODE_STRING DosName,
96     IN PUNICODE_STRING UdfName,
97     IN BOOLEAN KeepIntact
98     );
99 
100 VOID     UDFNormalizeFileName(IN PUNICODE_STRING FName,
101                               IN USHORT valueCRC);
102 
103 NTSTATUS MyAppendUnicodeStringToString_(IN PUNICODE_STRING Str1,
104                                         IN PUNICODE_STRING Str2
105 #ifdef UDF_TRACK_UNICODE_STR
106                                        ,IN PCHAR Tag
107 #endif
108                                        );
109 
110 NTSTATUS MyAppendUnicodeToString_(IN PUNICODE_STRING Str1,
111                                   IN PCWSTR Str2
112 #ifdef UDF_TRACK_UNICODE_STR
113                                  ,IN PCHAR Tag
114 #endif
115                                  );
116 
117 #ifdef UDF_TRACK_UNICODE_STR
118   #define MyAppendUnicodeStringToString(s1,s2)         MyAppendUnicodeStringToString_(s1,s2,"AppUStr")
119   #define MyAppendUnicodeStringToStringTag(s1,s2,tag)  MyAppendUnicodeStringToString_(s1,s2,tag)
120   #define MyAppendUnicodeToString(s1,s2)               MyAppendUnicodeToString_(s1,s2,"AppStr")
121   #define MyAppendUnicodeToStringTag(s1,s2,tag)        MyAppendUnicodeToString_(s1,s2,tag)
122 #else
123   #define MyAppendUnicodeStringToString(s1,s2)  MyAppendUnicodeStringToString_(s1,s2)
124   #define MyAppendUnicodeStringToStringTag(s1,s2,tag)  MyAppendUnicodeStringToString_(s1,s2)
125   #define MyAppendUnicodeToString(s1,s2)               MyAppendUnicodeToString_(s1,s2)
126   #define MyAppendUnicodeToStringTag(s1,s2,tag)        MyAppendUnicodeToString_(s1,s2)
127 #endif
128 
129 NTSTATUS MyInitUnicodeString(IN PUNICODE_STRING Str1,
130                              IN PCWSTR Str2);
131 
132 NTSTATUS MyCloneUnicodeString(IN PUNICODE_STRING Str1,
133                               IN PUNICODE_STRING Str2);
134 
135 /*ULONG    MyCompareUnicodeString(PUNICODE_STRING s1,
136                                 PUNICODE_STRING s2,
137                                 BOOLEAN UpCase);*/
138 
139 /*
140 #define UDFAllocFileInfo() \
141     ExAllocateFromZone(&(UDFGlobalData.FileInfoZoneHeader))
142 */
143 
144 #define UDFIsDataCached(Vcb,Lba,BCount) \
145     ( WCacheIsInitialized__(&((Vcb)->FastCache)) &&        \
146      (KeGetCurrentIrql() < DISPATCH_LEVEL) && \
147       WCacheIsCached__(&((Vcb)->FastCache),Lba, BCount) )
148 
149 BOOLEAN  UDFIsDirInfoCached(IN PVCB Vcb,
150                             IN PUDF_FILE_INFO DirInfo);
151 
152 #define UDFGetNTFileId(Vcb, fi, fn) (((fi)->Dloc->FELoc.Mapping[0].extLocation - UDFPartStart(Vcb, -2)) + \
153                                      ((ULONG)(UDFUnicodeCksum((fn)->Buffer, (fn)->Length/sizeof(WCHAR))) << 16) + \
154                                      ((LONGLONG)Vcb<<32) )
155 
156 #define UnicodeIsPrint(a) RtlIsValidOemCharacter(&(a))
157 
158 #define UDFSysGetAllocSize(Vcb, Size) ((Size + Vcb->LBlockSize - 1) & ~((LONGLONG)(Vcb->LBlockSize - 1)))
159 
160 NTSTATUS UDFDoesOSAllowFileToBeTargetForRename__(IN PUDF_FILE_INFO FileInfo);
161 #define UDFDoesOSAllowFileToBeTargetForHLink__  UDFDoesOSAllowFileToBeTargetForRename__
162 NTSTATUS UDFDoesOSAllowFileToBeUnlinked__(IN PUDF_FILE_INFO FileInfo);
163 #define UDFDoesOSAllowFileToBeMoved__  UDFDoesOSAllowFileToBeUnlinked__
164 NTSTATUS UDFDoesOSAllowFilePretendDeleted__(IN PUDF_FILE_INFO FileInfo);
165 BOOLEAN UDFRemoveOSReferences__(IN PUDF_FILE_INFO FileInfo);
166 
167 #define UDFIsFSDevObj(DeviceObject) \
168     (DeviceObject->DeviceExtension && \
169       ( (((PVCB)(DeviceObject->DeviceExtension))->NodeIdentifier.NodeType == \
170               UDF_NODE_TYPE_UDFFS_DEVOBJ) || \
171         (((PVCB)(DeviceObject->DeviceExtension))->NodeIdentifier.NodeType == \
172               UDF_NODE_TYPE_UDFFS_DRVOBJ) \
173       ) \
174     )
175 /*
176 extern ULONG  MajorVersion;
177 extern ULONG  MinorVersion;
178 extern ULONG  BuildNumber;
179 
180 #define WinVer_Is351  (MajorVersion==0x03 && MinorVersion==51)
181 #define WinVer_IsNT   (MajorVersion==0x04)
182 #define WinVer_Is2k   (MajorVersion==0x05 && MinorVersion==0x00)
183 #define WinVer_IsXP   (MajorVersion==0x05 && MinorVersion==0x01)
184 #define WinVer_IsdNET (MajorVersion==0x05 && MinorVersion==0x02)
185 */
186 #endif //_BROWSE_UDF_
187 
188 #endif  // _UDF_SYS_SPEC_LIB__H_
189