vfs_fruit: remove now unused AppleDouble code for resource fork in xattr
[metze/samba/wip.git] / source3 / modules / vfs_fruit.c
index 0e2c07c5fd6fb0512b347bbd04968119063ec07c..ba53abfdd6a3f6955ef78e5bb1ac49575dd30577 100644 (file)
@@ -413,7 +413,6 @@ struct ad_entry {
 };
 
 struct adouble {
-       vfs_handle_struct        *ad_handle;
        int                       ad_fd;
        bool                      ad_opened;
        adouble_type_t            ad_type;
@@ -1059,7 +1058,8 @@ static bool ad_convert_move_reso(struct adouble *ad,
        return true;
 }
 
-static bool ad_convert_xattr(struct adouble *ad,
+static bool ad_convert_xattr(vfs_handle_struct *handle,
+                            struct adouble *ad,
                             const struct smb_filename *smb_fname,
                             bool *converted_xattr)
 {
@@ -1110,7 +1110,7 @@ static bool ad_convert_xattr(struct adouble *ad,
                files_struct *fsp = NULL;
                ssize_t nwritten;
 
-               status = string_replace_allocate(ad->ad_handle->conn,
+               status = string_replace_allocate(handle->conn,
                                                 e->adx_name,
                                                 string_replace_cmaps,
                                                 talloc_tos(),
@@ -1147,7 +1147,7 @@ static bool ad_convert_xattr(struct adouble *ad,
                DBG_DEBUG("stream_name: %s\n", smb_fname_str_dbg(stream_name));
 
                status = SMB_VFS_CREATE_FILE(
-                       ad->ad_handle->conn,            /* conn */
+                       handle->conn,                   /* conn */
                        NULL,                           /* req */
                        0,                              /* root_dir_fid */
                        stream_name,                    /* fname */
@@ -1226,7 +1226,8 @@ fail:
        return ok;
 }
 
-static bool ad_convert_finderinfo(struct adouble *ad,
+static bool ad_convert_finderinfo(vfs_handle_struct *handle,
+                                 struct adouble *ad,
                                  const struct smb_filename *smb_fname)
 {
        char *p_ad = NULL;
@@ -1283,7 +1284,7 @@ static bool ad_convert_finderinfo(struct adouble *ad,
        DBG_DEBUG("stream_name: %s\n", smb_fname_str_dbg(stream_name));
 
        status = SMB_VFS_CREATE_FILE(
-               ad->ad_handle->conn,            /* conn */
+               handle->conn,                   /* conn */
                NULL,                           /* req */
                0,                              /* root_dir_fid */
                stream_name,                    /* fname */
@@ -1346,7 +1347,8 @@ static bool ad_convert_truncate(struct adouble *ad,
        return true;
 }
 
-static bool ad_convert_blank_rfork(struct adouble *ad,
+static bool ad_convert_blank_rfork(vfs_handle_struct *handle,
+                                  struct adouble *ad,
                                   bool *blank)
 {
        struct fruit_config_data *config = NULL;
@@ -1359,7 +1361,7 @@ static bool ad_convert_blank_rfork(struct adouble *ad,
 
        *blank = false;
 
-       SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
+       SMB_VFS_HANDLE_GET_DATA(handle, config,
                                struct fruit_config_data, return false);
 
        if (!config->wipe_intentionally_left_blank_rfork) {
@@ -1410,7 +1412,8 @@ static bool ad_convert_blank_rfork(struct adouble *ad,
        return true;
 }
 
-static bool ad_convert_delete_adfile(struct adouble *ad,
+static bool ad_convert_delete_adfile(vfs_handle_struct *handle,
+                                    struct adouble *ad,
                                     const struct smb_filename *smb_fname)
 {
        struct fruit_config_data *config = NULL;
@@ -1421,7 +1424,7 @@ static bool ad_convert_delete_adfile(struct adouble *ad,
                return true;
        }
 
-       SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
+       SMB_VFS_HANDLE_GET_DATA(handle, config,
                                struct fruit_config_data, return false);
 
        if (!config->delete_empty_adfiles) {
@@ -1433,7 +1436,7 @@ static bool ad_convert_delete_adfile(struct adouble *ad,
                return false;
        }
 
-       rc = SMB_VFS_NEXT_UNLINK(ad->ad_handle, ad_name);
+       rc = SMB_VFS_NEXT_UNLINK(handle, ad_name);
        if (rc != 0) {
                DBG_ERR("Unlinking [%s] failed: %s\n",
                        smb_fname_str_dbg(ad_name), strerror(errno));
@@ -1470,13 +1473,13 @@ static int ad_convert(struct vfs_handle_struct *handle,
                return 0;
        }
 
-       ok = ad_convert_xattr(ad, smb_fname, &converted_xattr);
+       ok = ad_convert_xattr(handle, ad, smb_fname, &converted_xattr);
        if (!ok) {
                ret = -1;
                goto done;
        }
 
-       ok = ad_convert_blank_rfork(ad, &blank);
+       ok = ad_convert_blank_rfork(handle, ad, &blank);
        if (!ok) {
                ret = -1;
                goto done;
@@ -1490,7 +1493,7 @@ static int ad_convert(struct vfs_handle_struct *handle,
                }
        }
 
-       ok = ad_convert_finderinfo(ad, smb_fname);
+       ok = ad_convert_finderinfo(handle, ad, smb_fname);
        if (!ok) {
                DBG_ERR("Failed to convert [%s]\n",
                        smb_fname_str_dbg(smb_fname));
@@ -1498,7 +1501,7 @@ static int ad_convert(struct vfs_handle_struct *handle,
                goto done;
        }
 
-       ok = ad_convert_delete_adfile(ad, smb_fname);
+       ok = ad_convert_delete_adfile(handle, ad, smb_fname);
        if (!ok) {
                ret = -1;
                goto done;
@@ -1590,20 +1593,6 @@ exit:
        return ealen;
 }
 
-static int ad_open_rsrc_xattr(const struct smb_filename *smb_fname,
-                               int flags,
-                               mode_t mode)
-{
-#ifdef HAVE_ATTROPEN
-       /* FIXME: direct Solaris xattr syscall */
-       return attropen(smb_fname->base_name,
-                       AFPRESOURCE_EA_NETATALK, flags, mode);
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
 static int ad_open_rsrc_adouble(const struct smb_filename *smb_fname,
                                int flags,
                                mode_t mode)
@@ -1628,19 +1617,7 @@ static int ad_open_rsrc(vfs_handle_struct *handle,
                        int flags,
                        mode_t mode)
 {
-       struct fruit_config_data *config = NULL;
-       int fd;
-
-       SMB_VFS_HANDLE_GET_DATA(handle, config,
-                               struct fruit_config_data, return -1);
-
-       if (config->rsrc == FRUIT_RSRC_XATTR) {
-               fd = ad_open_rsrc_xattr(smb_fname, flags, mode);
-       } else {
-               fd = ad_open_rsrc_adouble(smb_fname, flags, mode);
-       }
-
-       return fd;
+       return ad_open_rsrc_adouble(smb_fname, flags, mode);
 }
 
 /*
@@ -1684,27 +1661,9 @@ static int ad_open(vfs_handle_struct *handle,
        return 0;
 }
 
-static ssize_t ad_read_rsrc_xattr(vfs_handle_struct *handle,
-                                 struct adouble *ad)
-{
-       int ret;
-       SMB_STRUCT_STAT st;
-
-       /* FIXME: direct sys_fstat(), don't have an fsp */
-       ret = sys_fstat(ad->ad_fd, &st,
-                       lp_fake_directory_create_times(
-                               SNUM(handle->conn)));
-       if (ret != 0) {
-               return -1;
-       }
-
-       ad_setentrylen(ad, ADEID_RFORK, st.st_ex_size);
-       return st.st_ex_size;
-}
-
 static ssize_t ad_read_rsrc_adouble(vfs_handle_struct *handle,
                                    struct adouble *ad,
-                               const struct smb_filename *smb_fname)
+                                   const struct smb_filename *smb_fname)
 {
        SMB_STRUCT_STAT sbuf;
        char *p_ad = NULL;
@@ -1773,21 +1732,9 @@ static ssize_t ad_read_rsrc_adouble(vfs_handle_struct *handle,
  **/
 static ssize_t ad_read_rsrc(vfs_handle_struct *handle,
                            struct adouble *ad,
-                       const struct smb_filename *smb_fname)
+                           const struct smb_filename *smb_fname)
 {
-       struct fruit_config_data *config = NULL;
-       ssize_t len;
-
-       SMB_VFS_HANDLE_GET_DATA(handle, config,
-                               struct fruit_config_data, return -1);
-
-       if (config->rsrc == FRUIT_RSRC_XATTR) {
-               len = ad_read_rsrc_xattr(handle, ad);
-       } else {
-               len = ad_read_rsrc_adouble(handle, ad, smb_fname);
-       }
-
-       return len;
+       return ad_read_rsrc_adouble(handle, ad, smb_fname);
 }
 
 /**
@@ -1866,7 +1813,6 @@ static struct adouble *ad_alloc(TALLOC_CTX *ctx, vfs_handle_struct *handle,
                }
        }
 
-       ad->ad_handle = handle;
        ad->ad_type = type;
        ad->ad_magic = AD_MAGIC;
        ad->ad_version = AD_VERSION;
@@ -1896,22 +1842,14 @@ static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle,
        int rc = 0;
        const struct ad_entry_order  *eid;
        struct adouble *ad = NULL;
-       struct fruit_config_data *config;
        time_t t = time(NULL);
 
-       SMB_VFS_HANDLE_GET_DATA(handle, config,
-                               struct fruit_config_data, return NULL);
-
        switch (type) {
        case ADOUBLE_META:
                eid = entry_order_meta_xattr;
                break;
        case ADOUBLE_RSRC:
-               if (config->rsrc == FRUIT_RSRC_ADFILE) {
-                       eid = entry_order_dot_und;
-               } else {
-                       eid = entry_order_rsrc_xattr;
-               }
+               eid = entry_order_dot_und;
                break;
        default:
                return NULL;
@@ -2172,6 +2110,27 @@ static bool is_apple_stream(const struct smb_filename *smb_fname)
        return false;
 }
 
+static bool is_adouble_file(const char *path)
+{
+       const char *p = NULL;
+       int match;
+
+       p = strrchr(path, '/');
+       if (p == NULL) {
+               p = path;
+       } else {
+               p++;
+       }
+
+       match = strncmp(p,
+                       ADOUBLE_NAME_PREFIX,
+                       strlen(ADOUBLE_NAME_PREFIX));
+       if (match != 0) {
+               return false;
+       }
+       return true;
+}
+
 /**
  * Initialize config struct from our smb.conf config parameters
  **/
@@ -3218,12 +3177,12 @@ static uint64_t readdir_attr_rfork_size(struct vfs_handle_struct *handle,
 
        switch (config->rsrc) {
        case FRUIT_RSRC_ADFILE:
-       case FRUIT_RSRC_XATTR:
                rfork_size = readdir_attr_rfork_size_adouble(handle,
                                                             smb_fname);
                break;
 
-       case FRUIT_META_STREAM:
+       case FRUIT_RSRC_XATTR:
+       case FRUIT_RSRC_STREAM:
                rfork_size = readdir_attr_rfork_size_stream(handle,
                                                            smb_fname);
                break;
@@ -4079,7 +4038,9 @@ static int fruit_unlink(vfs_handle_struct *handle,
                return fruit_unlink_meta(handle, smb_fname);
        } else if (is_afpresource_stream(smb_fname)) {
                return fruit_unlink_rsrc(handle, smb_fname, false);
-       } if (is_ntfs_stream_smb_fname(smb_fname)) {
+       } else if (is_ntfs_stream_smb_fname(smb_fname)) {
+               return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+       } else if (is_adouble_file(smb_fname->base_name)) {
                return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
        }
 
@@ -4225,16 +4186,12 @@ static int fruit_rmdir(struct vfs_handle_struct *handle,
        }
 
        while ((de = SMB_VFS_READDIR(handle->conn, dh, NULL)) != NULL) {
-               int match;
                struct adouble *ad = NULL;
                char *p = NULL;
                struct smb_filename *ad_smb_fname = NULL;
                int ret;
 
-               match = strncmp(de->d_name,
-                               ADOUBLE_NAME_PREFIX,
-                               strlen(ADOUBLE_NAME_PREFIX));
-               if (match != 0) {
+               if (!is_adouble_file(de->d_name)) {
                        continue;
                }