Add a libfrog library function that will print tagged error messages.
This will eliminate the need for a lot of open-coded:
errno = ret;
perror("...");
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
#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"
ret = xfd_prepare_geometry(&xfd);
if (ret) {
- errno = ret;
- perror("xfd_prepare_geometry");
+ xfrog_perror(ret, "xfd_prepare_geometry");
exitcode = 1;
return 0;
}
}
}
if (ret) {
- errno = ret;
- perror("xfrog_bulkstat");
+ xfrog_perror(ret, "xfrog_bulkstat");
exitcode = 1;
}
ret = xfd_prepare_geometry(&xfd);
if (ret) {
- errno = ret;
- perror("xfd_prepare_geometry");
+ xfrog_perror(ret, "xfd_prepare_geometry");
exitcode = 1;
return 0;
}
ret = xfrog_bulkstat_single(&xfd, ino, flags, &bulkstat);
if (ret) {
- errno = ret;
- perror("xfrog_bulkstat_single");
+ xfrog_perror(ret, "xfrog_bulkstat_single");
continue;
}
ret = xfd_prepare_geometry(&xfd);
if (ret) {
- errno = ret;
- perror("xfd_prepare_geometry");
+ xfrog_perror(ret, "xfd_prepare_geometry");
exitcode = 1;
return 0;
}
}
}
if (ret) {
- errno = ret;
- perror("xfrog_inumbers");
+ xfrog_perror(ret, "xfrog_inumbers");
exitcode = 1;
}
#include "input.h"
#include "init.h"
#include "io.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
}
if (error) {
- errno = error;
- perror("xfsctl(XFS_IOC_FSINUMBERS)");
+ xfrog_perror(error, "xfsctl(XFS_IOC_FSINUMBERS)");
exitcode = 1;
}
free(ireq);
#include "init.h"
#include "io.h"
#include "libxfs.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
ret = xfrog_geometry(fd, geom);
if (ret) {
- errno = ret;
- perror("XFS_IOC_FSGEOMETRY");
+ xfrog_perror(ret, "XFS_IOC_FSGEOMETRY");
close(fd);
return -1;
}
ret = xfrog_inumbers(&xfd, ireq);
if (ret) {
- errno = ret;
- perror("XFS_IOC_FSINUMBERS");
+ xfrog_perror(ret, "XFS_IOC_FSINUMBERS");
goto out;
}
/* get next inode */
ret = xfrog_bulkstat(&xfd, breq);
if (ret) {
- errno = ret;
- perror("bulkstat");
+ xfrog_perror(ret, "bulkstat");
free(breq);
exitcode = 1;
return 0;
/* Not in use */
result_ino = 0;
} else if (ret) {
- errno = ret;
- perror("bulkstat_single");
+ xfrog_perror(ret, "bulkstat_single");
exitcode = 1;
return 0;
} else {
#include "io.h"
#include "statx.h"
#include "libxfs.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include <fcntl.h>
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);
#include "input.h"
#include "init.h"
#include "io.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
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;
fsgeom.c \
list_sort.c \
linux.c \
+logging.c \
paths.c \
projects.c \
ptvar.c \
crc32defs.h \
crc32table.h \
fsgeom.h \
+logging.h \
paths.h \
projects.h \
ptvar.h \
--- /dev/null
+// 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);
+}
--- /dev/null
+/* 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__ */
#include "command.h"
#include "init.h"
#include "quota.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
static cmdinfo_t free_cmd;
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;
}
#include <grp.h>
#include "init.h"
#include "quota.h"
+#include "libfrog/logging.h"
#include "libfrog/fsgeom.h"
#include "libfrog/bulkstat.h"
ret = xfd_open(&fsxfd, fsdir, O_RDONLY);
if (ret) {
- errno = ret;
- perror(fsdir);
+ xfrog_perror(ret, fsdir);
return;
}
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);
}
#include "command.h"
#include "input.h"
#include "init.h"
+#include "libfrog/logging.h"
#include "libfrog/paths.h"
#include "libfrog/fsgeom.h"
#include "space.h"
fprintf(stderr,
_("%s: Not on a mounted XFS filesystem.\n"),
path);
- else {
- errno = ret;
- perror(path);
- }
+ else
+ xfrog_perror(ret, path);
return -1;
}
#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"
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);
ret = xfrog_bulkstat_single(&file->xfd, ino, 0, &bs);
if (ret) {
- errno = ret;
- perror(descr);
+ xfrog_perror(ret, descr);
return 1;
}
}
} while (breq->hdr.ocount > 0);
- if (error) {
- errno = error;
- perror("bulkstat");
- }
+ if (error)
+ xfrog_perror(error, "bulkstat");
free(breq);
return error;