diff options
author | Rosen Penev <rosenp@gmail.com> | 2018-01-07 13:54:21 -0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-01-31 15:14:03 +0100 |
commit | e4df433b8a2d5ef944ab4764a5ad237bcdbd1fdc (patch) | |
tree | 19aa758dee389cea7c86c68ce1c8cc8e9a52836c /cmds-subvolume.c | |
parent | 24103f42ad7a65457a62ae5c0190ea0e428cb14b (diff) |
btrfs-progs: treewide: Replace strerror(errno) with %m.
As btrfs is specific to Linux, %m can be used instead of strerror(errno)
in format strings. This has some size reduction benefits for embedded
systems.
glibc, musl, and uclibc-ng all support %m as a modifier to printf.
A quick glance at the BIONIC libc source indicates that it has
support for %m as well. BSDs and Windows do not but I do believe
them to be beyond the scope of btrfs-progs.
Compiled sizes on Ubuntu 16.04:
Before:
3916512 btrfs
233688 libbtrfs.so.0.1
4899 bcp
2367672 btrfs-convert
2208488 btrfs-corrupt-block
13302 btrfs-debugfs
2152160 btrfs-debug-tree
2136024 btrfs-find-root
2287592 btrfs-image
2144600 btrfs-map-logical
2130760 btrfs-select-super
2152608 btrfstune
2131760 btrfs-zero-log
2277752 mkfs.btrfs
9166 show-blocks
After:
3908744 btrfs
233256 libbtrfs.so.0.1
4899 bcp
2366560 btrfs-convert
2207432 btrfs-corrupt-block
13302 btrfs-debugfs
2151104 btrfs-debug-tree
2134968 btrfs-find-root
2281864 btrfs-image
2143536 btrfs-map-logical
2129704 btrfs-select-super
2151552 btrfstune
2130696 btrfs-zero-log
2276272 mkfs.btrfs
9166 show-blocks
Total savings: 23928 (24 kilo)bytes
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r-- | cmds-subvolume.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c index dc626a64..8a473f7a 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -210,7 +210,7 @@ static int cmd_subvol_create(int argc, char **argv) } if (res < 0) { - error("cannot create subvolume: %s", strerror(errno)); + error("cannot create subvolume: %m"); goto out; } @@ -325,8 +325,7 @@ again: cpath = realpath(path, NULL); if (!cpath) { ret = errno; - error("cannot find real path for '%s': %s", - path, strerror(errno)); + error("cannot find real path for '%s': %m", path); goto out; } dupdname = strdup(cpath); @@ -348,8 +347,7 @@ again: strncpy_null(args.name, vname); res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args); if(res < 0 ){ - error("cannot delete '%s/%s': %s", dname, vname, - strerror(errno)); + error("cannot delete '%s/%s': %m", dname, vname); ret = 1; goto out; } @@ -357,8 +355,7 @@ again: if (commit_mode == COMMIT_EACH) { res = wait_for_commit(fd); if (res < 0) { - error("unable to wait for commit after '%s': %s", - path, strerror(errno)); + error("unable to wait for commit after '%s': %m", path); ret = 1; } } else if (commit_mode == COMMIT_AFTER) { @@ -415,8 +412,8 @@ keep_fd: if (res < 0) { uuid_unparse(seen->fsid, uuidbuf); error( - "unable to do final sync after deletion: %s, fsid: %s", - strerror(errno), uuidbuf); + "unable to do final sync after deletion: %m, fsid: %s", + uuidbuf); ret = 1; } else if (verbose > 0) { uuid_unparse(seen->fsid, uuidbuf); @@ -776,7 +773,7 @@ static int cmd_subvol_snapshot(int argc, char **argv) res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_V2, &args); if (res < 0) { - error("cannot snapshot '%s': %s", subvol, strerror(errno)); + error("cannot snapshot '%s': %m", subvol); goto out; } @@ -819,8 +816,7 @@ static int cmd_subvol_get_default(int argc, char **argv) ret = btrfs_list_get_default_subvolume(fd, &default_id); if (ret) { - error("failed to look up default subvolume: %s", - strerror(errno)); + error("failed to look up default subvolume: %m"); goto out; } @@ -868,7 +864,7 @@ static const char * const cmd_subvol_set_default_usage[] = { static int cmd_subvol_set_default(int argc, char **argv) { - int ret=0, fd, e; + int ret=0, fd; u64 objectid; char *path; char *subvolid; @@ -915,11 +911,9 @@ static int cmd_subvol_set_default(int argc, char **argv) } ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid); - e = errno; close_file_or_dir(fd, dirstream); if (ret < 0) { - error("unable to set a new default subvolume: %s", - strerror(e)); + error("unable to set a new default subvolume: %m"); return 1; } return 0; @@ -963,8 +957,7 @@ static int cmd_subvol_find_new(int argc, char **argv) ret = ioctl(fd, BTRFS_IOC_SYNC); if (ret < 0) { - error("sync ioctl failed on '%s': %s", - subvol, strerror(errno)); + error("sync ioctl failed on '%s': %m", subvol); close_file_or_dir(fd, dirstream); return 1; } @@ -1039,8 +1032,7 @@ static int cmd_subvol_show(int argc, char **argv) memset(&get_ri, 0, sizeof(get_ri)); fullpath = realpath(argv[optind], NULL); if (!fullpath) { - error("cannot find real path for '%s': %s", - argv[optind], strerror(errno)); + error("cannot find real path for '%s': %m", argv[optind]); goto out; } |