randbytes.c \
scrub.c \
util.c \
-workqueue.c
+workqueue.c \
+zones.c
HFILES = \
avl64.h \
randbytes.h \
scrub.h \
statx.h \
-workqueue.h
+workqueue.h \
+zones.h
GETTEXT_PY = \
gettext.py
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025, Western Digital Corporation or its affiliates.
+ */
+#include "platform_defs.h"
+#include "libfrog/zones.h"
+#include <sys/ioctl.h>
+
+/* random size that allows efficient processing */
+#define ZONES_PER_REPORT 16384
+
+struct xfrog_zone_report *
+xfrog_report_zones(
+ int fd,
+ uint64_t sector,
+ struct xfrog_zone_report *rep)
+{
+ if (!rep) {
+ rep = calloc(1, struct_size(rep, zones, ZONES_PER_REPORT));
+ if (!rep) {
+ fprintf(stderr, "%s\n",
+_("Failed to allocate memory for reporting zones."));
+ return NULL;
+ }
+ }
+
+ rep->rep.sector = sector;
+ rep->rep.nr_zones = ZONES_PER_REPORT;
+
+ if (ioctl(fd, BLKREPORTZONE, &rep->rep)) {
+ fprintf(stderr, "%s %s\n",
+_("ioctl(BLKREPORTZONE) failed:\n"),
+ strerror(-errno));
+ free(rep);
+ return NULL;
+ }
+
+ return rep;
+}
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025, Western Digital Corporation or its affiliates.
+ */
+#ifndef __LIBFROG_ZONES_H__
+#define __LIBFROG_ZONES_H__
+
+struct xfrog_zone_report {
+ struct blk_zone_report rep;
+ struct blk_zone zones[];
+};
+
+struct xfrog_zone_report *
+xfrog_report_zones(int fd, uint64_t sector, struct xfrog_zone_report *rep);
+
+#endif /* __LIBFROG_ZONES_H__ */
#include "libfrog/crc32cselftest.h"
#include "libfrog/dahashselftest.h"
#include "libfrog/fsproperties.h"
+#include "libfrog/zones.h"
#include "proto.h"
#include <ini.h>
struct zone_info log;
};
-/* random size that allows efficient processing */
-#define ZONES_PER_IOCTL 16384
-
static void
zone_validate_capacity(
struct zone_info *zi,
const char *name,
struct zone_info *zi)
{
- struct blk_zone_report *rep;
+ struct xfrog_zone_report *rep = NULL;
bool found_seq = false;
- int fd, ret = 0;
+ int fd;
uint64_t device_size;
uint64_t sector = 0;
- size_t rep_size;
unsigned int i, n = 0;
struct stat st;
zi->nr_zones = device_size / zi->zone_size;
zi->nr_conv_zones = 0;
- rep_size = sizeof(struct blk_zone_report) +
- sizeof(struct blk_zone) * ZONES_PER_IOCTL;
- rep = malloc(rep_size);
- if (!rep) {
- fprintf(stderr,
-_("Failed to allocate memory for zone reporting.\n"));
- exit(1);
- }
-
while (n < zi->nr_zones) {
- struct blk_zone *zones = (struct blk_zone *)(rep + 1);
+ struct blk_zone *zones;
- memset(rep, 0, rep_size);
- rep->sector = sector;
- rep->nr_zones = ZONES_PER_IOCTL;
-
- ret = ioctl(fd, BLKREPORTZONE, rep);
- if (ret) {
- fprintf(stderr,
-_("ioctl(BLKREPORTZONE) failed: %d!\n"), -errno);
+ rep = xfrog_report_zones(fd, sector, rep);
+ if (!rep)
exit(1);
- }
- if (!rep->nr_zones)
+
+ if (!rep->rep.nr_zones)
break;
- for (i = 0; i < rep->nr_zones; i++) {
+ zones = rep->zones;
+ for (i = 0; i < rep->rep.nr_zones; i++) {
if (n >= zi->nr_zones)
break;
n++;
}
- sector = zones[rep->nr_zones - 1].start +
- zones[rep->nr_zones - 1].len;
+ sector = zones[rep->rep.nr_zones - 1].start +
+ zones[rep->rep.nr_zones - 1].len;
}
free(rep);
#include "libxfs_priv.h"
#include "libxfs.h"
#include "xfs_zones.h"
+#include "libfrog/zones.h"
#include "err_protos.h"
#include "zoned.h"
uint64_t sector = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart);
unsigned int zone_size, zone_capacity;
uint64_t device_size;
- size_t rep_size;
- struct blk_zone_report *rep;
+ struct xfrog_zone_report *rep = NULL;
unsigned int i, n = 0;
if (ioctl(fd, BLKGETSIZE64, &device_size))
return;
}
- rep_size = sizeof(struct blk_zone_report) +
- sizeof(struct blk_zone) * ZONES_PER_IOCTL;
- rep = malloc(rep_size);
- if (!rep) {
- do_warn(_("malloc failed for zone report\n"));
- return;
- }
-
while (n < mp->m_sb.sb_rgcount) {
- struct blk_zone *zones = (struct blk_zone *)(rep + 1);
- int ret;
+ struct blk_zone *zones;
- memset(rep, 0, rep_size);
- rep->sector = sector;
- rep->nr_zones = ZONES_PER_IOCTL;
+ rep = xfrog_report_zones(fd, sector, rep);
+ if (!rep)
+ return;
- ret = ioctl(fd, BLKREPORTZONE, rep);
- if (ret) {
- do_error(_("ioctl(BLKREPORTZONE) failed: %d!\n"), ret);
- goto out_free;
- }
- if (!rep->nr_zones)
+ if (!rep->rep.nr_zones)
break;
- for (i = 0; i < rep->nr_zones; i++) {
+ zones = rep->zones;
+ for (i = 0; i < rep->rep.nr_zones; i++) {
if (n >= mp->m_sb.sb_rgcount)
break;
report_zones_cb(mp, &zones[i]);
n++;
}
- sector = zones[rep->nr_zones - 1].start +
- zones[rep->nr_zones - 1].len;
+ sector = zones[rep->rep.nr_zones - 1].start +
+ zones[rep->rep.nr_zones - 1].len;
}
out_free: