nwatalk: use standalone mars_nwe AFP xattr backend
This commit is contained in:
119
src/nwatalk.c
119
src/nwatalk.c
@@ -1,4 +1,4 @@
|
||||
/* Optional Netatalk/libatalk AFP metadata backend helpers. */
|
||||
/* mars_nwe AFP xattr metadata backend helpers. */
|
||||
#include "net.h"
|
||||
#include "config.h"
|
||||
#include "nwatalk.h"
|
||||
@@ -11,11 +11,6 @@
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
#include <sys/stat.h>
|
||||
#include <atalk/adouble.h>
|
||||
#endif
|
||||
|
||||
#define MARS_NWE_AFP_ENTRY_ID_XATTR "org.mars-nwe.afp.entry-id"
|
||||
#define MARS_NWE_AFP_FINDER_INFO_XATTR "org.mars-nwe.afp.finder-info"
|
||||
#define MARS_NWE_AFP_ATTRIBUTES_XATTR "org.mars-nwe.afp.attributes"
|
||||
@@ -40,6 +35,14 @@ typedef struct {
|
||||
uint8 attributes[2];
|
||||
} MARS_NWE_AFP_ATTRIBUTES_XATTR_DATA;
|
||||
|
||||
int nwatalk_backend_available(void)
|
||||
{
|
||||
#if XATTR_SUPPORT
|
||||
return(1);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if XATTR_SUPPORT
|
||||
static int nwatalk_get_mars_entry_id_xattr(const char *path, uint32 *entry_id)
|
||||
@@ -73,46 +76,12 @@ static int nwatalk_get_mars_entry_id_xattr(const char *path, uint32 *entry_id)
|
||||
}
|
||||
#endif
|
||||
|
||||
int nwatalk_backend_available(void)
|
||||
{
|
||||
#if NETATALK_SUPPORT
|
||||
return(1);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
static int nwatalk_open_adouble(const char *path, struct adouble *ad)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!path || !*path) return(-0x9c); /* invalid path */
|
||||
|
||||
ad_init_old(ad, AD_VERSION, 0);
|
||||
|
||||
result = ad_open(ad, path,
|
||||
ADFLAGS_HF | ADFLAGS_RF | ADFLAGS_RDONLY |
|
||||
ADFLAGS_NOHF | ADFLAGS_NORF);
|
||||
if (result < 0) {
|
||||
return(-0x9c);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int nwatalk_get_finder_info(const char *path, uint8 *finder_info,
|
||||
int finder_info_len)
|
||||
{
|
||||
#if XATTR_SUPPORT
|
||||
ssize_t len;
|
||||
#endif
|
||||
#if NETATALK_SUPPORT
|
||||
struct adouble ad;
|
||||
void *entry;
|
||||
int result;
|
||||
#endif
|
||||
|
||||
if (!finder_info || finder_info_len < NWATALK_FINDER_INFO_LEN) {
|
||||
return(-0x9c);
|
||||
@@ -128,23 +97,12 @@ int nwatalk_get_finder_info(const char *path, uint8 *finder_info,
|
||||
return(0);
|
||||
memset(finder_info, 0, finder_info_len);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
result = nwatalk_open_adouble(path, &ad);
|
||||
if (result < 0) return(result);
|
||||
|
||||
entry = ad_entry(&ad, ADEID_FINDERI);
|
||||
if (entry && ad_getentrylen(&ad, ADEID_FINDERI) >= NWATALK_FINDER_INFO_LEN) {
|
||||
memcpy(finder_info, entry, NWATALK_FINDER_INFO_LEN);
|
||||
}
|
||||
|
||||
ad_close(&ad, 0);
|
||||
return(0);
|
||||
#else
|
||||
(void)path;
|
||||
return(-0xbf); /* invalid namespace / backend unavailable */
|
||||
#endif
|
||||
|
||||
/* Missing FinderInfo is a valid AFP state; absent metadata reads as zeroes. */
|
||||
return(0);
|
||||
}
|
||||
|
||||
int nwatalk_set_finder_info(const char *path, const uint8 *finder_info,
|
||||
@@ -170,8 +128,6 @@ int nwatalk_set_finder_info(const char *path, const uint8 *finder_info,
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int nwatalk_get_afp_attributes(const char *path, uint16 *attributes)
|
||||
{
|
||||
#if XATTR_SUPPORT
|
||||
@@ -269,64 +225,17 @@ int nwatalk_set_entry_id(const char *path, uint32 entry_id)
|
||||
|
||||
int nwatalk_get_resource_fork_size(const char *path, uint32 *resource_size)
|
||||
{
|
||||
#if NETATALK_SUPPORT
|
||||
struct adouble ad;
|
||||
off_t size;
|
||||
int result;
|
||||
|
||||
(void)path;
|
||||
if (!resource_size) return(-0x9c);
|
||||
*resource_size = 0;
|
||||
|
||||
result = nwatalk_open_adouble(path, &ad);
|
||||
if (result < 0) return(result);
|
||||
|
||||
size = ad_size(&ad, ADEID_RFORK);
|
||||
if (size > 0) {
|
||||
if (size > 0xffffffffUL) size = 0xffffffffUL;
|
||||
*resource_size = (uint32)size;
|
||||
}
|
||||
|
||||
ad_close(&ad, 0);
|
||||
return(0);
|
||||
#else
|
||||
(void)path;
|
||||
(void)resource_size;
|
||||
return(-0xbf); /* invalid namespace / backend unavailable */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int nwatalk_get_entry_id(const char *path, uint32 *entry_id)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!entry_id) return(-0x9c);
|
||||
*entry_id = 0;
|
||||
if (!path || !*path) return(-0x9c);
|
||||
|
||||
result = nwatalk_get_mars_entry_id_xattr(path, entry_id);
|
||||
if (!result && *entry_id)
|
||||
return(0);
|
||||
|
||||
#if NETATALK_SUPPORT
|
||||
{
|
||||
struct adouble ad;
|
||||
struct stat stbuff;
|
||||
uint32_t id;
|
||||
|
||||
if (stat(path, &stbuff)) return(-0x9c);
|
||||
|
||||
result = nwatalk_open_adouble(path, &ad);
|
||||
if (result < 0) return(result);
|
||||
|
||||
id = ad_getid(&ad, stbuff.st_dev, stbuff.st_ino, 0, NULL);
|
||||
if (id) *entry_id = (uint32)id;
|
||||
|
||||
ad_close(&ad, 0);
|
||||
return(id ? 0 : -0x9c);
|
||||
}
|
||||
#else
|
||||
(void)result;
|
||||
return(-0xbf); /* invalid namespace / backend unavailable */
|
||||
#endif
|
||||
return(nwatalk_get_mars_entry_id_xattr(path, entry_id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user