2 * $Id: cnid_cdb_private.h,v 1.1.4.6 2004-02-07 19:46:09 didg Exp $
5 #ifndef LIBATALK_CDB_PRIVATE_H
6 #define LIBATALK_CDB_PRIVATE_H 1
10 #endif /* HAVE_CONFIG_H */
12 #include <netatalk/endian.h>
16 #endif /* HAVE_UNISTD_H */
22 #endif /* HAVE_FCNTL_H */
23 #include <sys/param.h>
25 #ifdef HAVE_SYS_TIME_H
27 #endif /* HAVE_SYS_TIME_H */
28 #include <sys/cdefs.h>
31 #include <atalk/logger.h>
32 #include <atalk/adouble.h>
33 #include <atalk/cnid.h>
34 #include <atalk/util.h>
37 #define CNID_DB_MAGIC 0x434E4944U /* CNID */
38 #define CNID_DATA_MAGIC 0x434E4945U /* CNIE */
44 type/last cnid 4 Not used
56 typedef struct cnid_record { /* helper for debug don't use */
68 #define CNID_DEV_OFS CNID_LEN
69 #define CNID_DEV_LEN 8
71 #define CNID_INO_OFS (CNID_DEV_OFS + CNID_DEV_LEN)
72 #define CNID_INO_LEN 8
74 #define CNID_DEVINO_OFS CNID_LEN
75 #define CNID_DEVINO_LEN (CNID_DEV_LEN +CNID_INO_LEN)
77 #define CNID_TYPE_OFS (CNID_DEVINO_OFS +CNID_DEVINO_LEN)
78 #define CNID_TYPE_LEN 4
80 #define CNID_DID_OFS (CNID_TYPE_OFS +CNID_TYPE_LEN)
81 #define CNID_DID_LEN CNID_LEN
83 #define CNID_NAME_OFS (CNID_DID_OFS + CNID_DID_LEN)
84 #define CNID_HEADER_LEN (CNID_NAME_OFS)
88 #define CNIDFLAG_ROOTINFO_RO (1 << 0)
89 #define CNIDFLAG_DB_RO (1 << 1)
92 * we use 0/RootInfo. */
93 #define ROOTINFO_KEY "\0\0\0\0"
94 #define ROOTINFO_KEYLEN 4
96 /* cnid - dev - inode - type - did - name */
97 #define ROOTINFO_DATA "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0RootInfo"
98 #define ROOTINFO_DATALEN (3*4 +2*8 +9)
101 typedef struct CNID_private {
108 char lock_file[MAXPATHLEN + 1];
111 /* on-disk data format (in network byte order where appropriate) --
112 * db_cnid: (key: cnid)
113 * name size (in bytes)
117 * unix name strlen(name) + 1
119 * db_didname: (key: did/unix name)
120 * -- this also caches the bits of .AppleDouble used by FPGetFilDirParam
121 * so that we don't have to open the header file.
122 * NOTE: FPCatSearch has to search through all of the directories as
123 * this stuff doesn't get entered until needed.
124 * if the entire volume is in the database, though, we can use
125 * cursor operations to make this faster.
127 * version number is stored with did/name key of 0/0
130 * modfiller 4 (dates only use 4 bytes right now, but we leave space
131 * moddate 4 for 8. moddate is also used to keep this info
132 * createfiller 4 up-to-date.)
136 * accfiller 4 (unused)
138 * AFP info 4 (stores a couple permission bits as well)
143 * macname 32 (nul-terminated)
144 * shortname 12 (nul-terminated)
145 * longname longnamelen (nul-terminated)
147 * 132 bytes + longnamelen
149 * db_devino: (key: dev/ino)
150 * -- this is only used for consistency checks and isn't 1-1
153 * these correspond to the different path types. longname is for the
154 * 255 unicode character names (path type == ?), macname is for the
155 * 32-character names (path type == 2), and shortname is for the
156 * 8+3-character names (path type == 1).
158 * db_longname: (key: did/longname)
159 * name namelen = strlen(name) + 1
161 * db_macname: (key: did/macname)
162 * name namelen = strlen(name) + 1
164 * db_shortname: (key: did/shortname)
165 * name namelen = strlen(name) + 1
170 #endif /* __inline__ */
172 /* construct db_cnid data. NOTE: this is not re-entrant. */
174 static void make_devino_data(unsigned char *buf, dev_t dev, ino_t ino)
176 buf[CNID_DEV_LEN - 1] = dev; dev >>= 8;
177 buf[CNID_DEV_LEN - 2] = dev; dev >>= 8;
178 buf[CNID_DEV_LEN - 3] = dev; dev >>= 8;
179 buf[CNID_DEV_LEN - 4] = dev; dev >>= 8;
180 buf[CNID_DEV_LEN - 5] = dev; dev >>= 8;
181 buf[CNID_DEV_LEN - 6] = dev; dev >>= 8;
182 buf[CNID_DEV_LEN - 7] = dev; dev >>= 8;
183 buf[CNID_DEV_LEN - 8] = dev;
185 buf[CNID_DEV_LEN + CNID_INO_LEN - 1] = ino; ino >>= 8;
186 buf[CNID_DEV_LEN + CNID_INO_LEN - 2] = ino; ino >>= 8;
187 buf[CNID_DEV_LEN + CNID_INO_LEN - 3] = ino; ino >>= 8;
188 buf[CNID_DEV_LEN + CNID_INO_LEN - 4] = ino; ino >>= 8;
189 buf[CNID_DEV_LEN + CNID_INO_LEN - 5] = ino; ino >>= 8;
190 buf[CNID_DEV_LEN + CNID_INO_LEN - 6] = ino; ino >>= 8;
191 buf[CNID_DEV_LEN + CNID_INO_LEN - 7] = ino; ino >>= 8;
192 buf[CNID_DEV_LEN + CNID_INO_LEN - 8] = ino;
195 static __inline__ char *make_cnid_data(const struct stat *st,
197 const char *name, const int len)
199 static char start[CNID_HEADER_LEN + MAXPATHLEN + 1];
200 char *buf = start +CNID_LEN;
203 if (len > MAXPATHLEN)
206 make_devino_data(buf, st->st_dev, st->st_ino);
207 buf += CNID_DEVINO_LEN;
209 i = S_ISDIR(st->st_mode)?1:0;
211 memcpy(buf, &i, sizeof(i));
214 /* did is already in network byte order */
215 memcpy(buf, &did, sizeof(did));
218 memcpy(buf, name, len);
224 extern char *make_cnid_data __P((const struct stat *,const cnid_t ,
225 const char *, const int ));
228 #endif /* atalk/cnid/cnid_private.h */