@@ -7,6 +7,7 @@
#include "platform_defs.h"
#include "command.h"
#include "init.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
#include "libfrog/paths.h"
@@ -165,8 +166,7 @@ bulkstat_f(
ret = xfd_prepare_geometry(&xfd);
if (ret) {
- errno = ret;
- perror("xfd_prepare_geometry");
+ xfrog_perror(ret, "xfd_prepare_geometry");
exitcode = 1;
return 0;
}
@@ -203,8 +203,7 @@ _("bulkstat: startino=%lld flags=0x%x agno=%u ret=%d icount=%u ocount=%u\n"),
}
}
if (ret) {
- errno = ret;
- perror("xfrog_bulkstat");
+ xfrog_perror(ret, "xfrog_bulkstat");
exitcode = 1;
return 0;
}
@@ -269,8 +268,7 @@ bulkstat_single_f(
ret = xfd_prepare_geometry(&xfd);
if (ret) {
- errno = ret;
- perror("xfd_prepare_geometry");
+ xfrog_perror(ret, "xfd_prepare_geometry");
exitcode = 1;
return 0;
}
@@ -313,8 +311,7 @@ bulkstat_single_f(
ret = xfrog_bulkstat_single(&xfd, ino, flags, &bulkstat);
if (ret) {
- errno = ret;
- perror("xfrog_bulkstat_single");
+ xfrog_perror(ret, "xfrog_bulkstat_single");
continue;
}
@@ -427,8 +424,7 @@ inumbers_f(
ret = xfd_prepare_geometry(&xfd);
if (ret) {
- errno = ret;
- perror("xfd_prepare_geometry");
+ xfrog_perror(ret, "xfd_prepare_geometry");
exitcode = 1;
return 0;
}
@@ -465,8 +461,7 @@ _("bulkstat: startino=%"PRIu64" flags=0x%"PRIx32" agno=%"PRIu32" ret=%d icount=%
}
}
if (ret) {
- errno = ret;
- perror("xfrog_inumbers");
+ xfrog_perror(ret, "xfrog_inumbers");
exitcode = 1;
return 0;
}
@@ -8,6 +8,7 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
@@ -44,8 +45,7 @@ imap_f(int argc, char **argv)
}
if (error) {
- errno = error;
- perror("xfsctl(XFS_IOC_FSINUMBERS)");
+ xfrog_perror(error, "xfsctl(XFS_IOC_FSINUMBERS)");
exitcode = 1;
}
free(ireq);
@@ -9,6 +9,7 @@
#include "init.h"
#include "io.h"
#include "libxfs.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
@@ -125,8 +126,7 @@ openfile(
ret = xfrog_geometry(fd, geom);
if (ret) {
- errno = ret;
- perror("XFS_IOC_FSGEOMETRY");
+ xfrog_perror(ret, "XFS_IOC_FSGEOMETRY");
close(fd);
return -1;
}
@@ -696,8 +696,7 @@ get_last_inode(void)
ret = xfrog_inumbers(&xfd, ireq);
if (ret) {
- errno = ret;
- perror("XFS_IOC_FSINUMBERS");
+ xfrog_perror(ret, "XFS_IOC_FSINUMBERS");
free(ireq);
goto out;
}
@@ -798,8 +797,7 @@ inode_f(
/* get next inode */
ret = xfrog_bulkstat(&xfd, breq);
if (ret) {
- errno = ret;
- perror("bulkstat");
+ xfrog_perror(ret, "bulkstat");
free(breq);
exitcode = 1;
return 0;
@@ -820,8 +818,7 @@ inode_f(
/* Not in use */
result_ino = 0;
} else if (ret) {
- errno = ret;
- perror("bulkstat_single");
+ xfrog_perror(ret, "bulkstat_single");
exitcode = 1;
return 0;
} else {
@@ -12,6 +12,7 @@
#include "io.h"
#include "statx.h"
#include "libxfs.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include <fcntl.h>
@@ -198,8 +199,7 @@ statfs_f(
return 0;
ret = xfrog_geometry(file->fd, &fsgeo);
if (ret) {
- errno = ret;
- perror("XFS_IOC_FSGEOMETRY");
+ xfrog_perror(ret, "XFS_IOC_FSGEOMETRY");
} else {
printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
printf(_("geom.agcount = %u\n"), fsgeo.agcount);
@@ -8,6 +8,7 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
@@ -51,14 +52,12 @@ swapext_f(
error = xfrog_bulkstat_single(&fxfd, stat.st_ino, 0, &bulkstat);
if (error) {
- errno = error;
- perror("bulkstat");
+ xfrog_perror(error, "bulkstat");
goto out;
}
error = xfrog_bulkstat_v5_to_v1(&fxfd, &sx.sx_stat, &bulkstat);
if (error) {
- errno = error;
- perror("bulkstat conversion");
+ xfrog_perror(error, "bulkstat conversion");
goto out;
}
sx.sx_version = XFS_SX_VERSION;
@@ -19,6 +19,7 @@ crc32.c \
fsgeom.c \
list_sort.c \
linux.c \
+logging.c \
paths.c \
projects.c \
ptvar.c \
@@ -38,6 +39,7 @@ crc32cselftest.h \
crc32defs.h \
crc32table.h \
fsgeom.h \
+logging.h \
paths.h \
projects.h \
ptvar.h \
new file mode 100644
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2019 Oracle. All Rights Reserved.
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ */
+#include <errno.h>
+#include <stdio.h>
+#include "logging.h"
+
+/* Print an error. */
+void
+xfrog_perror(
+ int error,
+ const char *s)
+{
+ errno = error < 0 ? -error : error;
+ perror(s);
+}
new file mode 100644
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2019 Oracle, Inc.
+ * All Rights Reserved.
+ */
+#ifndef __LIBFROG_LOGGING_H__
+#define __LIBFROG_LOGGING_H__
+
+void xfrog_perror(int error, const char *s);
+
+#endif /* __LIBFROG_LOGGING_H__ */
@@ -8,6 +8,7 @@
#include "command.h"
#include "init.h"
#include "quota.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
static cmdinfo_t free_cmd;
@@ -70,8 +71,7 @@ mount_free_space_data(
if (!(mount->fs_flags & FS_FOREIGN)) {
ret = xfrog_geometry(fd, &fsgeo);
if (ret) {
- errno = ret;
- perror("XFS_IOC_FSGEOMETRY");
+ xfrog_perror(ret, "XFS_IOC_FSGEOMETRY");
close(fd);
return 0;
}
@@ -11,6 +11,7 @@
#include <grp.h>
#include "init.h"
#include "quota.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
@@ -147,8 +148,7 @@ quot_bulkstat_mount(
ret = xfd_open(&fsxfd, fsdir, O_RDONLY);
if (ret) {
- errno = ret;
- perror(fsdir);
+ xfrog_perror(ret, fsdir);
return;
}
@@ -165,10 +165,8 @@ quot_bulkstat_mount(
for (i = 0; i < breq->hdr.ocount; i++)
quot_bulkstat_add(&breq->bulkstat[i], flags);
}
- if (sts < 0) {
- errno = sts;
- perror("XFS_IOC_FSBULKSTAT");
- }
+ if (sts < 0)
+ xfrog_perror(sts, "XFS_IOC_FSBULKSTAT");
free(breq);
xfd_close(&fsxfd);
}
@@ -10,6 +10,7 @@
#include "command.h"
#include "input.h"
#include "init.h"
+#include "libfrog/logging.h"
#include "libfrog/paths.h"
#include "libfrog/fsgeom.h"
#include "space.h"
@@ -57,10 +58,8 @@ openfile(
fprintf(stderr,
_("%s: Not on a mounted XFS filesystem.\n"),
path);
- else {
- errno = ret;
- perror(path);
- }
+ else
+ xfrog_perror(ret, path);
return -1;
}
@@ -8,6 +8,7 @@
#include "command.h"
#include "init.h"
#include "input.h"
+#include "libfrog/logging.h"
#include "libfrog/paths.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
@@ -193,8 +194,7 @@ report_ag_sick(
ret = xfrog_ag_geometry(file->xfd.fd, agno, &ageo);
if (ret) {
- errno = ret;
- perror("ag_geometry");
+ xfrog_perror(ret, "ag_geometry");
return 1;
}
snprintf(descr, sizeof(descr) - 1, _("AG %u"), agno);
@@ -219,8 +219,7 @@ report_inode_health(
ret = xfrog_bulkstat_single(&file->xfd, ino, 0, &bs);
if (ret) {
- errno = ret;
- perror(descr);
+ xfrog_perror(ret, descr);
return 1;
}
@@ -294,10 +293,8 @@ report_bulkstat_health(
}
} while (breq->hdr.ocount > 0);
- if (error) {
- errno = error;
- perror("bulkstat");
- }
+ if (error)
+ xfrog_perror(error, "bulkstat");
free(breq);
return error;