]> arthur.barton.de Git - netatalk.git/blob - libatalk/cnid/tdb/cnid_tdb.h
remove gcc warnings and cleanup inline mess
[netatalk.git] / libatalk / cnid / tdb / cnid_tdb.h
1 /* 
2  * interface for database access to cnids. i do it this way to abstract
3  * things a bit in case we want to change the underlying implementation.
4  */
5
6 #ifndef _ATALK_CNID_TDB__H
7 #define _ATALK_CNID_TDB__H 1
8
9 #include <sys/cdefs.h>
10 #include <sys/stat.h>
11 #include <unistd.h>
12 #include <string.h>
13
14 #include <sys/param.h>
15
16 #include <netatalk/endian.h>
17 #include <atalk/cnid.h>
18 #define STANDALONE 1
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <sys/mman.h>
28 #include <sys/stat.h>
29 #include <signal.h>
30 #include <atalk/tdb.h>
31
32 #define TDB_ERROR_LINK  1
33 #define TDB_ERROR_DEV   2
34 #define TDB_ERROR_INODE 4
35
36 #define TDB_DB_MAGIC   0x434E4944U  /* CNID */
37 #define TDB_DATA_MAGIC 0x434E4945U  /* CNIE */
38
39 #define TDB_DEVINO_LEN          8
40 #define TDB_DID_LEN             4
41 #define TDB_HEADER_LEN          (TDB_DEVINO_LEN + TDB_DID_LEN)
42
43 #define TDB_START               17
44
45 #define TDBFLAG_ROOTINFO_RO     (1 << 0)
46 #define TDBFLAG_DB_RO           (1 << 1)
47
48 /* the key is in the form of a did/name pair. in this case,
49  * we use 0/RootInfo. */
50 #define ROOTINFO_KEY    "\0\0\0\0RootInfo"
51 #define ROOTINFO_KEYLEN 12
52
53 struct _cnid_tdb_private {
54     dev_t  st_dev;
55     int    st_set;
56     int    error;
57     int    flags;
58     TDB_CONTEXT *tdb_cnid;
59     TDB_CONTEXT *tdb_didname;
60     TDB_CONTEXT *tdb_devino;
61
62 };
63
64 /* cnid_open.c */
65 extern struct _cnid_module cnid_tdb_module;
66 extern struct _cnid_db *cnid_tdb_open __P((const char *, mode_t));
67
68 /* cnid_close.c */
69 extern void cnid_tdb_close __P((struct _cnid_db *));
70
71 /* cnid_add.c */
72 extern cnid_t cnid_tdb_add __P((struct _cnid_db *, const struct stat *, const cnid_t,
73                                  char *, const size_t, cnid_t));
74
75 /* cnid_get.c */
76 extern cnid_t cnid_tdb_get __P((struct _cnid_db *, const cnid_t, char *, const size_t));
77 extern char *cnid_tdb_resolve __P((struct _cnid_db *, cnid_t *, void *, size_t));
78 extern cnid_t cnid_tdb_lookup __P((struct _cnid_db *, const struct stat *, const cnid_t, char *, const size_t));
79
80 /* cnid_update.c */
81 extern int cnid_tdb_update __P((struct _cnid_db *, const cnid_t, const struct stat *,
82                                  const cnid_t, char *, size_t));
83
84 /* cnid_delete.c */
85 extern int cnid_tdb_delete __P((struct _cnid_db *, const cnid_t));
86
87 /* cnid_nextid.c */
88 extern cnid_t cnid_tdb_nextid __P((struct _cnid_db *));
89
90 /* construct db_cnid data. NOTE: this is not re-entrant.  */
91 static inline char *make_tdb_data(const struct stat *st,
92                                        const cnid_t did,
93                                        const char *name, const size_t len)
94 {
95     static char start[TDB_HEADER_LEN + MAXPATHLEN + 1];
96     char *buf = start;
97     u_int32_t i;
98
99     if (len > MAXPATHLEN)
100         return NULL;
101
102     i = htonl(st->st_dev);
103     buf = memcpy(buf, &i, sizeof(i));
104     i = htonl(st->st_ino);
105     buf = memcpy(buf + sizeof(i), &i, sizeof(i));
106     /* did is already in network byte order */
107     buf = memcpy(buf + sizeof(i), &did, sizeof(did));
108     buf = memcpy(buf + sizeof(did), name, len);
109     *(buf + len) = '\0';
110     buf += len + 1;
111
112     return start;
113 }
114
115 #endif /* include/atalk/cnid_tdb.h */