From ec19ba243cd30f9030091e5a2bf0dab13da61c0e Mon Sep 17 00:00:00 2001 From: didg Date: Tue, 2 Mar 2004 13:27:07 +0000 Subject: [PATCH] deal with folders deleted by a different process. --- etc/afpd/filedir.c | 8 +++--- etc/afpd/fork.h | 3 ++- etc/afpd/ofork.c | 22 +++++++++++++++- etc/afpd/volume.c | 65 ++++++++++++++++++++++++---------------------- 4 files changed, 61 insertions(+), 37 deletions(-) diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index 5f43b98d..d2c849b7 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.45.2.2.2.7 2004-02-20 21:23:13 didg Exp $ + * $Id: filedir.c,v 1.45.2.2.2.8 2004-03-02 13:27:07 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -177,10 +177,10 @@ int ibuflen, *rbuflen; if (!s_path->st_valid) { /* it's a dir and it should be there * because we chdir in it in cname or - * it's curdir (maybe deleted, but then we can't know) - * + * it's curdir (maybe deleted, but then we can't know). + * So we need to try harder. */ - of_stat(s_path); + of_statdir(s_path); } if ( s_path->st_errno != 0 ) { return( AFPERR_NOOBJ ); diff --git a/etc/afpd/fork.h b/etc/afpd/fork.h index 8c00a38d..3600a6e7 100644 --- a/etc/afpd/fork.h +++ b/etc/afpd/fork.h @@ -1,5 +1,5 @@ /* - * $Id: fork.h,v 1.8 2003-01-16 21:18:15 didg Exp $ + * $Id: fork.h,v 1.8.6.1 2004-03-02 13:27:08 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -68,6 +68,7 @@ extern int of_rename __P((const struct vol *, extern int of_flush __P((const struct vol *)); extern void of_pforkdesc __P((FILE *)); extern int of_stat __P((struct path *)); +extern int of_statdir __P((struct path *)); /* in fork.c */ extern int flushfork __P((struct ofork *)); diff --git a/etc/afpd/ofork.c b/etc/afpd/ofork.c index 8d47061c..225f2539 100644 --- a/etc/afpd/ofork.c +++ b/etc/afpd/ofork.c @@ -1,5 +1,5 @@ /* - * $Id: ofork.c,v 1.20.6.4 2004-02-14 15:47:20 didg Exp $ + * $Id: ofork.c,v 1.20.6.5 2004-03-02 13:27:08 didg Exp $ * * Copyright (c) 1996 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -286,6 +286,26 @@ int ret; return ret; } +/* -------------------------- + * assume +*/ +int of_statdir (struct path *path) +{ +static char pathname[ MAXPATHLEN + 1]; +int ret; + + if (*path->m_name) { + /* not curdir */ + return of_stat (path); + } + path->st_errno = 0; + path->st_valid = 1; + strcpy(pathname, "../"); + strlcat(pathname, path->dir->d_u_name, MAXPATHLEN); + if ((ret = stat(pathname, &path->st)) < 0) + path->st_errno = errno; + return ret; +} /* -------------------------- */ struct ofork * diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 7633fb0a..4b03f06b 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -1,5 +1,5 @@ /* - * $Id: volume.c,v 1.51.2.7.2.23 2004-03-01 14:01:02 bfernhomberg Exp $ + * $Id: volume.c,v 1.51.2.7.2.24 2004-03-02 13:27:08 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1500,6 +1500,7 @@ int ibuflen, *rbuflen; int len, ret; size_t namelen; u_int16_t bitmap; + char path[ MAXPATHLEN + 1]; char *vol_uname; char *vol_mname; @@ -1564,36 +1565,6 @@ int ibuflen, *rbuflen; volume->v_dir = volume->v_root = NULL; - /* FIXME unix name != mac name */ - - len = convert_string_allocate( CH_UCS2, (utf8_encoding()?CH_UTF8_MAC:obj->options.maccharset), - volume->v_name, namelen, &vol_mname); - if ( !vol_mname || len <= 0) { - ret = AFPERR_MISC; - goto openvol_err; - } - - len = convert_string_allocate( CH_UCS2 , volume->v_volcharset, volume->v_name, namelen, &vol_uname); - - if ( !vol_uname || len <= 0) { - free(vol_mname); - ret = AFPERR_MISC; - goto openvol_err; - } - - if ((dir = dirnew(vol_mname, vol_uname) ) == NULL) { - free(vol_mname); - free(vol_uname); - LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) ); - ret = AFPERR_MISC; - goto openvol_err; - } - free(vol_mname); - free(vol_uname); - - dir->d_did = DIRDID_ROOT; - dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */ - volume->v_dir = volume->v_root = dir; volume->v_flags |= AFPVOL_OPEN; volume->v_cdb = NULL; @@ -1626,6 +1597,38 @@ int ibuflen, *rbuflen; ret = AFPERR_PARAM; goto openvol_err; } + + len = convert_string_allocate( CH_UCS2, (utf8_encoding()?CH_UTF8_MAC:obj->options.maccharset), + volume->v_name, namelen, &vol_mname); + if ( !vol_mname || len <= 0) { + ret = AFPERR_MISC; + goto openvol_err; + } + + if ( NULL == getcwd(path, MAXPATHLEN)) { + /* shouldn't be fatal but it will fail later */ + LOG(log_error, logtype_afpd, "afp_openvol: volume pathlen too long" ); + ret = AFPERR_MISC; + goto openvol_err; + } + + if ((vol_uname = strrchr(path, '/')) == NULL) + vol_uname = path; + else if (*(vol_uname + 1) != '\0') + vol_uname++; + + if ((dir = dirnew(vol_mname, vol_uname) ) == NULL) { + free(vol_mname); + LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) ); + ret = AFPERR_MISC; + goto openvol_err; + } + free(vol_mname); + + dir->d_did = DIRDID_ROOT; + dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */ + volume->v_dir = volume->v_root = dir; + curdir = volume->v_dir; if (volume->v_cnidscheme == NULL) { volume->v_cnidscheme = strdup(DEFAULT_CNID_SCHEME); -- 2.39.2