dll: fuse: streamline time calculations

This commit is contained in:
Bill Zissimopoulos 2017-11-14 21:37:50 -08:00
parent efc93cacd3
commit 658d873efb
No known key found for this signature in database
GPG Key ID: 3D4F95D52C7B3EA3
3 changed files with 27 additions and 42 deletions

View File

@ -1472,6 +1472,21 @@ NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPat
FSP_API VOID FspPosixDeletePath(void *Path); FSP_API VOID FspPosixDeletePath(void *Path);
FSP_API VOID FspPosixEncodeWindowsPath(PWSTR WindowsPath, ULONG Size); FSP_API VOID FspPosixEncodeWindowsPath(PWSTR WindowsPath, ULONG Size);
FSP_API VOID FspPosixDecodeWindowsPath(PWSTR WindowsPath, ULONG Size); FSP_API VOID FspPosixDecodeWindowsPath(PWSTR WindowsPath, ULONG Size);
static inline
VOID FspPosixFileTimeToUnixTime(UINT64 FileTime0, __int3264 UnixTime[2])
{
INT64 FileTime = (INT64)FileTime0 - 116444736000000000LL;
UnixTime[0] = (__int3264)(FileTime / 10000000);
UnixTime[1] = (__int3264)(FileTime % 10000000 * 100);
/* may produce negative nsec for times before UNIX epoch; strictly speaking this is incorrect */
}
static inline
VOID FspPosixUnixTimeToFileTime(const __int3264 UnixTime[2], PUINT64 PFileTime)
{
INT64 FileTime = (INT64)UnixTime[0] * 10000000 + (INT64)UnixTime[1] / 100 +
116444736000000000LL;
*PFileTime = FileTime;
}
/* /*
* Path Handling * Path Handling

View File

@ -355,14 +355,12 @@ static NTSTATUS fsp_fuse_svcstart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
if (0 == f->VolumeParams.VolumeCreationTime) if (0 == f->VolumeParams.VolumeCreationTime)
{ {
if (0 != stbuf.st_birthtim.tv_sec) if (0 != stbuf.st_birthtim.tv_sec)
f->VolumeParams.VolumeCreationTime = FspPosixUnixTimeToFileTime((void *)&stbuf.st_birthtim,
Int32x32To64(stbuf.st_birthtim.tv_sec, 10000000) + 116444736000000000 + &f->VolumeParams.VolumeCreationTime);
stbuf.st_birthtim.tv_nsec / 100;
else else
if (0 != stbuf.st_ctim.tv_sec) if (0 != stbuf.st_ctim.tv_sec)
f->VolumeParams.VolumeCreationTime = FspPosixUnixTimeToFileTime((void *)&stbuf.st_ctim,
Int32x32To64(stbuf.st_ctim.tv_sec, 10000000) + 116444736000000000 + &f->VolumeParams.VolumeCreationTime);
stbuf.st_ctim.tv_nsec / 100;
} }
} }

View File

@ -428,18 +428,10 @@ static NTSTATUS fsp_fuse_intf_GetFileInfoFunnel(FSP_FILE_SYSTEM *FileSystem,
FileInfo->FileSize = stbuf.st_size; FileInfo->FileSize = stbuf.st_size;
FileInfo->AllocationSize = FileInfo->AllocationSize =
(FileInfo->FileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit; (FileInfo->FileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit;
FileInfo->CreationTime = FspPosixUnixTimeToFileTime((void *)&stbuf.st_birthtim, &FileInfo->CreationTime);
Int32x32To64(stbuf.st_birthtim.tv_sec, 10000000) + 116444736000000000 + FspPosixUnixTimeToFileTime((void *)&stbuf.st_atim, &FileInfo->LastAccessTime);
stbuf.st_birthtim.tv_nsec / 100; FspPosixUnixTimeToFileTime((void *)&stbuf.st_mtim, &FileInfo->LastWriteTime);
FileInfo->LastAccessTime = FspPosixUnixTimeToFileTime((void *)&stbuf.st_ctim, &FileInfo->ChangeTime);
Int32x32To64(stbuf.st_atim.tv_sec, 10000000) + 116444736000000000 +
stbuf.st_atim.tv_nsec / 100;
FileInfo->LastWriteTime =
Int32x32To64(stbuf.st_mtim.tv_sec, 10000000) + 116444736000000000 +
stbuf.st_mtim.tv_nsec / 100;
FileInfo->ChangeTime =
Int32x32To64(stbuf.st_ctim.tv_sec, 10000000) + 116444736000000000 +
stbuf.st_ctim.tv_nsec / 100;
FileInfo->IndexNumber = stbuf.st_ino; FileInfo->IndexNumber = stbuf.st_ino;
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -1306,37 +1298,17 @@ static NTSTATUS fsp_fuse_intf_SetBasicInfo(FSP_FILE_SYSTEM *FileSystem,
LastWriteTime = FileInfoBuf.LastWriteTime; LastWriteTime = FileInfoBuf.LastWriteTime;
} }
/* UNIX epoch in 100-ns intervals */ FspPosixFileTimeToUnixTime(LastAccessTime, (void *)&tv[0]);
LastAccessTime -= 116444736000000000; FspPosixFileTimeToUnixTime(LastWriteTime, (void *)&tv[1]);
LastWriteTime -= 116444736000000000;
if (0 != f->ops.utimens) if (0 != f->ops.utimens)
{ {
#if defined(_WIN64)
tv[0].tv_sec = (int64_t)(LastAccessTime / 10000000);
tv[0].tv_nsec = (int64_t)(LastAccessTime % 10000000) * 100;
tv[1].tv_sec = (int64_t)(LastWriteTime / 10000000);
tv[1].tv_nsec = (int64_t)(LastWriteTime % 10000000) * 100;
#else
tv[0].tv_sec = (int32_t)(LastAccessTime / 10000000);
tv[0].tv_nsec = (int32_t)(LastAccessTime % 10000000) * 100;
tv[1].tv_sec = (int32_t)(LastWriteTime / 10000000);
tv[1].tv_nsec = (int32_t)(LastWriteTime % 10000000) * 100;
#endif
err = f->ops.utimens(filedesc->PosixPath, tv); err = f->ops.utimens(filedesc->PosixPath, tv);
Result = fsp_fuse_ntstatus_from_errno(f->env, err); Result = fsp_fuse_ntstatus_from_errno(f->env, err);
} }
else else
{ {
#if defined(_WIN64) timbuf.actime = tv[0].tv_sec;
timbuf.actime = (int64_t)(LastAccessTime / 10000000); timbuf.modtime = tv[1].tv_sec;
timbuf.modtime = (int64_t)(LastWriteTime / 10000000);
#else
timbuf.actime = (int32_t)(LastAccessTime / 10000000);
timbuf.modtime = (int32_t)(LastWriteTime / 10000000);
#endif
err = f->ops.utime(filedesc->PosixPath, &timbuf); err = f->ops.utime(filedesc->PosixPath, &timbuf);
Result = fsp_fuse_ntstatus_from_errno(f->env, err); Result = fsp_fuse_ntstatus_from_errno(f->env, err);
} }