]> arthur.barton.de Git - netatalk.git/commitdiff
Successfully created first EA adouble object
authorFrank Lahm <franklahm@googlemail.com>
Wed, 1 Dec 2010 13:57:43 +0000 (14:57 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 1 Dec 2010 13:57:43 +0000 (14:57 +0100)
etc/afpd/file.c
include/atalk/ea.h
libatalk/adouble/ad_flush.c
libatalk/adouble/ad_open.c
libatalk/vfs/ea_sys.c
libatalk/vfs/extattr.c

index d3bf5600b36e1f68c91a15d3b1fadfe2eaa73f71..100e439b3d42bb4d00517ae7ae84f5c2fee837cf 100644 (file)
@@ -712,7 +712,7 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
         openf = O_RDWR|O_CREAT|O_EXCL;
     }
 
-    if ( ad_open( upath, ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF|ADFLAGS_CREATE,
+    if ( ad_open( upath, ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF,
                   openf, 0666, adp) < 0 ) {
         switch ( errno ) {
         case EROFS:
@@ -730,7 +730,7 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
             return( AFPERR_PARAM );
         }
     }
-    if ( ad_reso_fileno( adp ) == -1 ) { /* Hard META / HF */
+    if ( ad_meta_fileno( adp ) == -1 ) { /* Hard META / HF */
          /* on noadouble volumes, just creating the data fork is ok */
          if (vol_noadouble(vol)) {
              ad_close( adp, ADFLAGS_DF );
index 8f10086e3cf1b0c80dacaf19280f6d2f6055303b..3c92529b10f437d08de7223ac605fb8e4c4e1e01 100644 (file)
 #include <sys/acl.h>
 #endif
 
+#ifndef ENOATTR
+#define ENOATTR ENODATA
+#endif
+
 #include <atalk/vfs.h>
 
 /*
index a6235775ea796e5a3f43304b5ddc49e3a8cf1ddb..e234ed7b5ab55d15e80523e1625ce76ee00565eb 100644 (file)
@@ -58,6 +58,8 @@ int  ad_rebuild_adouble_header(struct adouble *ad)
     memcpy(buf, &temp, sizeof( temp ));
     buf += sizeof( temp );
 
+    buf += sizeof( ad->ad_filler );
+
     nentp = buf;
     buf += sizeof( nent );
     for ( eid = 0, nent = 0; eid < ADEID_MAX; eid++ ) {
@@ -80,7 +82,7 @@ int  ad_rebuild_adouble_header(struct adouble *ad)
     nent = htons( nent );
     memcpy(nentp, &nent, sizeof( nent ));
 
-    switch (ad->ad_version) {
+    switch (ad->ad_flags) {
     case AD_VERSION2:
         len = ad_getentryoff(ad, ADEID_RFORK);
         break;
@@ -144,7 +146,7 @@ int ad_flush(struct adouble *ad)
         }
         len = ad->ad_ops->ad_rebuild_header(ad);
 
-        switch (ad->ad_version) {
+        switch (ad->ad_flags) {
         case AD_VERSION2:
             if (adf_pwrite(ad->ad_md, ad->ad_data, len, 0) != len) {
                 if (errno == 0)
index ba88b5d7ac82c1c269b9a8b6d793d2570452b17a..fe248ab4e085ea42a0ba8bcdc5302cfb958be8b5 100644 (file)
@@ -202,7 +202,7 @@ static int new_ad_header(const char *path, struct adouble *ad, int adflags)
         ad->ad_version = AD_VERSION;
     }
 
-    memset(ad->ad_filler, 0, sizeof( ad->ad_filler ));
+
     memset(ad->ad_data, 0, sizeof(ad->ad_data));
 
     if (ad->ad_flags == AD_VERSION2)
@@ -365,14 +365,15 @@ static int ad_header_read_ea(struct adouble *ad, struct stat *hst _U_)
     int      len;
     ssize_t  header_len;
     char     *buf = ad->ad_data;
+
     /* read the header */
-    if ((header_len = sys_fgetxattr(ad->ad_md->adf_fd, AD_EA_META, ad->ad_data, AD_DATASZ_EA)) < 0) {
-        LOG(log_error, logtype_default, "ad_open: can't parse AppleDouble header.");
-        errno = EIO;
+    if ((header_len = sys_fgetxattr(ad->ad_md->adf_fd, AD_EA_META, ad->ad_data, AD_DATASZ_EA)) < 1) {
+        LOG(log_debug, logtype_default, "ad_header_read_ea: %s (%u)", strerror(errno), errno);
         return -1;
     }
+
     if (header_len < AD_HEADER_LEN) {
-        LOG(log_error, logtype_default, "ad_open: can't parse AppleDouble header.");
+        LOG(log_error, logtype_default, "ad_header_read_ea: bogus AppleDouble header.");
         errno = EIO;
         return -1;
     }
@@ -383,8 +384,8 @@ static int ad_header_read_ea(struct adouble *ad, struct stat *hst _U_)
     ad->ad_magic = ntohl( ad->ad_magic );
     ad->ad_version = ntohl( ad->ad_version );
 
-    if ((ad->ad_magic != AD_MAGIC) || (ad->ad_version != AD_VERSION_EA)) {
-        LOG(log_error, logtype_default, "ad_open: can't parse AppleDouble header.");
+    if ((ad->ad_magic != AD_MAGIC) || (ad->ad_version != AD_VERSION2)) {
+        LOG(log_error, logtype_default, "ad_header_read_ea: wrong magic or version");
         errno = EIO;
         return -1;
     }
@@ -397,7 +398,7 @@ static int ad_header_read_ea(struct adouble *ad, struct stat *hst _U_)
     if (len + AD_HEADER_LEN > sizeof(ad->ad_data))
         len = sizeof(ad->ad_data) - AD_HEADER_LEN;
     if (len > header_len - AD_HEADER_LEN) {
-        LOG(log_error, logtype_default, "ad_header_read: can't read entry info.");
+        LOG(log_error, logtype_default, "ad_header_read_ea: can't read entry info.");
         errno = EIO;
         return -1;
     }
@@ -508,6 +509,9 @@ static int ad_open_df(const char *path, int adflags, int oflags, int mode, struc
     int         hoflags, admode;
     int         st_invalid = -1;
 
+    LOG(log_maxdebug, logtype_default, "ad_open_df(\"%s/%s\", adf: 0x%04x, of: 0x%04x)",
+        getcwdpath(), path, adflags, oflags);
+
     if (ad_data_fileno(ad) == -1) {
         hoflags = (oflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
         admode = mode;
@@ -671,43 +675,63 @@ static int ad_open_hf_v2(const char *path, int adflags, int oflags, int mode, st
 
 static int ad_open_hf_ea(const char *path, int adflags, int oflags, int mode, struct adouble *ad)
 {
-    int hoflags;
     ssize_t rforklen;
+    int ret;
+    int err;
+
+    LOG(log_maxdebug, logtype_default, "ad_open_hf_ea(\"%s/%s\", adf: 0x%04x, of: 0x%04x)",
+        getcwdpath(), path, adflags, oflags);
 
-    hoflags = (oflags & ~(O_CREAT | O_EXCL)) | O_NOFOLLOW;
-    if ((ad->ad_md->adf_fd = open(path, hoflags)) == -1)
+    if ((ad->ad_md->adf_fd = open(path, O_RDONLY | O_NOFOLLOW)) == -1)
         return -1;
 
     /* Read the adouble header in and parse it.*/
     if (ad->ad_ops->ad_header_read(ad, NULL) != 0) {
+        if (!(oflags & O_CREAT)) {
+            ret = 0;
+            goto error;
+        }
+
         /* It doesnt exist, EPERM or another error */
-        if (errno != ENOENT)
-            return -1;
+        if (errno != ENOATTR) {
+            LOG(log_maxdebug, logtype_default, "ad_open_hf_ea: unexpected: %s", strerror(errno));
+            ret = -1;
+            goto error;
+        }
 
         /* Create one */
         if (new_ad_header(path, ad, adflags) < 0) {
-            int err = errno;
-            /* the file is already deleted, perm, whatever, so return an error */
-            ad_close(ad, adflags);
-            errno = err;
-            return -1;
+            ret = -1;
+            goto error;
         }
+
         ad_flush(ad);
     }
 
-    if ((rforklen = sys_lgetxattr(path, AD_EA_RESO, NULL, 0)) < 0) {
-        rforklen = 0;
-    }
+    ad->ad_md->adf_flags = O_RDWR; /* Pretend its rw, in fact for the EA API it is */
+
+    if ((rforklen = sys_fgetxattr(ad->ad_md->adf_fd, AD_EA_RESO, NULL, 0)) > 0)
+        ad->ad_rlen = rforklen;
 
-    ad->ad_rlen = rforklen;
     return 0;
+
+error:
+    err = errno;
+    ad_close(ad, adflags);
+    errno = err;
+    LOG(log_error, logtype_default, "ad_open_hf_ea: error: %s", strerror(errno));
+    return ret;
 }
 
 static int ad_open_hf(const char *path, int adflags, int oflags, int mode, struct adouble *ad)
 {
     int ret = 0;
 
+    LOG(log_maxdebug, logtype_default, "ad_open_hf(\"%s/%s\", adf: 0x%04x, of: 0x%04x)",
+        getcwdpath(), path, adflags, oflags);
+
     if (ad_meta_fileno(ad) != -1) { /* the file is already open */
+        LOG(log_maxdebug, logtype_default,"the file is already open");
         if ((oflags & ( O_RDWR | O_WRONLY))
             && !(ad->ad_md->adf_flags & ( O_RDWR | O_WRONLY))) {
             if ((adflags & ADFLAGS_HF) && ad->ad_data_fork.adf_refcount)
@@ -726,7 +750,7 @@ static int ad_open_hf(const char *path, int adflags, int oflags, int mode, struc
     memset(ad->ad_eid, 0, sizeof( ad->ad_eid ));
     ad->ad_rlen = 0;
 
-    switch (ad->ad_version) {
+    switch (ad->ad_flags) {
     case AD_VERSION2:
         ret = ad_open_hf_v2(path, adflags, oflags, mode, ad);
         break;
@@ -997,10 +1021,12 @@ int ad_open(const char *path, int adflags, int oflags, int mode, struct adouble
             return -1;
     }
 
+#if 0
     if ((adflags & ADFLAGS_RF)) {
         if (ad_open_rf(path, adflags, oflags, mode, ad) != 0)
             return -1;
     }
+#endif
 
     return 0;
 }
index 49d6b2837c15ba80bb6da4c30559127d1b30fe27..2b1879a5efe9254358736c6b0c9c66f4cae19300 100644 (file)
 #include <atalk/unix.h>
 #include <atalk/compat.h>
 
-#ifndef ENOATTR
-#define ENOATTR ENODATA
-#endif
-
-
 /**********************************************************************************
  * EA VFS funcs for storing EAs in nativa filesystem EAs
  **********************************************************************************/
index 35587a6ede683236ba727253df8ffe0bcf033b7e..7b3ea32e012d9ff57b0651fef8e9be0cb0ca9560 100644 (file)
 #include <atalk/logger.h>
 #include <atalk/ea.h>
 
-#ifndef ENOATTR
-#define ENOATTR ENODATA
-#endif
-
 /******** Solaris EA helper function prototypes ********/
 #ifdef HAVE_ATTROPEN
 #define SOLARIS_ATTRMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
@@ -149,8 +145,10 @@ ssize_t sys_getxattr (const char *path, const char *uname, void *value, size_t s
 #endif
 }
 
-ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
+ssize_t sys_fgetxattr (int filedes, const char *uname, void *value, size_t size)
 {
+    const char *name = prefix(uname);
+
 #if defined(HAVE_FGETXATTR)
 #ifndef XATTR_ADD_OPT
     return fgetxattr(filedes, name, value, size);
@@ -176,7 +174,8 @@ ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
             return retval;
     }
 
-    DEBUG(10,("sys_fgetxattr: extattr_get_fd() failed with: %s\n", strerror(errno)));
+    LOG(log_debug, logtype_default, "sys_fgetxattr: extattr_get_fd(): %s",
+        strerror(errno)));
     return -1;
 #elif defined(HAVE_ATTR_GETF)
     int retval, flags = 0;
@@ -630,8 +629,10 @@ int sys_setxattr (const char *path, const char *uname, const void *value, size_t
 #endif
 }
 
-int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags)
+int sys_fsetxattr (int filedes, const char *uname, const void *value, size_t size, int flags)
 {
+    const char *name = prefix(uname);
+
 #if defined(HAVE_FSETXATTR)
 #ifndef XATTR_ADD_OPT
     return fsetxattr(filedes, name, value, size, flags);
@@ -659,7 +660,7 @@ int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size
             /* Ignore other errors */
         }
         else {
-            /* CREATE attribute, that already exists */
+            log_error, logtype_default            /* CREATE attribute, that already exists */
             if (flags & XATTR_CREATE) {
                 errno = EEXIST;
                 return -1;