]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/directory.h
BIG commit to improve code style using astyle as well as fix up CNID DB
[netatalk.git] / etc / afpd / directory.h
1 /*
2  * $Id: directory.h,v 1.3 2001-12-03 05:03:38 jmarcus 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
34 /* sys/types.h usually snarfs in major/minor macros. if they don't
35  * try this file. */
36 #ifndef major
37 #include <sys/sysmacros.h>
38 #endif
39
40 #include "globals.h"
41 #include "volume.h"
42
43 /* the did tree is now a red-black tree while the parent/child
44  * tree is a circular doubly-linked list. how exciting. */
45 struct dir {
46     struct dir  *d_left, *d_right, *d_back; /* for red-black tree */
47     int         d_color;
48     struct dir  *d_parent, *d_child; /* parent-child */
49     struct dir  *d_prev, *d_next;    /* siblings */
50     void        *d_ofork;            /* oforks using this directory. */
51     u_int32_t   d_did;
52     int         d_flags;
53     char        *d_name;
54 };
55
56 /* child addition/removal macros */
57 #define dirchildadd(a, b) do { \
58         if (!(a)->d_child) \
59                 (a)->d_child = (b); \
60         else { \
61                 (b)->d_next = (a)->d_child; \
62                 (b)->d_prev = (b)->d_next->d_prev; \
63                 (b)->d_next->d_prev = (b); \
64                 (b)->d_prev->d_next = (b); \
65         } \
66 } while (0)
67
68 #define dirchildremove(a,b) do { \
69         if ((a)->d_child == (b)) \
70                 (a)->d_child = ((b) == (b)->d_next) ? NULL : (b)->d_next; \
71         (b)->d_next->d_prev = (b)->d_prev; \
72         (b)->d_prev->d_next = (b)->d_next; \
73         (b)->d_next = (b)->d_prev = (b); \
74 } while (0)
75
76 #define DIRTREE_COLOR_RED    0
77 #define DIRTREE_COLOR_BLACK  1
78
79 /* setgid directories */
80 #ifndef DIRBITS
81 #define DIRBITS S_ISGID
82 #endif /* DIRBITS */
83
84 #define DIRF_FSMASK     (3<<0)
85 #define DIRF_NOFS       (0<<0)
86 #define DIRF_AFS        (1<<0)
87 #define DIRF_UFS        (2<<0)
88
89 #define AFPDIR_READ     (1<<0)
90
91 /* directory bits */
92 #define DIRPBIT_ATTR    0
93 #define DIRPBIT_PDID    1
94 #define DIRPBIT_CDATE   2
95 #define DIRPBIT_MDATE   3
96 #define DIRPBIT_BDATE   4
97 #define DIRPBIT_FINFO   5
98 #define DIRPBIT_LNAME   6
99 #define DIRPBIT_SNAME   7
100 #define DIRPBIT_DID     8
101 #define DIRPBIT_OFFCNT  9
102 #define DIRPBIT_UID     10
103 #define DIRPBIT_GID     11
104 #define DIRPBIT_ACCESS  12
105 #define DIRPBIT_PDINFO  13         /* ProDOS Info */
106
107 /* directory attribute bits (see file.h for other bits) */
108 #define ATTRBIT_EXPFOLDER   (1 << 1) /* shared point */
109 #define ATTRBIT_MOUNTED     (1 << 3) /* mounted share point by non-admin */
110 #define ATTRBIT_INEXPFOLDER (1 << 4) /* folder in a shared area */
111
112 #define FILDIRBIT_ISDIR        (1 << 7) /* is a directory */
113 #define FILDIRBIT_ISFILE       (0)      /* is a file */
114
115 /* reserved directory id's */
116 #define DIRDID_ROOT_PARENT    htonl(1)  /* parent directory of root */
117 #define DIRDID_ROOT           htonl(2)  /* root directory */
118
119 /* file/directory ids. what a mess. we scramble things in a vain attempt
120  * to get something meaningful */
121 #ifndef AFS
122 #define CNID_XOR(a)  (((a) >> 16) ^ (a))
123 #define CNID_DEV(a)   ((((CNID_XOR(major((a)->st_dev)) & 0xf) << 3) | \
124         (CNID_XOR(minor((a)->st_dev)) & 0x7)) << 24)
125 #define CNID_INODE(a) (((a)->st_ino ^ (((a)->st_ino & 0xff000000) >> 8)) \
126                                        & 0x00ffffff)
127 #define CNID_FILE(a)  (((a) & 0x1) << 31)
128 #define CNID(a,b)     (CNID_DEV(a) | CNID_INODE(a) | CNID_FILE(b))
129 #else /* AFS */
130 #define CNID(a,b)     (((a)->st_ino & 0x7fffffff) | CNID_FILE(b))
131 #endif /* AFS */
132
133
134 struct maccess {
135     u_char      ma_user;
136     u_char      ma_world;
137     u_char      ma_group;
138     u_char      ma_owner;
139 };
140
141 #define AR_USEARCH      (1<<0)
142 #define AR_UREAD        (1<<1)
143 #define AR_UWRITE       (1<<2)
144 #define AR_UOWN         (1<<7)
145
146 extern struct dir       *dirnew __P((const int));
147 extern void             dirfree __P((struct dir *));
148 extern struct dir       *dirsearch __P((const struct vol *, u_int32_t));
149 extern struct dir       *adddir __P((struct vol *, struct dir *, char *,
150                                                int, char *, int, struct stat *));
151 extern struct dir       *dirinsert __P((struct vol *, struct dir *));
152 extern int              movecwd __P((const struct vol *, struct dir *));
153 extern int              deletecurdir __P((const struct vol *, char *, int));
154 extern char             *cname __P((const struct vol *, struct dir *,
155                              char **));
156 extern mode_t           mtoumode __P((struct maccess *));
157 extern void             utommode __P((struct stat *, struct maccess *));
158 extern int getdirparams __P((const struct vol *, u_int16_t, char *,
159                                  struct dir *, struct stat *, char *, int *));
160 extern int setdirparams __P((const struct vol *, char *, u_int16_t, char *));
161 extern int renamedir __P((char *, char *, struct dir *,
162                               struct dir *, char *, const int));
163
164
165 /* FP functions */
166 extern int      afp_createdir __P((AFPObj *, char *, int, char *, int *));
167 extern int      afp_opendir __P((AFPObj *, char *, int, char *, int *));
168 extern int      afp_setdirparams __P((AFPObj *, char *, int, char *, int *));
169 extern int      afp_closedir __P((AFPObj *, char *, int, char *, int *));
170 extern int      afp_mapid __P((AFPObj *, char *, int, char *, int *));
171 extern int      afp_mapname __P((AFPObj *, char *, int, char *, int *));
172
173 /* from enumerate.c */
174 extern int      afp_enumerate __P((AFPObj *, char *, int, char *, int *));
175 extern int      afp_catsearch __P((AFPObj *, char *, int, char *, int *));
176
177 #endif