netatalk  4.6.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
include/atalk/directory.h
Go to the documentation of this file.
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 ATALK_DIRECTORY_H
25#define ATALK_DIRECTORY_H 1
26
27#include <arpa/inet.h>
28#include <dirent.h>
29#include <stdint.h>
30#include <sys/types.h>
31
32#include <bstrlib.h>
33
34#include <atalk/cnid.h>
35#include <atalk/hash.h>
36#include <atalk/queue.h>
37#include <atalk/unicode.h>
38
39/* setgid directories */
40#ifndef DIRBITS
41# define DIRBITS S_ISGID
42#endif /* DIRBITS */
43
44/* reserved directory id's */
45#define DIRDID_ROOT_PARENT htonl(1)
46#define DIRDID_ROOT htonl(2)
47
48/* struct dir.d_flags */
49#define DIRF_FSMASK (3<<0)
50#define DIRF_NOFS (0<<0)
51#define DIRF_UFS (1<<1)
52#define DIRF_ISFILE (1<<3)
53#define DIRF_OFFCNT (1<<4)
54#define DIRF_CNID (1<<5)
55#define DIRF_ARC_GHOST (1<<6)
56#define DIRF_INDEXED (1<<7)
57
58/* dcache_rlen states. AD_RLEN_NO_RFORK is the floor of the positive
59 * range, not a sentinel: test >= 0 for "metadata cached". */
60#define AD_RLEN_NO_RFORK ((off_t) 0)
61#define AD_RLEN_UNKNOWN ((off_t) -1)
62#define AD_RLEN_NO_AD ((off_t) -2)
63#define AD_RLEN_RFORK_ONLY ((off_t) -3)
65
67static inline int ad_rlen_meta_absent(off_t rlen)
68{
69 return rlen == AD_RLEN_NO_AD || rlen == AD_RLEN_RFORK_ONLY;
70}
71
72struct dir { // NOSONAR (max 20 fields) — fields are intentionally grouped for cache locality
73 /* Fields requiring 8-byte alignment: pointers, time_t, ino_t, off_t */
75 /* be careful here! if d_m_name == d_u_name, d_u_name
76 * will just point to the same storage as d_m_name !! */
83
84 /* Tier 2: Resource Fork data cache.
85 * Dynamically allocated buffer containing dcache_rlen bytes of rfork data.
86 * Freed automatically when the struct dir entry is evicted from dircache.
87 * Only populated for files with resource forks <= rfork_max_entry_size.
88 * NULL = not cached (may or may not have an rfork on disk).
89 * Buffer size is always dcache_rlen (Tier 1) — no separate size field needed.
90 * INVARIANT: dcache_rfork_buf != NULL implies dcache_rlen >= 0. */
93
94 time_t d_ctime;
96 time_t dcache_ctime;
98 ino_t dcache_ino;
105
106 /* Fields requiring 4-byte alignment: int, uint32_t, cnid_t, mode_t, uid_t, gid_t */
110 uint32_t d_offcnt;
111 uint32_t d_rights_cache;
115 mode_t dcache_mode;
118
119 /* Fields requiring 2-byte alignment */
120 uint16_t d_vid;
122
123 /* === 1-byte + byte arrays (no alignment requirement, packed densely) === */
124 uint8_t
126
127 /* Cached AppleDouble metadata (Tier 1 AD cache).
128 * Populated from ad_metadata() via ad_store_to_cache().
129 * dcache_filedatesi stores the SERVED representation (not raw AD):
130 * the AD_DATE_MODIFY slot contains max(ad_mdate, st_mtime).
131 * Trusted implicitly (same model as stat fields). Invalidated by
132 * ctime-based validation or dir_modify(DCMOD_AD_INV) on AFP writes.
133 * Zero-initialized by calloc — zeros are valid defaults. */
134 uint8_t dcache_afpfilei[4];
135 uint8_t dcache_finderinfo[32];
136 uint8_t
138};
139
140struct path {
141 int m_type;
142 char *m_name;
143 char *u_name;
145 struct dir *d_dir;
148 /* st was filled by fstat on an open fd: the object is live but the
149 * path may no longer name it. 0 = path-derived stat. */
150 int st_fd;
151 struct stat st;
152 /* Caller-resolved dircache entry for a FILE path; NULL = unknown.
153 * Directories use d_dir. Valid for the current request only. */
154 struct dir *d_cached;
155};
156
159static inline struct dir *path_cached_file(const struct path *path)
160{
162 return path->d_cached;
163 }
164
165 return NULL;
166}
167
172extern const char *dir_event_path(char *buf, size_t buflen,
173 const struct dir *parent,
174 const char *name);
175
176static inline int path_isadir(struct path *o_path)
177{
178 return o_path->d_dir != NULL;
179#if 0
180 return o_path->m_name == '\0' || /* we are in a it */
181 !o_path->st_valid || /* in cache but we can't chdir in it */
182 /* not in cache and can't chdir */
183 (!o_path->st_errno && S_ISDIR(o_path->st.st_mode));
184#endif
185}
186
187/* directory.c */
188extern struct dir rootParent;
189
190#endif /* ATALK_DIRECTORY_H */
uint32_t cnid_t
Definition adouble.h:157
static char buf[MAXPATHLEN+1]
Definition afppasswd.c:85
C implementaion of bstring functions.
struct tagbstring * bstring
Definition bstrlib.h:86
#define CNID_INVALID
Definition cnid.h:47
const char * dir_event_path(char *buf, size_t buflen, const struct dir *parent, const char *name)
Definition directory.c:3389
struct dir rootParent
Definition directory.c:73
#define AD_RLEN_RFORK_ONLY
Definition include/atalk/directory.h:63
static struct dir * path_cached_file(const struct path *path)
Definition include/atalk/directory.h:159
#define AD_RLEN_NO_AD
Definition include/atalk/directory.h:62
static int path_isadir(struct path *o_path)
Definition include/atalk/directory.h:176
static int ad_rlen_meta_absent(off_t rlen)
Definition include/atalk/directory.h:67
#define S_ISDIR(s)
Definition megatron.h:96
struct qnode qnode_t
Definition include/atalk/directory.h:72
time_t d_ctime
Definition include/atalk/directory.h:94
uint16_t d_vid
Definition include/atalk/directory.h:120
time_t dcache_ctime
Definition include/atalk/directory.h:96
off_t dcache_size
Definition include/atalk/directory.h:101
ino_t dcache_ino
Definition include/atalk/directory.h:98
uint8_t dcache_finderinfo[32]
Definition include/atalk/directory.h:135
void * dcache_rfork_buf
Definition include/atalk/directory.h:91
cnid_t d_did
Definition include/atalk/directory.h:109
hnode_t * d_didname_node
Definition include/atalk/directory.h:82
mode_t dcache_mode
Definition include/atalk/directory.h:115
uid_t dcache_uid
Definition include/atalk/directory.h:116
uint8_t dcache_afpfilei[4]
Definition include/atalk/directory.h:134
qnode_t * qidx_node
Definition include/atalk/directory.h:80
bstring d_fullpath
Definition include/atalk/directory.h:74
ucs2_t * d_m_name_ucs2
Definition include/atalk/directory.h:79
uint32_t d_rights_cache
Definition include/atalk/directory.h:111
time_t dcache_mtime
Definition include/atalk/directory.h:100
gid_t dcache_gid
Definition include/atalk/directory.h:117
int d_flags
Definition include/atalk/directory.h:107
qnode_t * rfork_lru_node
Definition include/atalk/directory.h:92
uint8_t arc_list
Definition include/atalk/directory.h:125
uint32_t d_offcnt
Definition include/atalk/directory.h:110
uint8_t dcache_filedatesi[16]
Definition include/atalk/directory.h:137
hnode_t * d_index_node
Definition include/atalk/directory.h:81
bstring d_m_name
Definition include/atalk/directory.h:77
bstring d_u_name
Definition include/atalk/directory.h:78
cnid_t d_pdid
Definition include/atalk/directory.h:108
off_t dcache_rlen
Definition include/atalk/directory.h:104
Hash chain node structure.
Definition include/atalk/hash.h:63
Definition include/atalk/directory.h:140
char * u_name
Definition include/atalk/directory.h:143
int st_valid
Definition include/atalk/directory.h:146
struct stat st
Definition include/atalk/directory.h:151
int m_type
Definition include/atalk/directory.h:141
struct dir * d_cached
Definition include/atalk/directory.h:154
int st_errno
Definition include/atalk/directory.h:147
cnid_t id
Definition include/atalk/directory.h:144
struct dir * d_dir
Definition include/atalk/directory.h:145
int st_fd
Definition include/atalk/directory.h:150
char * m_name
Definition include/atalk/directory.h:142
#define ucs2_t
Definition unicode.h:8
#define NULL
Definition utf8util.c:47