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