]> arthur.barton.de Git - netatalk.git/blob - libatalk/cnid/cnid_private.h
eb104e25661c3523edd444689fa4156aa3633ae5
[netatalk.git] / libatalk / cnid / cnid_private.h
1 /*
2  * $Id: cnid_private.h,v 1.5 2001-12-14 03:10:37 jmarcus 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
15 #include <db.h>
16
17 #include <atalk/adouble.h>
18 #include <atalk/cnid.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               3
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 #ifdef EXTENDED_DB
43     DB *db_shortname;
44     DB *db_macname;
45     DB *db_longname;
46 #endif /* EXTENDED_DB */
47     DB_ENV* dbenv;
48     int lockfd, flags;
49     char close_file[MAXPATHLEN + 1];
50 } CNID_private;
51
52 /* on-disk data format (in network byte order where appropriate) --
53  * db_cnid:      (key: cnid)
54  * name          size (in bytes)
55  * dev           4
56  * ino           4
57  * did           4
58  * unix name     strlen(name) + 1 
59  *
60  * db_didname:   (key: did/unix name)
61  * -- this also caches the bits of .AppleDouble used by FPGetFilDirParam
62  *    so that we don't have to open the header file.
63  *    NOTE: FPCatSearch has to search through all of the directories as
64  *          this stuff doesn't get entered until needed.
65  *          if the entire volume is in the database, though, we can use
66  *          cursor operations to make this faster.
67  *
68  *    version number is stored with did/name key of 0/0
69  *
70  * cnid          4
71  * modfiller     4 (dates only use 4 bytes right now, but we leave space 
72  * moddate       4  for 8. moddate is also used to keep this info 
73  * createfiller  4  up-to-date.)
74  * createdate    4
75  * backfiller    4
76  * backupdate    4
77  * accfiller     4 (unused)
78  * accdate       4 (unused)
79  * AFP info      4 (stores a couple permission bits as well)
80  * finder info   32
81  * prodos info   8
82  * rforkfiller   4
83  * rforklen      4
84  * macname       32 (nul-terminated)
85  * shortname     12 (nul-terminated)
86  * longname      longnamelen (nul-terminated)
87  * ---------------
88  *             132 bytes + longnamelen
89  * 
90  * db_devino:    (key: dev/ino) 
91  * -- this is only used for consistency checks and isn't 1-1
92  * cnid          4 
93  *
94  * these correspond to the different path types. longname is for the
95  * 255 unicode character names (path type == ?), macname is for the
96  * 32-character names (path type == 2), and shortname is for the
97  * 8+3-character names (path type == 1).
98  *
99  * db_longname: (key: did/longname)
100  * name          namelen = strlen(name) + 1
101  *
102  * db_macname:   (key: did/macname)
103  * name          namelen = strlen(name) + 1
104  *
105  * db_shortname: (key: did/shortname)
106  * name namelen = strlen(name) + 1 
107  */
108
109 #ifndef __inline__
110 #define __inline__
111 #endif /* __inline__ */
112
113 /* construct db_cnid data. NOTE: this is not re-entrant.  */
114 static __inline__ char *make_cnid_data(const struct stat *st,
115                                        const cnid_t did,
116                                        const char *name, const int len)
117 {
118     static char start[CNID_HEADER_LEN + MAXPATHLEN + 1];
119     char *buf = start;
120     u_int32_t i;
121
122     if (len > MAXPATHLEN)
123         return NULL;
124
125     i = htonl(st->st_dev);
126     buf = memcpy(buf, &i, sizeof(i));
127     i = htonl(st->st_ino);
128     buf = memcpy(buf + sizeof(i), &i, sizeof(i));
129     /* did is already in network byte order */
130     buf = memcpy(buf + sizeof(i), &did, sizeof(did));
131     buf = memcpy(buf + sizeof(did), name, len);
132     *(buf + len) = '\0';
133     buf += len + 1;
134
135     return start;
136 }
137
138 #endif /* atalk/cnid/cnid_private.h */