初步实现

This commit is contained in:
asypost committed 2026-06-23 16:48:14 +08:00
1 parent aace751d01
commit 6e60886fd3
8 files changed
+451 -120

No files matched your search

+93 -49
View File
@@ -6,14 +6,18 @@
//
#include <unordered_map>
namespace seafile::fs {
namespace {
namespace seafile::fs
{
namespace
{
FSP_FILE_SYSTEM_INTERFACE FsInterface = {
.GetVolumeInfo = WinFSPAdapter::GetVolumeInfo,
.SetVolumeLabel = WinFSPAdapter::SetVolumeLabel_,
.GetSecurityByName = WinFSPAdapter::GetSecurityByName,
.Create = WinFSPAdapter::Create,
.Open = WinFSPAdapter::Open,
.Overwrite = WinFSPAdapter::Overwrite,
.Cleanup = WinFSPAdapter::Cleanup,
.Close = WinFSPAdapter::Close,
.Read = WinFSPAdapter::Read,
.GetFileInfo = WinFSPAdapter::GetFileInfo,
@@ -22,15 +26,14 @@ namespace seafile::fs {
.ReadDirectory = WinFSPAdapter::ReadDirectory,
.GetDirInfoByName = WinFSPAdapter::GetDirInfoByName
};
std::unordered_map<FSP_FILE_SYSTEM *, SeafileFileSystem *> fstab;
std::unordered_map<FSP_FILE_SYSTEM*, SeafileFileSystem*> fstab;
}
NTSTATUS WinFSPAdapter::SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv) {
DWORD LastError;
NTSTATUS WinFSPAdapter::SvcStart(FSP_SERVICE* Service, ULONG argc, PWSTR* argv)
{
FILETIME CreationTime;
FSP_FSCTL_VOLUME_PARAMS VolumeParams = {};
FSP_FILE_SYSTEM *FileSystem = nullptr;
FSP_FILE_SYSTEM* FileSystem = nullptr;
GetSystemTimeAsFileTime(&CreationTime);
@@ -44,7 +47,7 @@ namespace seafile::fs {
VolumeParams.CaseSensitiveSearch = 0;
VolumeParams.CasePreservedNames = 1;
VolumeParams.UnicodeOnDisk = 1;
VolumeParams.PersistentAcls = 1;
VolumeParams.PersistentAcls = 0;
VolumeParams.PostCleanupWhenModifiedOnly = 1; // (4)
VolumeParams.UmFileContextIsUserContext2 = 1; // (4)
VolumeParams.ReadOnlyVolume = 1;
@@ -56,21 +59,23 @@ namespace seafile::fs {
&FsInterface,
&FileSystem);
if (!NT_SUCCESS(Result)) {
if (!NT_SUCCESS(Result))
{
return Result;
}
const auto mount_point = std::wstring(L"X:");
auto mount_point = std::wstring(L"X:");
auto seafile_file_system = new SeafileFileSystem("https://pan.hanwangsoft.com", mount_point);
seafile_file_system->auth("asypost@yeah.net", "Shell0805@china");
FileSystem->UserContext = seafile_file_system;
fstab.insert({FileSystem, seafile_file_system});
Result = FspFileSystemSetMountPoint(FileSystem, PWSTR(mount_point.data()));
Result = FspFileSystemSetMountPoint(FileSystem, static_cast<PWSTR>(mount_point.data()));
LastError = GetLastError();
DWORD LastError = GetLastError();
std::cout << LastError << std::endl;
if (!NT_SUCCESS(Result)) {
if (!NT_SUCCESS(Result))
{
FspFileSystemDelete(FileSystem);
fstab.erase(FileSystem);
@@ -80,11 +85,13 @@ namespace seafile::fs {
Result = FspFileSystemStartDispatcher(FileSystem, 0);
if (!NT_SUCCESS(Result)) {
if (!NT_SUCCESS(Result))
{
FspFileSystemDelete(FileSystem);
fstab.erase(FileSystem);
delete seafile_file_system;
return Result;
}
FspFileSystemSetDebugLog(
FileSystem,
@@ -94,8 +101,10 @@ namespace seafile::fs {
return Result;
}
NTSTATUS WinFSPAdapter::SvcStop(FSP_SERVICE *Service) {
for (auto &[fileSystem, seafileFs]: fstab) {
NTSTATUS WinFSPAdapter::SvcStop(FSP_SERVICE* Service)
{
for (auto& [fileSystem, seafileFs] : fstab)
{
FspFileSystemStopDispatcher(fileSystem);
fileSystem->UserContext = nullptr;
FspFileSystemDelete(fileSystem);
@@ -106,70 +115,105 @@ namespace seafile::fs {
return STATUS_SUCCESS;
}
NTSTATUS WinFSPAdapter::GetVolumeInfo(FSP_FILE_SYSTEM *FileSystem, FSP_FSCTL_VOLUME_INFO *VolumeInfo) {
std::cout<<"Getting Volume Info" <<std::endl;
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
NTSTATUS WinFSPAdapter::GetVolumeInfo(FSP_FILE_SYSTEM* FileSystem, FSP_FSCTL_VOLUME_INFO* VolumeInfo)
{
std::cout << "Getting Volume Info" << std::endl;
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->GetVolumeInfo(VolumeInfo);
}
void WinFSPAdapter::Close(FSP_FILE_SYSTEM *FileSystem, PVOID FileContext0) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
fs->Close(FileContext0);
NTSTATUS WinFSPAdapter::Overwrite(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext, UINT32 FileAttributes,
BOOLEAN ReplaceFileAttributes, UINT64 AllocationSize,
FSP_FSCTL_FILE_INFO* FileInfo)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->Overwrite(FileContext, FileAttributes, ReplaceFileAttributes, AllocationSize, FileInfo);
}
NTSTATUS WinFSPAdapter::Create(FSP_FILE_SYSTEM *FileSystem, PWSTR FileName, UINT32 CreateOptions, UINT32 GrantedAccess, UINT32 FileAttributes, PSECURITY_DESCRIPTOR SecurityDescriptor, UINT64 AllocationSize, PVOID *PFileContext, FSP_FSCTL_FILE_INFO *FileInfo) {
return STATUS_NOT_IMPLEMENTED;
void WinFSPAdapter::Close(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
fs->Close(FileContext);
}
NTSTATUS WinFSPAdapter::ReadDirectory(FSP_FILE_SYSTEM *FileSystem, PVOID FileContext0, PWSTR Pattern, PWSTR Marker,
PVOID Buffer, ULONG BufferLength, PULONG PBytesTransferred) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
NTSTATUS WinFSPAdapter::Create(FSP_FILE_SYSTEM* FileSystem, PWSTR FileName, UINT32 CreateOptions,
UINT32 GrantedAccess, UINT32 FileAttributes, PSECURITY_DESCRIPTOR SecurityDescriptor,
UINT64 AllocationSize, PVOID* PFileContext, FSP_FSCTL_FILE_INFO* FileInfo)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->Create(FileName, CreateOptions,
GrantedAccess, FileAttributes, SecurityDescriptor,
AllocationSize, PFileContext, FileInfo);
}
VOID WinFSPAdapter::Cleanup(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext, PWSTR FileName, ULONG Flags)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
fs->Cleanup(FileContext, FileName, Flags);
}
NTSTATUS WinFSPAdapter::ReadDirectory(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext0, PWSTR Pattern, PWSTR Marker,
PVOID Buffer, ULONG BufferLength, PULONG PBytesTransferred)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->ReadDirectory(FileContext0, Pattern, Marker, Buffer, BufferLength, PBytesTransferred);
}
NTSTATUS WinFSPAdapter::GetDirInfoByName(FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext, PWSTR FileName,
FSP_FSCTL_DIR_INFO *DirInfo) {
return STATUS_NOT_IMPLEMENTED;
NTSTATUS WinFSPAdapter::GetDirInfoByName(FSP_FILE_SYSTEM* FileSystem,
PVOID FileContext, PWSTR FileName,
FSP_FSCTL_DIR_INFO* DirInfo)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->GetDirInfoByName(FileContext, FileName, DirInfo);
}
NTSTATUS WinFSPAdapter::GetSecurityByName(FSP_FILE_SYSTEM *FileSystem, PWSTR FileName, PUINT32 PFileAttributes,
NTSTATUS WinFSPAdapter::GetSecurityByName(FSP_FILE_SYSTEM* FileSystem, PWSTR FileName, PUINT32 PFileAttributes,
PSECURITY_DESCRIPTOR SecurityDescriptor,
SIZE_T *PSecurityDescriptorSize) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
SIZE_T* PSecurityDescriptorSize)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->GetSecurityByName(FileName, PFileAttributes, SecurityDescriptor, PSecurityDescriptorSize);
}
NTSTATUS WinFSPAdapter::SetVolumeLabel_(FSP_FILE_SYSTEM *FileSystem, PWSTR VolumeLabel,
FSP_FSCTL_VOLUME_INFO *VolumeInfo) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
NTSTATUS WinFSPAdapter::SetVolumeLabel_(FSP_FILE_SYSTEM* FileSystem, PWSTR VolumeLabel,
FSP_FSCTL_VOLUME_INFO* VolumeInfo)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->SetVolumeLabel_(VolumeLabel, VolumeInfo);
}
NTSTATUS WinFSPAdapter::Open(FSP_FILE_SYSTEM *FileSystem, PWSTR FileName, UINT32 CreateOptions,
UINT32 GrantedAccess, PVOID *PFileContext, FSP_FSCTL_FILE_INFO *FileInfo) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
NTSTATUS WinFSPAdapter::Open(FSP_FILE_SYSTEM* FileSystem, PWSTR FileName, UINT32 CreateOptions,
UINT32 GrantedAccess, PVOID* PFileContext, FSP_FSCTL_FILE_INFO* FileInfo)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->Open(FileName, CreateOptions, GrantedAccess, PFileContext, FileInfo);
}
NTSTATUS WinFSPAdapter::Read(FSP_FILE_SYSTEM *FileSystem, PVOID FileContext, PVOID Buffer, UINT64 Offset,
ULONG Length, PULONG PBytesTransferred) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
NTSTATUS WinFSPAdapter::Read(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext, PVOID Buffer, UINT64 Offset,
ULONG Length, PULONG PBytesTransferred)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->Read(FileContext, Buffer, Offset, Length, PBytesTransferred);
}
NTSTATUS WinFSPAdapter::GetFileInfo(FSP_FILE_SYSTEM *FileSystem, HANDLE Handle,
FSP_FSCTL_FILE_INFO *FileInfo) {
auto fs = static_cast<SeafileFileSystem *>(FileSystem->UserContext);
NTSTATUS WinFSPAdapter::GetFileInfo(FSP_FILE_SYSTEM* FileSystem, HANDLE Handle,
FSP_FSCTL_FILE_INFO* FileInfo)
{
const auto fs = static_cast<SeafileFileSystem*>(FileSystem->UserContext);
return fs->GetFileInfo(Handle, FileInfo);
}
NTSTATUS WinFSPAdapter::SetSecurity(FSP_FILE_SYSTEM *FileSystem, PVOID FileContext, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR ModificationDescriptor) {
NTSTATUS WinFSPAdapter::SetSecurity(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext,
SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR ModificationDescriptor)
{
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS WinFSPAdapter::GetSecurity(FSP_FILE_SYSTEM *FileSystem, PVOID FileContext, PSECURITY_DESCRIPTOR SecurityDescriptor, SIZE_T *PSecurityDescriptorSize) {
NTSTATUS WinFSPAdapter::GetSecurity(FSP_FILE_SYSTEM* FileSystem, PVOID FileContext,
PSECURITY_DESCRIPTOR SecurityDescriptor, SIZE_T* PSecurityDescriptorSize)
{
return STATUS_NOT_IMPLEMENTED;
}
}