2 * $Id: directory.h,v 1.9 2003-01-24 07:08:42 didg Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
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.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
26 #ifndef AFPD_DIRECTORY_H
27 #define AFPD_DIRECTORY_H 1
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>
35 /* sys/types.h usually snarfs in major/minor macros. if they don't
38 #include <sys/sysmacros.h>
44 /* the did tree is now a red-black tree while the parent/child
45 * tree is a circular doubly-linked list. how exciting. */
47 struct dir *d_left, *d_right, *d_back; /* for red-black tree */
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. */
55 time_t ctime; /* inode ctime */
56 int offcnt; /* offspring count */
58 char *d_m_name; /* mac name */
59 char *d_u_name; /* unix name */
64 char *m_name; /* mac name */
65 char *u_name; /* unix name */
73 static __inline__ int path_isadir(struct path *o_path)
75 return o_path->m_name == '\0' || /* we are in a it */
76 !o_path->st_valid || /* in cache but we can't chdir in it */
77 (!o_path->st_errno && S_ISDIR(o_path->st.st_mode)); /* not in cache an can't chdir */
80 extern int path_isadir(struct path *o_path);
83 /* child addition/removal macros */
84 #define dirchildadd(a, b) do { \
88 (b)->d_next = (a)->d_child; \
89 (b)->d_prev = (b)->d_next->d_prev; \
90 (b)->d_next->d_prev = (b); \
91 (b)->d_prev->d_next = (b); \
95 #define dirchildremove(a,b) do { \
96 if ((a)->d_child == (b)) \
97 (a)->d_child = ((b) == (b)->d_next) ? NULL : (b)->d_next; \
98 (b)->d_next->d_prev = (b)->d_prev; \
99 (b)->d_prev->d_next = (b)->d_next; \
100 (b)->d_next = (b)->d_prev = (b); \
103 #define DIRTREE_COLOR_RED 0
104 #define DIRTREE_COLOR_BLACK 1
106 /* setgid directories */
111 # define DIRBITS S_ISGID
115 #define DIRF_FSMASK (3<<0)
116 #define DIRF_NOFS (0<<0)
117 #define DIRF_AFS (1<<0)
118 #define DIRF_UFS (2<<0)
120 #define AFPDIR_READ (1<<0)
123 #define DIRPBIT_ATTR 0
124 #define DIRPBIT_PDID 1
125 #define DIRPBIT_CDATE 2
126 #define DIRPBIT_MDATE 3
127 #define DIRPBIT_BDATE 4
128 #define DIRPBIT_FINFO 5
129 #define DIRPBIT_LNAME 6
130 #define DIRPBIT_SNAME 7
131 #define DIRPBIT_DID 8
132 #define DIRPBIT_OFFCNT 9
133 #define DIRPBIT_UID 10
134 #define DIRPBIT_GID 11
135 #define DIRPBIT_ACCESS 12
136 #define DIRPBIT_PDINFO 13 /* ProDOS Info */
138 /* directory attribute bits (see file.h for other bits) */
139 #define ATTRBIT_EXPFOLDER (1 << 1) /* shared point */
140 #define ATTRBIT_MOUNTED (1 << 3) /* mounted share point by non-admin */
141 #define ATTRBIT_INEXPFOLDER (1 << 4) /* folder in a shared area */
143 #define FILDIRBIT_ISDIR (1 << 7) /* is a directory */
144 #define FILDIRBIT_ISFILE (0) /* is a file */
146 /* reserved directory id's */
147 #define DIRDID_ROOT_PARENT htonl(1) /* parent directory of root */
148 #define DIRDID_ROOT htonl(2) /* root directory */
150 /* file/directory ids. what a mess. we scramble things in a vain attempt
151 * to get something meaningful */
153 #define CNID_XOR(a) (((a) >> 16) ^ (a))
154 #define CNID_DEV(a) ((((CNID_XOR(major((a)->st_dev)) & 0xf) << 3) | \
155 (CNID_XOR(minor((a)->st_dev)) & 0x7)) << 24)
156 #define CNID_INODE(a) (((a)->st_ino ^ (((a)->st_ino & 0xff000000) >> 8)) \
158 #define CNID_FILE(a) (((a) & 0x1) << 31)
159 #define CNID(a,b) (CNID_DEV(a) | CNID_INODE(a) | CNID_FILE(b))
161 #define CNID(a,b) (((a)->st_ino & 0x7fffffff) | CNID_FILE(b))
172 #define AR_USEARCH (1<<0)
173 #define AR_UREAD (1<<1)
174 #define AR_UWRITE (1<<2)
175 #define AR_UOWN (1<<7)
177 extern struct dir *dirnew __P((const char *, const char *));
178 extern void dirfree __P((struct dir *));
179 extern struct dir *dirsearch __P((const struct vol *, u_int32_t));
180 extern struct dir *dirlookup __P((const struct vol *, u_int32_t));
181 extern struct dir *dirsearch_byname __P((struct dir *,const char *));
183 extern struct dir *adddir __P((struct vol *, struct dir *,
186 extern struct dir *dirinsert __P((struct vol *, struct dir *));
187 extern int movecwd __P((const struct vol *, struct dir *));
188 extern int deletecurdir __P((const struct vol *, char *, int));
189 extern struct path *cname __P((const struct vol *, struct dir *,
191 extern mode_t mtoumode __P((struct maccess *));
192 extern void utommode __P((struct stat *, struct maccess *));
193 extern int getdirparams __P((const struct vol *, u_int16_t, struct path *,
194 struct dir *, char *, int *));
195 extern int setdirparams __P((const struct vol *, struct path *, u_int16_t, char *));
196 extern int renamedir __P((char *, char *, struct dir *,
197 struct dir *, char *, const int));
199 typedef int (*dir_loop)(struct dirent *, char *, void *);
201 extern int for_each_dirent __P((const struct vol *, char *, dir_loop , void *));
203 extern int check_access __P((char *name , int mode));
205 /* from enumerate.c */
206 extern char *check_dirent __P((const struct vol *, char *));
209 extern int afp_createdir __P((AFPObj *, char *, int, char *, int *));
210 extern int afp_opendir __P((AFPObj *, char *, int, char *, int *));
211 extern int afp_setdirparams __P((AFPObj *, char *, int, char *, int *));
212 extern int afp_closedir __P((AFPObj *, char *, int, char *, int *));
213 extern int afp_mapid __P((AFPObj *, char *, int, char *, int *));
214 extern int afp_mapname __P((AFPObj *, char *, int, char *, int *));
216 /* from enumerate.c */
217 extern int afp_enumerate __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
218 extern int afp_enumerate_ext __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
219 extern int afp_enumerate_ext2 __P((AFPObj *, char *, unsigned int, char *, unsigned int *));
220 extern int afp_catsearch __P((AFPObj *, char *, int, char *, int *));