From 60f6ec7dd64db458ace3cc15545693a96d6c7adf Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 17 Aug 2015 23:09:47 +0300 Subject: [PATCH] files-reg: Rework strip_deleted helper Make it handle both postfixes and return non-zero code if stipping happened. Signed-off-by: Cyrill Gorcunov Acked-by: Tycho Andersen Signed-off-by: Pavel Emelyanov --- files-reg.c | 34 ++++++++++++++++++++++++++-------- include/files-reg.h | 2 ++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/files-reg.c b/files-reg.c index 2812e7895..f3ba898f6 100644 --- a/files-reg.c +++ b/files-reg.c @@ -639,20 +639,38 @@ static inline bool nfs_silly_rename(char *rpath, const struct fd_parms *parms) return (parms->fs_type == NFS_SUPER_MAGIC) && is_sillyrename_name(rpath); } -static void strip_deleted(struct fd_link *link) +int strip_deleted(struct fd_link *link) { - const char postfix[] = " (deleted)"; - const size_t plen = strlen(postfix); + struct dcache_prepends { + const char *str; + size_t len; + } static const prepends[] = { + { + .str = " (deleted)", + .len = 10, + }, { + .str = "//deleted", + .len = 9, + } + }; + size_t i; - if (link->len > plen) { - size_t at = link->len - plen; - if (!strcmp(&link->name[at], postfix)) { + for (i = 0; i < ARRAY_SIZE(prepends); i++) { + size_t at; + + if (link->len <= prepends[i].len) + continue; + + at = link->len - prepends[i].len; + if (!strcmp(&link->name[at], prepends[i].str)) { pr_debug("Stip %s' tag from '%s'\n", - postfix, link->name); + prepends[i].str, link->name); link->name[at] = '\0'; - link->len -= plen; + link->len -= prepends[i].len; + return 1; } } + return 0; } static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, diff --git a/include/files-reg.h b/include/files-reg.h index 09cd90fe9..a9a8d4aae 100644 --- a/include/files-reg.h +++ b/include/files-reg.h @@ -51,4 +51,6 @@ extern struct collect_image_info remap_cinfo; extern void delete_link_remaps(void); extern void free_link_remaps(void); +extern int strip_deleted(struct fd_link *link); + #endif /* __CR_FILES_REG_H__ */