Replace STAILQ with TAILQ. TAILQs are portable enough that they can
be used on both macOS and Linux. STAILQs are not. In particular, STAILQ_LAST does not next on Linux. Since neither STAILQ_FOREACH_SAFE nor TAILQ_FOREACH_SAFE exist on Linux, replace its use with a regular TAILQ_FOREACH. The _SAFE variant was only used for having the next pointer in a local variable.
This commit is contained in:
parent
2abb9b42a5
commit
1080fb197b
@ -91,7 +91,7 @@ apm_write(lba_t imgsz, void *bootcode __unused)
|
||||
strncpy(ent->ent_type, APM_ENT_TYPE_SELF, sizeof(ent->ent_type));
|
||||
strncpy(ent->ent_name, "Apple", sizeof(ent->ent_name));
|
||||
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
ent = (void *)(buf + (part->index + 2) * secsz);
|
||||
be16enc(&ent->ent_sig, APM_ENT_SIG);
|
||||
be32enc(&ent->ent_pmblkcnt, nparts + 1);
|
||||
|
@ -103,7 +103,7 @@ bsd_write(lba_t imgsz, void *bootcode)
|
||||
|
||||
dp = &d->d_partitions[RAW_PART];
|
||||
le32enc(&dp->p_size, imgsz);
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
n = part->index + ((part->index >= RAW_PART) ? 1 : 0);
|
||||
dp = &d->d_partitions[n];
|
||||
le32enc(&dp->p_size, part->size);
|
||||
|
@ -88,7 +88,7 @@ ebr_write(lba_t imgsz __unused, void *bootcode __unused)
|
||||
le16enc(ebr + DOSMAGICOFFSET, DOSMAGIC);
|
||||
|
||||
error = 0;
|
||||
STAILQ_FOREACH_SAFE(part, &partlist, link, next) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
block = part->block - nsecs;
|
||||
size = round_track(part->size);
|
||||
dp = (void *)(ebr + DOSPARTOFF);
|
||||
@ -100,6 +100,7 @@ ebr_write(lba_t imgsz __unused, void *bootcode __unused)
|
||||
le32enc(&dp->dp_size, size);
|
||||
|
||||
/* Add link entry */
|
||||
next = TAILQ_NEXT(part, link);
|
||||
if (next != NULL) {
|
||||
size = round_track(next->size);
|
||||
dp++;
|
||||
|
@ -208,7 +208,7 @@ gpt_mktbl(u_int tblsz)
|
||||
if (tbl == NULL)
|
||||
return (NULL);
|
||||
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
ent = tbl + part->index;
|
||||
gpt_uuid_enc(&ent->ent_type, ALIAS_TYPE2PTR(part->type));
|
||||
mkimg_uuid(&uuid);
|
||||
|
@ -60,7 +60,7 @@ __FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
struct chunk {
|
||||
STAILQ_ENTRY(chunk) ch_list;
|
||||
TAILQ_ENTRY(chunk) ch_list;
|
||||
size_t ch_size; /* Size of chunk in bytes. */
|
||||
lba_t ch_block; /* Block address in image. */
|
||||
union {
|
||||
@ -78,7 +78,7 @@ struct chunk {
|
||||
#define CH_TYPE_MEMORY 2 /* Memory-backed chunk */
|
||||
};
|
||||
|
||||
static STAILQ_HEAD(chunk_head, chunk) image_chunks;
|
||||
static TAILQ_HEAD(chunk_head, chunk) image_chunks;
|
||||
static u_int image_nchunks;
|
||||
|
||||
static char image_swap_file[PATH_MAX];
|
||||
@ -139,14 +139,14 @@ image_chunk_find(lba_t blk)
|
||||
struct chunk *ch;
|
||||
|
||||
ch = (last != NULL && last->ch_block <= blk)
|
||||
? last : STAILQ_FIRST(&image_chunks);
|
||||
? last : TAILQ_FIRST(&image_chunks);
|
||||
while (ch != NULL) {
|
||||
if (ch->ch_block <= blk &&
|
||||
(lba_t)(ch->ch_block + (ch->ch_size / secsz)) > blk) {
|
||||
last = ch;
|
||||
break;
|
||||
}
|
||||
ch = STAILQ_NEXT(ch, ch_list);
|
||||
ch = TAILQ_NEXT(ch, ch_list);
|
||||
}
|
||||
return (ch);
|
||||
}
|
||||
@ -188,7 +188,7 @@ image_chunk_memory(struct chunk *ch, lba_t blk)
|
||||
ch->ch_size = (blk - ch->ch_block) * secsz;
|
||||
new->ch_block = blk;
|
||||
new->ch_size -= ch->ch_size;
|
||||
STAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list);
|
||||
TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list);
|
||||
image_nchunks++;
|
||||
ch = new;
|
||||
}
|
||||
@ -203,7 +203,7 @@ image_chunk_memory(struct chunk *ch, lba_t blk)
|
||||
ch->ch_size = secsz;
|
||||
new->ch_block++;
|
||||
new->ch_size -= secsz;
|
||||
STAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list);
|
||||
TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list);
|
||||
image_nchunks++;
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ image_chunk_skipto(lba_t to)
|
||||
lba_t from;
|
||||
size_t sz;
|
||||
|
||||
ch = STAILQ_LAST(&image_chunks, chunk, ch_list);
|
||||
ch = TAILQ_LAST(&image_chunks, chunk_head);
|
||||
from = (ch != NULL) ? ch->ch_block + (ch->ch_size / secsz) : 0LL;
|
||||
|
||||
assert(from <= to);
|
||||
@ -244,7 +244,7 @@ image_chunk_skipto(lba_t to)
|
||||
ch->ch_block = from;
|
||||
ch->ch_size = sz;
|
||||
ch->ch_type = CH_TYPE_ZEROES;
|
||||
STAILQ_INSERT_TAIL(&image_chunks, ch, ch_list);
|
||||
TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list);
|
||||
image_nchunks++;
|
||||
return (0);
|
||||
}
|
||||
@ -254,7 +254,7 @@ image_chunk_append(lba_t blk, size_t sz, off_t ofs, int fd)
|
||||
{
|
||||
struct chunk *ch;
|
||||
|
||||
ch = STAILQ_LAST(&image_chunks, chunk, ch_list);
|
||||
ch = TAILQ_LAST(&image_chunks, chunk_head);
|
||||
if (ch != NULL && ch->ch_type == CH_TYPE_FILE) {
|
||||
if (fd == ch->ch_u.file.fd &&
|
||||
blk == (lba_t)(ch->ch_block + (ch->ch_size / secsz)) &&
|
||||
@ -275,7 +275,7 @@ image_chunk_append(lba_t blk, size_t sz, off_t ofs, int fd)
|
||||
ch->ch_type = CH_TYPE_FILE;
|
||||
ch->ch_u.file.ofs = ofs;
|
||||
ch->ch_u.file.fd = fd;
|
||||
STAILQ_INSERT_TAIL(&image_chunks, ch, ch_list);
|
||||
TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list);
|
||||
image_nchunks++;
|
||||
return (0);
|
||||
}
|
||||
@ -698,7 +698,7 @@ image_cleanup(void)
|
||||
{
|
||||
struct chunk *ch;
|
||||
|
||||
while ((ch = STAILQ_FIRST(&image_chunks)) != NULL) {
|
||||
while ((ch = TAILQ_FIRST(&image_chunks)) != NULL) {
|
||||
switch (ch->ch_type) {
|
||||
case CH_TYPE_FILE:
|
||||
/* We may be closing the same file multiple times. */
|
||||
@ -711,7 +711,7 @@ image_cleanup(void)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
STAILQ_REMOVE_HEAD(&image_chunks, ch_list);
|
||||
TAILQ_REMOVE(&image_chunks, ch, ch_list);
|
||||
free(ch);
|
||||
}
|
||||
if (image_swap_fd != -1)
|
||||
@ -724,7 +724,7 @@ image_init(void)
|
||||
{
|
||||
const char *tmpdir;
|
||||
|
||||
STAILQ_INIT(&image_chunks);
|
||||
TAILQ_INIT(&image_chunks);
|
||||
image_nchunks = 0;
|
||||
|
||||
image_swap_size = 0;
|
||||
|
@ -101,7 +101,7 @@ mbr_write(lba_t imgsz __unused, void *bootcode)
|
||||
memset(mbr, 0, secsz);
|
||||
le16enc(mbr + DOSMAGICOFFSET, DOSMAGIC);
|
||||
dpbase = (void *)(mbr + DOSPARTOFF);
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
size = round_track(part->size);
|
||||
dp = dpbase + part->index;
|
||||
dp->dp_flag = (part->index == 0 && bootcode != NULL) ? 0x80 : 0;
|
||||
|
@ -61,7 +61,7 @@ static struct option longopts[] = {
|
||||
|
||||
static uint64_t capacity;
|
||||
|
||||
struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist);
|
||||
struct partlisthead partlist = TAILQ_HEAD_INITIALIZER(partlist);
|
||||
u_int nparts = 0;
|
||||
|
||||
u_int unit_testing;
|
||||
@ -301,7 +301,7 @@ parse_part(const char *spec)
|
||||
}
|
||||
|
||||
part->index = nparts;
|
||||
STAILQ_INSERT_TAIL(&partlist, part, link);
|
||||
TAILQ_INSERT_TAIL(&partlist, part, link);
|
||||
nparts++;
|
||||
return (0);
|
||||
|
||||
@ -412,14 +412,14 @@ mkimg(void)
|
||||
int error, fd;
|
||||
|
||||
/* First check partition information */
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
error = scheme_check_part(part);
|
||||
if (error)
|
||||
errc(EX_DATAERR, error, "partition %d", part->index+1);
|
||||
}
|
||||
|
||||
block = scheme_metadata(SCHEME_META_IMG_START, 0);
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
block = scheme_metadata(SCHEME_META_PART_BEFORE, block);
|
||||
if (verbose)
|
||||
fprintf(stderr, "partition %d: starting block %llu "
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include <sys/queue.h>
|
||||
|
||||
struct part {
|
||||
STAILQ_ENTRY(part) link;
|
||||
TAILQ_ENTRY(part) link;
|
||||
char *alias; /* Partition type alias. */
|
||||
char *contents; /* Contents/size specification. */
|
||||
u_int kind; /* Content kind. */
|
||||
@ -47,7 +47,7 @@ struct part {
|
||||
char *label; /* Partition label. */
|
||||
};
|
||||
|
||||
extern STAILQ_HEAD(partlisthead, part) partlist;
|
||||
extern TAILQ_HEAD(partlisthead, part) partlist;
|
||||
extern u_int nparts;
|
||||
|
||||
extern u_int unit_testing;
|
||||
|
@ -97,7 +97,7 @@ pc98_write(lba_t imgsz __unused, void *bootcode)
|
||||
memset(buf, 0, PC98_BOOTCODESZ);
|
||||
le16enc(buf + PC98_MAGICOFS, PC98_MAGIC);
|
||||
dpbase = (void *)(buf + secsz);
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
size = round_track(part->size);
|
||||
dp = dpbase + part->index;
|
||||
ptyp = ALIAS_TYPE2INT(part->type);
|
||||
|
@ -87,7 +87,7 @@ vtoc8_write(lba_t imgsz, void *bootcode __unused)
|
||||
be16enc(&vtoc8.magic, VTOC_MAGIC);
|
||||
|
||||
be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
|
||||
STAILQ_FOREACH(part, &partlist, link) {
|
||||
TAILQ_FOREACH(part, &partlist, link) {
|
||||
n = part->index + ((part->index >= VTOC_RAW_PART) ? 1 : 0);
|
||||
be16enc(&vtoc8.part[n].tag, ALIAS_TYPE2INT(part->type));
|
||||
be32enc(&vtoc8.map[n].cyl, part->block / (nsecs * nheads));
|
||||
|
Loading…
Reference in New Issue
Block a user