]> arthur.barton.de Git - netatalk.git/blobdiff - include/atalk/adouble.h
Apply patch after importing new version
[netatalk.git] / include / atalk / adouble.h
index a1a2ecbd8047ba9346a4248c77ff458a2208f641..5de2b4ebf169fdf6c7794943352e5bbf1408832c 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
 #define AD_DATASZ   AD_DATASZ_EA
 #endif
 
-typedef u_int32_t cnid_t;
+#define RFORK_EA_ALLOCSIZE (128*1024) /* 128k */
+
+typedef uint32_t cnid_t;
 
 struct ad_entry {
     uint32_t   ade_off;
@@ -160,47 +164,52 @@ struct ad_fd {
     char         *adf_syml;
     int          adf_flags;
     int          adf_excl;
+#if 0
     adf_lock_t   *adf_lock;
     int          adf_refcount, adf_lockcount, adf_lockmax;
+#endif
 };
 
 /* some header protection */
 #define AD_INITED  0xad494e54  /* ad"INT" */
+#define AD_CLOSED  0xadc10ced
 
 struct adouble;
 
 struct adouble_fops {
-    char *(*ad_path)(const char *, int);
-    int  (*ad_mkrf)(char *);
+    const char *(*ad_path)(const char *, int);
+    int  (*ad_mkrf)(const char *);
     int  (*ad_rebuild_header)(struct adouble *);
     int  (*ad_header_read)(struct adouble *, struct stat *);
-    int  (*ad_header_upgrade)(struct adouble *, char *);
+    int  (*ad_header_upgrade)(struct adouble *, const char *);
 };
 
 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;
+    uint32_t            ad_magic;         /* Official adouble magic                   */
+    uint32_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;
-    int                 ad_fileordir;
-    int                 ad_refcount; /* used in afpd/ofork.c */
-    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;       /* fullpath of file, adouble:ea need this  */
     struct adouble_fops *ad_ops;
-    uint16_t            ad_open_forks;      /* open forks (by others) */
-#ifdef USE_MMAPPED_HEADERS
-    char                *ad_data;
-#else
+    uint16_t            ad_open_forks;     /* open forks (by others)                  */
     char                ad_data[AD_DATASZ_MAX];
-#endif
 };
 
 #define ADFLAGS_DF        (1<<0)
@@ -208,9 +217,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_RDONLY    (1<<5)  /* don't try readwrite */
-#define ADFLAGS_OPENFORKS (1<<6)  /* check for open fork in ad_metadata function */
-#define ADFLAGS_CREATE    (1<<7)
+#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 +341,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 *);
@@ -345,41 +356,36 @@ extern int ad_flush (struct adouble *);
 extern int ad_close (struct adouble *, int);
 
 /* ad_lock.c */
-extern int ad_fcntl_lock    (struct adouble *, const u_int32_t /*eid*/,
-                                 const int /*type*/, const off_t /*offset*/,
-                                 const off_t /*len*/, const int /*user*/);
-extern void ad_fcntl_unlock (struct adouble *, const int /*user*/);
-extern int ad_fcntl_tmplock (struct adouble *, const u_int32_t /*eid*/,
-                                 const int /*type*/, const off_t /*offset*/,
-                                 const off_t /*len*/, const int /*user*/);
-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*/);
-
-#define ad_lock ad_fcntl_lock
-#define ad_tmplock ad_fcntl_tmplock
-#define ad_unlock ad_fcntl_unlock
+extern int ad_testlock      (struct adouble *adp, int eid, off_t off);
+extern uint16_t ad_openforks(struct adouble *adp, uint16_t);
+extern int ad_excl_lock     (struct adouble *adp, uint32_t eid);
+
+extern int ad_lock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+extern void ad_unlock(struct adouble *, int user);
+extern int ad_tmplock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
 
 /* ad_open.c */
-extern uint32_t get_eid   (uint32_t eid);
+extern const char *oflags2logstr(int oflags);
+extern const char *adflags2logstr(int adflags);
 extern int ad_setfuid     (const uid_t );
 extern uid_t ad_getfuid   (void );
 extern char *ad_dir       (const char *);
-extern char *ad_path      (const char *, int);
-extern char *ad_path_ea   (const char *, int);
+extern const char *ad_path      (const char *, int);
+extern const char *ad_path_ea   (const char *, int);
 extern int ad_mode        (const char *, int);
 extern int ad_mkdir       (const char *, int);
 extern void ad_init       (struct adouble *, int, int );
-extern int ad_open        (const char *, int, int, int, struct adouble *);
-extern int ad_openat      (int dirfd, const char *, int, int, int, struct adouble *);
+extern int ad_open        (struct adouble *ad, const char *path, int adflags, ...);
+extern int ad_openat      (struct adouble *, int dirfd, const char *path, int adflags, ...);
 extern int ad_refresh     (struct adouble *);
 extern int ad_stat        (const char *, struct stat *);
 extern int ad_metadata    (const char *, int, struct adouble *);
 extern int ad_metadataat  (int, const char *, int, struct adouble *);
 
+#if 0
 #define ad_open_metadata(name, flags, mode, adp)\
    ad_open(name, ADFLAGS_HF | (flags), O_RDWR |(mode), 0666, (adp))
+#endif
 
 #define ad_close_metadata(adp) ad_close( (adp), ADFLAGS_HF)
 
@@ -435,8 +441,8 @@ extern int       ad_setattr(const struct adouble *, uint16_t);
 extern int       ad_getattr(const struct adouble *, uint16_t *);
 extern int       ad_setname(struct adouble *, const char *);
 extern int       ad_setid(struct adouble *, dev_t dev, ino_t ino, uint32_t, uint32_t, const void *);
-extern u_int32_t ad_getid(struct adouble *, dev_t, ino_t, cnid_t, const void *);
-extern u_int32_t ad_forcegetid(struct adouble *adp);
+extern uint32_t  ad_getid(struct adouble *, dev_t, ino_t, cnid_t, const void *);
+extern uint32_t  ad_forcegetid(struct adouble *adp);
 
 #ifdef WITH_SENDFILE
 extern int ad_readfile_init(const struct adouble *ad, int eid, off_t *off, int end);