... which works on block devices as well as ordinary files.
static void check_img(const char *file)
{
int fd = -1;
static void check_img(const char *file)
{
int fd = -1;
unsigned char b[SECTORSZ], bb[SECTORSZ];
unsigned char b[SECTORSZ], bb[SECTORSZ];
+ off_t volsz;
+ int blksz;
secaddr end;
unsigned i, j;
fd = open(file, (flags&F_FIX) ? O_RDWR : O_RDONLY);
if (fd < 0)
{ gripe_syserr(2, errno, "failed to open `%s'", file); goto end; }
secaddr end;
unsigned i, j;
fd = open(file, (flags&F_FIX) ? O_RDWR : O_RDONLY);
if (fd < 0)
{ gripe_syserr(2, errno, "failed to open `%s'", file); goto end; }
- if (fstat(fd, &st)) {
- gripe_syserr(2, errno, "failed to retrieve file status for `%s'", file);
- goto end;
- }
- if (st.st_size%SECTORSZ) {
+ blksz = SECTORSZ; volsz = device_size(fd, file, &blksz);
+ if (SECTORSZ != 2048)
+ { gripe(2, "device sector size %d /= 2048", blksz); goto end; }
+ if (volsz%SECTORSZ) {
gripe(2, "bad length for `%s' -- not whole number of sectors", file);
goto end;
}
gripe(2, "bad length for `%s' -- not whole number of sectors", file);
goto end;
}
- end = st.st_size/SECTORSZ;
if (carefully_read(fd, 256*SECTORSZ, b, SECTORSZ, file) ||
check_anchor_header(b, 256, CAHF_GRIPE | CAHF_FULL, file))
if (carefully_read(fd, 256*SECTORSZ, b, SECTORSZ, file) ||
check_anchor_header(b, 256, CAHF_GRIPE | CAHF_FULL, file))