Files
linux/block/partitions/sysv68.c
Kees Cook c2d466b9fe block: partitions: Replace pp_buf with struct seq_buf
In preparation for removing the strlcat API[1], replace the char *pp_buf
with a struct seq_buf, which tracks the current write position and
remaining space internally. This allows for:

- Direct use of seq_buf_printf() in place of snprintf()+strlcat()
  pairs, eliminating local tmp buffers throughout.
- Adjacent strlcat() calls that build strings piece-by-piece
  (e.g., strlcat("["); strlcat(name); strlcat("]")) to be collapsed
  into single seq_buf_printf() calls.
- Simpler call sites: seq_buf_puts() takes only the buffer and string,
  with no need to pass PAGE_SIZE at every call.

The backing buffer allocation is unchanged (__get_free_page), and the
output path uses seq_buf_str() to NUL-terminate before passing to
printk().

Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Josh Law <objecting@objecting.org>
Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: Josh Law <objecting@objecting.org>
Link: https://patch.msgid.link/20260321004840.work.670-kees@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-03-21 08:27:08 -06:00

93 lines
1.8 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* fs/partitions/sysv68.c
*
* Copyright (C) 2007 Philippe De Muyter <phdm@macqel.be>
*/
#include "check.h"
/*
* Volume ID structure: on first 256-bytes sector of disk
*/
struct volumeid {
u8 vid_unused[248];
u8 vid_mac[8]; /* ASCII string "MOTOROLA" */
};
/*
* config block: second 256-bytes sector on disk
*/
struct dkconfig {
u8 ios_unused0[128];
__be32 ios_slcblk; /* Slice table block number */
__be16 ios_slccnt; /* Number of entries in slice table */
u8 ios_unused1[122];
};
/*
* combined volumeid and dkconfig block
*/
struct dkblk0 {
struct volumeid dk_vid;
struct dkconfig dk_ios;
};
/*
* Slice Table Structure
*/
struct slice {
__be32 nblocks; /* slice size (in blocks) */
__be32 blkoff; /* block offset of slice */
};
int sysv68_partition(struct parsed_partitions *state)
{
int i, slices;
int slot = 1;
Sector sect;
unsigned char *data;
struct dkblk0 *b;
struct slice *slice;
data = read_part_sector(state, 0, &sect);
if (!data)
return -1;
b = (struct dkblk0 *)data;
if (memcmp(b->dk_vid.vid_mac, "MOTOROLA", sizeof(b->dk_vid.vid_mac))) {
put_dev_sector(sect);
return 0;
}
slices = be16_to_cpu(b->dk_ios.ios_slccnt);
i = be32_to_cpu(b->dk_ios.ios_slcblk);
put_dev_sector(sect);
data = read_part_sector(state, i, &sect);
if (!data)
return -1;
slices -= 1; /* last slice is the whole disk */
seq_buf_printf(&state->pp_buf, "sysV68: %s(s%u)", state->name, slices);
slice = (struct slice *)data;
for (i = 0; i < slices; i++, slice++) {
if (slot == state->limit)
break;
if (be32_to_cpu(slice->nblocks)) {
put_partition(state, slot,
be32_to_cpu(slice->blkoff),
be32_to_cpu(slice->nblocks));
seq_buf_printf(&state->pp_buf, "(s%u)", i);
}
slot++;
}
seq_buf_puts(&state->pp_buf, "\n");
put_dev_sector(sect);
return 1;
}