sfdisk: fix -N return code detection, add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
c949fa98d8
commit
31c79e1823
|
@ -469,23 +469,32 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa
|
||||||
dst = (backward ? to + nsectors : to) * ss;
|
dst = (backward ? to + nsectors : to) * ss;
|
||||||
buf = xmalloc(step_bytes);
|
buf = xmalloc(step_bytes);
|
||||||
|
|
||||||
|
DBG(MISC, ul_debug(" initial: src=%ju dst=%ju", src, dst));
|
||||||
|
|
||||||
for (cc = 1, i = 0; i < nsectors; i += step, cc++) {
|
for (cc = 1, i = 0; i < nsectors; i += step, cc++) {
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
|
|
||||||
if (backward)
|
if (backward)
|
||||||
src -= step_bytes, dst -= step_bytes;
|
src -= step_bytes, dst -= step_bytes;
|
||||||
|
|
||||||
lseek(fd, src, SEEK_SET);
|
DBG(MISC, ul_debug("#%05zu: src=%ju dst=%ju", cc, src, dst));
|
||||||
|
|
||||||
|
/* read source */
|
||||||
|
if (lseek(fd, src, SEEK_SET) == (off_t) -1)
|
||||||
|
goto fail;
|
||||||
rc = read(fd, buf, step_bytes);
|
rc = read(fd, buf, step_bytes);
|
||||||
if (rc < 0 || rc != (ssize_t) step_bytes)
|
if (rc < 0 || rc != (ssize_t) step_bytes)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
lseek(fd, dst, SEEK_SET);
|
/* write target */
|
||||||
|
if (lseek(fd, dst, SEEK_SET) == (off_t) -1)
|
||||||
|
goto fail;
|
||||||
rc = write(fd, buf, step_bytes);
|
rc = write(fd, buf, step_bytes);
|
||||||
if (rc < 0 || rc != (ssize_t) step_bytes)
|
if (rc < 0 || rc != (ssize_t) step_bytes)
|
||||||
goto fail;
|
goto fail;
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
|
|
||||||
|
/* write log */
|
||||||
fprintf(f, "%05zu: %12ju %12ju\n", cc, src, dst);
|
fprintf(f, "%05zu: %12ju %12ju\n", cc, src, dst);
|
||||||
|
|
||||||
#if defined(POSIX_FADV_DONTNEED) && defined(HAVE_POSIX_FADVISE)
|
#if defined(POSIX_FADV_DONTNEED) && defined(HAVE_POSIX_FADVISE)
|
||||||
|
@ -501,8 +510,9 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa
|
||||||
free(typescript);
|
free(typescript);
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
|
warn(_("%s: failed to move data"), devname);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
err(EXIT_FAILURE, _("%s: failed to move data"), devname);
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_changes(struct sfdisk *sf)
|
static int write_changes(struct sfdisk *sf)
|
||||||
|
@ -1583,8 +1593,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
|
||||||
}
|
}
|
||||||
if (!rc && partno >= 0) { /* -N <partno>, modify partition */
|
if (!rc && partno >= 0) { /* -N <partno>, modify partition */
|
||||||
rc = fdisk_set_partition(sf->cxt, partno, pa);
|
rc = fdisk_set_partition(sf->cxt, partno, pa);
|
||||||
if (rc == 0)
|
rc = rc == 0 ? SFDISK_DONE_ASK : SFDISK_DONE_ABORT;
|
||||||
rc = SFDISK_DONE_ASK;
|
|
||||||
break;
|
break;
|
||||||
} else if (!rc) { /* add partition */
|
} else if (!rc) { /* add partition */
|
||||||
rc = fdisk_add_partition(sf->cxt, pa, &cur_partno);
|
rc = fdisk_add_partition(sf->cxt, pa, &cur_partno);
|
||||||
|
|
Loading…
Reference in New Issue