]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
dokan: Made file/dir access mode configurable 49280/head
authorStefan Chivu <schivu@cloudbasesolutions.com>
Mon, 28 Nov 2022 15:24:08 +0000 (17:24 +0200)
committerStefan Chivu <schivu@cloudbasesolutions.com>
Mon, 5 Dec 2022 09:21:47 +0000 (11:21 +0200)
By default, when mounting a filesystem using ceph-dokan, the file
and directory access modes were hardcoded as 755.

Now, both the file and directory access modes are configurable
using the --file-mode and --dir-mode optargs, accepting values
ranging from 001 to 777.

If no value is specified, the default value of 755 will be used.

Signed-off-by: Stefan Chivu <schivu@cloudbasesolutions.com>
src/dokan/ceph_dokan.cc
src/dokan/ceph_dokan.h
src/dokan/options.cc

index 4a4f78cdb66e83b9a2e935d5b0e243b2c6c96201..4738d096ac4ba18abcadfed7a28f2c71bb0a5827 100644 (file)
@@ -111,7 +111,7 @@ static NTSTATUS WinCephCreateDirectory(
     return 0;
   }
 
-  int ret = ceph_mkdir(cmount, path.c_str(), 0755);
+  int ret = ceph_mkdir(cmount, path.c_str(), g_cfg->dir_mode);
   if (ret < 0) {
     dout(2) << __func__ << " " << path
             << ": ceph_mkdir failed. Error: " << ret << dendl;
@@ -166,13 +166,14 @@ static NTSTATUS WinCephCreateFile(
         return STATUS_OBJECT_NAME_COLLISION;
       case TRUNCATE_EXISTING:
         // open O_TRUNC & return 0
-        return do_open_file(path, O_CREAT | O_TRUNC | O_RDWR, 0755, fdc);
+        return do_open_file(path, O_CREAT | O_TRUNC | O_RDWR,
+                            g_cfg->file_mode, fdc);
       case OPEN_ALWAYS:
         // open & return STATUS_OBJECT_NAME_COLLISION
         if (!WRITE_ACCESS_REQUESTED(AccessMode))
           fdc->read_only = 1;
         if ((st = do_open_file(path, fdc->read_only ? O_RDONLY : O_RDWR,
-                               0755, fdc)))
+                               g_cfg->file_mode, fdc)))
           return st;
         return STATUS_OBJECT_NAME_COLLISION;
       case OPEN_EXISTING:
@@ -180,12 +181,13 @@ static NTSTATUS WinCephCreateFile(
         if (!WRITE_ACCESS_REQUESTED(AccessMode))
           fdc->read_only = 1;
         if ((st = do_open_file(path, fdc->read_only ? O_RDONLY : O_RDWR,
-                               0755, fdc)))
+                               g_cfg->file_mode, fdc)))
           return st;
         return 0;
       case CREATE_ALWAYS:
         // open O_TRUNC & return STATUS_OBJECT_NAME_COLLISION
-        if ((st = do_open_file(path, O_CREAT | O_TRUNC | O_RDWR, 0755, fdc)))
+        if ((st = do_open_file(path, O_CREAT | O_TRUNC | O_RDWR,
+                               g_cfg->file_mode, fdc)))
           return st;
         return STATUS_OBJECT_NAME_COLLISION;
       }
@@ -204,7 +206,7 @@ static NTSTATUS WinCephCreateFile(
         return 0;
       case OPEN_ALWAYS:
       case OPEN_EXISTING:
-        return do_open_file(path, O_RDONLY, 0755, fdc);
+        return do_open_file(path, O_RDONLY, g_cfg->file_mode, fdc);
       case CREATE_ALWAYS:
         return STATUS_OBJECT_NAME_COLLISION;
       }
