hdparm/hdparm-7.6-err_return.patch

565 lines
14 KiB
Diff

--- hdparm.c
+++ hdparm.c
@@ -281,17 +281,20 @@
}
#endif
rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors
- if (rc)
+ if (rc) {
+ rc = errno;
perror(" BLKGETSIZE failed");
+ }
*blksize64 = blksize32;
return rc;
}
-static void time_device (int fd)
+static int time_device (int fd)
{
char *buf;
double elapsed;
struct itimerval e1, e2;
+ int err = 0;
unsigned int max_iterations = 1024, total_MB, iterations;
/*
@@ -300,12 +303,12 @@
if (do_ctimings || do_timings) {
unsigned long long blksize;
do_flush = 1;
- if (0 == do_blkgetsize(fd, &blksize))
+ if (0 == (err = do_blkgetsize(fd, &blksize)))
max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB;
}
buf = prepare_timing_buf(TIMING_BUF_BYTES);
if (!buf)
- return;
+ return 1;
printf(" Timing %s disk reads: ", (open_flags & O_DIRECT) ? "O_DIRECT" : "buffered");
fflush(stdout);
@@ -338,6 +341,7 @@
quit:
munlockall();
munmap(buf, TIMING_BUF_BYTES);
+ return err;
}
static void dmpstr (const char *prefix, unsigned int i, const char *s[], unsigned int maxi)
@@ -789,21 +793,25 @@
}
}
-static void flush_wcache (int fd, __u16 **id_p)
+static int flush_wcache (int fd, __u16 **id_p)
{
__u8 args[4] = {ATA_OP_FLUSHCACHE,0,0,0};
__u16 *id;
+ int err = 0;
*id_p = id = get_identify_data(fd, *id_p);
if (id && (id[83] & 0xe000) == 0x6000)
args[0] = ATA_OP_FLUSHCACHE_EXT;
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror (" HDIO_DRIVE_CMD(flushcache) failed");
+ }
+ return err;
}
void process_dev (char *devname)
{
- int fd;
+ int fd, err = 0;
static long parm, multcount;
__u16 *id = (void *)-1;
@@ -819,14 +827,18 @@
if (set_fsreadahead) {
if (get_fsreadahead)
printf(" setting fs readahead to %d\n", fsreadahead);
- if (ioctl(fd, BLKRASET, fsreadahead))
+ if (ioctl(fd, BLKRASET, fsreadahead)) {
+ err = errno;
perror(" BLKRASET failed");
+ }
}
if (set_unregister) {
if (get_unregister)
printf(" attempting to unregister hwif#%u\n", hwif);
- if (ioctl(fd, HDIO_UNREGISTER_HWIF, hwif))
+ if (ioctl(fd, HDIO_UNREGISTER_HWIF, hwif)) {
+ err = errno;
perror(" HDIO_UNREGISTER_HWIF failed");
+ }
}
if (scan_hwif) {
int args[3];
@@ -834,8 +846,10 @@
args[0] = hwif_data;
args[1] = hwif_ctrl;
args[2] = hwif_irq;
- if (ioctl(fd, HDIO_SCAN_HWIF, args))
+ if (ioctl(fd, HDIO_SCAN_HWIF, args)) {
+ err = errno;
perror(" HDIO_SCAN_HWIF failed");
+ }
}
if (set_piomode) {
if (get_piomode) {
@@ -848,68 +862,86 @@
else
printf(" attempting to set UDMA mode to %d\n", (piomode-200));
}
- if (ioctl(fd, HDIO_SET_PIO_MODE, piomode))
+ if (ioctl(fd, HDIO_SET_PIO_MODE, piomode)) {
+ err = errno;
perror(" HDIO_SET_PIO_MODE failed");
+ }
}
if (set_io32bit) {
if (get_io32bit)
printf(" setting 32-bit IO_support flag to %d\n", io32bit);
- if (ioctl(fd, HDIO_SET_32BIT, io32bit))
+ if (ioctl(fd, HDIO_SET_32BIT, io32bit)) {
+ err = errno;
perror(" HDIO_SET_32BIT failed");
+ }
}
if (set_mult) {
if (get_mult)
printf(" setting multcount to %d\n", mult);
- if (ioctl(fd, HDIO_SET_MULTCOUNT, mult))
+ if (ioctl(fd, HDIO_SET_MULTCOUNT, mult)) {
+ err = errno;
perror(" HDIO_SET_MULTCOUNT failed");
+ }
}
if (set_readonly) {
if (get_readonly) {
printf(" setting readonly to %d", readonly);
on_off(readonly);
}
- if (ioctl(fd, BLKROSET, &readonly))
+ if (ioctl(fd, BLKROSET, &readonly)) {
+ err = errno;
perror(" BLKROSET failed");
+ }
}
if (set_unmask) {
if (get_unmask) {
printf(" setting unmaskirq to %d", unmask);
on_off(unmask);
}
- if (ioctl(fd, HDIO_SET_UNMASKINTR, unmask))
+ if (ioctl(fd, HDIO_SET_UNMASKINTR, unmask)) {
+ err = errno;
perror(" HDIO_SET_UNMASKINTR failed");
+ }
}
if (set_dma) {
if (get_dma) {
printf(" setting using_dma to %d", dma);
on_off(dma);
}
- if (ioctl(fd, HDIO_SET_DMA, dma))
+ if (ioctl(fd, HDIO_SET_DMA, dma)) {
+ err = errno;
perror(" HDIO_SET_DMA failed");
+ }
}
if (set_dma_q) {
if (get_dma_q) {
printf(" setting DMA queue_depth to %d", dma_q);
on_off(dma_q);
}
- if (ioctl(fd, HDIO_SET_QDMA, dma_q))
+ if (ioctl(fd, HDIO_SET_QDMA, dma_q)) {
+ err = errno;
perror(" HDIO_SET_QDMA failed");
+ }
}
if (set_nowerr) {
if (get_nowerr) {
printf(" setting nowerr to %d", nowerr);
on_off(nowerr);
}
- if (ioctl(fd, HDIO_SET_NOWERR, nowerr))
+ if (ioctl(fd, HDIO_SET_NOWERR, nowerr)) {
+ err = errno;
perror(" HDIO_SET_NOWERR failed");
+ }
}
if (set_keep) {
if (get_keep) {
printf(" setting keep_settings to %d", keep);
on_off(keep);
}
- if (ioctl(fd, HDIO_SET_KEEPSETTINGS, keep))
+ if (ioctl(fd, HDIO_SET_KEEPSETTINGS, keep)) {
+ err = errno;
perror(" HDIO_SET_KEEPSETTINGS failed");
+ }
}
if (set_doorlock) {
__u8 args[4] = {0,0,0,0};
@@ -918,8 +950,10 @@
printf(" setting drive doorlock to %d", doorlock);
on_off(doorlock);
}
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(doorlock) failed");
+ }
}
if (set_dkeep) {
/* lock/unlock the drive's "feature" settings */
@@ -929,24 +963,30 @@
on_off(dkeep);
}
args[2] = dkeep ? 0x66 : 0xcc;
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(keepsettings) failed");
+ }
}
if (set_defects) {
__u8 args[4] = {ATA_OP_SETFEATURES,0,0x04,0};
args[2] = defects ? 0x04 : 0x84;
if (get_defects)
printf(" setting drive defect management to %d\n", defects);
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(defectmgmt) failed");
+ }
}
if (set_prefetch) {
__u8 args[4] = {ATA_OP_SETFEATURES,0,0xab,0};
args[1] = prefetch;
if (get_prefetch)
printf(" setting drive prefetch to %d\n", prefetch);
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(setprefetch) failed");
+ }
}
if (set_xfermode) {
__u8 args[4] = {ATA_OP_SETFEATURES,0,3,0};
@@ -955,8 +995,10 @@
printf(" setting xfermode to %d", xfermode_requested);
interpret_xfermode(xfermode_requested);
}
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(setxfermode) failed");
+ }
}
if (set_lookahead) {
__u8 args[4] = {ATA_OP_SETFEATURES,0,0,0};
@@ -965,8 +1007,10 @@
printf(" setting drive read-lookahead to %d", lookahead);
on_off(lookahead);
}
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(setreadahead) failed");
+ }
}
if (set_powerup_in_standby) {
__u8 args[4] = {ATA_OP_SETFEATURES,0,0,0};
@@ -1004,14 +1048,18 @@
if (get_apmmode)
printf(" 0x%02x (%d)\n",apmmode,apmmode);
}
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD failed");
+ }
}
if (set_cdromspeed) {
if (get_cdromspeed)
printf ("setting cdrom speed to %d\n", cdromspeed);
- if (ioctl (fd, CDROM_SELECT_SPEED, cdromspeed))
+ if (ioctl (fd, CDROM_SELECT_SPEED, cdromspeed)) {
+ err = errno;
perror(" CDROM_SELECT_SPEED failed");
+ }
}
if (set_acoustic) {
__u8 args[4];
@@ -1021,8 +1069,10 @@
args[1] = acoustic;
args[2] = acoustic ? 0x42 : 0xc2;
args[3] = 0;
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD:ACOUSTIC failed");
+ }
}
if (set_wcache) {
if (get_wcache) {
@@ -1030,15 +1080,17 @@
on_off(wcache);
}
if (!wcache)
- flush_wcache(fd, &id);
+ err = flush_wcache(fd, &id);
if (ioctl(fd, HDIO_SET_WCACHE, wcache)) {
__u8 setcache[4] = {ATA_OP_SETFEATURES,0,0,0};
setcache[2] = wcache ? 0x02 : 0x82;
- if (do_drive_cmd(fd, setcache))
+ if (do_drive_cmd(fd, setcache)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(setcache) failed");
+ }
}
if (!wcache)
- flush_wcache(fd, &id);
+ err = flush_wcache(fd, &id);
}
if (set_standbynow) {
__u8 args1[4] = {ATA_OP_STANDBYNOW1,0,0,0};
@@ -1046,8 +1098,10 @@
if (get_standbynow)
printf(" issuing standby command\n");
if (do_drive_cmd(fd, args1)
- && do_drive_cmd(fd, args2))
+ && do_drive_cmd(fd, args2)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(standby) failed");
+ }
}
if (set_sleepnow) {
__u8 args1[4] = {ATA_OP_SLEEPNOW1,0,0,0};
@@ -1055,8 +1109,10 @@
if (get_sleepnow)
printf(" issuing sleep command\n");
if (do_drive_cmd(fd, args1)
- && do_drive_cmd(fd, args2))
+ && do_drive_cmd(fd, args2)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(sleep) failed");
+ }
}
if (set_security) {
do_set_security(fd);
@@ -1064,15 +1120,19 @@
if (set_freeze) {
__u8 args[4] = {ATA_OP_SECURITY_FREEZE_LOCK,0,0,0};
printf(" issuing Security Freeze command\n");
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(freeze) failed");
+ }
}
if (set_seagate) {
__u8 args[4] = {0xfb,0,0,0};
if (get_seagate)
printf(" disabling Seagate auto powersaving mode\n");
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(seagatepwrsave) failed");
+ }
}
if (set_standby) {
__u8 args[4] = {ATA_OP_SETIDLE1,standby,0,0};
@@ -1080,14 +1140,18 @@
printf(" setting standby to %u", standby);
interpret_standby();
}
- if (do_drive_cmd(fd, args))
+ if (do_drive_cmd(fd, args)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(setidle1) failed");
+ }
}
if (set_busstate) {
if (get_busstate)
printf(" setting bus state to %d (%s)\n", busstate, busstate_str(busstate));
- if (ioctl(fd, HDIO_SET_BUSSTATE, busstate))
+ if (ioctl(fd, HDIO_SET_BUSSTATE, busstate)) {
+ err = errno;
perror(" HDIO_SET_BUSSTATE failed");
+ }
}
if (do_drq_hsm_error) {
id = get_identify_data(fd, id);
@@ -1143,12 +1207,18 @@
break;
default:printf("\?\?\?)\n");
}
+ } else {
+ err = errno;
+ perror(" HDIO_GET_32BIT failed");
}
}
if (do_defaults || get_unmask) {
if (0 == ioctl(fd, HDIO_GET_UNMASKINTR, &parm)) {
printf(" unmaskirq = %2ld", parm);
on_off(parm);
+ } else {
+ err = errno;
+ perror(" HDIO_GET_UNMASKINTR failed");
}
}
@@ -1159,6 +1229,9 @@
printf(" (DMA-Assisted-PIO)\n");
else
on_off(parm);
+ } else {
+ err = errno;
+ perror(" HDIO_GET_DMA failed");
}
}
if (get_dma_q) {
@@ -1173,28 +1246,34 @@
if (0 == ioctl(fd, HDIO_GET_KEEPSETTINGS, &parm)) {
printf(" keepsettings = %2ld", parm);
on_off(parm);
+ } else {
+ err = errno;
+ perror(" HDIO_GET_KEEPSETTINGS failed");
}
}
if (get_nowerr) {
- if (ioctl(fd, HDIO_GET_NOWERR, &parm))
+ if (ioctl(fd, HDIO_GET_NOWERR, &parm)) {
+ err = errno;
perror(" HDIO_GET_NOWERR failed");
- else {
+ } else {
printf(" nowerr = %2ld", parm);
on_off(parm);
}
}
if (do_defaults || get_readonly) {
- if (ioctl(fd, BLKROGET, &parm))
+ if (ioctl(fd, BLKROGET, &parm)) {
+ err = errno;
perror(" BLKROGET failed");
- else {
+ } else {
printf(" readonly = %2ld", parm);
on_off(parm);
}
}
if (do_defaults || get_fsreadahead) {
- if (ioctl(fd, BLKRAGET, &parm))
+ if (ioctl(fd, BLKRAGET, &parm)) {
+ err = errno;
perror(" BLKRAGET failed");
- else {
+ } else {
printf(" readahead = %2ld", parm);
on_off(parm);
}
@@ -1209,12 +1288,13 @@
static struct hd_geometry g;
static struct local_hd_big_geometry bg;
- if (0 == do_blkgetsize(fd, &blksize)) {
+ if (0 == (err = do_blkgetsize(fd, &blksize))) {
if (!ioctl(fd, HDIO_GETGEO_BIG, &bg))
printf(msg, bg.cylinders, bg.heads, bg.sectors, blksize, bg.start);
- else if (ioctl(fd, HDIO_GETGEO, &g))
+ else if (ioctl(fd, HDIO_GETGEO, &g)) {
+ err = errno;
perror(" HDIO_GETGEO failed");
- else
+ } else
printf(msg, g.cylinders, g.heads, g.sectors, blksize, g.start);
}
}
@@ -1223,9 +1303,10 @@
const char *state;
if (do_drive_cmd(fd, args)
&& (args[0] = ATA_OP_CHECKPOWERMODE2) /* (single =) try again with 0x98 */
- && do_drive_cmd(fd, args))
+ && do_drive_cmd(fd, args)) {
+ err = errno;
state = "unknown";
- else
+ } else
state = (args[2] == 255) ? "active/idle" : "standby";
printf(" drive state is: %s\n", state);
}
@@ -1240,8 +1321,10 @@
dump_identity(id2);
} else if (errno == -ENOMSG)
printf(" no identification info available\n");
- else
+ else {
+ err = errno;
perror(" HDIO_GET_IDENTITY failed");
+ }
}
if (do_IDentity) {
id = get_identify_data(fd, id);
@@ -1294,41 +1377,48 @@
}
}
if (get_busstate) {
- if (ioctl(fd, HDIO_GET_BUSSTATE, &parm))
+ if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) {
+ err = errno;
perror(" HDIO_GET_BUSSTATE failed");
- else
+ } else
printf(" busstate = %2ld (%s)\n", parm, busstate_str(parm));
}
if (do_ctimings)
time_cache(fd);
if (do_flush_wcache)
- flush_wcache(fd, &id);
+ err = flush_wcache(fd, &id);
if (do_timings)
- time_device(fd);
+ err = time_device(fd);
if (do_flush)
flush_buffer_cache(fd);
if (set_reread_partn) {
if (get_reread_partn)
printf(" re-reading partition table\n");
if (ioctl(fd, BLKRRPART, NULL)) {
+ err = errno;
perror(" BLKRRPART failed");
}
}
if (set_doreset) {
if (get_doreset)
printf(" resetting drive\n");
- if (ioctl(fd, HDIO_DRIVE_RESET, NULL))
+ if (ioctl(fd, HDIO_DRIVE_RESET, NULL)) {
+ err = errno;
perror(" HDIO_DRIVE_RESET failed");
+ }
}
if (set_tristate) {
__u8 args[4] = {0,tristate,0,0};
if (get_tristate)
printf(" setting tri-state to %d\n", tristate);
- if (ioctl(fd, HDIO_TRISTATE_HWIF, &args))
+ if (ioctl(fd, HDIO_TRISTATE_HWIF, &args)) {
+ err = errno;
perror(" HDIO_TRISTATE_HWIF failed");
+ }
}
close (fd);
+ exit (err);
}
static void usage_help (int rc)