From 2339d4bc05e65d871cd19a58ef4f28bb1e46cad8 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 24 May 2017 09:17:19 +0200 Subject: [PATCH] vfs_fruit: factor out common code from ad_get() and ad_fget() As a result of the previous changes ad_get() and ad_fget() do completey the same, so factor out the common code to a new helper function. No change in behaviour. Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791 Signed-off-by: Ralph Boehme Reviewed-by: Richard Sharpe Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Wed Aug 9 22:33:36 CEST 2017 on sn-devel-144 (backported from commit d55c27abc5a7357f740c7065bbe12e7f36b57125) Autobuild-User(v4-5-test): Karolin Seeger Autobuild-Date(v4-5-test): Mon Aug 14 14:52:17 CEST 2017 on sn-devel-144 --- source3/modules/vfs_fruit.c | 90 +++++++++++++------------------------ 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index bd3a49437f3..a0fce49fa04 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1230,24 +1230,21 @@ static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle, return ad; } -/** - * Return AppleDouble data for a file - * - * @param[in] ctx talloc context - * @param[in] handle vfs handle - * @param[in] path pathname to file or directory - * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC - * - * @return talloced struct adouble or NULL on error - **/ -static struct adouble *ad_get(TALLOC_CTX *ctx, vfs_handle_struct *handle, - const char *path, adouble_type_t type) +static struct adouble *ad_get_internal(TALLOC_CTX *ctx, + vfs_handle_struct *handle, + files_struct *fsp, + const char *path, + adouble_type_t type) { int rc = 0; ssize_t len; struct adouble *ad = NULL; int mode; + if (fsp != NULL) { + path = fsp->base_fsp->fsp_name->base_name; + } + DEBUG(10, ("ad_get(%s) called for %s\n", type == ADOUBLE_META ? "meta" : "rsrc", path)); @@ -1260,12 +1257,11 @@ static struct adouble *ad_get(TALLOC_CTX *ctx, vfs_handle_struct *handle, /* Try rw first so we can use the fd in ad_convert() */ mode = O_RDWR; - rc = ad_open(handle, ad, NULL, path, mode, 0); + rc = ad_open(handle, ad, fsp, path, mode, 0); if (rc == -1 && ((errno == EROFS) || (errno == EACCES))) { mode = O_RDONLY; - rc = ad_open(handle, ad, NULL, path, mode, 0); + rc = ad_open(handle, ad, fsp, path, mode, 0); } - if (rc == -1) { DBG_DEBUG("ad_open [%s] error [%s]\n", path, strerror(errno)); @@ -1289,6 +1285,24 @@ exit: return ad; } +/** + * Return AppleDouble data for a file + * + * @param[in] ctx talloc context + * @param[in] handle vfs handle + * @param[in] path pathname to file or directory + * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC + * + * @return talloced struct adouble or NULL on error + **/ +static struct adouble *ad_get(TALLOC_CTX *ctx, + vfs_handle_struct *handle, + const char *path, + adouble_type_t type) +{ + return ad_get_internal(ctx, handle, NULL, path, type); +} + /** * Return AppleDouble data for a file * @@ -1302,51 +1316,7 @@ exit: static struct adouble *ad_fget(TALLOC_CTX *ctx, vfs_handle_struct *handle, files_struct *fsp, adouble_type_t type) { - int rc = 0; - ssize_t len; - struct adouble *ad = NULL; - char *path = fsp->base_fsp->fsp_name->base_name; - int mode; - - DBG_DEBUG("ad_get(%s) path [%s]\n", - type == ADOUBLE_META ? "meta" : "rsrc", - fsp_str_dbg(fsp)); - - ad = ad_alloc(ctx, handle, type); - if (ad == NULL) { - rc = -1; - goto exit; - } - - /* Try rw first so we can use the fd in ad_convert() */ - mode = O_RDWR; - - rc = ad_open(handle, ad, fsp, path, mode, 0); - if (rc == -1 && ((errno == EROFS) || (errno == EACCES))) { - mode = O_RDONLY; - rc = ad_open(handle, ad, fsp, path, mode, 0); - } - if (rc == -1) { - DBG_DEBUG("error opening AppleDouble [%s]\n", fsp_str_dbg(fsp)); - goto exit; - } - - len = ad_read(ad, path); - if (len == -1) { - DBG_DEBUG("error reading AppleDouble for %s\n", path); - rc = -1; - goto exit; - } - -exit: - DBG_DEBUG("ad_get(%s) path [%s] rc [%d]\n", - type == ADOUBLE_META ? "meta" : "rsrc", - fsp_str_dbg(fsp), rc); - - if (rc != 0) { - TALLOC_FREE(ad); - } - return ad; + return ad_get_internal(ctx, handle, fsp, NULL, type); } /** -- 2.47.2