1、接口实现
This commit is contained in:
1 parent
cc2fdef069
commit
500c927883
7 files changed
+316
-75
No files matched your search
@@ -4,13 +4,57 @@
|
||||
|
||||
#include "seafile/fs/seafile_file_system.hpp"
|
||||
|
||||
namespace seafile::fs
|
||||
{
|
||||
void SeafileFileSystem::auth(const std::string& username, const std::string& password)
|
||||
{
|
||||
if (const auto authToken = api.authToken(username, password); authToken.has_value())
|
||||
{
|
||||
namespace seafile::fs {
|
||||
void SeafileFileSystem::auth(const std::string &username, const std::string &password) {
|
||||
if (const auto authToken = api.authToken(username, password); authToken.has_value()) {
|
||||
this->token = authToken.value().token;
|
||||
}
|
||||
}
|
||||
|
||||
void SeafileFileSystem::Close(PVOID FileContext0) {
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::GetSecurityByName(PWSTR FileName, PUINT32 PFileAttributes,
|
||||
PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||
SIZE_T *PSecurityDescriptorSize) {
|
||||
*PFileAttributes = FILE_ATTRIBUTE_NORMAL;
|
||||
*PSecurityDescriptorSize = 0;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::GetVolumeInfo(FSP_FSCTL_VOLUME_INFO *VolumeInfo) {
|
||||
const auto userInfo = api.accountInfo(this->token, this->token_type);
|
||||
if (userInfo.has_value()) {
|
||||
const auto &info = userInfo.value();
|
||||
VolumeInfo->FreeSize = info.total - info.usage;
|
||||
VolumeInfo->TotalSize = info.total;
|
||||
wcscpy(VolumeInfo->VolumeLabel, L"Seafile");
|
||||
VolumeInfo->VolumeLabelLength = static_cast<UINT16>((wcslen(VolumeInfo->VolumeLabel) * sizeof(WCHAR)));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
return STATUS_END_OF_MEDIA;
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::Open(PWSTR FileName, UINT32 CreateOptions, UINT32 GrantedAccess, PVOID *PFileContext,
|
||||
FSP_FSCTL_FILE_INFO *FileInfo) {
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::Read(PVOID FileContext, PVOID Buffer, UINT64 Offset, ULONG Length, PULONG PBytesTransferred) {
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::ReadDirectory(PVOID FileContext0, PWSTR Pattern, PWSTR Marker, PVOID Buffer,
|
||||
ULONG BufferLength, PULONG PBytesTransferred) {
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::SetVolumeLabel_(PWSTR VolumeLabel, FSP_FSCTL_VOLUME_INFO *VolumeInfo) {
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS SeafileFileSystem::GetFileInfo(HANDLE Handle, FSP_FSCTL_FILE_INFO *FileInfo) {
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
#include "seafile/fs/winfsp_adapter.hpp"
|
||||
|
||||
#include "seafile/fs/seafile_file_system.hpp"
|
||||
//
|
||||
// Created by Shell on 2026/6/20.
|
||||
//
|
||||
#include "seafile/fs/winfsp_adapter.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace seafile::fs {
|
||||
namespace {
|
||||
FSP_FILE_SYSTEM_INTERFACE FsInterface = {
|
||||
.GetVolumeInfo = WinFSPAdapter::GetVolumeInfo,
|
||||
.SetVolumeLabel = WinFSPAdapter::SetVolumeLabel_,
|
||||
.GetSecurityByName = WinFSPAdapter::GetSecurityByName,
|
||||
.Create = WinFSPAdapter::Create,
|
||||
.Open = WinFSPAdapter::Open,
|
||||
.Close = WinFSPAdapter::Close,
|
||||
.Read = WinFSPAdapter::Read,
|
||||
.GetFileInfo = WinFSPAdapter::GetFileInfo,
|
||||
.GetSecurity = WinFSPAdapter::GetSecurity,
|
||||
.SetSecurity = WinFSPAdapter::SetSecurity,
|
||||
.ReadDirectory = WinFSPAdapter::ReadDirectory,
|
||||
|
||||
};
|
||||
std::unordered_map<FSP_FILE_SYSTEM *, SeafileFileSystem *> fstab;
|
||||
|
||||
}
|
||||
|
||||
NTSTATUS WinFSPAdapter::SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv) {
|
||||
DWORD LastError;
|
||||
FILETIME CreationTime;
|
||||
FSP_FSCTL_VOLUME_PARAMS VolumeParams = {};
|
||||
FSP_FILE_SYSTEM *FileSystem = nullptr;
|
||||
|
||||
GetSystemTimeAsFileTime(&CreationTime);
|
||||
|
||||
std::memset(&VolumeParams, 0, sizeof(VolumeParams));
|
||||
VolumeParams.SectorSize = 4096;
|
||||
VolumeParams.SectorsPerAllocationUnit = 1;
|
||||
VolumeParams.MaxComponentLength = 255;
|
||||
VolumeParams.VolumeCreationTime = reinterpret_cast<PLARGE_INTEGER>(&CreationTime)->QuadPart;
|
||||
VolumeParams.VolumeSerialNumber = 0;
|
||||
VolumeParams.FileInfoTimeout = 1000;
|
||||
VolumeParams.CaseSensitiveSearch = 0;
|
||||
VolumeParams.CasePreservedNames = 1;
|
||||
VolumeParams.UnicodeOnDisk = 1;
|
||||
VolumeParams.PersistentAcls = 1;
|
||||
VolumeParams.PostCleanupWhenModifiedOnly = 1; // (4)
|
||||
VolumeParams.UmFileContextIsUserContext2 = 1; // (4)
|
||||
VolumeParams.ReadOnlyVolume = 1;
|
||||
wcscpy_s(VolumeParams.FileSystemName, sizeof VolumeParams.FileSystemName / sizeof(WCHAR),
|
||||
L"SeafileFS");
|
||||
NTSTATUS Result = FspFileSystemCreate(
|
||||
const_cast<PWSTR>(L"" FSP_FSCTL_DISK_DEVICE_NAME),
|
||||
&VolumeParams,
|
||||
&FsInterface,
|
||||
&FileSystem);
|
||||
|
||||
if (!NT_SUCCESS(Result)) {
|
||||
return Result;
|
||||
}
|
||||
const 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()));
|
||||
|
||||
LastError = GetLastError();
|
||||
std::cout << LastError << std::endl;
|
||||
|
||||
if (!NT_SUCCESS(Result)) {
|
||||
FspFileSystemDelete(FileSystem);
|
||||
fstab.erase(FileSystem);
|
||||
|
||||
delete seafile_file_system;
|
||||
return Result;
|
||||
}
|
||||
|
||||
Result = FspFileSystemStartDispatcher(FileSystem, 0);
|
||||
|
||||
if (!NT_SUCCESS(Result)) {
|
||||
FspFileSystemDelete(FileSystem);
|
||||
fstab.erase(FileSystem);
|
||||
|
||||
delete seafile_file_system;
|
||||
}
|
||||
FspFileSystemSetDebugLog(
|
||||
FileSystem,
|
||||
TRUE);
|
||||
std::cout << Result << std::endl;
|
||||
|
||||
FSP_FSCTL_VOLUME_INFO volumeInfo{};
|
||||
auto status = GetVolumeInfo(FileSystem, &volumeInfo);
|
||||
|
||||
std::cout << "GetVolumeInfo direct call = "
|
||||
<< std::hex << status
|
||||
<< std::endl;
|
||||
return Result;
|
||||
}
|
||||
|
||||
NTSTATUS WinFSPAdapter::SvcStop(FSP_SERVICE *Service) {
|
||||
for (auto &[fileSystem, seafileFs]: fstab) {
|
||||
FspFileSystemStopDispatcher(fileSystem);
|
||||
fileSystem->UserContext = nullptr;
|
||||
FspFileSystemDelete(fileSystem);
|
||||
delete seafileFs;
|
||||
}
|
||||
|
||||
fstab.clear();
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS WinFSPAdapter::GetVolumeInfo(FSP_FILE_SYSTEM *FileSystem, FSP_FSCTL_VOLUME_INFO *VolumeInfo) {
|
||||
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::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;
|
||||
}
|
||||
|
||||
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);
|
||||
return fs->ReadDirectory(FileContext0, Pattern, Marker, Buffer, BufferLength, PBytesTransferred);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS WinFSPAdapter::GetSecurityByName(FSP_FILE_SYSTEM *FileSystem, PWSTR FileName, PUINT32 PFileAttributes,
|
||||
PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||
SIZE_T *PSecurityDescriptorSize) {
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
return fs->GetFileInfo(Handle, FileInfo);
|
||||
}
|
||||
|
||||
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) {
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user