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