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/types.h>
28#include <arpa/inet.h>
29#include <dirent.h>
30
31/* sys/types.h usually snarfs in major/minor macros. if they don't
32 * try this file. */
33#ifndef major
34#include <sys/sysmacros.h>
35#endif
36
37#include <atalk/directory.h>
38#include <atalk/globals.h>
39
40#include "volume.h"
41
42/* directory bits */
43#define DIRPBIT_ATTR	0
44#define DIRPBIT_PDID	1
45#define DIRPBIT_CDATE	2
46#define DIRPBIT_MDATE	3
47#define DIRPBIT_BDATE	4
48#define DIRPBIT_FINFO	5
49#define DIRPBIT_LNAME	6
50#define DIRPBIT_SNAME	7
51#define DIRPBIT_DID	8
52#define DIRPBIT_OFFCNT	9
53#define DIRPBIT_UID	10
54#define DIRPBIT_GID	11
55#define DIRPBIT_ACCESS	12
56#define DIRPBIT_PDINFO  13         /* ProDOS Info */
57#define DIRPBIT_UNIXPR  15
58
59#define FILDIRBIT_ISDIR        (1 << 7) /* is a directory */
60#define FILDIRBIT_ISFILE       (0)      /* is a file */
61
62/* file/directory ids. what a mess. we scramble things in a vain attempt
63 * to get something meaningful */
64#ifndef AFS
65
66#if 0
67#define CNID_XOR(a)  (((a) >> 16) ^ (a))
68#define CNID_DEV(a)   ((((CNID_XOR(major((a)->st_dev)) & 0xf) << 3) | \
69	(CNID_XOR(minor((a)->st_dev)) & 0x7)) << 24)
70#define CNID_INODE(a) (((a)->st_ino ^ (((a)->st_ino & 0xff000000) >> 8)) \
71				       & 0x00ffffff)
72#define CNID_FILE(a)  (((a) & 0x1) << 31)
73#define CNID(a,b)     (CNID_DEV(a) | CNID_INODE(a) | CNID_FILE(b))
74#endif
75
76#define CNID(a,b)     ((a)->st_ino & 0xffffffff)
77
78#else /* AFS */
79#define CNID(a,b)     (((a)->st_ino & 0x7fffffff) | CNID_FILE(b))
80#endif /* AFS */
81
82struct maccess {
83    u_char	ma_user;
84    u_char	ma_world;
85    u_char	ma_group;
86    u_char	ma_owner;
87};
88
89#define	AR_USEARCH	(1<<0)
90#define	AR_UREAD	(1<<1)
91#define	AR_UWRITE	(1<<2)
92#define	AR_UOWN		(1<<7)
93
94q_t *invalid_dircache_entries;
95
96typedef int (*dir_loop)(struct dirent *, char *, void *);
97
98extern void        dir_free_invalid_q(void);
99extern struct dir  *dir_new(const char *mname, const char *uname, const struct vol *,
100                            cnid_t pdid, cnid_t did, bstring fullpath, struct stat *);
101extern void        dir_free (struct dir *);
102extern struct dir  *dir_add(struct vol *, const struct dir *, struct path *, int);
103extern int         dir_modify(const struct vol *vol, struct dir *dir, cnid_t pdid, cnid_t did,
104                              const char *new_mname, const char *new_uname, bstring pdir_fullpath);
105extern int         dir_remove(const struct vol *vol, struct dir *dir);
106extern struct dir  *dirlookup (const struct vol *, cnid_t);
107extern struct dir *dirlookup_bypath(const struct vol *vol, const char *path);
108
109extern int         movecwd (const struct vol *, struct dir *);
110extern struct path *cname (struct vol *, struct dir *, char **);
111
112extern int         deletecurdir (struct vol *);
113extern mode_t      mtoumode (struct maccess *);
114extern int         getdirparams (const AFPObj *obj, const struct vol *, uint16_t, struct path *,
115                                 struct dir *, char *, size_t *);
116
117extern int         setdirparams(struct vol *, struct path *, uint16_t, char *);
118extern int         renamedir(struct vol *, int, char *, char *, struct dir *,
119                             struct dir *, char *);
120extern int         path_error(struct path *, int error);
121extern void        setdiroffcnt(struct dir *dir, struct stat *st,  uint32_t count);
122extern int         dirreenumerate(struct dir *dir, struct stat *st);
123extern int         for_each_dirent(const struct vol *, char *, dir_loop , void *);
124extern int         check_access(const AFPObj *obj, struct vol *, char *name , int mode);
125extern int         file_access(const AFPObj *obj, struct vol *vol, struct path *path, int mode);
126extern int         netatalk_unlink (const char *name);
127
128/* from enumerate.c */
129extern char        *check_dirent (const struct vol *, char *);
130
131/* FP functions */
132int afp_createdir (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
133int afp_opendir (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
134int afp_setdirparams (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
135int afp_closedir (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
136int afp_mapid (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
137int afp_mapname (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
138int afp_syncdir (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
139
140/* from enumerate.c */
141int afp_enumerate (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
142int afp_enumerate_ext (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
143int afp_enumerate_ext2 (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
144
145/* from catsearch.c */
146int afp_catsearch (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
147int afp_catsearch_ext (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
148
149#endif
150