forked from Mirrors/btrfs-progs
btrfs-progs: mkfs: use existing helper for path concatenation
Mkfs uses make_path that is duplicate of path_cat* functions, so we can switch to them and add the error handling. Signed-off-by: David Sterba <dsterba@suse.com>master
parent
fe667f6e7d
commit
d07e349800
20
mkfs/main.c
20
mkfs/main.c
|
@ -47,6 +47,8 @@
|
||||||
#include "mkfs/common.h"
|
#include "mkfs/common.h"
|
||||||
#include "fsfeatures.h"
|
#include "fsfeatures.h"
|
||||||
|
|
||||||
|
int path_cat_out(char *out, const char *p1, const char *p2);
|
||||||
|
|
||||||
static u64 index_cnt = 2;
|
static u64 index_cnt = 2;
|
||||||
static int verbose = 1;
|
static int verbose = 1;
|
||||||
|
|
||||||
|
@ -941,14 +943,28 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
|
char tmp[PATH_MAX];
|
||||||
|
|
||||||
dir_entry = malloc(sizeof(struct directory_name_entry));
|
dir_entry = malloc(sizeof(struct directory_name_entry));
|
||||||
if (!dir_entry) {
|
if (!dir_entry) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
dir_entry->dir_name = cur_file->d_name;
|
dir_entry->dir_name = cur_file->d_name;
|
||||||
dir_entry->path = make_path(parent_dir_entry->path,
|
if (path_cat_out(tmp, parent_dir_entry->path,
|
||||||
cur_file->d_name);
|
cur_file->d_name)) {
|
||||||
|
error("invalid path: %s/%s",
|
||||||
|
parent_dir_entry->path,
|
||||||
|
cur_file->d_name);
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
dir_entry->path = strdup(tmp);
|
||||||
|
if (!dir_entry->path) {
|
||||||
|
error("not enough memory to store path");
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
dir_entry->inum = cur_inum;
|
dir_entry->inum = cur_inum;
|
||||||
list_add_tail(&dir_entry->list, &dir_head->list);
|
list_add_tail(&dir_entry->list, &dir_head->list);
|
||||||
} else if (S_ISREG(st.st_mode)) {
|
} else if (S_ISREG(st.st_mode)) {
|
||||||
|
|
Loading…
Reference in New Issue