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