netatalk: directory.h Source File

netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
etc/afpd/directory.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
3 * Copyright (c) 2025 Andy Lemin (andylemin)
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and distribute this software and
7 * its documentation for any purpose and without fee is hereby granted,
8 * provided that the above copyright notice appears in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation, and that the name of The University
11 * of Michigan not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior
13 * permission. This software is supplied as is without expressed or
14 * implied warranties of any kind.
15 *
16 * Research Systems Unix Group
17 * The University of Michigan
18 * c/o Mike Clark
19 * 535 W. William Street
20 * Ann Arbor, Michigan
21 * +1-313-763-0525
22 * netatalk@itd.umich.edu
23 *
24 * You may also use it under the terms of the General Public License (GPL). See COPYING.
25 */
26
27#ifndef AFPD_DIRECTORY_H
28#define AFPD_DIRECTORY_H 1
29
30#include <arpa/inet.h>
31#include <dirent.h>
32#include <stdbool.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 <sys/types.h>
41
42#include <atalk/adouble.h>
43#include <atalk/directory.h>
44#include <atalk/globals.h>
45
46#include "volume.h"
47
48/* Dircache modify flags — bitmask for selective field updates in dir_modify() */
49#define DCMOD_PATH (1 << 0)
50#define DCMOD_STAT (1 << 1)
51#define DCMOD_AD (1 << 2)
52#define DCMOD_AD_INV (1 << 3)
53#define DCMOD_NO_PROMOTE (1 << 4) /* Skip ARC promotion (cross-process hints) */
54
61 struct dir_modify_args {
62 unsigned int flags;
63 cnid_t new_pdid;
64 const char
65 *new_mname;
66 const char *new_uname;
67 bstring
68 new_pdir_path;
69 struct stat *st;
70 struct adouble *adp;
71};
72
73/* directory bits */
74#define DIRPBIT_ATTR 0
75#define DIRPBIT_PDID 1
76#define DIRPBIT_CDATE 2
77#define DIRPBIT_MDATE 3
78#define DIRPBIT_BDATE 4
79#define DIRPBIT_FINFO 5
80#define DIRPBIT_LNAME 6
81#define DIRPBIT_SNAME 7
82#define DIRPBIT_DID 8
83#define DIRPBIT_OFFCNT 9
84#define DIRPBIT_UID 10
85#define DIRPBIT_GID 11
86#define DIRPBIT_ACCESS 12
87#define DIRPBIT_PDINFO 13
88#define DIRPBIT_UNIXPR 15
89
90#define FILDIRBIT_ISDIR (1 << 7)
91#define FILDIRBIT_ISFILE (0)
92
93/* file/directory ids. what a mess. we scramble things in a vain attempt
94 * to get something meaningful */
95
96#define CNID(a,b) ((a)->st_ino & 0xffffffff)
97
98 struct maccess {
99 uint8_t ma_user;
100 uint8_t ma_world;
101 uint8_t ma_group;
102 uint8_t ma_owner;
103};
104
105#define AR_USEARCH (1<<0)
106#define AR_UREAD (1<<1)
107#define AR_UWRITE (1<<2)
108#define AR_UOWN (1<<7)
109
110extern q_t *invalid_dircache_entries;
111
112extern void dir_remove_and_free(const struct vol *, struct dir *);
113
114 typedef int (*dir_loop)(struct dirent *, char *, void *);
115
116extern void dir_free_invalid_q(void);
117extern struct dir *dir_new(const char *mname, const char *uname,
118 const struct vol *,
119 cnid_t pdid, cnid_t did, bstring fullpath, struct stat *);
120extern void dir_free(struct dir *);
121extern struct dir *dir_add(struct vol *, const struct dir *, struct path *,
122 int);
123extern int dir_modify(const struct vol *vol, struct dir *dir,
124 const struct dir_modify_args *args);
125extern int dir_remove(const struct vol *vol, struct dir *dir,
126 int report_invalid);
127extern struct dir *dirlookup(const struct vol *, cnid_t);
128extern struct dir *dirlookup_strict(const struct vol *, cnid_t);
129 extern struct dir *dirlookup_bypath(const struct vol *vol, const char *path);
130
131extern int movecwd(const struct vol *, struct dir *);
132extern struct path *cname(struct vol *, struct dir *, char **);
133
134extern int deletecurdir(struct vol *);
135extern mode_t mtoumode(struct maccess *);
136extern int getdirparams(const AFPObj *obj, const struct vol *, uint16_t,
137 struct path *,
138 struct dir *, char *, size_t *);
139
140extern int setdirparams(struct vol *, struct path *, uint16_t, char *);
141extern int renamedir(struct vol *, int, char *, char *, struct dir *,
142 char *);
143extern int path_error(struct path *, int error);
144extern void setdiroffcnt(struct dir *dir, struct stat *st,
145 uint32_t count);
146extern int dirreenumerate(struct dir *dir, struct stat *st);
147extern int for_each_dirent(const struct vol *, char *, dir_loop,
148 void *);
149extern int check_access(const AFPObj *obj, struct vol *, char *name,
150 int mode);
151extern int file_access(const AFPObj *obj, struct vol *vol,
152 struct path *path, int mode);
153extern int netatalk_unlink(const char *name);
154
155/* from enumerate.c */
156extern char *check_dirent(const struct vol *, char *);
157
158/* FP functions */
159int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
160 size_t *rbuflen);
161int afp_opendir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
162 size_t *rbuflen);
163int afp_setdirparams(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
164 size_t *rbuflen);
165int afp_closedir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
166 size_t *rbuflen);
167int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
168 size_t *rbuflen);
169int afp_mapname(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
170 size_t *rbuflen);
171int afp_syncdir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
172 size_t *rbuflen);
173
174/* from enumerate.c */
175int afp_enumerate(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
176 size_t *rbuflen);
177int afp_enumerate_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
178 size_t *rbuflen);
179int afp_enumerate_ext2(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
180 size_t *rbuflen);
181
182/* from catsearch.c */
183int afp_catsearch(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
184 size_t *rbuflen);
185int afp_catsearch_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,
186 size_t *rbuflen);
187
188#endif
adouble.h
Part of Netatalk's AppleDouble implementatation.
cnid_t
uint32_t cnid_t
Definition adouble.h:156
rbuflen
static size_t rbuflen
Definition afpfunc_helpers.c:45
rbuf
static char rbuf[rbufsize]
Definition afpfunc_helpers.c:44
bstring
struct tagbstring * bstring
Definition bstrlib.h:86
invalid_dircache_entries
q_t * invalid_dircache_entries
Definition directory.c:114
renamedir
int renamedir(struct vol *, int, char *, char *, struct dir *, char *)
Rename a directory.
Definition directory.c:3200
afp_enumerate_ext
int afp_enumerate_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition enumerate.c:654
check_access
int check_access(const AFPObj *obj, struct vol *, char *name, int mode)
Definition directory.c:2115
setdirparams
int setdirparams(struct vol *, struct path *, uint16_t, char *)
Definition directory.c:2538
file_access
int file_access(const AFPObj *obj, struct vol *vol, struct path *path, int mode)
Definition directory.c:2139
dir_free_invalid_q
void dir_free_invalid_q(void)
Free the queue with invalid struct dirs.
Definition directory.c:1458
for_each_dirent
int for_each_dirent(const struct vol *, char *, dir_loop, void *)
Definition enumerate.c:135
afp_setdirparams
int afp_setdirparams(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:2475
dir_add
struct dir * dir_add(struct vol *, const struct dir *, struct path *, int)
Create struct dir from struct path.
Definition directory.c:1331
afp_mapid
int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:3344
dir_remove_and_free
void dir_remove_and_free(const struct vol *, struct dir *)
Remove a cache entry and free it immediately.
Definition directory.c:1480
afp_opendir
int afp_opendir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:3619
check_dirent
char * check_dirent(const struct vol *, char *)
Definition enumerate.c:102
dir_modify
int dir_modify(const struct vol *vol, struct dir *dir, const struct dir_modify_args *args)
Update a cached entry in-place with selective field updates.
Definition directory.c:1005
dir_new
struct dir * dir_new(const char *mname, const char *uname, const struct vol *, cnid_t pdid, cnid_t did, bstring fullpath, struct stat *)
Construct struct dir.
Definition directory.c:887
dirreenumerate
int dirreenumerate(struct dir *dir, struct stat *st)
Definition directory.c:2173
getdirparams
int getdirparams(const AFPObj *obj, const struct vol *, uint16_t, struct path *, struct dir *, char *, size_t *)
Definition directory.c:2183
movecwd
int movecwd(const struct vol *, struct dir *)
chdir() to dir
Definition directory.c:2003
dir_remove
int dir_remove(const struct vol *vol, struct dir *dir, int report_invalid)
Remove a file/directory from dircache with automatic curdir recovery.
Definition directory.c:1519
setdiroffcnt
void setdiroffcnt(struct dir *dir, struct stat *st, uint32_t count)
Definition directory.c:2162
mtoumode
mode_t mtoumode(struct maccess *)
Definition etc/afpd/unix.c:168
path_error
int path_error(struct path *, int error)
Definition directory.c:2457
dirlookup
struct dir * dirlookup(const struct vol *, cnid_t)
Optimistic CNID resolution for read/safe code paths.
Definition directory.c:793
afp_catsearch_ext
int afp_catsearch_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition catsearch.c:1429
dirlookup_strict
struct dir * dirlookup_strict(const struct vol *, cnid_t)
Validated DID resolution for write/change code paths.
Definition directory.c:815
cname
struct path * cname(struct vol *, struct dir *, char **)
Resolve a catalog node name path.
Definition directory.c:1645
afp_syncdir
int afp_syncdir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:2985
deletecurdir
int deletecurdir(struct vol *)
Definition directory.c:3262
afp_enumerate_ext2
int afp_enumerate_ext2(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition enumerate.c:661
afp_enumerate
int afp_enumerate(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition enumerate.c:647
dir_loop
int(* dir_loop)(struct dirent *, char *, void *)
Definition etc/afpd/directory.h:114
afp_catsearch
int afp_catsearch(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition catsearch.c:1422
afp_closedir
int afp_closedir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:3600
dirlookup_bypath
struct dir * dirlookup_bypath(const struct vol *vol, const char *path)
afp_createdir
int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:3085
netatalk_unlink
int netatalk_unlink(const char *name)
system unlink with afp error code.
Definition libatalk/vfs/unix.c:124
afp_mapname
int afp_mapname(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition directory.c:3488
dir_free
void dir_free(struct dir *)
Free a struct dir and all its members.
Definition directory.c:959
volume.h
globals.h
directory.h
did
cnid_t did
Definition nad_cp.c:93
pdid
cnid_t pdid
Definition nad_cp.c:93
obj
static AFPObj obj
Definition netatalk.c:69
q_t
qnode_t q_t
Definition queue.h:32
count
int count
Definition server_ipc.c:89
AFPObj
Definition globals.h:166
adouble
Definition adouble.h:191
dir_modify_args
Parameters for dir_modify() selective field updates.
Definition etc/afpd/directory.h:61
dir_modify_args::flags
unsigned int flags
Definition etc/afpd/directory.h:62
dir_modify_args::new_pdir_path
bstring new_pdir_path
Definition etc/afpd/directory.h:68
dir_modify_args::new_mname
const char * new_mname
Definition etc/afpd/directory.h:65
dir_modify_args::new_uname
const char * new_uname
Definition etc/afpd/directory.h:66
dir_modify_args::st
struct stat * st
Definition etc/afpd/directory.h:69
dir_modify_args::adp
struct adouble * adp
Definition etc/afpd/directory.h:70
dir_modify_args::new_pdid
cnid_t new_pdid
Definition etc/afpd/directory.h:63
dir
Definition include/atalk/directory.h:56
maccess
Definition etc/afpd/directory.h:98
maccess::ma_owner
uint8_t ma_owner
Definition etc/afpd/directory.h:102
maccess::ma_world
uint8_t ma_world
Definition etc/afpd/directory.h:100
maccess::ma_user
uint8_t ma_user
Definition etc/afpd/directory.h:99
maccess::ma_group
uint8_t ma_group
Definition etc/afpd/directory.h:101
path
Definition include/atalk/directory.h:123
path::st
struct stat st
Definition include/atalk/directory.h:131
vol
Definition include/atalk/volume.h:33
args
static char * args[]
Definition test.c:48