]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/directory.h
remove gcc warnings and cleanup inline mess
[netatalk.git] / etc / afpd / directory.h
1 /*
2  * $Id: directory.h,v 1.13.2.4.2.2.2.1 2008-11-25 15:16:32 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     u_int32_t   offcnt;               /* offspring count */
57
58     char        *d_m_name;            /* mac name */
59     char        *d_u_name;            /* unix name */
60 };
61
62 struct path {
63     int         m_type;             /* mac name type (long name, unicode */
64     char        *m_name;            /* mac name */
65     char        *u_name;            /* unix name */
66     struct dir  *d_dir;             /* */
67     int         st_valid;           /* does st_errno and st set */
68     int         st_errno;
69     struct stat st;
70 };
71
72 #ifndef ATACC
73 static inline int path_isadir(struct path *o_path)
74 {
75     return o_path->d_dir != NULL;
76 #if 0
77     return o_path->m_name == '\0' || /* we are in a it */
78            !o_path->st_valid ||      /* in cache but we can't chdir in it */ 
79            (!o_path->st_errno && S_ISDIR(o_path->st.st_mode)); /* not in cache an can't chdir */
80 #endif
81 }
82 #else
83 extern int path_isadir(struct path *o_path);
84 #endif
85
86 /* child addition/removal macros */
87 #define dirchildadd(a, b) do { \
88         if (!(a)->d_child) \
89                 (a)->d_child = (b); \
90         else { \
91                 (b)->d_next = (a)->d_child; \
92                 (b)->d_prev = (b)->d_next->d_prev; \
93                 (b)->d_next->d_prev = (b); \
94                 (b)->d_prev->d_next = (b); \
95         } \
96 } while (0)
97
98 #define dirchildremove(a,b) do { \
99         if ((a)->d_child == (b)) \
100                 (a)->d_child = ((b) == (b)->d_next) ? NULL : (b)->d_next; \
101         (b)->d_next->d_prev = (b)->d_prev; \
102         (b)->d_prev->d_next = (b)->d_next; \
103         (b)->d_next = (b)->d_prev = (b); \
104 } while (0)
105
106 #define DIRTREE_COLOR_RED    0
107 #define DIRTREE_COLOR_BLACK  1
108
109 /* setgid directories */
110 #ifndef DIRBITS
111 # ifdef AFS
112 #  define DIRBITS 0
113 # else /* AFS */
114 #  define DIRBITS S_ISGID
115 # endif /* AFS */
116 #endif /* DIRBITS */
117
118 #define DIRF_FSMASK     (3<<0)
119 #define DIRF_NOFS       (0<<0)
120 #define DIRF_AFS        (1<<0)
121 #define DIRF_UFS        (2<<0)
122
123 #define AFPDIR_READ     (1<<0)
124
125 /* directory bits */
126 #define DIRPBIT_ATTR    0
127 #define DIRPBIT_PDID    1
128 #define DIRPBIT_CDATE   2
129 #define DIRPBIT_MDATE   3
130 #define DIRPBIT_BDATE   4
131 #define DIRPBIT_FINFO   5
132 #define DIRPBIT_LNAME   6
133 #define DIRPBIT_SNAME   7
134 #define DIRPBIT_DID     8
135 #define DIRPBIT_OFFCNT  9
136 #define DIRPBIT_UID     10
137 #define DIRPBIT_GID     11
138 #define DIRPBIT_ACCESS  12
139 #define DIRPBIT_PDINFO  13         /* ProDOS Info */
140 #define DIRPBIT_UNIXPR  15
141
142 /* directory attribute bits (see file.h for other bits) */
143 #define ATTRBIT_EXPFOLDER   (1 << 1) /* shared point */
144 #define ATTRBIT_MOUNTED     (1 << 3) /* mounted share point by non-admin */
145 #define ATTRBIT_INEXPFOLDER (1 << 4) /* folder in a shared area */
146
147 #define FILDIRBIT_ISDIR        (1 << 7) /* is a directory */
148 #define FILDIRBIT_ISFILE       (0)      /* is a file */
149
150 /* reserved directory id's */
151 #define DIRDID_ROOT_PARENT    htonl(1)  /* parent directory of root */
152 #define DIRDID_ROOT           htonl(2)  /* root directory */
153
154 /* file/directory ids. what a mess. we scramble things in a vain attempt
155  * to get something meaningful */
156 #ifndef AFS
157
158 #if 0
159 #define CNID_XOR(a)  (((a) >> 16) ^ (a))
160 #define CNID_DEV(a)   ((((CNID_XOR(major((a)->st_dev)) & 0xf) << 3) | \
161         (CNID_XOR(minor((a)->st_dev)) & 0x7)) << 24)
162 #define CNID_INODE(a) (((a)->st_ino ^ (((a)->st_ino & 0xff000000) >> 8)) \
163                                        & 0x00ffffff)
164 #define CNID_FILE(a)  (((a) & 0x1) << 31)
165 #define CNID(a,b)     (CNID_DEV(a) | CNID_INODE(a) | CNID_FILE(b))
166 #endif
167
168 #define CNID(a,b)     ((a)->st_ino & 0xffffffff)
169
170 #else /* AFS */
171 #define CNID(a,b)     (((a)->st_ino & 0x7fffffff) | CNID_FILE(b))
172 #endif /* AFS */
173
174
175 struct maccess {
176     u_char      ma_user;
177     u_char      ma_world;
178     u_char      ma_group;
179     u_char      ma_owner;
180 };
181
182 #define AR_USEARCH      (1<<0)
183 #define AR_UREAD        (1<<1)
184 #define AR_UWRITE       (1<<2)
185 #define AR_UOWN         (1<<7)
186
187 extern struct dir       *dirnew __P((const char *, const char *));
188 extern void             dirfreename __P((struct dir *));
189 extern void             dirfree __P((struct dir *));
190 extern struct dir       *dirsearch __P((const struct vol *, u_int32_t));
191 extern struct dir       *dirlookup __P((const struct vol *, u_int32_t));
192 extern struct dir       *dirsearch_byname __P((struct dir *,const char *));
193
194 extern struct dir       *adddir __P((struct vol *, struct dir *, 
195                                                struct path *));
196
197 extern struct dir       *dirinsert __P((struct vol *, struct dir *));
198 extern int              movecwd __P((const struct vol *, struct dir *));
199 extern int              deletecurdir __P((const struct vol *, char *));
200 extern struct path      *cname __P((const struct vol *, struct dir *,
201                              char **));
202 extern mode_t           mtoumode __P((struct maccess *));
203 extern void             utommode __P((struct stat *, struct maccess *));
204 extern int getdirparams __P((const struct vol *, u_int16_t, struct path *,
205                                  struct dir *, char *, int *));
206 extern int setdirparams __P((const struct vol *, struct path *, u_int16_t, char *));
207 extern int renamedir __P((const struct vol *, char *, char *, struct dir *,
208                               struct dir *, char *));
209 extern int path_error __P((struct path *, int error));
210
211 typedef int (*dir_loop)(struct dirent *, char *, void *);
212
213 extern int  for_each_dirent __P((const struct vol *, char *, dir_loop , void *));
214
215 extern int  check_access __P((char *name , int mode));
216 extern int file_access   __P((struct path *path, int mode));
217
218 extern int netatalk_unlink __P((const char *name));
219
220 /* from enumerate.c */
221 extern char *check_dirent __P((const struct vol *, char *));
222
223 /* FP functions */
224 extern int      afp_createdir __P((AFPObj *, char *, int, char *, int *));
225 extern int      afp_opendir __P((AFPObj *, char *, int, char *, int *));
226 extern int      afp_setdirparams __P((AFPObj *, char *, int, char *, int *));
227 extern int      afp_closedir __P((AFPObj *, char *, int, char *, int *));
228 extern int      afp_mapid __P((AFPObj *, char *, int, char *, int *));
229 extern int      afp_mapname __P((AFPObj *, char *, int, char *, int *));
230
231 /* from enumerate.c */
232 extern int      afp_enumerate __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
233 extern int      afp_enumerate_ext __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
234 extern int      afp_enumerate_ext2 __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
235
236 /* from catsearch.c */
237 extern int      afp_catsearch __P((AFPObj *, char *, int, char *, int *));
238 extern int      afp_catsearch_ext __P((AFPObj *, char *, int, char *, int *));
239
240 #endif