Store winattrs in GPFS
authorMathias Dietz <mdietz@de.ibm.com>
Wed, 27 May 2009 10:03:12 +0000 (12:03 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 2 Jun 2009 15:03:59 +0000 (17:03 +0200)
    1. Store win attributes in gpfs instead of posix bits.
    2. use of path based winattr calls of gpfs.

Signed-off-by: Mathias Dietz <mdietz@de.ibm.com>
source3/modules/gpfs.c
source3/modules/vfs_gpfs.c
source3/modules/vfs_gpfs.h

index 9fc4524654b3263c0605496e30a4ee1cbbc9ec62..d20c024ccd6f3fc8e3485bac6a660332a432f250 100644 (file)
@@ -27,6 +27,7 @@
 static bool gpfs_share_modes;
 static bool gpfs_leases;
 static bool gpfs_getrealfilename;
+static bool gpfs_winattr;
 
 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
 static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
@@ -34,6 +35,8 @@ static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
                                            int *buflen);
+static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags, struct gpfs_winattr *attrs);
+static int (*gpfs_get_winattrs_path_fn)(char *pathname, struct gpfs_winattr *attrs);
 
 
 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
@@ -149,6 +152,28 @@ int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
        return gpfs_get_realfilename_path_fn(pathname, filenamep, buflen);
 }
 
+int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
+{
+
+        if ((!gpfs_winattr) || (gpfs_get_winattrs_path_fn == NULL)) {
+                errno = ENOSYS;
+                return -1;
+        }
+        DEBUG(0, ("gpfs_get_winattrs_path:open call %s\n",pathname));
+        return gpfs_get_winattrs_path_fn(pathname, attrs);
+}
+
+int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
+{
+        if ((!gpfs_winattr) || (gpfs_set_winattrs_path_fn == NULL)) {
+                errno = ENOSYS;
+                return -1;
+        }
+
+        DEBUG(0, ("gpfs_set_winattrs_path:open call %s\n",pathname));
+        return gpfs_set_winattrs_path_fn(pathname,flags, attrs);
+}
+
 static bool init_gpfs_function_lib(void *plibhandle_pointer,
                                   const char *libname,
                                   void *pfn_pointer, const char *fn_name)
@@ -207,11 +232,15 @@ void init_gpfs(void)
        init_gpfs_function(&gpfs_putacl_fn, "gpfs_putacl");
        init_gpfs_function(&gpfs_get_realfilename_path_fn,
                           "gpfs_get_realfilename_path");
+       init_gpfs_function(&gpfs_get_winattrs_path_fn,"gpfs_get_winattrs_path");
+        init_gpfs_function(&gpfs_set_winattrs_path_fn,"gpfs_set_winattrs_path");
+
 
        gpfs_share_modes = lp_parm_bool(-1, "gpfs", "sharemodes", True);
        gpfs_leases      = lp_parm_bool(-1, "gpfs", "leases", True);
        gpfs_getrealfilename = lp_parm_bool(-1, "gpfs", "getrealfilename",
                                            True);
+       gpfs_winattr = lp_parm_bool(-1, "gpfs", "winattr", False);
 
        return;
 }
@@ -255,6 +284,18 @@ int smbd_gpfs_get_realfilename_path(char *pathname, char *fileamep,
        return -1;
 }
 
+int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
+{
+        errno = ENOSYS;
+        return -1;
+}
+
+int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
+{
+        errno = ENOSYS;
+        return -1;
+}
+
 void init_gpfs(void)
 {
        return;
index 2e4e7ede55c6309ffee30abda262554dd2021f27..4215e13200c4b8591143469d4488f449fdff1c72 100644 (file)
@@ -876,6 +876,97 @@ static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t
                 return rc;
 }
 
