-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_info.c
107 lines (90 loc) · 3.71 KB
/
file_info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "file_info.h"
#include "file.h"
#include "general.h"
#include "debug.h"
#include "inode.h"
void MxfsFileTimeFromTimeT(LPFILETIME FileTime, time_t t)
{
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000ull;
FileTime->dwLowDateTime = (DWORD)ll;
FileTime->dwHighDateTime = ll >> 32;
}
time_t MxfsTimeTFromFileTime(CONST FILETIME *FileTime)
{
ULARGE_INTEGER ull;
ull.LowPart = FileTime->dwLowDateTime;
ull.HighPart = FileTime->dwHighDateTime;
return ull.QuadPart / 10000000ULL - 11644473600ULL;
}
int DOKAN_CALLBACK MxfsGetFileInformation(
LPCWSTR FileName,
LPBY_HANDLE_FILE_INFORMATION Buffer,
PDOKAN_FILE_INFO FileInfo)
{
TRACE("%ls %p", FileName, FileInfo);
MINIX_FS *FileSys = (MINIX_FS*)(LONG_PTR)FileInfo->DokanOptions->GlobalContext;
FILE_CTX *FileCtx = (FILE_CTX*)(LONG_PTR)FileInfo->Context;
ASSERT(FileCtx);
minix_inode Info;
MxfsReadInode(FileSys, FileCtx->Index, &Info);
ZeroMemory(Buffer, sizeof(*Buffer));
Buffer->dwFileAttributes = FileInfo->IsDirectory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL;
MxfsFileTimeFromTimeT(&Buffer->ftCreationTime, Info.d2_mtime);
MxfsFileTimeFromTimeT(&Buffer->ftLastAccessTime, Info.d2_atime);
MxfsFileTimeFromTimeT(&Buffer->ftLastWriteTime, Info.d2_mtime);
Buffer->dwVolumeSerialNumber = MINIX_VOLUME_ID;
Buffer->nFileSizeLow = Info.d2_size;
Buffer->nNumberOfLinks = 1;
Buffer->nFileIndexLow = FileCtx->Index;
return 0;
}
int DOKAN_CALLBACK MxfsSetFileTime(
LPCWSTR FileName,
CONST FILETIME *CreationTime,
CONST FILETIME *LastAccessTime,
CONST FILETIME *LastWriteTime,
PDOKAN_FILE_INFO FileInfo)
{
TRACE("%ls", FileName);
MINIX_FS *FileSys = (MINIX_FS*)(ULONG_PTR)FileInfo->DokanOptions->GlobalContext;
FILE_CTX *FileCtx = (FILE_CTX*)(ULONG_PTR)FileInfo->Context;
ASSERT(FileCtx);
minix_inode Info;
int Result = MxfsReadInode(FileSys, FileCtx->Index, &Info);
if(Result < 0)
return Result;
if(LastAccessTime && (LastAccessTime->dwHighDateTime || LastAccessTime->dwLowDateTime))
{
if(LastAccessTime->dwHighDateTime == 0xFFFFFFFF && LastAccessTime->dwLowDateTime == 0xFFFFFFFF)
WARN("TODO: Support -1!\n"); // preserve access time
else
Info.d2_atime = MxfsTimeTFromFileTime(LastAccessTime);
}
if(LastWriteTime && (LastWriteTime->dwHighDateTime || LastWriteTime->dwLowDateTime))
{
if(LastWriteTime->dwHighDateTime == 0xFFFFFFFF && LastWriteTime->dwLowDateTime == 0xFFFFFFFF)
WARN("TODO: Support -1!\n"); // preserve write time
else
Info.d2_mtime = MxfsTimeTFromFileTime(LastWriteTime);
}
return MxfsWriteInode(FileSys, FileCtx->Index, &Info);
}
void MxfsFillFindData(WIN32_FIND_DATAW *pFindData, const minix_dir_entry *pDirEntry, const minix_inode *pInfo)
{
/* Attributes */
if(pInfo->d2_mode & I_DIRECTORY)
pFindData->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
else
pFindData->dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
/* Times */
MxfsFileTimeFromTimeT(&pFindData->ftCreationTime, pInfo->d2_mtime);
MxfsFileTimeFromTimeT(&pFindData->ftLastAccessTime, pInfo->d2_atime);
MxfsFileTimeFromTimeT(&pFindData->ftLastWriteTime, pInfo->d2_mtime);
/* Size */
pFindData->nFileSizeLow = pInfo->d2_size;
/* Name */
int NameLen = strnlen(pDirEntry->name, MAX_NAME_LEN);
MultiByteToWideChar(CP_ACP, 0, pDirEntry->name, NameLen, pFindData->cFileName, COUNTOF(pFindData->cFileName));
pFindData->cFileName[min(NameLen, COUNTOF(pFindData->cFileName))] = 0;
wcscpy_s(pFindData->cAlternateFileName, sizeof(pFindData->cAlternateFileName), pFindData->cFileName);
}