]> arthur.barton.de Git - netatalk.git/blob - include/atalk/cnid_dbd_private.h
Overhaul CNID dbd backend, make it default, txn only... See #2724774
[netatalk.git] / include / atalk / cnid_dbd_private.h
1 /*
2  *  Interface to the cnid_dbd daemon that stores/retrieves CNIDs from a database.
3  */
4
5
6 #ifndef _ATALK_CNID_DBD_PRIVATE_H
7 #define _ATALK_CNID_DBD_PRIVATE_H 1
8
9 #include <sys/stat.h>
10 #include <atalk/adouble.h>
11 #include <sys/param.h>
12
13 #define CNID_DBD_OP_OPEN        0x01
14 #define CNID_DBD_OP_CLOSE       0x02
15 #define CNID_DBD_OP_ADD         0x03
16 #define CNID_DBD_OP_GET         0x04
17 #define CNID_DBD_OP_RESOLVE     0x05
18 #define CNID_DBD_OP_LOOKUP      0x06
19 #define CNID_DBD_OP_UPDATE      0x07
20 #define CNID_DBD_OP_DELETE      0x08
21 #define CNID_DBD_OP_MANGLE_ADD  0x09
22 #define CNID_DBD_OP_MANGLE_GET  0x0a
23 #define CNID_DBD_OP_GETSTAMP    0x0b
24 #define CNID_DBD_OP_REBUILD_ADD 0x0c
25
26 #define CNID_DBD_RES_OK            0x00
27 #define CNID_DBD_RES_NOTFOUND      0x01
28 #define CNID_DBD_RES_ERR_DB        0x02
29 #define CNID_DBD_RES_ERR_MAX       0x03
30 #define CNID_DBD_RES_ERR_DUPLCNID  0x04
31
32 #define CNID_DB_MAGIC   0x434E4944U  /* CNID */
33 #define CNID_DATA_MAGIC 0x434E4945U  /* CNIE */
34
35 #define CNID_OFS                 0
36 #define CNID_LEN                 4
37  
38 #define CNID_DEV_OFS             CNID_LEN
39 #define CNID_DEV_LEN             8
40  
41 #define CNID_INO_OFS             (CNID_DEV_OFS + CNID_DEV_LEN)
42 #define CNID_INO_LEN             8
43  
44 #define CNID_DEVINO_OFS          CNID_LEN
45 #define CNID_DEVINO_LEN          (CNID_DEV_LEN +CNID_INO_LEN)
46  
47 #define CNID_TYPE_OFS            (CNID_DEVINO_OFS +CNID_DEVINO_LEN)
48 #define CNID_TYPE_LEN            4
49  
50 #define CNID_DID_OFS             (CNID_TYPE_OFS +CNID_TYPE_LEN)
51 #define CNID_DID_LEN             CNID_LEN
52  
53 #define CNID_NAME_OFS            (CNID_DID_OFS + CNID_DID_LEN)
54 #define CNID_HEADER_LEN          (CNID_NAME_OFS)
55
56 #define CNID_START               17
57
58 #define CNIDFLAG_ROOTINFO_RO     (1 << 0)
59 #define CNIDFLAG_DB_RO           (1 << 1)
60
61 /* special key/data pair we use to store current cnid and database stamp in cnid2.db */
62
63 #define ROOTINFO_KEY    "\0\0\0\0"
64 #define ROOTINFO_KEYLEN 4
65
66 /* 
67    Rootinfo data:
68    4 unused bytes (cnid) 
69    8 bytes, in first 4 bytes db stamp: struct stat.st_ctime of database file (dev)
70    8 unused bytes (inode)
71    4 bytes: last used cnid (type)
72    4 unused bytes (did)
73    9 bytes name "RootInfo"
74 */
75 #define ROOTINFO_DATA    "\0\0\0\0" \
76                          "\0\0\0\0\0\0\0\0" \
77                          "\0\0\0\0\0\0\0\0" \
78                          "\0\0\0\0" \
79                          "\0\0\0\0" \
80                          "RootInfo"
81 #define ROOTINFO_DATALEN (3*4 + 2*8 + 9)
82
83 struct cnid_dbd_rqst {
84     int     op;
85     cnid_t  cnid;
86     dev_t   dev;
87     ino_t   ino;
88     u_int32_t type;
89     cnid_t  did;
90     char   *name;
91     size_t  namelen;
92 };
93
94 struct cnid_dbd_rply {
95     int     result;    
96     cnid_t  cnid;
97     cnid_t  did;
98     char   *name;
99     size_t  namelen;
100 };
101
102 typedef struct CNID_private {
103     u_int32_t magic;
104     char      db_dir[MAXPATHLEN + 1]; /* Database directory without /.AppleDB appended */
105     int       fd;               /* File descriptor to cnid_dbd */
106     char      stamp[ADEDLEN_PRIVSYN]; /* db timestamp */
107     char      *client_stamp;
108     size_t    stamp_size;
109     int       notfirst;   /* already open before */
110     int       changed;  /* stamp differ */
111 } CNID_private;
112
113
114 #endif /* include/atalk/cnid_dbd.h */