1 Workaround for Network Trash and system without byte locking (broken nfs/afs)
2 mangle OS9 "Network Trash Folder/Trash Can #2" name to
3 "Network Trash Folder/Trash Can #2.<client ip>.<tcp port>"
4 So multiple clients can share the same volume and have a working trash.
6 Index: etc/afpd/directory.c
7 ===================================================================
8 RCS file: /cvsroot/netatalk/netatalk/etc/afpd/directory.c,v
9 retrieving revision 1.71.2.4.2.12
10 diff -u -r1.71.2.4.2.12 directory.c
11 --- etc/afpd/directory.c 11 Mar 2004 16:16:40 -0000 1.71.2.4.2.12
12 +++ etc/afpd/directory.c 21 Apr 2004 12:42:03 -0000
14 * attempt to extend the current dir. tree to include path
15 * as a side-effect, movecwd to that point and return the new dir
19 extenddir( vol, dir, path )
24 if ( path->u_name == NULL) {
25 - path->u_name = mtoupath(vol, path->m_name, dir->d_did, (path->m_type==3) );
26 +#ifdef DISABLE_LOCKING
27 + int l = strlen(TRASH_PREFIX);
28 + /* XXX replace mac name with unix name */
29 + if (vol->v_trash_id && vol->v_trash_id == dir->d_did && vol->v_ip &&
30 + !strncmp(TRASH_PREFIX , path->m_name, l ) )
32 + static char temp[MAXPATHLEN + 1];
35 + strcpy(temp, path->m_name);
38 + strcat(temp, vol->v_ip);
39 + path->u_name = temp;
44 + path->u_name = mtoupath(vol, path->m_name, dir->d_did, (path->m_type==3) );
48 Index: etc/afpd/enumerate.c
49 ===================================================================
50 RCS file: /cvsroot/netatalk/netatalk/etc/afpd/enumerate.c,v
51 retrieving revision 1.39.2.2.2.4
52 diff -u -r1.39.2.2.2.4 enumerate.c
53 --- etc/afpd/enumerate.c 11 Mar 2004 02:01:59 -0000 1.39.2.2.2.4
54 +++ etc/afpd/enumerate.c 21 Apr 2004 12:42:04 -0000
60 +#ifdef DISABLE_LOCKING
61 + if (!path->m_name) {
62 + int l = strlen(TRASH_PREFIX);
64 + if (vol->v_trash_id && vol->v_trash_id == dir->d_did && vol->v_ip &&
65 + !strncmp(TRASH_PREFIX , upath, l ) )
67 + static char temp[MAXPATHLEN + 1];
70 + strcpy(temp, upath);
73 + while (*u >= '0' && *u <= '9') {
79 + path->m_name = temp;
82 + else if(!(path->m_name = utompath(vol, upath, id , utf8_encoding()))) {
87 if (!path->m_name && !(path->m_name = utompath(vol, upath, id , utf8_encoding()))) {
94 if ((cdir = dirnew(name, upath)) == NULL) {
95 LOG(log_error, logtype_afpd, "adddir: malloc: %s", strerror(errno) );
100 +#ifdef DISABLE_LOCKING
101 +/* ----------------------------- */
102 +int check_trash(const struct vol *vol, char *name)
104 +int l = strlen(TRASH_PREFIX);
107 + if (strncmp(TRASH_PREFIX , name, l))
111 + while (*u >= '0' && *u <= '9') {
118 + if (*u == '.' && !strcmp(vol->v_ip, u +1)) {
121 + /* hide this one */
126 /* ----------------------------- */
128 for_each_dirent(const struct vol *vol, char *name, dir_loop fn, void *data)
129 @@ -193,15 +249,28 @@
133 +#ifdef DISABLE_LOCKING
134 + int mangle_trash = 0;
137 if (NULL == ( dp = opendir( name)) ) {
141 +#ifdef DISABLE_LOCKING
142 + if (vol->v_trash_id && vol->v_trash_id == curdir->d_did && !strcmp(name, ".")) {
147 for ( de = readdir( dp ); de != NULL; de = readdir( dp )) {
148 if (!(m_name = check_dirent(vol, de->d_name)))
151 +#ifdef DISABLE_LOCKING
152 + if (mangle_trash && check_trash(vol, de->d_name))
156 if (fn && fn(de,m_name, data) < 0) {
158 Index: etc/afpd/volume.c
159 ===================================================================
160 RCS file: /cvsroot/netatalk/netatalk/etc/afpd/volume.c,v
161 retrieving revision 1.51.2.7.2.28
162 diff -u -r1.51.2.7.2.28 volume.c
163 --- etc/afpd/volume.c 6 Apr 2004 23:29:37 -0000 1.51.2.7.2.28
164 +++ etc/afpd/volume.c 21 Apr 2004 12:42:05 -0000
167 static struct vol *Volumes = NULL;
168 static u_int16_t lastvid = 0;
169 -static char *Trash = "\02\024Network Trash Folder";
171 +/* type, len, name */
172 +static char *Trash2 = "\02\024Network Trash Folder";
173 +/* type, hint (4 bytes), len (2bytes), name */
174 +static char *Trash3 = "\03\0\0\0\0\0\024Network Trash Folder";
176 static struct extmap *Extmap = NULL, *Defextmap = NULL;
177 static int Extmap_cnt;
178 @@ -1038,6 +1042,10 @@
179 free(vol->v_forceuid);
180 free(vol->v_forcegid);
181 #endif /* FORCE_UIDGID */
183 +#ifdef DISABLE_LOCKING
188 /* ------------------------------- */
189 @@ -1730,9 +1738,31 @@
195 - cname( volume, volume->v_dir, &p );
196 +#ifndef DISABLE_LOCKING
200 + struct path *s_path;
202 + /* use the right name format */
203 + p = (afp_version>= 30)?Trash3:Trash2;
204 + s_path = cname( volume, volume->v_dir, &p );
205 +#ifdef DISABLE_LOCKING
206 + if (s_path && *s_path->m_name == '\0' ) {
207 + /* XXXX should do the same with ASP, could use volxlate but there's ':' in $p */
208 + if (obj->proto == AFPPROTO_DSI) {
209 + DSI *dsi = obj->handle;
211 + /* cname moved into dest folder */
212 + volume->v_trash_id = curdir->d_did;
213 + volume->v_ip = malloc(MAXPATHLEN +1);
214 + if (volume->v_ip) {
215 + sprintf(volume->v_ip, "%s.%u", inet_ntoa(dsi->client.sin_addr),
216 + ntohs(dsi->client.sin_port));
224 Index: etc/afpd/volume.h
225 ===================================================================
226 RCS file: /cvsroot/netatalk/netatalk/etc/afpd/volume.h,v
227 retrieving revision 1.19.2.5.2.6
228 diff -u -r1.19.2.5.2.6 volume.h
229 --- etc/afpd/volume.h 11 Mar 2004 02:02:04 -0000 1.19.2.5.2.6
230 +++ etc/afpd/volume.h 21 Apr 2004 12:42:05 -0000
232 /* adouble indirection */
233 int (*validupath)(const struct vol *, const char *);
234 char *(*ad_path)(const char *, int);
236 +#ifdef DISABLE_LOCKING
237 + /* for OS 9 trash when there's no working byte locking (afs, nfs) */
243 #ifdef NO_LARGE_VOL_SUPPORT
245 #define VOLPBIT_BSIZE 11 /* block size */
248 +#define TRASH_PREFIX "Trash Can #"
250 #define vol_noadouble(vol) (((vol)->v_flags & AFPVOL_NOADOUBLE) ? \
251 ADFLAGS_NOADOUBLE : 0)