]> arthur.barton.de Git - netatalk.git/blobdiff - include/atalk/adouble.h
Fixes
[netatalk.git] / include / atalk / adouble.h
index d0813083dd8b359951edf0e8ac0fc253aa012d7a..eac8be144cc7ecfec168d5b809b3a67edddb9f9a 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <sys/cdefs.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/time.h>
 
 #include <netatalk/endian.h>
 #include <atalk/bstrlib.h>
+#include <atalk/locking.h>
 
 /* version info */
 #define AD_VERSION2     0x00020000
@@ -171,6 +171,7 @@ struct ad_fd {
 
 /* some header protection */
 #define AD_INITED  0xad494e54  /* ad"INT" */
+#define AD_CLOSED  0xadc10ced
 
 struct adouble;
 
@@ -183,25 +184,30 @@ struct adouble_fops {
 };
 
 struct adouble {
-    u_int32_t           ad_magic;
-    u_int32_t           ad_version;
-    char                ad_filler[ 16 ];
-    struct ad_entry     ad_eid[ ADEID_MAX ];
-    struct ad_fd        ad_data_fork, ad_resource_fork, ad_metadata_fork;
-    struct ad_fd        *ad_md; /* either ad_resource or ad_metadata */
-    int                 ad_flags;    /* This really stores version info too (AD_VERSION*) */
-    int                 ad_adflags;  /* ad_open flags adflags like ADFLAGS_DIR */
-    unsigned int        ad_inited;
+    u_int32_t           ad_magic;         /* Official adouble magic                   */
+    u_int32_t           ad_version;       /* Official adouble version number          */
+    char                ad_filler[16];
+    struct ad_entry     ad_eid[ADEID_MAX];
+    struct ad_fd        ad_data_fork;     /* the data fork                            */
+    struct ad_fd        ad_resource_fork; /* adouble:v2 -> the adouble file           *
+                                           * adouble:ea -> the rfork EA               */
+    struct ad_fd        ad_metadata_fork; /* adouble:v2 -> unused                     *
+                                           * adouble:ea -> the metadata EA            */
+    struct ad_fd        *ad_md;           /* either ad_resource or ad_metadata        */
+    int                 ad_flags;         /* Our adouble version info (AD_VERSION*)   */
+    int                 ad_adflags;       /* ad_open flags adflags like ADFLAGS_DIR   */
+    uint32_t            ad_inited;
     int                 ad_options;
-    void                *ad_resforkbuf;  /* buffer for AD_VERSION_EA ressource fork */
-    size_t              ad_resforkbufsize; /* size of ad_resforkbuf */
-    off_t               ad_rlen;     /* ressource fork len with AFP 3.0
-                                        the header parameter size is too small. */
-    char                *ad_m_name;   /* mac name for open fork */
+    int                 ad_refcount;       /* multiple forks may open one adouble     */
+    void                *ad_resforkbuf;    /* buffer for AD_VERSION_EA ressource fork */
+    size_t              ad_resforkbufsize; /* size of ad_resforkbuf                   */
+    off_t               ad_rlen;           /* ressource fork len with AFP 3.0         *
+                                            * the header parameter size is too small. */
+    char                *ad_m_name;        /* mac name for open fork                  */
     int                 ad_m_namelen;
-    bstring             ad_fullpath; /* adouble EA need this */
+    bstring             ad_fullpath;       /* fullpath of file, adouble:ea need this  */
     struct adouble_fops *ad_ops;
-    uint16_t            ad_open_forks; /* open forks (by others) */
+    uint16_t            ad_open_forks;     /* open forks (by others)                  */
     char                ad_data[AD_DATASZ_MAX];
 };
 
@@ -210,7 +216,7 @@ struct adouble {
 #define ADFLAGS_HF        (1<<2)
 #define ADFLAGS_DIR       (1<<3)
 #define ADFLAGS_NOHF      (1<<4)  /* not an error if no ressource fork */
-#define ADFLAGS_OPENFORKS (1<<5)  /* check for open fork in ad_metadata function */
+#define ADFLAGS_CHECK_OF  (1<<6)  /* check for open forks from us and other afpd's */
 
 #define ADVOL_NODEV      (1 << 0)
 #define ADVOL_CACHE      (1 << 1)
@@ -334,9 +340,13 @@ struct adouble {
 #define ad_getentryoff(ad,eid)     ((ad)->ad_eid[(eid)].ade_off)
 #define ad_entry(ad,eid)           ((caddr_t)(ad)->ad_data + (ad)->ad_eid[(eid)].ade_off)
 
-#define ad_get_HF_flags(ad) ((ad)->ad_resource_fork.adf_flags)
+#define ad_get_RF_flags(ad) ((ad)->ad_resource_fork.adf_flags)
 #define ad_get_MD_flags(ad) ((ad)->ad_md->adf_flags)
 
+/* Refcounting open forks using one struct adouble */
+#define ad_ref(ad)   (ad)->ad_refcount++
+#define ad_unref(ad) --((ad)->ad_refcount)
+
 /* ad_flush.c */
 extern int ad_rebuild_adouble_header (struct adouble *);
 extern int ad_rebuild_sfm_header (struct adouble *);
@@ -357,9 +367,16 @@ extern int ad_testlock      (struct adouble * /*adp*/, int /*eid*/, off_t /*off*
 extern u_int16_t ad_openforks (struct adouble * /*adp*/, u_int16_t);
 extern int ad_excl_lock     (struct adouble * /*adp*/, const u_int32_t /*eid*/);
 
+#if 0
 #define ad_lock ad_fcntl_lock
 #define ad_tmplock ad_fcntl_tmplock
 #define ad_unlock ad_fcntl_unlock
+#endif
+
+#define ad_lock rpc_lock
+#define ad_tmplock rpc_tmplock
+#define ad_unlock rpc_unlock
+
 
 /* ad_open.c */
 extern const char *oflags2logstr(int oflags);