1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

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 <slow@samba.org>
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Wed Aug  9 22:33:36 CEST 2017 on sn-devel-144
This commit is contained in:
Ralph Boehme 2017-05-24 09:17:19 +02:00 committed by Volker Lendecke
parent 7583ee6e1c
commit d55c27abc5

View File

@ -1241,25 +1241,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] smb_fname 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 struct smb_filename *smb_fname,
adouble_type_t type)
static struct adouble *ad_get_internal(TALLOC_CTX *ctx,
vfs_handle_struct *handle,
files_struct *fsp,
const struct smb_filename *smb_fname,
adouble_type_t type)
{
int rc = 0;
ssize_t len;
struct adouble *ad = NULL;
int mode;
if (fsp != NULL) {
smb_fname = fsp->base_fsp->fsp_name;
}
DEBUG(10, ("ad_get(%s) called for %s\n",
type == ADOUBLE_META ? "meta" : "rsrc",
smb_fname->base_name));
@ -1273,12 +1269,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, smb_fname, mode, 0);
rc = ad_open(handle, ad, fsp, smb_fname, mode, 0);
if (rc == -1 && ((errno == EROFS) || (errno == EACCES))) {
mode = O_RDONLY;
rc = ad_open(handle, ad, NULL, smb_fname, mode, 0);
rc = ad_open(handle, ad, fsp, smb_fname, mode, 0);
}
if (rc == -1) {
DBG_DEBUG("ad_open [%s] error [%s]\n",
smb_fname->base_name, strerror(errno));
@ -1305,6 +1300,24 @@ exit:
return ad;
}
/**
* Return AppleDouble data for a file
*
* @param[in] ctx talloc context
* @param[in] handle vfs handle
* @param[in] smb_fname 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 struct smb_filename *smb_fname,
adouble_type_t type)
{
return ad_get_internal(ctx, handle, NULL, smb_fname, type);
}
/**
* Return AppleDouble data for a file
*
@ -1318,51 +1331,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;
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, fsp->base_fsp->fsp_name, mode, 0);
if (rc == -1 && ((errno == EROFS) || (errno == EACCES))) {
mode = O_RDONLY;
rc = ad_open(handle, ad, fsp, fsp->base_fsp->fsp_name, mode, 0);
}
if (rc == -1) {
DBG_DEBUG("error opening AppleDouble [%s]\n", fsp_str_dbg(fsp));
goto exit;
}
len = ad_read(ad, fsp->base_fsp->fsp_name);
if (len == -1) {
DBG_DEBUG("error reading AppleDouble for %s\n",
fsp_str_dbg(fsp));
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);
}
/**