]> arthur.barton.de Git - netatalk.git/blob - libatalk/cnid/db3/cnid_db3_private.h
remove gcc warnings and cleanup inline mess
[netatalk.git] / libatalk / cnid / db3 / cnid_db3_private.h
1 /*
2  * $Id: cnid_db3_private.h,v 1.1.4.3.2.2 2008-11-25 15:16:35 didg Exp $
3  */
4
5 #ifndef LIBATALK_CNID_PRIVATE_H
6 #define LIBATALK_CNID_PRIVATE_H 1
7
8 #include <string.h>
9 #include <sys/param.h>
10 #include <sys/stat.h>
11 #ifdef HAVE_UNISTD_H
12 #include <unistd.h>
13 #endif /* HAVE_UNISTD_H */
14 #include <sys/cdefs.h>
15 #include <db.h>
16
17 #include <atalk/adouble.h>
18 #include "cnid_db3.h"
19
20 #define CNID_DB_MAGIC   0x434E4944U  /* CNID */
21 #define CNID_DATA_MAGIC 0x434E4945U  /* CNIE */
22
23 #define CNID_DEVINO_LEN          8
24 #define CNID_DID_LEN             4
25 #define CNID_HEADER_LEN          (CNID_DEVINO_LEN + CNID_DID_LEN)
26
27 #define CNID_START               17
28
29 #define CNIDFLAG_ROOTINFO_RO     (1 << 0)
30 #define CNIDFLAG_DB_RO           (1 << 1)
31
32 /* the key is in the form of a did/name pair. in this case,
33  * we use 0/RootInfo. */
34 #define ROOTINFO_KEY    "\0\0\0\0RootInfo"
35 #define ROOTINFO_KEYLEN 12
36
37 typedef struct CNID_private {
38     u_int32_t magic;
39     DB *db_cnid;
40     DB *db_didname;
41     DB *db_devino;
42     DB_ENV *dbenv;
43     int lockfd, flags;
44     char lock_file[MAXPATHLEN + 1];
45 } CNID_private;
46
47 /* on-disk data format (in network byte order where appropriate) --
48  * db_cnid:      (key: cnid)
49  * name          size (in bytes)
50  * dev           4
51  * ino           4
52  * did           4
53  * unix name     strlen(name) + 1 
54  *
55  * db_didname:   (key: did/unix name)
56  * -- this also caches the bits of .AppleDouble used by FPGetFilDirParam
57  *    so that we don't have to open the header file.
58  *    NOTE: FPCatSearch has to search through all of the directories as
59  *          this stuff doesn't get entered until needed.
60  *          if the entire volume is in the database, though, we can use
61  *          cursor operations to make this faster.
62  *
63  *    version number is stored with did/name key of 0/0
64  *
65  * cnid          4
66  * modfiller     4 (dates only use 4 bytes right now, but we leave space 
67  * moddate       4  for 8. moddate is also used to keep this info 
68  * createfiller  4  up-to-date.)
69  * createdate    4
70  * backfiller    4
71  * backupdate    4
72  * accfiller     4 (unused)
73  * accdate       4 (unused)
74  * AFP info      4 (stores a couple permission bits as well)
75  * finder info   32
76  * prodos info   8
77  * rforkfiller   4
78  * rforklen      4
79  * macname       32 (nul-terminated)
80  * shortname     12 (nul-terminated)
81  * longname      longnamelen (nul-terminated)
82  * ---------------
83  *             132 bytes + longnamelen
84  * 
85  * db_devino:    (key: dev/ino) 
86  * -- this is only used for consistency checks and isn't 1-1
87  * cnid          4 
88  *
89  * these correspond to the different path types. longname is for the
90  * 255 unicode character names (path type == ?), macname is for the
91  * 32-character names (path type == 2), and shortname is for the
92  * 8+3-character names (path type == 1).
93  *
94  * db_longname: (key: did/longname)
95  * name          namelen = strlen(name) + 1
96  *
97  * db_macname:   (key: did/macname)
98  * name          namelen = strlen(name) + 1
99  *
100  * db_shortname: (key: did/shortname)
101  * name namelen = strlen(name) + 1 
102  */
103
104 /* construct db_cnid data. NOTE: this is not re-entrant.  */
105 static inline unsigned char *make_cnid_data(const struct stat *st,
106                                        const cnid_t did,
107                                        const char *name, const size_t len)
108 {
109     static unsigned char start[CNID_HEADER_LEN + MAXPATHLEN + 1];
110     unsigned char *buf = start;
111     u_int32_t i;
112
113     if (len > MAXPATHLEN)
114         return NULL;
115
116     i = htonl(st->st_dev);
117     buf = memcpy(buf, &i, sizeof(i));
118     i = htonl(st->st_ino);
119     buf = memcpy(buf + sizeof(i), &i, sizeof(i));
120     /* did is already in network byte order */
121     buf = memcpy(buf + sizeof(i), &did, sizeof(did));
122     buf = memcpy(buf + sizeof(did), name, len);
123     *(buf + len) = '\0';
124     buf += len + 1;
125
126     return start;
127 }
128
129 #endif /* atalk/cnid/cnid_private.h */