SHA256
1
0
forked from pool/hdparm
hdparm/hdparm-6.3-err_return.patch

569 lines
14 KiB
Diff

--- hdparm.c
+++ hdparm.c
@@ -401,18 +401,20 @@
return 0;
}
rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors
- if (rc)
+ if (rc) {
+ rc = errno;
perror(" BLKGETSIZE failed");
+ }
*blksize64 = blksize32;
return rc;
}
-void time_device (int fd)
+int time_device (int fd)
{
char *buf;
double elapsed;
struct itimerval e1, e2;
- int shmid;
+ int shmid, err = 0;
unsigned int max_iterations = 1024, total_MB, iterations;
/*
@@ -421,23 +423,26 @@
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;
}
if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) {
+ err = errno;
perror ("could not allocate sharedmem buf");
- return;
+ return err;
}
if (shmctl(shmid, SHM_LOCK, NULL) == -1) {
+ err = errno;
perror ("could not lock sharedmem buf");
(void) shmctl(shmid, IPC_RMID, NULL);
- return;
+ return err;
}
if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) {
+ err = errno;
perror ("could not attach sharedmem buf");
(void) shmctl(shmid, IPC_RMID, NULL);
- return;
+ return err;
}
if (shmctl(shmid, IPC_RMID, NULL) == -1)
perror ("shmctl(,IPC_RMID,) failed");
@@ -477,6 +482,7 @@
quit:
if (-1 == shmdt(buf))
perror ("could not detach sharedmem buf");
+ return err;
}
static void on_off (unsigned int value)
@@ -784,7 +790,7 @@
void process_dev (char *devname)
{
- int fd;
+ int fd, err = 0;
static long parm, multcount;
__u16 *id = (void *)-1;
@@ -800,14 +806,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];
@@ -815,8 +825,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) {
@@ -829,68 +841,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};
@@ -899,8 +929,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 */
@@ -910,24 +942,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};
@@ -936,8 +974,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};
@@ -946,8 +986,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};
@@ -982,14 +1024,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];
@@ -999,8 +1045,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) {
__u8 flushcache1[4] = {ATA_OP_FLUSHCACHE,0,0,0};
@@ -1013,11 +1061,16 @@
}
if (!wcache && do_drive_cmd(fd, flushcache1))
perror (" HDIO_DRIVE_CMD(flushcache1) failed");
- if (ioctl(fd, HDIO_SET_WCACHE, wcache))
- if (do_drive_cmd(fd, setcache))
+ if (ioctl(fd, HDIO_SET_WCACHE, wcache)) {
+ if (do_drive_cmd(fd, setcache)) {
+ err = errno;
perror(" HDIO_DRIVE_CMD(setcache) failed");
- if (!wcache && do_drive_cmd(fd, flushcache2))
+ }
+ }
+ if (!wcache && do_drive_cmd(fd, flushcache2)) {
+ err = errno;
perror (" HDIO_DRIVE_CMD(flushcache2) failed");
+ }
}
if (set_standbynow) {
__u8 args1[4] = {ATA_OP_STANDBYNOW1,0,0,0};
@@ -1025,8 +1078,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};
@@ -1034,8 +1089,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);
@@ -1043,15 +1100,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};
@@ -1059,14 +1120,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);
@@ -1122,12 +1187,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");
}
}
@@ -1138,6 +1209,9 @@
printf(" (DMA-Assisted-PIO)\n");
else
on_off(parm);
+ } else {
+ err = errno;
+ perror(" HDIO_GET_DMA failed");
}
}
if (get_dma_q) {
@@ -1152,28 +1226,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);
}
@@ -1188,12 +1268,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);
}
}
@@ -1202,9 +1283,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);
}
@@ -1219,8 +1301,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);
@@ -1273,39 +1357,46 @@
}
}
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_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)
--- hdparm.h
+++ hdparm.h
@@ -19,7 +19,7 @@
extern int seek_to_zero (int fd);
extern int read_big_block (int fd, char *buf);
extern void time_cache (int fd);
-extern void time_device (int fd);
+extern int time_device (int fd);
extern void no_scsi (void);
extern void no_xt (void);
extern void process_dev (char *devname);