Skip to content

Commit

Permalink
started wrapping cloud file api
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsgrill committed Aug 5, 2024
1 parent 5e6a8b2 commit f1e97a1
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bindings/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"syscall"
"time"

"github.com/balazsgrill/potatodrive/filesystem"
"github.com/balazsgrill/potatodrive/win/projfs/filesystem"
"github.com/spf13/afero"
"golang.org/x/sys/windows/registry"
)
Expand Down
91 changes: 91 additions & 0 deletions win/cfapi/functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//go:build windows

package cfapi

import (
"syscall"
"unsafe"
)

var (
cldapilib = syscall.NewLazyDLL("cldapi.dll")
cfCloseHandle = cldapilib.NewProc("CfCloseHandle")
cfConnectSyncRoot = cldapilib.NewProc("CfConnectSyncRoot")
cfConvertToPlaceholder = cldapilib.NewProc("CfConvertToPlaceholder")
cfCreatePlaceholders = cldapilib.NewProc("CfCreatePlaceholders")
cfDisconnectSyncRoot = cldapilib.NewProc("CfDisconnectSyncRoot")
cfExecute = cldapilib.NewProc("CfExecute")
cfGetCorrelationVector = cldapilib.NewProc("CfGetCorrelationVector")
cfGetPlaceholderInfo = cldapilib.NewProc("CfGetPlaceholderInfo")
cfGetPlaceholderRangeInfo = cldapilib.NewProc("CfGetPlaceholderRangeInfo")
cfGetPlaceholderRangeInfoForHydration = cldapilib.NewProc("CfGetPlaceholderRangeInfoForHydration")
cfGetPlaceholderStateFromAttributeTag = cldapilib.NewProc("CfGetPlaceholderStateFromAttributeTag")
cfGetPlaceholderStateFromFileInfo = cldapilib.NewProc("CfGetPlaceholderStateFromFileInfo")
cfGetPlaceholderStateFromFindData = cldapilib.NewProc("CfGetPlaceholderStateFromFindData")
cfGetPlatformInfo = cldapilib.NewProc("CfGetPlatformInfo")
cfGetSyncRootInfoByHandle = cldapilib.NewProc("CfGetSyncRootInfoByHandle")
cfGetSyncRootInfoByPath = cldapilib.NewProc("CfGetSyncRootInfoByPath")
cfGetTransferKey = cldapilib.NewProc("CfGetTransferKey")
cfGetWin32HandleFromProtectedHandle = cldapilib.NewProc("CfGetWin32HandleFromProtectedHandle")
cfHydratePlaceholder = cldapilib.NewProc("CfHydratePlaceholder")
cfOpenFileWithOplock = cldapilib.NewProc("CfOpenFileWithOplock")
cfQuerySyncProviderStatus = cldapilib.NewProc("CfQuerySyncProviderStatus")
cfReferenceProtectedHandle = cldapilib.NewProc("CfReferenceProtectedHandle")
cfRegisterSyncRoot = cldapilib.NewProc("CfRegisterSyncRoot")
cfReleaseProtectedHandle = cldapilib.NewProc("CfReleaseProtectedHandle")
cfReleaseTransferKey = cldapilib.NewProc("CfReleaseTransferKey")
cfReportProviderProgress = cldapilib.NewProc("CfReportProviderProgress")
cfReportProviderProgress2 = cldapilib.NewProc("CfReportProviderProgress2")
cfReportSyncStatus = cldapilib.NewProc("CfReportSyncStatus")
cfRevertPlaceholder = cldapilib.NewProc("CfRevertPlaceholder")
cfSetCorrelationVector = cldapilib.NewProc("CfSetCorrelationVector")
cfSetInSyncState = cldapilib.NewProc("CfSetInSyncState")
cfSetPinState = cldapilib.NewProc("CfSetPinState")
cfUnregisterSyncRoot = cldapilib.NewProc("CfUnregisterSyncRoot")
cfUpdatePlaceholder = cldapilib.NewProc("CfUpdatePlaceholder")
cfUpdateSyncProviderStatus = cldapilib.NewProc("CfUpdateSyncProviderStatus")
)

func CfCloseHandle(Handle syscall.Handle) uintptr {
ret, _, _ := cfCloseHandle.Call(uintptr(Handle))
return ret
}
func CfConnectSyncRoot(SyncRootPath uintptr, CallbackTable []CF_CALLBACK_REGISTRATION, CallbackContext uintptr, ConnectFlags CF_CONNECT_FLAGS, ConnectionKey *CF_CONNECTION_KEY) uintptr {
ret, _, _ := cfConnectSyncRoot.Call(SyncRootPath, uintptr(unsafe.Pointer(&CallbackTable[0])), CallbackContext, uintptr(ConnectFlags), uintptr(unsafe.Pointer(ConnectionKey)))
return ret
}

func CfRegisterSyncRoot(SyncRootPath uintptr, Registration *CF_SYNC_REGISTRATION, Policies *CF_SYNC_POLICIES, RegisterFlags CF_REGISTER_FLAGS) uintptr {
ret, _, _ := cfRegisterSyncRoot.Call(SyncRootPath, uintptr(unsafe.Pointer(Registration)), uintptr(unsafe.Pointer(Policies)), uintptr(RegisterFlags))
return ret
}

func CfConvertToPlaceholder(FileHandle syscall.Handle, FileIdentity uintptr, FileIdentityLength uint32, ConvertFlags CF_CONVERT_FLAGS, ConvertUsn uintptr, Overlapped uintptr) uintptr {
ret, _, _ := cfConvertToPlaceholder.Call(uintptr(FileHandle), FileIdentity, uintptr(FileIdentityLength), uintptr(ConvertFlags), ConvertUsn, Overlapped)
return ret
}

func CfCreatePlaceholders(BaseDirectoryPath uintptr, PlaceholderArray []CF_PLACEHOLDER_CREATE_INFO, PlaceholderCount uint32, CreateFlags CF_CREATE_FLAGS, EntriesProcessed *uint32) uintptr {
ret, _, _ := cfCreatePlaceholders.Call(BaseDirectoryPath, uintptr(unsafe.Pointer(&PlaceholderArray[0])), uintptr(PlaceholderCount), uintptr(CreateFlags), uintptr(unsafe.Pointer(EntriesProcessed)))
return ret
}

func CfDisconnectSyncRoot(ConnectionKey CF_CONNECTION_KEY) uintptr {
ret, _, _ := cfDisconnectSyncRoot.Call(uintptr(ConnectionKey))
return ret
}

func CfExecute(OpInfo *CF_OPERATION_INFO, OpParams uintptr) uintptr {
ret, _, _ := cfExecute.Call(uintptr(unsafe.Pointer(OpInfo)), OpParams)
return ret
}

func CfGetCorrelationVector(FileHandle syscall.Handle, CorrelationVector *CorrelationVector) uintptr {
ret, _, _ := cfGetCorrelationVector.Call(uintptr(unsafe.Pointer(CorrelationVector)))
return ret
}

func CfGetPlaceholderInfo(FileHandle syscall.Handle, InfoClass CF_PLACEHOLDER_INFO_CLASS, InfoBuffer uintptr, InfoBufferLength uint32, ReturnedLength *uint32) uintptr {
ret, _, _ := cfGetPlaceholderInfo.Call(uintptr(FileHandle), uintptr(InfoClass), InfoBuffer, uintptr(InfoBufferLength), uintptr(unsafe.Pointer(ReturnedLength)))
return ret
}
Loading

0 comments on commit f1e97a1

Please sign in to comment.