Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfullfat.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS FAT file system driver 00003 * LICENSE: GNU GPLv3 as published by the Free Software Foundation 00004 * FILE: drivers/filesystems/fastfat/fullfat.c 00005 * PURPOSE: FullFAT integration routines 00006 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org) 00007 */ 00008 00009 /* INCLUDES *****************************************************************/ 00010 00011 #define NDEBUG 00012 #include "fastfat.h" 00013 00014 /* GLOBALS ******************************************************************/ 00015 00016 #define TAG_FULLFAT 'FLUF' 00017 00018 /* FUNCTIONS ****************************************************************/ 00019 00020 VOID * 00021 FF_Malloc(FF_T_UINT32 allocSize) 00022 { 00023 return ExAllocatePoolWithTag(PagedPool, allocSize, TAG_FULLFAT); 00024 } 00025 00026 VOID 00027 FF_Free(VOID *pBuffer) 00028 { 00029 ExFreePoolWithTag(pBuffer, TAG_FULLFAT); 00030 } 00031 00032 FF_T_SINT32 00033 FatWriteBlocks(FF_T_UINT8 *pBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam) 00034 { 00035 DPRINT1("FatWriteBlocks %p %d %d %p\n", pBuffer, SectorAddress, Count, pParam); 00036 00037 return 0; 00038 } 00039 00040 FF_T_SINT32 00041 FatReadBlocks(FF_T_UINT8 *DestBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam) 00042 { 00043 LARGE_INTEGER Offset; 00044 //PVOID Buffer; 00045 PVCB Vcb = (PVCB)pParam; 00046 //PBCB Bcb; 00047 ULONG SectorSize = 512; // FIXME: hardcoding 512 is bad 00048 IO_STATUS_BLOCK IoSb; 00049 00050 DPRINT("FatReadBlocks %p %d %d %p\n", DestBuffer, SectorAddress, Count, pParam); 00051 00052 /* Calculate the offset */ 00053 Offset.QuadPart = Int32x32To64(SectorAddress, SectorSize); 00054 #if 0 00055 if (!CcMapData(Vcb->StreamFileObject, 00056 &Offset, 00057 Count * SectorSize, 00058 TRUE, 00059 &Bcb, 00060 &Buffer)) 00061 { 00062 ASSERT(FALSE); 00063 /* Mapping failed */ 00064 return 0; 00065 } 00066 00067 /* Copy data to the buffer */ 00068 RtlCopyMemory(DestBuffer, Buffer, Count * SectorSize); 00069 00070 /* Unpin unneeded data */ 00071 CcUnpinData(Bcb); 00072 #else 00073 CcCopyRead(Vcb->StreamFileObject, &Offset, Count * SectorSize, TRUE, DestBuffer, &IoSb); 00074 #endif 00075 00076 /* Return amount of read data in sectors */ 00077 return Count; 00078 } 00079 00080 FF_FILE *FF_OpenW(FF_IOMAN *pIoman, PUNICODE_STRING pathW, FF_T_UINT8 Mode, FF_ERROR *pError) 00081 { 00082 OEM_STRING AnsiName; 00083 CHAR AnsiNameBuf[512]; 00084 NTSTATUS Status; 00085 00086 /* Convert the name to ANSI */ 00087 AnsiName.Buffer = AnsiNameBuf; 00088 AnsiName.Length = 0; 00089 AnsiName.MaximumLength = sizeof(AnsiNameBuf); 00090 RtlZeroMemory(AnsiNameBuf, sizeof(AnsiNameBuf)); 00091 Status = RtlUpcaseUnicodeStringToCountedOemString(&AnsiName, pathW, FALSE); 00092 if (!NT_SUCCESS(Status)) 00093 { 00094 ASSERT(FALSE); 00095 } 00096 00097 DPRINT1("Opening '%s'\n", AnsiName.Buffer); 00098 00099 /* Call FullFAT's handler */ 00100 return FF_Open(pIoman, AnsiName.Buffer, Mode, pError); 00101 } 00102 00103 FORCEINLINE 00104 VOID 00105 FatDateTimeToSystemTime(OUT PLARGE_INTEGER SystemTime, 00106 IN PFAT_DATETIME FatDateTime, 00107 IN UCHAR TenMs OPTIONAL) 00108 { 00109 TIME_FIELDS TimeFields; 00110 00111 /* Setup time fields */ 00112 TimeFields.Year = FatDateTime->Date.Year + 1980; 00113 TimeFields.Month = FatDateTime->Date.Month; 00114 TimeFields.Day = FatDateTime->Date.Day; 00115 TimeFields.Hour = FatDateTime->Time.Hour; 00116 TimeFields.Minute = FatDateTime->Time.Minute; 00117 TimeFields.Second = (FatDateTime->Time.DoubleSeconds << 1); 00118 00119 /* Adjust up to 10 milliseconds 00120 * if the parameter was supplied 00121 */ 00122 if (ARGUMENT_PRESENT(TenMs)) 00123 { 00124 TimeFields.Second += TenMs / 100; 00125 TimeFields.Milliseconds = (TenMs % 100) * 10; 00126 } 00127 else 00128 { 00129 TimeFields.Milliseconds = 0; 00130 } 00131 00132 /* Fix seconds value that might get beyoud the bound */ 00133 if (TimeFields.Second > 59) TimeFields.Second = 0; 00134 00135 /* Perform ceonversion to system time if possible */ 00136 if (RtlTimeFieldsToTime(&TimeFields, SystemTime)) 00137 { 00138 /* Convert to system time */ 00139 ExLocalTimeToSystemTime(SystemTime, SystemTime); 00140 } 00141 else 00142 { 00143 /* Set to default time if conversion failed */ 00144 *SystemTime = FatGlobalData.DefaultFileTime; 00145 } 00146 } 00147 00148 // TODO: Make it a helper around FullFAT library 00149 VOID 00150 NTAPI 00151 FatQueryFileTimes(OUT PLARGE_INTEGER FileTimes, 00152 IN PDIR_ENTRY Dirent) 00153 { 00154 /* Convert LastWriteTime */ 00155 FatDateTimeToSystemTime(&FileTimes[FileLastWriteTime], 00156 &Dirent->LastWriteDateTime, 00157 0); 00158 /* All other time fileds are valid (according to MS) 00159 * only if Win31 compatability mode is set. 00160 */ 00161 if (FatGlobalData.Win31FileSystem) 00162 { 00163 /* We can avoid calling conversion routine 00164 * if time in dirent is 0 or equals to already 00165 * known time (LastWriteTime). 00166 */ 00167 if (Dirent->CreationDateTime.Value == 0) 00168 { 00169 /* Set it to default time */ 00170 FileTimes[FileCreationTime] = FatGlobalData.DefaultFileTime; 00171 } 00172 else if (Dirent->CreationDateTime.Value 00173 == Dirent->LastWriteDateTime.Value) 00174 { 00175 /* Assign the already known time */ 00176 FileTimes[FileCreationTime] = FileTimes[FileLastWriteTime]; 00177 /* Adjust milliseconds from extra dirent field */ 00178 FileTimes[FileCreationTime].QuadPart 00179 += (ULONG) Dirent->CreationTimeTenMs * 100000; 00180 } 00181 else 00182 { 00183 /* Perform conversion */ 00184 FatDateTimeToSystemTime(&FileTimes[FileCreationTime], 00185 &Dirent->CreationDateTime, 00186 Dirent->CreationTimeTenMs); 00187 } 00188 if (Dirent->LastAccessDate.Value == 0) 00189 { 00190 /* Set it to default time */ 00191 FileTimes[FileLastAccessTime] = FatGlobalData.DefaultFileTime; 00192 } 00193 else if (Dirent->LastAccessDate.Value 00194 == Dirent->LastWriteDateTime.Date.Value) 00195 { 00196 /* Assign the already known time */ 00197 FileTimes[FileLastAccessTime] = FileTimes[FileLastWriteTime]; 00198 } 00199 else 00200 { 00201 /* Perform conversion */ 00202 FAT_DATETIME LastAccessDateTime; 00203 00204 LastAccessDateTime.Date.Value = Dirent->LastAccessDate.Value; 00205 LastAccessDateTime.Time.Value = 0; 00206 FatDateTimeToSystemTime(&FileTimes[FileLastAccessTime], 00207 &LastAccessDateTime, 00208 0); 00209 } 00210 } 00211 } 00212 00213 /* EOF */ Generated on Sun May 27 2012 04:27:47 for ReactOS by
1.7.6.1
|