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
|
//export gcf_get_attrs
|
||||||
func gcf_get_attrs(sessionID int, relPath string) (uint64, int64, bool) {
|
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)
|
dirfd, cName, err := volume.prepareAtSyscall(relPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, false
|
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
|
// libgocryptfs: using Renameat instead of Renameat2 to support older kernels
|
||||||
//export gcf_rename
|
//export gcf_rename
|
||||||
func gcf_rename(sessionID int, oldPath string, newPath string) bool {
|
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)
|
dirfd, cName, err := volume.prepareAtSyscall(oldPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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
|
//export gcf_list_dir
|
||||||
func gcf_list_dir(sessionID int, dirName string) (*C.char, *C.int, C.int) {
|
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)
|
parentDirFd, cDirName, err := volume.prepareAtSyscallMyself(dirName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, 0
|
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
|
//export gcf_mkdir
|
||||||
func gcf_mkdir(sessionID int, path string, mode uint32) bool {
|
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)
|
dirfd, cName, err := volume.prepareAtSyscall(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -187,7 +193,10 @@ func gcf_mkdir(sessionID int, path string, mode uint32) bool {
|
|||||||
|
|
||||||
//export gcf_rmdir
|
//export gcf_rmdir
|
||||||
func gcf_rmdir(sessionID int, relPath string) bool {
|
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)
|
parentDirFd, cName, err := volume.prepareAtSyscall(relPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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
|
//export gcf_open_read_mode
|
||||||
func gcf_open_read_mode(sessionID int, path string) int {
|
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)
|
dirfd, cName, err := volume.prepareAtSyscallMyself(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1
|
return -1
|
||||||
@ -386,7 +389,10 @@ func gcf_open_read_mode(sessionID int, path string) int {
|
|||||||
|
|
||||||
//export gcf_open_write_mode
|
//export gcf_open_write_mode
|
||||||
func gcf_open_write_mode(sessionID int, path string, mode uint32) int {
|
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)
|
dirfd, cName, err := volume.prepareAtSyscall(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1
|
return -1
|
||||||
@ -419,7 +425,10 @@ func gcf_open_write_mode(sessionID int, path string, mode uint32) int {
|
|||||||
|
|
||||||
//export gcf_truncate
|
//export gcf_truncate
|
||||||
func gcf_truncate(sessionID int, handleID int, offset uint64) bool {
|
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)
|
return volume.truncate(handleID, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,7 +440,10 @@ func gcf_read_file(sessionID, handleID int, offset uint64, dst_buff []byte) uint
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
volume := OpenedVolumes[sessionID]
|
volume, ok := OpenedVolumes[sessionID]
|
||||||
|
if !ok {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
out, success := volume.doRead(handleID, dst_buff[:0], offset, uint64(length))
|
out, success := volume.doRead(handleID, dst_buff[:0], offset, uint64(length))
|
||||||
if !success {
|
if !success {
|
||||||
return 0
|
return 0
|
||||||
@ -448,14 +460,20 @@ func gcf_write_file(sessionID, handleID int, offset uint64, data []byte) uint32
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
volume := OpenedVolumes[sessionID]
|
volume, ok := OpenedVolumes[sessionID]
|
||||||
|
if !ok {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
n, _ := volume.doWrite(handleID, data, offset)
|
n, _ := volume.doWrite(handleID, data, offset)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gcf_close_file
|
//export gcf_close_file
|
||||||
func gcf_close_file(sessionID, handleID int) {
|
func gcf_close_file(sessionID, handleID int) {
|
||||||
volume := OpenedVolumes[sessionID]
|
volume, ok := OpenedVolumes[sessionID]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
f, ok := volume.file_handles[handleID]
|
f, ok := volume.file_handles[handleID]
|
||||||
if ok {
|
if ok {
|
||||||
f.fd.Close()
|
f.fd.Close()
|
||||||
@ -469,7 +487,10 @@ func gcf_close_file(sessionID, handleID int) {
|
|||||||
|
|
||||||
//export gcf_remove_file
|
//export gcf_remove_file
|
||||||
func gcf_remove_file(sessionID int, path string) bool {
|
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)
|
dirfd, cName, err := volume.prepareAtSyscall(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
@ -117,7 +117,10 @@ func gcf_init(rootCipherDir string, password, givenScryptHash, returnedScryptHas
|
|||||||
|
|
||||||
//export gcf_close
|
//export gcf_close
|
||||||
func gcf_close(volumeID int) {
|
func gcf_close(volumeID int) {
|
||||||
volume := OpenedVolumes[volumeID]
|
volume, ok := OpenedVolumes[volumeID]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
volume.cryptoCore.Wipe()
|
volume.cryptoCore.Wipe()
|
||||||
for handleID := range volume.file_handles {
|
for handleID := range volume.file_handles {
|
||||||
gcf_close_file(volumeID, handleID)
|
gcf_close_file(volumeID, handleID)
|
||||||
|
Loading…
Reference in New Issue
Block a user