Browse Source

Finalized SMB mounting mechanism

Toby Chui 3 years ago
parent
commit
eb58725309
2 changed files with 10 additions and 7 deletions
  1. 3 5
      mod/filesystem/abstractions/smbfs/smbfs.go
  2. 7 2
      mod/filesystem/filesystem.go

+ 3 - 5
mod/filesystem/abstractions/smbfs/smbfs.go

@@ -32,8 +32,8 @@ type ServerMessageBlockFileSystemAbstraction struct {
 	share     *smb2.Share
 }
 
-func NewServerMessageBlockFileSystemAbstraction(uuid string, hierarchy string, ipaddr string, username string, password string) (ServerMessageBlockFileSystemAbstraction, error) {
-	conn, err := net.Dial("tcp", ipaddr+":445")
+func NewServerMessageBlockFileSystemAbstraction(uuid string, hierarchy string, ipaddr string, rootShare string, username string, password string) (ServerMessageBlockFileSystemAbstraction, error) {
+	conn, err := net.Dial("tcp", ipaddr)
 	if err != nil {
 		log.Println("[SMB-FS] Unable to connect to remote: ", err.Error())
 		return ServerMessageBlockFileSystemAbstraction{}, err
@@ -53,9 +53,7 @@ func NewServerMessageBlockFileSystemAbstraction(uuid string, hierarchy string, i
 	}
 
 	//Mound remote storage
-	//SSDBuffer
-
-	fs, err := s.Mount("SSDBuffer")
+	fs, err := s.Mount(rootShare)
 	if err != nil {
 		log.Println("[SMB-FS] Unable to connect to remote: ", err.Error())
 		return ServerMessageBlockFileSystemAbstraction{}, err

+ 7 - 2
mod/filesystem/filesystem.go

@@ -197,11 +197,16 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 		}, nil
 	} else if fstype == "smb" {
 		//WebDAV. Create an object and mount it
-		ipAddr := option.Path
+		pathChunks := strings.Split(strings.ReplaceAll(option.Path, "\\", "/"), "/")
+		if len(pathChunks) != 2 {
+			return nil, errors.New("Invalid configured smb filepath: Path format not matching [ip_addr]:[port]/[root_share]")
+		}
+		ipAddr := pathChunks[0]
+		rootShare := pathChunks[1]
 		user := option.Username
 		password := option.Password
 
-		smbfs, err := smbfs.NewServerMessageBlockFileSystemAbstraction(option.Uuid, option.Hierarchy, ipAddr, user, password)
+		smbfs, err := smbfs.NewServerMessageBlockFileSystemAbstraction(option.Uuid, option.Hierarchy, ipAddr, rootShare, user, password)
 		if err != nil {
 			return nil, err
 		}