]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/adouble/ad_attr.c
Merge master
[netatalk.git] / libatalk / adouble / ad_attr.c
index 484961eeeb22597330a395504858bd36da24d4d3..e005577f026dd1fc661ef0ded2ef1aedc49bfdbf 100644 (file)
@@ -3,6 +3,7 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <string.h>
+#include <arpa/inet.h>
 #include <atalk/adouble.h>
 
 #define FILEIOFF_ATTR 14
@@ -14,9 +15,9 @@
    retrieved from the FinderFlags. This fixes Bug #2802236:
    <https://sourceforge.net/tracker/?func=detail&aid=2802236&group_id=8642&atid=108642>
  */
-int ad_getattr(const struct adouble *ad, u_int16_t *attr)
+int ad_getattr(const struct adouble *ad, uint16_t *attr)
 {
-    u_int16_t fflags;
+    uint16_t fflags;
     *attr = 0;
 
     if (ad->ad_version == AD_VERSION2) {
@@ -48,12 +49,12 @@ int ad_getattr(const struct adouble *ad, u_int16_t *attr)
 }
 
 /* ----------------- */
-int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
+int ad_setattr(const struct adouble *ad, const uint16_t attribute)
 {
     uint16_t fflags;
 
     /* we don't save open forks indicator */
-    u_int16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
+    uint16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
 
     /* Proactively (10.4 does indeed try to set ATTRBIT_MULTIUSER (=ATTRBIT_EXPFLDR)
        for dirs with SetFile -a M <dir> ) disable all flags not defined for dirs. */
@@ -89,7 +90,7 @@ int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
  * save file/folder ID in AppleDoubleV2 netatalk private parameters
  * return 1 if resource fork has been modified
  */
-int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const u_int32_t id, const cnid_t did, const void *stamp)
+int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const uint32_t id, const cnid_t did, const void *stamp)
 {
     if ((adp->ad_flags == AD_VERSION2) && (adp->ad_options & ADVOL_CACHE)) {
 
@@ -118,9 +119,9 @@ int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const u_in
 }
 
 /* ----------------------------- */
-u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino , const cnid_t did, const void *stamp)
+uint32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino , const cnid_t did, const void *stamp)
 {
-    u_int32_t aint = 0;
+    uint32_t aint = 0;
     dev_t  dev;
     ino_t  ino;
     cnid_t a_did;
@@ -132,7 +133,7 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino
      */
     if (adp
         && (adp->ad_options & ADVOL_CACHE)
-        && (adp->ad_md->adf_flags & O_RDWR )
+        && (adp->ad_mdp->adf_flags & O_RDWR )
         && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)) /* One check to ensure ALL values are there */
         ) {
         memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
@@ -152,9 +153,9 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino
 }
 
 /* ----------------------------- */
-u_int32_t ad_forcegetid (struct adouble *adp)
+uint32_t ad_forcegetid (struct adouble *adp)
 {
-    u_int32_t aint = 0;
+    uint32_t aint = 0;
 
     if (adp && (adp->ad_options & ADVOL_CACHE)) {
         memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
@@ -168,9 +169,12 @@ u_int32_t ad_forcegetid (struct adouble *adp)
  */
 int ad_setname(struct adouble *ad, const char *path)
 {
+    int len;
+    if ((len = strlen(path)) > ADEDLEN_NAME)
+        len = ADEDLEN_NAME;
     if (path && ad_getentryoff(ad, ADEID_NAME)) {
-        ad_setentrylen( ad, ADEID_NAME, strlen( path ));
-        memcpy(ad_entry( ad, ADEID_NAME ), path, ad_getentrylen( ad, ADEID_NAME ));
+        ad_setentrylen( ad, ADEID_NAME, len);
+        memcpy(ad_entry( ad, ADEID_NAME ), path, len);
         return 1;
     }
     return 0;