X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=diskutil.c;h=f074401501ba777de8f1f9516ed602feace0142c;hb=34d6090ea96ddaa4e2a0f914939e2b8ff7008bec;hp=1f2471be50470377c0acca7bdec3e441e5c1b8fa;hpb=971caeb177d3bc4f65fa31381bbfb83710bfc690;p=fio.git diff --git a/diskutil.c b/diskutil.c index 1f2471be..f0744015 100644 --- a/diskutil.c +++ b/diskutil.c @@ -1,13 +1,15 @@ #include #include -#include #include #include #include #include #include -#include -#include +#ifdef CONFIG_VALGRIND_DEV +#include +#else +#define DRD_IGNORE_VAR(x) do { } while (0) +#endif #include "fio.h" #include "smalloc.h" @@ -179,8 +181,7 @@ static int get_device_numbers(char *file_name, int *maj, int *min) /* * must be a file, open "." in that path */ - tempname[PATH_MAX - 1] = '\0'; - strncpy(tempname, file_name, PATH_MAX - 1); + snprintf(tempname, ARRAY_SIZE(tempname), "%s", file_name); p = dirname(tempname); if (stat(p, &st)) { perror("disk util stat"); @@ -240,7 +241,8 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, !strcmp(dirent->d_name, "..")) continue; - sprintf(temppath, "%s/%s", slavesdir, dirent->d_name); + nowarn_snprintf(temppath, sizeof(temppath), "%s/%s", slavesdir, + dirent->d_name); /* Can we always assume that the slaves device entries * are links to the real directories for the slave * devices? @@ -253,9 +255,12 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, } slavepath[linklen] = '\0'; - sprintf(temppath, "%s/%s/dev", slavesdir, slavepath); + nowarn_snprintf(temppath, sizeof(temppath), "%s/%s/dev", + slavesdir, slavepath); if (access(temppath, F_OK) != 0) - sprintf(temppath, "%s/%s/device/dev", slavesdir, slavepath); + nowarn_snprintf(temppath, sizeof(temppath), + "%s/%s/device/dev", slavesdir, + slavepath); if (read_block_dev_entry(temppath, &majdev, &mindev)) { perror("Error getting slave device numbers"); closedir(dirhandle); @@ -269,7 +274,8 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, if (slavedu) continue; - sprintf(temppath, "%s/%s", slavesdir, slavepath); + nowarn_snprintf(temppath, sizeof(temppath), "%s/%s", slavesdir, + slavepath); __init_per_file_disk_util(td, majdev, mindev, temppath); slavedu = disk_util_exists(majdev, mindev); @@ -297,6 +303,7 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev, if (!du) return NULL; + DRD_IGNORE_VAR(du->users); memset(du, 0, sizeof(*du)); INIT_FLIST_HEAD(&du->list); l = snprintf(du->path, sizeof(du->path), "%s/stat", path); @@ -306,7 +313,8 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev, sfree(du); return NULL; } - strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ - 1); + snprintf((char *) du->dus.name, ARRAY_SIZE(du->dus.name), "%s", + basename(path)); du->sysfs_root = strdup(path); du->major = majdev; du->minor = mindev; @@ -427,8 +435,7 @@ static struct disk_util *__init_per_file_disk_util(struct thread_data *td, log_err("unknown sysfs layout\n"); return NULL; } - tmp[PATH_MAX - 1] = '\0'; - strncpy(tmp, p, PATH_MAX - 1); + snprintf(tmp, ARRAY_SIZE(tmp), "%s", p); sprintf(path, "%s", tmp); } @@ -693,7 +700,7 @@ void show_disk_util(int terse, struct json_object *parent, struct disk_util *du; bool do_json; - if (!disk_util_sem) + if (!is_running_backend()) return; fio_sem_down(disk_util_sem);