@@ -220,18 +222,21 @@ static NTSTATUS WinCephCreateFile(
       if ((st = WinCephCreateDirectory(FileName, DokanFileInfo)))
         return st;
       // Dokan expects a file handle even when creating new directories.
-      return do_open_file(path, O_RDONLY, 0755, fdc);
+      return do_open_file(path, O_RDONLY, g_cfg->file_mode, fdc);
     }
     dout(20) << __func__ << " " << path << ". New file." << dendl;
     switch (CreationDisposition) {
       case CREATE_NEW:
         // create & return 0
-        return do_open_file(path, O_CREAT | O_RDWR | O_EXCL, 0755, fdc);
+        return do_open_file(path, O_CREAT | O_RDWR | O_EXCL,
+                            g_cfg->file_mode, fdc);
       case CREATE_ALWAYS:
         // create & return 0
-        return do_open_file(path, O_CREAT | O_TRUNC | O_RDWR, 0755, fdc);
+        return do_open_file(path, O_CREAT | O_TRUNC | O_RDWR,
+                            g_cfg->file_mode, fdc);
       case OPEN_ALWAYS:
-        return do_open_file(path, O_CREAT | O_RDWR, 0755, fdc);
+        return do_open_file(path, O_CREAT | O_RDWR,
+                            g_cfg->file_mode, fdc);
       case OPEN_EXISTING:
       case TRUNCATE_EXISTING:
         dout(2) << __func__ << " " << path << ": Not found." << dendl;
index 489ed6d26872b75c46bbe58fc2ec3803eb83c155..5957d4dead11e7aae8901985b11c82267504e0d8 100644 (file)
@@ -34,6 +34,8 @@ struct Config {
   std::wstring win_vol_name = L"";
   unsigned long win_vol_serial = 0;
   unsigned long max_path_len = 256;
+  mode_t file_mode = 0755;
+  mode_t dir_mode = 0755;
 };
 
 extern Config *g_cfg;
index 27b8569441eef41a96f66e9afbdd88a0e4dd981d..4cfe08cdbe2cae30a4f82fbcd3c4f4cf36739413 100644 (file)
@@ -7,6 +7,7 @@
  * Foundation.  See file COPYING.
  *
 */
+#include <regex>
 
 #include "include/compat.h"
 #include "include/cephfs/libcephfs.h"
@@ -41,6 +42,8 @@ Map options:
   --win-vol-name arg          The Windows volume name. Default: Ceph - <fs_name>.
   --win-vol-serial arg        The Windows volume serial number. Default: <fs_id>.
   --max-path-len              The value of the maximum path length. Default: 256.
+  --file-mode                 The access mode to be used when creating files.
+  --dir-mode                  The access mode to be used when creating directories.
 
 Unmap options:
   -l [ --mountpoint ] arg     mountpoint (path or drive letter) (e.g -l x).
@@ -87,6 +90,8 @@ int parse_args(
   std::string win_vol_name;
   std::string win_vol_serial;
   std::string max_path_len;
+  std::string file_mode;
+  std::string dir_mode;
 
   int thread_count;
 
@@ -134,6 +139,22 @@ int parse_args(
       }
 
       cfg->max_path_len = max_path_length;
+    } else if (ceph_argparse_witharg(args, i, &file_mode, "--file-mode", (char *)NULL)) {
+      mode_t mode = strtol(file_mode.c_str(), NULL, 8);
+      if (!std::regex_match(file_mode, std::regex("^[0-7]{3}$"))
+          || mode < 01 || mode > 0777) {
+        *err_msg << "ceph-dokan: invalid file access mode";
+        return -EINVAL;
+      }
+      cfg->file_mode = mode;
+    } else if (ceph_argparse_witharg(args, i, &dir_mode, "--dir-mode", (char *)NULL)) {
+      mode_t mode = strtol(dir_mode.c_str(), NULL, 8);
+      if (!std::regex_match(dir_mode, std::regex("^[0-7]{3}$"))
+          || mode < 01 || mode > 0777) {
+        *err_msg << "ceph-dokan: invalid directory access mode";
+        return -EINVAL;
+      }
+      cfg->dir_mode = mode;
     } else if (ceph_argparse_flag(args, i, "--current-session-only", (char *)NULL)) {
       cfg->current_session_only = true;
     } else if (ceph_argparse_witharg(args, i, &thread_count,