From: Antonio Huete Jimenez Date: Tue, 4 Mar 2014 23:24:38 +0000 (+0100) Subject: sbin/hammer - Remove trailing '/' from paths. X-Git-Tag: v3.9.0~421 X-Git-Url: https://gitweb.dragonflybsd.org/~nant/dragonfly.git/commitdiff_plain/8b64066296d5525d9bd923cd841c5084d8e668b5 sbin/hammer - Remove trailing '/' from paths. When operating PFSes through symbolic links, it was not possible to specify the trailing backslash since that translated to the PFS root dir instead of the symbolic link to the PFS itself. This caused problems when upgrading or downgrading PFSes (and probably in other cases too). The error was "Directory not empty". This commit should solve those cases, but keep in mind there are other cases where it is actually not possible to complete certain operations (like while destroying PFSes). Reported-by: Siju George, others --- diff --git a/sbin/hammer/cmd_mirror.c b/sbin/hammer/cmd_mirror.c index a3039be78a..4ccbb1d07c 100644 --- a/sbin/hammer/cmd_mirror.c +++ b/sbin/hammer/cmd_mirror.c @@ -87,7 +87,7 @@ hammer_cmd_mirror_read(char **av, int ac, int streaming) hammer_ioc_mrecord_any_t mrec; hammer_tid_t sync_tid; histogram_t histogram_ary; - const char *filesystem; + char *filesystem; char *buf = malloc(SERIALBUF_SIZE); int interrupted = 0; int error; @@ -757,7 +757,7 @@ void hammer_cmd_mirror_write(char **av, int ac) { struct hammer_ioc_mirror_rw mirror; - const char *filesystem; + char *filesystem; char *buf = malloc(SERIALBUF_SIZE); struct hammer_ioc_pseudofs_rw pfs; struct hammer_ioc_mrecord_head pickup; diff --git a/sbin/hammer/cmd_pseudofs.c b/sbin/hammer/cmd_pseudofs.c index 030f6c431c..7efc5e51b5 100644 --- a/sbin/hammer/cmd_pseudofs.c +++ b/sbin/hammer/cmd_pseudofs.c @@ -48,12 +48,13 @@ static int timetosecs(char *str); * softlink. */ int -getpfs(struct hammer_ioc_pseudofs_rw *pfs, const char *path) +getpfs(struct hammer_ioc_pseudofs_rw *pfs, char *path) { uintmax_t dummy_tid; struct stat st; char *dirpath; char buf[64]; + size_t len; int fd; int n; @@ -62,6 +63,16 @@ getpfs(struct hammer_ioc_pseudofs_rw *pfs, const char *path) bzero(pfs->ondisk, sizeof(*pfs->ondisk)); pfs->bytes = sizeof(*pfs->ondisk); + /* + * Remove the trailing '/' if there is one so that + * in the case path is a symbolic link to the PFS, + * the symbolic link is used and not the root dir of + * the PFS + */ + len = strnlen(path, MAXPATHLEN); + if (path[len-1] == '/' && path[len] == '\0') + path[len-1] = '\0'; + /* * Calculate the directory containing the softlink */ diff --git a/sbin/hammer/hammer.h b/sbin/hammer/hammer.h index 2a52f12522..946554fc45 100644 --- a/sbin/hammer/hammer.h +++ b/sbin/hammer/hammer.h @@ -137,7 +137,7 @@ void hammer_get_cycle(hammer_base_elm_t base, hammer_tid_t *tidp); void hammer_set_cycle(hammer_base_elm_t base, hammer_tid_t tid); void hammer_reset_cycle(void); -int getpfs(struct hammer_ioc_pseudofs_rw *pfs, const char *path); +int getpfs(struct hammer_ioc_pseudofs_rw *pfs, char *path); void relpfs(int fd, struct hammer_ioc_pseudofs_rw *pfs); void hammer_check_restrict(const char *path); void hammer_softprune_scandir(struct softprune **basep,