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