Return an error if the volume is already closed
This commit is contained in:
parent
71eb2bdf7c
commit
b2ddf58e89
@ -11,7 +11,10 @@ import (
|
||||
|
||||
//export gcf_get_attrs
|
||||
func gcf_get_attrs(sessionID int, relPath string) (uint64, int64, bool) {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return 0, 0, false
|
||||
}
|
||||
dirfd, cName, err := volume.prepareAtSyscall(relPath)
|
||||
if err != nil {
|
||||
return 0, 0, false
|
||||
@ -32,7 +35,10 @@ func gcf_get_attrs(sessionID int, relPath string) (uint64, int64, bool) {
|
||||
// libgocryptfs: using Renameat instead of Renameat2 to support older kernels
|
||||
//export gcf_rename
|
||||
func gcf_rename(sessionID int, oldPath string, newPath string) bool {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
dirfd, cName, err := volume.prepareAtSyscall(oldPath)
|
||||
if err != nil {
|
||||
return false
|
||||
|
15
directory.go
15
directory.go
@ -40,7 +40,10 @@ func mkdirWithIv(dirfd int, cName string, mode uint32) error {
|
||||
|
||||
//export gcf_list_dir
|
||||
func gcf_list_dir(sessionID int, dirName string) (*C.char, *C.int, C.int) {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return nil, nil, 0
|
||||
}
|
||||
parentDirFd, cDirName, err := volume.prepareAtSyscallMyself(dirName)
|
||||
if err != nil {
|
||||
return nil, nil, 0
|
||||
@ -116,7 +119,10 @@ func gcf_list_dir(sessionID int, dirName string) (*C.char, *C.int, C.int) {
|
||||
|
||||
//export gcf_mkdir
|
||||
func gcf_mkdir(sessionID int, path string, mode uint32) bool {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
dirfd, cName, err := volume.prepareAtSyscall(path)
|
||||
if err != nil {
|
||||
return false
|
||||
@ -187,7 +193,10 @@ func gcf_mkdir(sessionID int, path string, mode uint32) bool {
|
||||
|
||||
//export gcf_rmdir
|
||||
func gcf_rmdir(sessionID int, relPath string) bool {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
parentDirFd, cName, err := volume.prepareAtSyscall(relPath)
|
||||
if err != nil {
|
||||
return false
|
||||
|
35
file.go
35
file.go
@ -369,7 +369,10 @@ func (volume *Volume) truncate(handleID int, newSize uint64) bool {
|
||||
|
||||
//export gcf_open_read_mode
|
||||
func gcf_open_read_mode(sessionID int, path string) int {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
dirfd, cName, err := volume.prepareAtSyscallMyself(path)
|
||||
if err != nil {
|
||||
return -1
|
||||
@ -386,7 +389,10 @@ func gcf_open_read_mode(sessionID int, path string) int {
|
||||
|
||||
//export gcf_open_write_mode
|
||||
func gcf_open_write_mode(sessionID int, path string, mode uint32) int {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
dirfd, cName, err := volume.prepareAtSyscall(path)
|
||||
if err != nil {
|
||||
return -1
|
||||
@ -419,7 +425,10 @@ func gcf_open_write_mode(sessionID int, path string, mode uint32) int {
|
||||
|
||||
//export gcf_truncate
|
||||
func gcf_truncate(sessionID int, handleID int, offset uint64) bool {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return volume.truncate(handleID, offset)
|
||||
}
|
||||
|
||||
@ -431,7 +440,10 @@ func gcf_read_file(sessionID, handleID int, offset uint64, dst_buff []byte) uint
|
||||
return 0
|
||||
}
|
||||
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
out, success := volume.doRead(handleID, dst_buff[:0], offset, uint64(length))
|
||||
if !success {
|
||||
return 0
|
||||
@ -448,14 +460,20 @@ func gcf_write_file(sessionID, handleID int, offset uint64, data []byte) uint32
|
||||
return 0
|
||||
}
|
||||
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
n, _ := volume.doWrite(handleID, data, offset)
|
||||
return n
|
||||
}
|
||||
|
||||
//export gcf_close_file
|
||||
func gcf_close_file(sessionID, handleID int) {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
f, ok := volume.file_handles[handleID]
|
||||
if ok {
|
||||
f.fd.Close()
|
||||
@ -469,7 +487,10 @@ func gcf_close_file(sessionID, handleID int) {
|
||||
|
||||
//export gcf_remove_file
|
||||
func gcf_remove_file(sessionID int, path string) bool {
|
||||
volume := OpenedVolumes[sessionID]
|
||||
volume, ok := OpenedVolumes[sessionID]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
dirfd, cName, err := volume.prepareAtSyscall(path)
|
||||
if err != nil {
|
||||
return false
|
||||
|
@ -117,7 +117,10 @@ func gcf_init(rootCipherDir string, password, givenScryptHash, returnedScryptHas
|
||||
|
||||
//export gcf_close
|
||||
func gcf_close(volumeID int) {
|
||||
volume := OpenedVolumes[volumeID]
|
||||
volume, ok := OpenedVolumes[volumeID]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
volume.cryptoCore.Wipe()
|
||||
for handleID := range volume.file_handles {
|
||||
gcf_close_file(volumeID, handleID)
|
||||
|
Loading…
Reference in New Issue
Block a user