From f8420e1dff5f17c00803dd841d794882eb9fb1e0 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 30 May 2013 23:50:26 +0200 Subject: [PATCH] Reduces memory occupation for hardlinks and empty dirs. --- HISTORY | 1 + elem.c | 11 +++++++---- elem.h | 6 +++--- scan.c | 5 +++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/HISTORY b/HISTORY index e09dc5fb..8dd9633c 100644 --- a/HISTORY +++ b/HISTORY @@ -10,6 +10,7 @@ SnapRAID HISTORY excluded. * In Windows applies filters in case insensitive way. * The Windows binaries are now built with gcc 4.7.2. + * Reduced memory occupation for hardlinks and directories. 3.0 2013/3 ========== diff --git a/elem.c b/elem.c index fdee727a..175d391d 100644 --- a/elem.c +++ b/elem.c @@ -262,7 +262,7 @@ int filter_content(tommy_list* contentlist, const char* path) /* FNM_PATHNAME because we are comparing full path */ /* FNM_NOESCAPE because the pattern is also a path, surely without escape chars */ - /* FNM_NOCASEINWIN ignore case only in windows */ + /* FNM_CASEINSENSITIVE_FOR_WIN ignore case only in windows */ if (fnmatch(content->content, path, FNM_PATHNAME | FNM_NOESCAPE | FNM_CASEINSENSITIVE_FOR_WIN) == 0) return -1; @@ -413,8 +413,8 @@ struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned l struct snapraid_link* link; link = malloc_nofail(sizeof(struct snapraid_link)); - pathcpy(link->sub, sizeof(link->sub), sub); - pathcpy(link->linkto, sizeof(link->linkto), linkto); + link->sub = strdup_nofail(sub); + link->linkto = strdup_nofail(linkto); link->flag = link_flag; return link; @@ -422,6 +422,8 @@ struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned l void link_free(struct snapraid_link* link) { + free(link->sub); + free(link->linkto); free(link); } @@ -437,7 +439,7 @@ struct snapraid_dir* dir_alloc(const char* sub) struct snapraid_dir* dir; dir = malloc_nofail(sizeof(struct snapraid_dir)); - pathcpy(dir->sub, sizeof(dir->sub), sub); + dir->sub = strdup_nofail(sub); dir->flag = 0; return dir; @@ -445,6 +447,7 @@ struct snapraid_dir* dir_alloc(const char* sub) void dir_free(struct snapraid_dir* dir) { + free(dir->sub); free(dir); } diff --git a/elem.h b/elem.h index 86831c9b..b11e4602 100644 --- a/elem.h +++ b/elem.h @@ -207,8 +207,8 @@ struct snapraid_file { */ struct snapraid_link { unsigned flag; /**< FILE_IS_* flags. */ - char sub[PATH_MAX]; /**< Sub path of the file. Without the disk dir. The disk is implicit. */ - char linkto[PATH_MAX]; /**< Link to. */ + char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */ + char* linkto; /**< Link to. */ /* nodes for data structures */ tommy_node nodelist; @@ -220,7 +220,7 @@ struct snapraid_link { */ struct snapraid_dir { unsigned flag; /**< FILE_IS_* flags. */ - char sub[PATH_MAX]; /**< Sub path of the file. Without the disk dir. The disk is implicit. */ + char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */ /* nodes for data structures */ tommy_node nodelist; diff --git a/scan.c b/scan.c index 41f67ce6..976fc775 100644 --- a/scan.c +++ b/scan.c @@ -112,7 +112,8 @@ static void scan_link(struct snapraid_scan* scan, struct snapraid_state* state, ++scan->count_change; /* update it */ - pathcpy(link->linkto, sizeof(link->linkto), linkto); + free(link->linkto); + link->linkto = strdup_nofail(linkto); link_flag_let(link, link_flag, FILE_IS_LINK_MASK); /* nothing more to do */ @@ -618,7 +619,7 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in if (filter_path(&state->filterlist, disk->name, sub_next) == 0) { #if HAVE_LSTAT_EX /* get inode info about the file, Windows needs an additional step */ - /* also for hardlink, the real size of the file is read only with this function */ + /* also for hardlink, the real size of the file is read here */ if (lstat_ex(path_next, &st) != 0) { fprintf(stderr, "Error in stat_inode file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE);