]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/directory.h
- added a cache for directories offspring count.
[netatalk.git] / etc / afpd / directory.h
1 /*
2  * $Id: directory.h,v 1.6 2002-10-11 14:18:28 didg Exp $
3  *
4  * Copyright (c) 1990,1991 Regents of The University of Michigan.
5  * All Rights Reserved.
6  *
7  * Permission to use, copy, modify, and distribute this software and
8  * its documentation for any purpose and without fee is hereby granted,
9  * provided that the above copyright notice appears in all copies and
10  * that both that copyright notice and this permission notice appear
11  * in supporting documentation, and that the name of The University
12  * of Michigan not be used in advertising or publicity pertaining to
13  * distribution of the software without specific, written prior
14  * permission. This software is supplied as is without expressed or
15  * implied warranties of any kind.
16  *
17  *      Research Systems Unix Group
18  *      The University of Michigan
19  *      c/o Mike Clark
20  *      535 W. William Street
21  *      Ann Arbor, Michigan
22  *      +1-313-763-0525
23  *      netatalk@itd.umich.edu
24  */
25
26 #ifndef AFPD_DIRECTORY_H
27 #define AFPD_DIRECTORY_H 1
28
29 #include <sys/cdefs.h>
30 #include <sys/types.h>
31 /*#include <sys/stat.h>*/ /* including it here causes some confusion */
32 #include <netatalk/endian.h>
33 #include <dirent.h>
34
35 /* sys/types.h usually snarfs in major/minor macros. if they don't
36  * try this file. */
37 #ifndef major
38 #include <sys/sysmacros.h>
39 #endif
40
41 #include "globals.h"
42 #include "volume.h"
43
44 /* the did tree is now a red-black tree while the parent/child
45  * tree is a circular doubly-linked list. how exciting. */
46 struct dir {
47     struct dir  *d_left, *d_right, *d_back; /* for red-black tree */
48     int         d_color;
49     struct dir  *d_parent, *d_child; /* parent-child */
50     struct dir  *d_prev, *d_next;    /* siblings */
51     void        *d_ofork;            /* oforks using this directory. */
52     u_int32_t   d_did;
53     int         d_flags;
54
55     time_t      ctime;                /* inode ctime */
56     int         offcnt;               /* offspring count */
57
58     char        *d_m_name;             /* mac name */
59     char        *d_u_name;            /* unix name */
60 };
61
62 struct path {
63     char        *m_name;             /* mac name */
64     char        *u_name;            /* unix name */
65
66     int         st_valid;
67     int         st_errno;
68     struct stat st;
69 };
70
71 /* child addition/removal macros */
72 #define dirchildadd(a, b) do { \
73         if (!(a)->d_child) \
74                 (a)->d_child = (b); \
75         else { \
76                 (b)->d_next = (a)->d_child; \
77                 (b)->d_prev = (b)->d_next->d_prev; \
78                 (b)->d_next->d_prev = (b); \
79                 (b)->d_prev->d_next = (b); \
80         } \
81 } while (0)
82
83 #define dirchildremove(a,b) do { \
84         if ((a)->d_child == (b)) \
85                 (a)->d_child = ((b) == (b)->d_next) ? NULL : (b)->d_next; \
86         (b)->d_next->d_prev = (b)->d_prev; \
87         (b)->d_prev->d_next = (b)->d_next; \
88         (b)->d_next = (b)->d_prev = (b); \
89 } while (0)
90
91 #define DIRTREE_COLOR_RED    0
92 #define DIRTREE_COLOR_BLACK  1
93
94 /* setgid directories */
95 #ifndef DIRBITS
96 # ifdef AFS
97 #  define DIRBITS 0
98 # else /* AFS */
99 #  define DIRBITS S_ISGID
100 # endif /* AFS */
101 #endif /* DIRBITS */
102
103 #define DIRF_FSMASK     (3<<0)
104 #define DIRF_NOFS       (0<<0)
105 #define DIRF_AFS        (1<<0)
106 #define DIRF_UFS        (2<<0)
107
108 #define AFPDIR_READ     (1<<0)
109
110 /* directory bits */
111 #define DIRPBIT_ATTR    0
112 #define DIRPBIT_PDID    1
113 #define DIRPBIT_CDATE   2
114 #define DIRPBIT_MDATE   3
115 #define DIRPBIT_BDATE   4
116 #define DIRPBIT_FINFO   5
117 #define DIRPBIT_LNAME   6
118 #define DIRPBIT_SNAME   7
119 #define DIRPBIT_DID     8
120 #define DIRPBIT_OFFCNT  9
121 #define DIRPBIT_UID     10
122 #define DIRPBIT_GID     11
123 #define DIRPBIT_ACCESS  12
124 #define DIRPBIT_PDINFO  13         /* ProDOS Info */
125
126 /* directory attribute bits (see file.h for other bits) */
127 #define ATTRBIT_EXPFOLDER   (1 << 1) /* shared point */
128 #define ATTRBIT_MOUNTED     (1 << 3) /* mounted share point by non-admin */
129 #define ATTRBIT_INEXPFOLDER (1 << 4) /* folder in a shared area */
130
131 #define FILDIRBIT_ISDIR        (1 << 7) /* is a directory */
132 #define FILDIRBIT_ISFILE       (0)      /* is a file */
133
134 /* reserved directory id's */
135 #define DIRDID_ROOT_PARENT    htonl(1)  /* parent directory of root */
136 #define DIRDID_ROOT           htonl(2)  /* root directory */
137
138 /* file/directory ids. what a mess. we scramble things in a vain attempt
139  * to get something meaningful */
140 #ifndef AFS
141 #define CNID_XOR(a)  (((a) >> 16) ^ (a))
142 #define CNID_DEV(a)   ((((CNID_XOR(major((a)->st_dev)) & 0xf) << 3) | \
143         (CNID_XOR(minor((a)->st_dev)) & 0x7)) << 24)
144 #define CNID_INODE(a) (((a)->st_ino ^ (((a)->st_ino & 0xff000000) >> 8)) \
145                                        & 0x00ffffff)
146 #define CNID_FILE(a)  (((a) & 0x1) << 31)
147 #define CNID(a,b)     (CNID_DEV(a) | CNID_INODE(a) | CNID_FILE(b))
148 #else /* AFS */
149 #define CNID(a,b)     (((a)->st_ino & 0x7fffffff) | CNID_FILE(b))
150 #endif /* AFS */
151
152
153 struct maccess {
154     u_char      ma_user;
155     u_char      ma_world;
156     u_char      ma_group;
157     u_char      ma_owner;
158 };
159
160 #define AR_USEARCH      (1<<0)
161 #define AR_UREAD        (1<<1)
162 #define AR_UWRITE       (1<<2)
163 #define AR_UOWN         (1<<7)
164
165 extern struct dir       *dirnew __P((const char *, const char *));
166 extern void             dirfree __P((struct dir *));
167 extern struct dir       *dirsearch __P((const struct vol *, u_int32_t));
168 extern struct dir       *dirlookup __P((const struct vol *, u_int32_t));
169
170 extern struct dir       *adddir __P((struct vol *, struct dir *, 
171                                                struct path *));
172
173 extern struct dir       *dirinsert __P((struct vol *, struct dir *));
174 extern int              movecwd __P((const struct vol *, struct dir *));
175 extern int              deletecurdir __P((const struct vol *, char *, int));
176 extern struct path      *cname __P((const struct vol *, struct dir *,
177                              char **));
178 extern mode_t           mtoumode __P((struct maccess *));
179 extern void             utommode __P((struct stat *, struct maccess *));
180 extern int getdirparams __P((const struct vol *, u_int16_t, struct path *,
181                                  struct dir *, char *, int *));
182 extern int setdirparams __P((const struct vol *, struct path *, u_int16_t, char *));
183 extern int renamedir __P((char *, char *, struct dir *,
184                               struct dir *, char *, const int));
185
186 typedef int (*dir_loop)(struct dirent *, char *, void *);
187
188 extern int  for_each_dirent __P((const struct vol *, char *, dir_loop , void *));
189
190 extern int  check_access __P((char *name , int mode));
191
192 /* from enumerate.c */
193 extern char *check_dirent __P((const struct vol *, char *));
194
195 /* FP functions */
196 extern int      afp_createdir __P((AFPObj *, char *, int, char *, int *));
197 extern int      afp_opendir __P((AFPObj *, char *, int, char *, int *));
198 extern int      afp_setdirparams __P((AFPObj *, char *, int, char *, int *));
199 extern int      afp_closedir __P((AFPObj *, char *, int, char *, int *));
200 extern int      afp_mapid __P((AFPObj *, char *, int, char *, int *));
201 extern int      afp_mapname __P((AFPObj *, char *, int, char *, int *));
202
203 /* from enumerate.c */
204 extern int      afp_enumerate __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
205 extern int      afp_enumerate_ext2 __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
206 extern int      afp_catsearch __P((AFPObj *, char *, int, char *, int *));
207
208 #endif