#include <atalk/adouble.h>
#include <atalk/ea.h>
#include <atalk/logger.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
-#include "ad_private.h"
+#include "ad_lock.h"
static const u_int32_t set_eid[] = {
0,1,2,3,4,5,6,7,8,
}
break;
case AD_VERSION_EA:
- if (sys_fsetxattr(ad->ad_md->adf_fd, AD_EA_META, ad->ad_data, AD_DATASZ_EA, 0) != 0) {
+ if (sys_lsetxattr(cfrombstr(ad->ad_fullpath), AD_EA_META, ad->ad_data, AD_DATASZ_EA, 0) != 0) {
LOG(log_error, logtype_afpd, "ad_flush: sys_fsetxattr error: %s",
strerror(errno));
return -1;
return( 0 );
}
-/* use refcounts so that we don't have to re-establish fcntl locks. */
+/*!
+ * Close a struct adouble freeing all resources
+ *
+ * This close the whole thing, regardless of what you pass in adflags!
+ * When open forks are using this struct adouble (ad_refcount>0) the close
+ * request is ignored.
+ */
int ad_close( struct adouble *ad, int adflags)
{
- int err = 0;
+ int err = 0;
+
+ LOG(log_debug, logtype_default, "ad_close(\"%s\", %s)",
+ cfrombstr(ad->ad_fullpath),
+ adflags2logstr(adflags));
- if ((adflags & ADFLAGS_DF)
- && (ad_data_fileno(ad) >= 0 || ad_data_fileno(ad) == -2) /* -2 means symlink */
- && (--ad->ad_data_fork.adf_refcount == 0)) {
- if (ad->ad_data_fork.adf_syml != NULL) {
+ if (ad->ad_refcount) {
+ LOG(log_debug, logtype_default, "ad_close(\"%s\"): adouble in use by fork, not closing",
+ cfrombstr(ad->ad_fullpath));
+ return 0;
+ }
+
+ if (ad_data_fileno(ad) != -1) {
+ if ((ad_data_fileno(ad) == -2) && (ad->ad_data_fork.adf_syml != NULL)) {
free(ad->ad_data_fork.adf_syml);
- ad->ad_data_fork.adf_syml = 0;
+ ad->ad_data_fork.adf_syml = NULL;
} else {
if ( close( ad_data_fileno(ad) ) < 0 )
err = -1;
ad->ad_adflags &= ~ADFLAGS_DF;
}
- if ((adflags & ADFLAGS_HF)
- && (ad_meta_fileno(ad) != -1)
- && (--ad->ad_md->adf_refcount == 0)) {
+ if (ad_meta_fileno(ad) != -1) {
if ( close( ad_meta_fileno(ad) ) < 0 )
err = -1;
ad_meta_fileno(ad) = -1;
ad->ad_adflags &= ~ADFLAGS_HF;
}
- if ((adflags & ADFLAGS_RF)
- && (--ad->ad_resource_fork.adf_refcount == 0)
- && (ad->ad_resforkbuf)) {
+ if (ad->ad_resforkbuf) {
free(ad->ad_resforkbuf);
ad->ad_resforkbuf = NULL;
ad->ad_adflags &= ~ADFLAGS_RF;
}
- /* If both header and ressource are not open anymore, deallocate fullpath */
- if (!(adflags & (ADFLAGS_HF | ADFLAGS_RF))) {
- if (ad->ad_fullpath) {
- bdestroy(ad->ad_fullpath);
- ad->ad_fullpath = NULL;
- }
+ if (ad->ad_fullpath) {
+ bdestroy(ad->ad_fullpath);
+ ad->ad_fullpath = NULL;
}
return err;