+static int gpfs_set_xattr(struct vfs_handle_struct *handle,  const char *path,
+                           const char *name, const void *value, size_t size,  int flags){
+        const char *attrstr = value;
+        unsigned int dosmode=0;
+        struct gpfs_winattr attrs;
+        int ret = 0;
+
+        DEBUG(10, ("gpfs_set_xattr: %s \n",path));
+
+        /* Only handle DOS Attributes */
+        if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
+               DEBUG(1, ("gpfs_set_xattr:name is %s\n",name));
+               return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
+        }
+
+        if (size < 2 || attrstr[0] != '0' || attrstr[1] != 'x' ||
+                                sscanf(attrstr, "%x", &dosmode) != 1) {
+                        DEBUG(1,("gpfs_set_xattr: Trying to set badly formed DOSATTRIB on file %s - %s\n", path, attrstr));
+                return False;
+        }
+
+        attrs.winAttrs = 0;
+        /*Just map RD_ONLY, ARCHIVE, SYSTEM and HIDDEN. Ignore the others*/
+        if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
+                attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
+        }
+        if (dosmode & FILE_ATTRIBUTE_HIDDEN){
+                        attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
+                }
+        if (dosmode & FILE_ATTRIBUTE_SYSTEM){
+                        attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
+                }
+        if (dosmode & FILE_ATTRIBUTE_READONLY){
+                        attrs.winAttrs |= GPFS_WINATTR_READONLY;
+        }
+
+
+        ret = set_gpfs_winattrs(CONST_DISCARD(char *, path),
+                               GPFS_WINATTR_SET_ATTRS, &attrs);
+        if ( ret == -1){
+                DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
+                return -1;
+        }
+
+        DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
+        return 0;
+}
+
+static size_t gpfs_get_xattr(struct vfs_handle_struct *handle,  const char *path,
+                              const char *name, void *value, size_t size){
+        char *attrstr = value;
+        unsigned int dosmode = 0;
+        struct gpfs_winattr attrs;
+        int ret = 0;
+
+        DEBUG(10, ("gpfs_get_xattr: %s \n",path));
+
+        /* Only handle DOS Attributes */
+        if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
+                DEBUG(1, ("gpfs_get_xattr:name is %s\n",name));
+                return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
+        }
+
+        ret = get_gpfs_winattrs(CONST_DISCARD(char *, path), &attrs);
+        if ( ret == -1){
+                DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: %d\n",ret));
+                return -1;
+        }
+
+        DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
+
+        /*Just map RD_ONLY, ARCHIVE, SYSTEM and HIDDEN. Ignore the others*/
+        if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
+                dosmode |= FILE_ATTRIBUTE_ARCHIVE;
+        }
+        if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
+                dosmode |= FILE_ATTRIBUTE_HIDDEN;
+        }
+        if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
+                dosmode |= FILE_ATTRIBUTE_SYSTEM;
+        }
+        if (attrs.winAttrs & GPFS_WINATTR_READONLY){
+                dosmode |= FILE_ATTRIBUTE_READONLY;
+        }
+
+        snprintf(attrstr, size, "0x%x", dosmode & SAMBA_ATTRIBUTES_MASK);
+        DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
+        return size;
+}
+
+
 /* VFS operations structure */
 
 static vfs_op_tuple gpfs_op_tuples[] = {
@@ -936,6 +1027,14 @@ static vfs_op_tuple gpfs_op_tuples[] = {
          SMB_VFS_OP_CLOSE,
          SMB_VFS_LAYER_TRANSPARENT },
 
+        { SMB_VFS_OP(gpfs_set_xattr),
+          SMB_VFS_OP_SETXATTR,
+          SMB_VFS_LAYER_TRANSPARENT },
+
+        { SMB_VFS_OP(gpfs_get_xattr),
+          SMB_VFS_OP_GETXATTR,
+          SMB_VFS_LAYER_TRANSPARENT },
+
         { SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP }
 
 };
index efca5603aa44ebbd7247c6f9897e3a8f3574d747..e0c23dc8cc4a2776373f3a5472645767f9b733d9 100644 (file)
@@ -31,4 +31,6 @@ int smbd_gpfs_getacl(char *pathname, int flags, void *acl);
 int smbd_gpfs_putacl(char *pathname, int flags, void *acl);
 int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
                                    int *buflen);
+int get_gpfs_winattrs(char * pathname,struct gpfs_winattr *attrs);
+int set_gpfs_winattrs(char * pathname,int flags,struct gpfs_winattr *attrs);
 void init_gpfs(void);