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