-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FS implementation based on Cloud File API
- Loading branch information
1 parent
f1e97a1
commit 53d8e8f
Showing
19 changed files
with
1,922 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package cfapi | ||
|
||
import "syscall" | ||
import "C" | ||
|
||
type Callback_FetchData func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_FetchData) uintptr | ||
type Callback_ValidateData func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_ValidateData) uintptr | ||
type Callback_CancelFetchData func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_Cancel) uintptr | ||
type Callback_FetchPlaceholders func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_FetchPlaceholders) uintptr | ||
type Callback_CancelFetchPlaceholders func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_Cancel) uintptr | ||
type Callback_OpenCompletion func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_OpenCompletion) uintptr | ||
type Callback_CloseCompletion func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_CloseCompletion) uintptr | ||
type Callback_Dehydrate func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_Dehydrate) uintptr | ||
type Callback_DehydrateCompletion func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_DehydrateCompletion) uintptr | ||
type Callback_Delete func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_Delete) uintptr | ||
type Callback_DeleteCompletion func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_DeleteCompletion) uintptr | ||
type Callback_Rename func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_Rename) uintptr | ||
type Callback_RenameCompletion func(*CF_CALLBACK_INFO, *CF_CALLBACK_PARAMETERS_RenameCompletion) uintptr | ||
|
||
type Callbacks struct { | ||
FetchData Callback_FetchData | ||
ValidateData Callback_ValidateData | ||
CancelFetchData Callback_CancelFetchData | ||
FetchPlaceholders Callback_FetchPlaceholders | ||
CancelFetchPlaceholders Callback_CancelFetchPlaceholders | ||
OpenCompletion Callback_OpenCompletion | ||
CloseCompletion Callback_CloseCompletion | ||
Dehydrate Callback_Dehydrate | ||
DehydrateCompletion Callback_DehydrateCompletion | ||
Delete Callback_Delete | ||
DeleteCompletion Callback_DeleteCompletion | ||
Rename Callback_Rename | ||
RenameCompletion Callback_RenameCompletion | ||
} | ||
|
||
func (cb *Callbacks) CreateCallbackTable() []CF_CALLBACK_REGISTRATION { | ||
result := make([]CF_CALLBACK_REGISTRATION, 14) | ||
count := 0 | ||
if cb.FetchData != nil { | ||
result[count].Callback = syscall.NewCallback(cb.FetchData) | ||
result[count].Type = CF_CALLBACK_TYPE_FETCH_DATA | ||
count++ | ||
} | ||
if cb.ValidateData != nil { | ||
result[count].Callback = syscall.NewCallback(cb.ValidateData) | ||
result[count].Type = CF_CALLBACK_TYPE_VALIDATE_DATA | ||
count++ | ||
} | ||
if cb.CancelFetchData != nil { | ||
result[count].Callback = syscall.NewCallback(cb.CancelFetchData) | ||
result[count].Type = CF_CALLBACK_TYPE_CANCEL_FETCH_DATA | ||
count++ | ||
} | ||
if cb.FetchPlaceholders != nil { | ||
result[count].Callback = syscall.NewCallback(cb.FetchPlaceholders) | ||
result[count].Type = CF_CALLBACK_TYPE_FETCH_PLACEHOLDERS | ||
count++ | ||
} | ||
if cb.CancelFetchPlaceholders != nil { | ||
result[count].Callback = syscall.NewCallback(cb.CancelFetchPlaceholders) | ||
result[count].Type = CF_CALLBACK_TYPE_CANCEL_FETCH_PLACEHOLDERS | ||
count++ | ||
} | ||
if cb.OpenCompletion != nil { | ||
result[count].Callback = syscall.NewCallback(cb.OpenCompletion) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_FILE_OPEN_COMPLETION | ||
count++ | ||
} | ||
if cb.CloseCompletion != nil { | ||
result[count].Callback = syscall.NewCallback(cb.CloseCompletion) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_FILE_CLOSE_COMPLETION | ||
count++ | ||
} | ||
if cb.Dehydrate != nil { | ||
result[count].Callback = syscall.NewCallback(cb.Dehydrate) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_DEHYDRATE | ||
count++ | ||
} | ||
if cb.DehydrateCompletion != nil { | ||
result[count].Callback = syscall.NewCallback(cb.DehydrateCompletion) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_DEHYDRATE_COMPLETION | ||
count++ | ||
} | ||
if cb.Delete != nil { | ||
result[count].Callback = syscall.NewCallback(cb.Delete) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_DELETE | ||
count++ | ||
} | ||
if cb.DeleteCompletion != nil { | ||
result[count].Callback = syscall.NewCallback(cb.DeleteCompletion) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_DELETE_COMPLETION | ||
count++ | ||
} | ||
if cb.Rename != nil { | ||
result[count].Callback = syscall.NewCallback(cb.Rename) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_RENAME | ||
count++ | ||
} | ||
if cb.RenameCompletion != nil { | ||
result[count].Callback = syscall.NewCallback(cb.RenameCompletion) | ||
result[count].Type = CF_CALLBACK_TYPE_NOTIFY_RENAME_COMPLETION | ||
count++ | ||
} | ||
result[count].Type = CF_CALLBACK_TYPE_NONE | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cfapi_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/balazsgrill/potatodrive/win/cfapi" | ||
) | ||
|
||
func Test_PlatformVersion(t *testing.T) { | ||
var platforminfo cfapi.CF_PLATFORM_INFO | ||
hr := cfapi.CfGetPlatformInfo(&platforminfo) | ||
if hr != 0 { | ||
t.Fatal(hr) | ||
} | ||
t.Logf("platform version: b%d i%d, r%d", platforminfo.BuildNumber, platforminfo.IntegrationNumber, platforminfo.RevisionNumber) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package filesystem | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"syscall" | ||
"unsafe" | ||
|
||
"github.com/balazsgrill/potatodrive/win" | ||
"github.com/balazsgrill/potatodrive/win/cfapi" | ||
) | ||
|
||
func (instance *VirtualizationInstance) callback_getRemoteFilePath(info *cfapi.CF_CALLBACK_INFO) string { | ||
return instance.path_localToRemote(win.GetString(info.VolumeDosName) + win.GetString(info.NormalizedPath)) | ||
} | ||
|
||
func (instance *VirtualizationInstance) fetchData(info *cfapi.CF_CALLBACK_INFO, data *cfapi.CF_CALLBACK_PARAMETERS_FetchData) uintptr { | ||
instance.lock.Lock() | ||
defer instance.lock.Unlock() | ||
filename := instance.callback_getRemoteFilePath(info) | ||
length := data.RequiredLength | ||
byteOffset := data.RequiredFileOffset | ||
if length == 0 || length < 0 { | ||
length = info.FileSize | ||
} | ||
if data.OptionalLength > data.RequiredLength { | ||
length = data.OptionalLength | ||
byteOffset = data.OptionalFileOffset | ||
} | ||
log.Printf("Fetch data: %s %d bytes at %d", filename, length, byteOffset) | ||
log.Printf("Optional %d at %d", data.OptionalLength, data.OptionalFileOffset) | ||
file, err := instance.fs.Open(filename) | ||
if err != nil { | ||
log.Printf("Error opening file %s: %s", filename, err) | ||
return uintptr(syscall.EIO) | ||
} | ||
defer file.Close() | ||
buffer := make([]byte, length) | ||
|
||
var n int | ||
var count int64 | ||
for count < length { | ||
n, err = file.ReadAt(buffer[count:], byteOffset+count) | ||
count += int64(n) | ||
if err == io.EOF { | ||
err = nil | ||
break | ||
} | ||
} | ||
|
||
log.Printf("Read %d bytes", count) | ||
if err != nil { | ||
log.Printf("Error reading file %s: %s", filename, err) | ||
return uintptr(syscall.EIO) | ||
} | ||
|
||
var transfer cfapi.CF_OPERATION_PARAMETERS_TransferData | ||
transfer.Buffer = uintptr(unsafe.Pointer(&buffer[0])) | ||
transfer.Length = count | ||
transfer.Offset = byteOffset | ||
transfer.ParamSize = uint32(unsafe.Sizeof(transfer)) | ||
transfer.Flags = cfapi.CF_OPERATION_TRANSFER_DATA_FLAG_NONE | ||
hr := instance.transferData(info, &transfer) | ||
if hr != 0 { | ||
log.Printf("Error transferring data: %s", win.ErrorByCode(hr)) | ||
return hr | ||
} | ||
return 0 | ||
} |
Oops, something went wrong.