Browse Source

Finalized File System abstraction, broke zip handler

Toby Chui 3 years ago
parent
commit
d6c8350936

+ 11 - 11
file_system.go

@@ -27,7 +27,7 @@ import (
 	"imuslab.com/arozos/mod/common"
 	"imuslab.com/arozos/mod/compatibility"
 	"imuslab.com/arozos/mod/filesystem"
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 	fsp "imuslab.com/arozos/mod/filesystem/fspermission"
 	"imuslab.com/arozos/mod/filesystem/fuzzy"
 	hidden "imuslab.com/arozos/mod/filesystem/hidden"
@@ -591,7 +591,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 
 	//Merge the file. Merge file location must be on local machine
 	mergeFileLocation := decodedUploadLocation
-	var out *os.File
+	var out arozfs.File
 	if fsh.RequireBuffer {
 		//The merge file location must be local buffer
 		mergeFileLocation = getFsBufferFilepath(decodedUploadLocation, false)
@@ -611,7 +611,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 	}
 
 	for _, filesrc := range chunkName {
-		var srcChunkReader *os.File
+		var srcChunkReader arozfs.File
 		if isHugeFile {
 			srcChunkReader, err = fshAbs.Open(filesrc)
 		} else {
@@ -803,10 +803,10 @@ func system_fs_handleUpload(w http.ResponseWriter, r *http.Request) {
 
 	//Check if the upload target is read only.
 	accmode := userinfo.GetPathAccessPermission(uploadTarget)
-	if accmode == fsdef.FsReadOnly {
+	if accmode == arozfs.FsReadOnly {
 		common.SendErrorResponse(w, "The upload target is Read Only.")
 		return
-	} else if accmode == fsdef.FsDenied {
+	} else if accmode == arozfs.FsDenied {
 		common.SendErrorResponse(w, "Access Denied")
 		return
 	}
@@ -1246,10 +1246,10 @@ func system_fs_handleNewObjects(w http.ResponseWriter, r *http.Request) {
 
 		//Check if directory is readonly
 		accmode := userinfo.GetPathAccessPermission(vsrc)
-		if accmode == fsdef.FsReadOnly {
+		if accmode == arozfs.FsReadOnly {
 			common.SendErrorResponse(w, "This directory is Read Only")
 			return
-		} else if accmode == fsdef.FsDenied {
+		} else if accmode == arozfs.FsDenied {
 			common.SendErrorResponse(w, "Access Denied")
 			return
 		}
@@ -1841,10 +1841,10 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 
 				//Check if the target dir is not readonly
 				accmode := userinfo.GetPathAccessPermission(string(vsrcFile))
-				if accmode == fsdef.FsReadOnly {
+				if accmode == arozfs.FsReadOnly {
 					common.SendErrorResponse(w, "This directory is Read Only")
 					return
-				} else if accmode == fsdef.FsDenied {
+				} else if accmode == arozfs.FsDenied {
 					common.SendErrorResponse(w, "Access Denied")
 					return
 				}
@@ -1893,10 +1893,10 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 
 				//Check if the source file is read only.
 				accmode := userinfo.GetPathAccessPermission(string(vsrcFile))
-				if accmode == fsdef.FsReadOnly {
+				if accmode == arozfs.FsReadOnly {
 					common.SendErrorResponse(w, "This source file is Read Only")
 					return
-				} else if accmode == fsdef.FsDenied {
+				} else if accmode == arozfs.FsDenied {
 					common.SendErrorResponse(w, "Access Denied")
 					return
 				}

+ 25 - 25
mod/filesystem/abstractions/emptyfs/emptyfs.go

@@ -6,7 +6,7 @@ import (
 	"path/filepath"
 	"time"
 
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 /*
@@ -24,43 +24,43 @@ func NewEmptyFileSystemAbstraction() EmptyFileSystemAbstraction {
 }
 
 func (l EmptyFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Chown(filename string, uid int, gid int) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
-func (l EmptyFileSystemAbstraction) Create(filename string) (*os.File, error) {
-	return nil, fsdef.ErrNullOperation
+func (l EmptyFileSystemAbstraction) Create(filename string) (arozfs.File, error) {
+	return nil, arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) MkdirAll(filename string, mode os.FileMode) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Name() string {
 	return ""
 }
-func (l EmptyFileSystemAbstraction) Open(filename string) (*os.File, error) {
-	return nil, fsdef.ErrNullOperation
+func (l EmptyFileSystemAbstraction) Open(filename string) (arozfs.File, error) {
+	return nil, arozfs.ErrNullOperation
 }
-func (l EmptyFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
-	return nil, fsdef.ErrNullOperation
+func (l EmptyFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (arozfs.File, error) {
+	return nil, arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Remove(filename string) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) RemoveAll(path string) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Rename(oldname, newname string) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Stat(filename string) (os.FileInfo, error) {
-	return nil, fsdef.ErrNullOperation
+	return nil, arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) Close() error {
 	return nil
@@ -71,11 +71,11 @@ func (l EmptyFileSystemAbstraction) Close() error {
 */
 
 func (l EmptyFileSystemAbstraction) VirtualPathToRealPath(subpath string, username string) (string, error) {
-	return "", fsdef.ErrVpathResolveFailed
+	return "", arozfs.ErrVpathResolveFailed
 }
 
 func (l EmptyFileSystemAbstraction) RealPathToVirtualPath(fullpath string, username string) (string, error) {
-	return "", fsdef.ErrRpathResolveFailed
+	return "", arozfs.ErrRpathResolveFailed
 }
 
 func (l EmptyFileSystemAbstraction) FileExists(realpath string) bool {
@@ -87,7 +87,7 @@ func (l EmptyFileSystemAbstraction) IsDir(realpath string) bool {
 }
 
 func (l EmptyFileSystemAbstraction) Glob(realpathWildcard string) ([]string, error) {
-	return []string{}, fsdef.ErrNullOperation
+	return []string{}, arozfs.ErrNullOperation
 }
 
 func (l EmptyFileSystemAbstraction) GetFileSize(realpath string) int64 {
@@ -95,22 +95,22 @@ func (l EmptyFileSystemAbstraction) GetFileSize(realpath string) int64 {
 }
 
 func (l EmptyFileSystemAbstraction) GetModTime(realpath string) (int64, error) {
-	return 0, fsdef.ErrOperationNotSupported
+	return 0, arozfs.ErrOperationNotSupported
 }
 
 func (l EmptyFileSystemAbstraction) WriteFile(filename string, content []byte, mode os.FileMode) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) ReadFile(filename string) ([]byte, error) {
-	return []byte(""), fsdef.ErrOperationNotSupported
+	return []byte(""), arozfs.ErrOperationNotSupported
 }
 func (l EmptyFileSystemAbstraction) WriteStream(filename string, stream io.Reader, mode os.FileMode) error {
-	return fsdef.ErrNullOperation
+	return arozfs.ErrNullOperation
 }
 func (l EmptyFileSystemAbstraction) ReadStream(filename string) (io.ReadCloser, error) {
-	return nil, fsdef.ErrOperationNotSupported
+	return nil, arozfs.ErrOperationNotSupported
 }
 
 func (l EmptyFileSystemAbstraction) Walk(root string, walkFn filepath.WalkFunc) error {
-	return fsdef.ErrOperationNotSupported
+	return arozfs.ErrOperationNotSupported
 }

+ 6 - 6
mod/filesystem/abstractions/localfs/localfs.go

@@ -8,7 +8,7 @@ import (
 	"time"
 
 	"imuslab.com/arozos/mod/common"
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 /*
@@ -43,7 +43,7 @@ func (l LocalFileSystemAbstraction) Chown(filename string, uid int, gid int) err
 func (l LocalFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
 	return os.Chtimes(filename, atime, mtime)
 }
-func (l LocalFileSystemAbstraction) Create(filename string) (*os.File, error) {
+func (l LocalFileSystemAbstraction) Create(filename string) (arozfs.File, error) {
 	return os.Create(filename)
 }
 func (l LocalFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
@@ -55,10 +55,10 @@ func (l LocalFileSystemAbstraction) MkdirAll(filename string, mode os.FileMode)
 func (l LocalFileSystemAbstraction) Name() string {
 	return ""
 }
-func (l LocalFileSystemAbstraction) Open(filename string) (*os.File, error) {
+func (l LocalFileSystemAbstraction) Open(filename string) (arozfs.File, error) {
 	return os.Open(filename)
 }
-func (l LocalFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
+func (l LocalFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (arozfs.File, error) {
 	return os.OpenFile(filename, flag, perm)
 }
 func (l LocalFileSystemAbstraction) Remove(filename string) error {
@@ -93,7 +93,7 @@ func (l LocalFileSystemAbstraction) VirtualPathToRealPath(subpath string, userna
 	} else if l.Hierarchy == "public" {
 		return filepath.ToSlash(filepath.Join(l.Rootpath, subpath)), nil
 	}
-	return "", fsdef.ErrVpathResolveFailed
+	return "", arozfs.ErrVpathResolveFailed
 }
 
 func (l LocalFileSystemAbstraction) RealPathToVirtualPath(fullpath string, username string) (string, error) {
@@ -152,7 +152,7 @@ func (l LocalFileSystemAbstraction) RealPathToVirtualPath(fullpath string, usern
 	*/
 	fullpath = filepath.ToSlash(fullpath)
 	if strings.HasPrefix(fullpath, l.UUID+":") && !common.FileExists(fullpath) {
-		return "", fsdef.ErrRpathResolveFailed
+		return "", arozfs.ErrRpathResolveFailed
 	}
 	prefix := filepath.ToSlash(filepath.Join(l.Rootpath, "users", username))
 	if l.Hierarchy == "public" {

+ 83 - 0
mod/filesystem/abstractions/smbfs/smbFileWrapper.go

@@ -0,0 +1,83 @@
+package smbfs
+
+import (
+	"io"
+	"io/fs"
+	"os"
+
+	"github.com/hirochachacha/go-smb2"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
+)
+
+type smbfsFile struct {
+	file *smb2.File
+}
+
+func NewSmbFsFile(wrappingFile *smb2.File) *smbfsFile {
+	return &smbfsFile{
+		file: wrappingFile,
+	}
+}
+
+func (f *smbfsFile) Chdir() error {
+	return arozfs.ErrOperationNotSupported
+}
+func (f *smbfsFile) Chmod(mode os.FileMode) error {
+	return arozfs.ErrOperationNotSupported
+}
+func (f *smbfsFile) Chown(uid, gid int) error {
+	return arozfs.ErrOperationNotSupported
+}
+func (f *smbfsFile) Close() error {
+	return f.file.Close()
+}
+func (f *smbfsFile) Name() string {
+	return f.file.Name()
+}
+func (f *smbfsFile) Read(b []byte) (n int, err error) {
+	return f.file.Read(b)
+}
+func (f *smbfsFile) ReadAt(b []byte, off int64) (n int, err error) {
+	return f.file.ReadAt(b, off)
+}
+func (f *smbfsFile) ReadDir(n int) ([]fs.DirEntry, error) {
+	return []fs.DirEntry{}, arozfs.ErrOperationNotSupported
+}
+func (f *smbfsFile) Readdirnames(n int) (names []string, err error) {
+	fi, err := f.file.Readdir(n)
+	if err != nil {
+		return []string{}, err
+	}
+	names = []string{}
+	for _, i := range fi {
+		names = append(names, i.Name())
+	}
+	return names, nil
+}
+func (f *smbfsFile) ReadFrom(r io.Reader) (n int64, err error) {
+	return f.file.ReadFrom(r)
+}
+func (f *smbfsFile) Readdir(n int) ([]fs.FileInfo, error) {
+	return f.file.Readdir(n)
+}
+func (f *smbfsFile) Seek(offset int64, whence int) (ret int64, err error) {
+	return f.file.Seek(offset, whence)
+}
+func (f *smbfsFile) Stat() (fs.FileInfo, error) {
+	return f.file.Stat()
+}
+func (f *smbfsFile) Sync() error {
+	return f.file.Sync()
+}
+func (f *smbfsFile) Truncate(size int64) error {
+	return f.file.Truncate(size)
+}
+func (f *smbfsFile) Write(b []byte) (n int, err error) {
+	return f.file.Write(b)
+}
+func (f *smbfsFile) WriteAt(b []byte, off int64) (n int, err error) {
+	return f.file.WriteAt(b, off)
+}
+func (f *smbfsFile) WriteString(s string) (n int, err error) {
+	return f.file.WriteString(s)
+}

+ 34 - 10
mod/filesystem/abstractions/smbfs/smbfs.go

@@ -12,7 +12,7 @@ import (
 	"time"
 
 	"github.com/hirochachacha/go-smb2"
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 /*
@@ -79,15 +79,21 @@ func (a ServerMessageBlockFileSystemAbstraction) Chmod(filename string, mode os.
 	return a.share.Chmod(filename, mode)
 }
 func (a ServerMessageBlockFileSystemAbstraction) Chown(filename string, uid int, gid int) error {
-	return fsdef.ErrOperationNotSupported
+	return arozfs.ErrOperationNotSupported
 }
 func (a ServerMessageBlockFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
 	filename = filterFilepath(filename)
 	filename = toWinPath(filename)
 	return a.share.Chtimes(filename, atime, mtime)
 }
-func (a ServerMessageBlockFileSystemAbstraction) Create(filename string) (*os.File, error) {
-	return nil, fsdef.ErrOperationNotSupported
+func (a ServerMessageBlockFileSystemAbstraction) Create(filename string) (arozfs.File, error) {
+	filename = filterFilepath(filename)
+	f, err := a.share.Create(filename)
+	if err != nil {
+		return nil, err
+	}
+	af := NewSmbFsFile(f)
+	return af, nil
 }
 func (a ServerMessageBlockFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
 	filename = filterFilepath(filename)
@@ -102,11 +108,23 @@ func (a ServerMessageBlockFileSystemAbstraction) MkdirAll(filename string, mode
 func (a ServerMessageBlockFileSystemAbstraction) Name() string {
 	return ""
 }
-func (a ServerMessageBlockFileSystemAbstraction) Open(filename string) (*os.File, error) {
-	return nil, fsdef.ErrOperationNotSupported
+func (a ServerMessageBlockFileSystemAbstraction) Open(filename string) (arozfs.File, error) {
+	filename = toWinPath(filterFilepath(filename))
+	f, err := a.share.Open(filename)
+	if err != nil {
+		return nil, err
+	}
+	af := NewSmbFsFile(f)
+	return af, nil
 }
-func (a ServerMessageBlockFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
-	return nil, fsdef.ErrOperationNotSupported
+func (a ServerMessageBlockFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (arozfs.File, error) {
+	filename = toWinPath(filterFilepath(filename))
+	f, err := a.share.OpenFile(filename, flag, perm)
+	if err != nil {
+		return nil, err
+	}
+	af := NewSmbFsFile(f)
+	return af, nil
 }
 func (a ServerMessageBlockFileSystemAbstraction) Remove(filename string) error {
 	filename = filterFilepath(filename)
@@ -152,7 +170,7 @@ func (a ServerMessageBlockFileSystemAbstraction) VirtualPathToRealPath(subpath s
 		return toWinPath(filepath.ToSlash(filepath.Clean(subpath))), nil
 	}
 
-	return "", fsdef.ErrVpathResolveFailed
+	return "", arozfs.ErrVpathResolveFailed
 }
 
 func (a ServerMessageBlockFileSystemAbstraction) RealPathToVirtualPath(fullpath string, username string) (string, error) {
@@ -245,7 +263,13 @@ func (a ServerMessageBlockFileSystemAbstraction) ReadStream(filename string) (io
 func (a ServerMessageBlockFileSystemAbstraction) Walk(root string, walkFn filepath.WalkFunc) error {
 	root = toWinPath(filterFilepath(root))
 	err := fs.WalkDir(a.share.DirFS(root), ".", func(path string, d fs.DirEntry, err error) error {
-		statInfo, _ := d.Info()
+		if err != nil {
+			return err
+		}
+		statInfo, err := d.Info()
+		if err != nil {
+			return err
+		}
 		walkFn(path, statInfo, err)
 		return nil
 	})

+ 4 - 3
mod/filesystem/abstractions/webdavfs/webdavfs.go

@@ -11,6 +11,7 @@ import (
 	"time"
 
 	"github.com/studio-b12/gowebdav"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 /*
@@ -58,7 +59,7 @@ func (e WebDAVFileSystem) Chown(filename string, uid int, gid int) error {
 func (e WebDAVFileSystem) Chtimes(filename string, atime time.Time, mtime time.Time) error {
 	return errors.New("filesystem type not supported")
 }
-func (e WebDAVFileSystem) Create(filename string) (*os.File, error) {
+func (e WebDAVFileSystem) Create(filename string) (arozfs.File, error) {
 	return nil, errors.New("filesystem type not supported")
 }
 func (e WebDAVFileSystem) Mkdir(filename string, mode os.FileMode) error {
@@ -72,10 +73,10 @@ func (e WebDAVFileSystem) MkdirAll(filename string, mode os.FileMode) error {
 func (e WebDAVFileSystem) Name() string {
 	return ""
 }
-func (e WebDAVFileSystem) Open(filename string) (*os.File, error) {
+func (e WebDAVFileSystem) Open(filename string) (arozfs.File, error) {
 	return nil, errors.New("filesystem type not supported")
 }
-func (e WebDAVFileSystem) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
+func (e WebDAVFileSystem) OpenFile(filename string, flag int, perm os.FileMode) (arozfs.File, error) {
 	//Buffer the target file to memory
 	//To be implement: Wait for Golang's fs.File.Write function to be released
 	//f := bufffs.New(filename)

+ 15 - 7
mod/filesystem/fsdef/fsdef.go → mod/filesystem/arozfs/arozfs.go

@@ -1,7 +1,7 @@
-package fsdef
+package arozfs
 
 /*
-	fsdef.go
+	arozfs.go
 
 	This package handle error related to file systems.
 	See comments below for usage.
@@ -9,28 +9,31 @@ package fsdef
 import (
 	"errors"
 	"io"
-	"os"
+	"io/fs"
 )
 
 type File interface {
 	Chdir() error
-	Chmod(mode os.FileMode) error
+	Chmod(mode fs.FileMode) error
 	Chown(uid, gid int) error
 	Close() error
 	Name() string
 	Read(b []byte) (n int, err error)
 	ReadAt(b []byte, off int64) (n int, err error)
-	ReadDir(n int) ([]os.DirEntry, error)
+	Readdirnames(n int) (names []string, err error)
 	ReadFrom(r io.Reader) (n int64, err error)
-	Readdir(n int) ([]os.FileInfo, error)
+	Readdir(n int) ([]fs.FileInfo, error)
 	Seek(offset int64, whence int) (ret int64, err error)
-	Stat() (os.FileInfo, error)
+	Stat() (fs.FileInfo, error)
+	Sync() error
 	Truncate(size int64) error
 	Write(b []byte) (n int, err error)
+	WriteAt(b []byte, off int64) (n int, err error)
 	WriteString(s string) (n int, err error)
 }
 
 var (
+
 	/*
 		READ WRITE PERMISSIONS
 	*/
@@ -70,3 +73,8 @@ func IsNetworkDrive(fstype string) bool {
 
 	return false
 }
+
+//Get a list of supported file system types for mounting via arozos
+func GetSupportedFileSystemTypes() []string {
+	return []string{"ext4", "ext2", "ext3", "fat", "vfat", "ntfs", "webdav", "ftp", "smb"}
+}

+ 4 - 4
mod/filesystem/config.go

@@ -4,7 +4,7 @@ import (
 	"encoding/json"
 	"errors"
 
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 //FileSystem configuration. Append more lines if required.
@@ -46,12 +46,12 @@ func ValidateOption(options *FileSystemOption) error {
 		return errors.New("This File System Handler UUID is reserved by the system")
 	}
 
-	if !FileExists(options.Path) && !fsdef.IsNetworkDrive(options.Filesystem) {
+	if !FileExists(options.Path) && !arozfs.IsNetworkDrive(options.Filesystem) {
 		return errors.New("Path not exists, given: " + options.Path)
 	}
 
 	//Check if access mode is supported
-	if !inSlice([]string{fsdef.FsReadOnly, fsdef.FsReadWrite}, options.Access) {
+	if !inSlice([]string{arozfs.FsReadOnly, arozfs.FsReadWrite}, options.Access) {
 		return errors.New("Not supported access mode: " + options.Access)
 	}
 
@@ -61,7 +61,7 @@ func ValidateOption(options *FileSystemOption) error {
 	}
 
 	//Check disk format is supported
-	if !inSlice([]string{"ext4", "ext2", "ext3", "fat", "vfat", "ntfs", "webdav", "ftp"}, options.Filesystem) {
+	if !inSlice(arozfs.GetSupportedFileSystemTypes(), options.Filesystem) {
 		return errors.New("Not supported file system type: " + options.Filesystem)
 	}
 

+ 11 - 11
mod/filesystem/filesystem.go

@@ -25,7 +25,7 @@ import (
 	"imuslab.com/arozos/mod/filesystem/abstractions/localfs"
 	"imuslab.com/arozos/mod/filesystem/abstractions/smbfs"
 	"imuslab.com/arozos/mod/filesystem/abstractions/webdavfs"
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 //Options for creating new file system handler
@@ -55,12 +55,12 @@ type FileSystemAbstraction interface {
 	Chmod(string, os.FileMode) error
 	Chown(string, int, int) error
 	Chtimes(string, time.Time, time.Time) error
-	Create(string) (*os.File, error)
+	Create(string) (arozfs.File, error)
 	Mkdir(string, os.FileMode) error
 	MkdirAll(string, os.FileMode) error
 	Name() string
-	Open(string) (*os.File, error)
-	OpenFile(string, int, os.FileMode) (*os.File, error)
+	Open(string) (arozfs.File, error)
+	OpenFile(string, int, os.FileMode) (arozfs.File, error)
 	Remove(string) error
 	RemoveAll(string) error
 	Rename(string, string) error
@@ -148,9 +148,9 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 		var fsdb *db.Database = nil
 		dbp, err := db.NewDatabase(filepath.ToSlash(filepath.Join(filepath.Clean(option.Path), "aofs.db")), false)
 		if err != nil {
-			if option.Access != fsdef.FsReadOnly {
+			if option.Access != arozfs.FsReadOnly {
 				log.Println("[File System] Invalid config: Trying to mount a read only path as read-write mount point. Changing " + option.Name + " mount point to READONLY.")
-				option.Access = fsdef.FsReadOnly
+				option.Access = arozfs.FsReadOnly
 			}
 		} else {
 			fsdb = dbp
@@ -160,13 +160,13 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 			Name:                  option.Name,
 			UUID:                  option.Uuid,
 			Path:                  filepath.ToSlash(filepath.Clean(option.Path)) + "/",
-			ReadOnly:              option.Access == fsdef.FsReadOnly,
+			ReadOnly:              option.Access == arozfs.FsReadOnly,
 			RequireBuffer:         false,
 			Hierarchy:             option.Hierarchy,
 			HierarchyConfig:       DefaultEmptyHierarchySpecificConfig,
 			InitiationTime:        time.Now().Unix(),
 			FilesystemDatabase:    fsdb,
-			FileSystemAbstraction: localfs.NewLocalFileSystemAbstraction(option.Uuid, rootpath, option.Hierarchy, option.Access == fsdef.FsReadOnly),
+			FileSystemAbstraction: localfs.NewLocalFileSystemAbstraction(option.Uuid, rootpath, option.Hierarchy, option.Access == arozfs.FsReadOnly),
 			Filesystem:            fstype,
 			Closed:                false,
 		}, nil
@@ -185,7 +185,7 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 			Name:                  option.Name,
 			UUID:                  option.Uuid,
 			Path:                  option.Path,
-			ReadOnly:              option.Access == fsdef.FsReadOnly,
+			ReadOnly:              option.Access == arozfs.FsReadOnly,
 			RequireBuffer:         true,
 			Hierarchy:             option.Hierarchy,
 			HierarchyConfig:       nil,
@@ -214,8 +214,8 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 			Name:                  option.Name,
 			UUID:                  option.Uuid,
 			Path:                  option.Path,
-			ReadOnly:              option.Access == fsdef.FsReadOnly,
-			RequireBuffer:         true,
+			ReadOnly:              option.Access == arozfs.FsReadOnly,
+			RequireBuffer:         false,
 			Hierarchy:             option.Hierarchy,
 			HierarchyConfig:       nil,
 			InitiationTime:        time.Now().Unix(),

+ 2 - 2
mod/filesystem/fspermission/fspermission.go

@@ -8,7 +8,7 @@ import (
 	"strconv"
 
 	"imuslab.com/arozos/mod/filesystem"
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 /*
@@ -82,7 +82,7 @@ func SetFilePermisson(fsh *filesystem.FileSystemHandler, file string, permission
 			return err
 		}
 	} else {
-		return fsdef.ErrOperationNotSupported
+		return arozfs.ErrOperationNotSupported
 	}
 	return nil
 }

+ 5 - 5
mod/storage/storage.go

@@ -14,7 +14,7 @@ import (
 
 	"imuslab.com/arozos/mod/filesystem"
 	fs "imuslab.com/arozos/mod/filesystem"
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 )
 
 type StoragePool struct {
@@ -47,7 +47,7 @@ func NewStoragePool(fsHandlers []*fs.FileSystemHandler, owner string) (*StorageP
 
 	return &StoragePool{
 		Owner:           owner,
-		OtherPermission: fsdef.FsReadOnly,
+		OtherPermission: arozfs.FsReadOnly,
 		Storages:        storageHandlers,
 	}, nil
 }
@@ -65,9 +65,9 @@ func (s *StoragePool) ContainDiskID(diskID string) bool {
 
 //Use to compare two StoragePool permissions leve
 func (s *StoragePool) HasHigherOrEqualPermissionThan(a *StoragePool) bool {
-	if s.OtherPermission == fsdef.FsReadOnly && a.OtherPermission == fsdef.FsReadWrite {
+	if s.OtherPermission == arozfs.FsReadOnly && a.OtherPermission == arozfs.FsReadWrite {
 		return false
-	} else if s.OtherPermission == fsdef.FsDenied && a.OtherPermission != fsdef.FsDenied {
+	} else if s.OtherPermission == arozfs.FsDenied && a.OtherPermission != arozfs.FsDenied {
 		return false
 	}
 	return true
@@ -100,7 +100,7 @@ func (s *StoragePool) GetFsHandlerByUUID(uuid string) (*fs.FileSystemHandler, er
 		}
 	}
 
-	return nil, fsdef.ErrFSHNotFOund
+	return nil, arozfs.ErrFSHNotFOund
 }
 
 //Close all fsHandler under this storage pool

+ 10 - 10
mod/user/permissionHandler.go

@@ -6,7 +6,7 @@ import (
 	"path/filepath"
 	"strings"
 
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 	permission "imuslab.com/arozos/mod/permission"
 	storage "imuslab.com/arozos/mod/storage"
 )
@@ -94,31 +94,31 @@ func (u *User) GetInterfaceModules() []string {
 func (u *User) GetPathAccessPermission(vpath string) string {
 	fsid, _, err := getIDFromVirtualPath(filepath.ToSlash(vpath))
 	if err != nil {
-		return fsdef.FsDenied
+		return arozfs.FsDenied
 	}
 	topAccessRightStoragePool, err := u.GetHighestAccessRightStoragePool(fsid)
 	if err != nil {
-		return fsdef.FsDenied
+		return arozfs.FsDenied
 	}
 	if topAccessRightStoragePool.Owner == u.Username {
 		//This user own this storage pool. CHeck if the fs itself is readonly
 		fsHandler, _ := getHandlerFromID(u.GetAllFileSystemHandler(), fsid)
 		if fsHandler.ReadOnly {
-			return fsdef.FsReadOnly
+			return arozfs.FsReadOnly
 		}
-		return fsdef.FsReadWrite
+		return arozfs.FsReadWrite
 	} else if topAccessRightStoragePool.Owner == "system" {
 		//System storage pool. Allow both read and write if the system handler is readwrite
 		fsHandler, _ := getHandlerFromID(u.GetAllFileSystemHandler(), fsid)
 		if fsHandler.ReadOnly {
-			return fsdef.FsReadOnly
+			return arozfs.FsReadOnly
 		}
-		return fsdef.FsReadWrite
+		return arozfs.FsReadWrite
 	} else {
 		//This user do not own this storage pool. Use the pools' config
 		fsHandler, _ := getHandlerFromID(u.GetAllFileSystemHandler(), fsid)
 		if fsHandler.ReadOnly {
-			return fsdef.FsReadOnly
+			return arozfs.FsReadOnly
 		}
 		return topAccessRightStoragePool.OtherPermission
 	}
@@ -127,7 +127,7 @@ func (u *User) GetPathAccessPermission(vpath string) string {
 //Helper function for checking permission
 func (u *User) CanRead(vpath string) bool {
 	rwp := u.GetPathAccessPermission(vpath)
-	if rwp == fsdef.FsReadOnly || rwp == fsdef.FsReadWrite {
+	if rwp == arozfs.FsReadOnly || rwp == arozfs.FsReadWrite {
 		return true
 	} else {
 		return false
@@ -136,7 +136,7 @@ func (u *User) CanRead(vpath string) bool {
 
 func (u *User) CanWrite(vpath string) bool {
 	rwp := u.GetPathAccessPermission(vpath)
-	if rwp == fsdef.FsReadWrite || rwp == fsdef.FsWriteOnly {
+	if rwp == arozfs.FsReadWrite || rwp == arozfs.FsWriteOnly {
 		return true
 	} else {
 		return false

+ 4 - 4
storage.go

@@ -9,7 +9,7 @@ import (
 	"runtime"
 	"strings"
 
-	"imuslab.com/arozos/mod/filesystem/fsdef"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 	"imuslab.com/arozos/mod/permission"
 	"imuslab.com/arozos/mod/storage/bridge"
 
@@ -109,7 +109,7 @@ func LoadBaseStoragePool() error {
 	}
 
 	//Update the storage pool permission to readwrite
-	sp.OtherPermission = fsdef.FsReadWrite
+	sp.OtherPermission = arozfs.FsReadWrite
 	baseStoragePool = sp
 
 	return nil
@@ -162,7 +162,7 @@ func LoadStoragePoolForGroup(pg *permission.PermissionGroup) error {
 		}
 
 		//Set other permission to denied by default
-		sp.OtherPermission = fsdef.FsDenied
+		sp.OtherPermission = arozfs.FsDenied
 
 		//Assign storage pool to group
 		pg.StoragePool = sp
@@ -176,7 +176,7 @@ func LoadStoragePoolForGroup(pg *permission.PermissionGroup) error {
 			log.Println("Failed to create empty storage pool for group: ", pg.Name)
 		}
 		pg.StoragePool = sp
-		pg.StoragePool.OtherPermission = fsdef.FsDenied
+		pg.StoragePool.OtherPermission = arozfs.FsDenied
 	}
 
 	return nil

+ 1 - 0
web/SystemAO/storage/fshedit.html

@@ -142,6 +142,7 @@
                     <div class="item" data-value="vfat">VFAT</div>
                     <div class="item" data-value="fat">FAT</div>
                     <div class="item" data-value="webdav">WebDAV</div>
+                    <div class="item" data-value="smb">SMB</div>
                 </div>
                 </div>
             </div>