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