From: Jaegeuk Kim Date: Thu, 22 Nov 2018 11:57:06 +0000 (-0800) Subject: libf2fs: avoid to use static local string for global f2fs_conf X-Git-Tag: v1.13.0~86 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=095ab108993683d8b7036d800dac7910432236c9;p=platform%2Fupstream%2Ff2fs-tools.git libf2fs: avoid to use static local string for global f2fs_conf We don't need to use c.rootdev_name, but do it locally. Signed-off-by: Jaegeuk Kim --- diff --git a/lib/libf2fs.c b/lib/libf2fs.c index a1a5c02..cc335db 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -535,22 +535,21 @@ __u32 f2fs_inode_chksum(struct f2fs_node *node) /* * try to identify the root device */ -const char *get_rootdev() +char *get_rootdev() { #if defined(ANDROID_WINDOWS_HOST) || defined(WITH_ANDROID) return NULL; #else struct stat sb; int fd, ret; - char buf[32]; + char buf[PATH_MAX + 1]; char *uevent, *ptr; - - static char rootdev[PATH_MAX + 1]; + char *rootdev; if (stat("/", &sb) == -1) return NULL; - snprintf(buf, 32, "/sys/dev/block/%u:%u/uevent", + snprintf(buf, PATH_MAX, "/sys/dev/block/%u:%u/uevent", major(sb.st_dev), minor(sb.st_dev)); fd = open(buf, O_RDONLY); @@ -577,8 +576,16 @@ const char *get_rootdev() return NULL; ret = sscanf(ptr, "DEVNAME=%s\n", buf); - snprintf(rootdev, PATH_MAX + 1, "/dev/%s", buf); + if (strlen(buf) == 0) + return NULL; + ret = strlen(buf) + 5; + rootdev = malloc(ret + 1); + if (!rootdev) + return NULL; + rootdev[ret] = '\0'; + + snprintf(rootdev, ret, "/dev/%s", buf); return rootdev; #endif } @@ -594,7 +601,6 @@ void f2fs_init_configuration(void) c.ndevs = 1; c.sectors_per_blk = DEFAULT_SECTORS_PER_BLOCK; c.blks_per_seg = DEFAULT_BLOCKS_PER_SEGMENT; - c.rootdev_name = get_rootdev(); c.wanted_total_sectors = -1; c.wanted_sector_size = -1; #ifndef WITH_ANDROID @@ -654,9 +660,13 @@ int f2fs_dev_is_umounted(char *path) struct stat *st_buf; int is_rootdev = 0; int ret = 0; + char *rootdev_name = get_rootdev(); - if (c.rootdev_name && !strcmp(path, c.rootdev_name)) - is_rootdev = 1; + if (rootdev_name) { + if (!strcmp(path, rootdev_name)) + is_rootdev = 1; + free(rootdev_name); + } /* * try with /proc/mounts fist to detect RDONLY.