[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] remove kernel headers from hdparm
From:       Tito <farmatito () tiscali ! it>
Date:       2006-04-29 13:07:01
Message-ID: 200604291507.01830.farmatito () tiscali ! it
[Download RAW message or body]

On Friday 28 April 2006 21:17, Rob Landley wrote:
> On Friday 28 April 2006 8:35 am, Tito wrote:
> > In the meanwhile here is the patch.
> > It contains also a minor fix to the code
> > (for buggy logic)
> > and reduces the size as the elements
> > in linux/hdreg.h are defined only
> > when needed
> >
> >   text    data     bss     dec     hex filename
> >   27422     176     904   28502    6f56 hdparm.o.orig
> >   27294     176     888   28358    6ec6 hdparm.o
> >
> > This is tested and safe.
> 
> Reducing the size is definitely attractive.  Do you know what's responsible 
> for that?
> 
> > Please apply.
> >
> > PS: just take a look at this:
> >
> > #if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
> > # define __USE_XOPEN
> > /* From /linux/byteorder/big_endian.h */
> > #define __le16_to_cpus(x) __swab16s((x))
> > #else
> > /* From /linux/byteorder/little_endian.h */
> > #define __le16_to_cpus(x) do {} while (0)
> > #endif
> >
> > as this is tested only for little endian and maybe
> > should be moved to platform.h?
> 
> That looks outright disgusting.  I note also that it's only used in two 
> places.

I reworked a little this patch to try to be less disgusting  ;-)
I also backported some code cleanups and fixes 
from a devel version of hdparm that its author sent me. 
The no_scsi() and no_xt() functions were removed so size now is:

  26320     176     880   27376    6af0 miscutils/hdparm.o

Please apply.

Ciao,
Tito
> Wasn't there a proposal recently for something like TO_BIG_ENDIAN(value), 
> FROM_BIG_ENDIAN(value), TO_LITTLE_ENDIAN(value), and 
> FROM_LITTLE_ENDIAN(value)?
> 
> I'd like to disguise this in platform.h, yes.  But I'd also like to try to 
> find a more generic solution to whatever problem it's trying to solve.
> 
> Rob

["hdparm_05.patch" (text/x-diff)]

--- miscutils/hdparm_original.c	2006-04-28 13:39:01.000000000 +0200
+++ miscutils/hdparm.c	2006-04-29 15:04:32.000000000 +0200
@@ -26,15 +26,335 @@
 #include <sys/times.h>
 #include <sys/mount.h>
 #include "busybox.h"
-#include <linux/types.h>
-#include <linux/hdreg.h>
-#include <linux/major.h>
-#include <asm/byteorder.h>
-
 
 #if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
 # define __USE_XOPEN
 #endif
+#if BB_BIG_ENDIAN
+#include <asm/byteorder.h>
+#endif
+
+/* From <linux/hdreg.h> */
+#define WIN_DOORLOCK			0xDE /* lock door on removable drives */
+#define WIN_DOORUNLOCK			0xDF /* unlock door on removable drives */
+#define WIN_SETFEATURES			0xEF /* set special drive features */
+#define WIN_SETIDLE1			0xE3
+#define WIN_PIDENTIFY			0xA1 /* identify ATAPI device	*/
+#define WIN_IDENTIFY			0xEC /* ask drive to identify itself	*/
+
+/* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x030n/0x031n */
+#define HDIO_GETGEO		0x0301	/* get device geometry */
+#define HDIO_GET_UNMASKINTR	0x0302	/* get current unmask setting */
+#define HDIO_GET_MULTCOUNT	0x0304	/* get current IDE blockmode setting */
+#define HDIO_GET_QDMA		0x0305	/* get use-qdma flag */
+
+#define HDIO_SET_XFER		0x0306  /* set transfer rate via proc */
+
+#define HDIO_OBSOLETE_IDENTITY	0x0307	/* OBSOLETE, DO NOT USE: returns 142 bytes */
+#define HDIO_GET_KEEPSETTINGS	0x0308	/* get keep-settings-on-reset flag */
+#define HDIO_GET_32BIT		0x0309	/* get current io_32bit setting */
+#define HDIO_GET_NOWERR		0x030a	/* get ignore-write-error flag */
+#define HDIO_GET_DMA		0x030b	/* get use-dma flag */
+#define HDIO_GET_NICE		0x030c	/* get nice flags */
+#define HDIO_GET_IDENTITY	0x030d	/* get IDE identification info */
+#define HDIO_GET_WCACHE		0x030e	/* get write cache mode on|off */
+#define HDIO_GET_ACOUSTIC	0x030f	/* get acoustic value */
+#define	HDIO_GET_ADDRESS	0x0310	/* */
+
+#define HDIO_GET_BUSSTATE	0x031a	/* get the bus state of the hwif */
+#define HDIO_TRISTATE_HWIF	0x031b	/* execute a channel tristate */
+#define HDIO_DRIVE_RESET	0x031c	/* execute a device reset */
+#define HDIO_DRIVE_TASKFILE	0x031d	/* execute raw taskfile */
+#define HDIO_DRIVE_TASK		0x031e	/* execute task and special drive command */
+#define HDIO_DRIVE_CMD		0x031f	/* execute a special drive command */
+#define HDIO_DRIVE_CMD_AEB	HDIO_DRIVE_TASK
+
+/* hd/ide ctl's that pass (arg) non-ptr values are numbered 0x032n/0x033n */
+#define HDIO_SET_MULTCOUNT	0x0321	/* change IDE blockmode */
+#define HDIO_SET_UNMASKINTR	0x0322	/* permit other irqs during I/O */
+#define HDIO_SET_KEEPSETTINGS	0x0323	/* keep ioctl settings on reset */
+#define HDIO_SET_32BIT		0x0324	/* change io_32bit flags */
+#define HDIO_SET_NOWERR		0x0325	/* change ignore-write-error flag */
+#define HDIO_SET_DMA		0x0326	/* change use-dma flag */
+#define HDIO_SET_PIO_MODE	0x0327	/* reconfig interface to new speed */
+#define HDIO_SCAN_HWIF		0x0328	/* register and (re)scan interface */
+#define HDIO_SET_NICE		0x0329	/* set nice flags */
+#define HDIO_UNREGISTER_HWIF	0x032a  /* unregister interface */
+#define HDIO_SET_WCACHE		0x032b	/* change write cache enable-disable */
+#define HDIO_SET_ACOUSTIC	0x032c	/* change acoustic behavior */
+#define HDIO_SET_BUSSTATE	0x032d	/* set the bus state of the hwif */
+#define HDIO_SET_QDMA		0x032e	/* change use-qdma flag */
+#define HDIO_SET_ADDRESS	0x032f	/* change lba addressing modes */
+
+struct hd_geometry {
+      unsigned char heads;
+      unsigned char sectors;
+      unsigned short cylinders;
+      unsigned long start;
+};
+
+#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
+/* bus states */
+enum {
+	BUSSTATE_OFF = 0,
+	BUSSTATE_ON,
+	BUSSTATE_TRISTATE
+};
+#endif
+/*
+ * Structure returned by HDIO_GET_IDENTITY, as per ANSI NCITS ATA6 rev.1b spec.
+ *
+ */
+
+#define __NEW_HD_DRIVE_ID
+#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
+struct hd_driveid {
+	unsigned short	config;		/* lots of obsolete bit flags */
+	unsigned short	cyls;		/* Obsolete, "physical" cyls */
+	unsigned short	reserved2;	/* reserved (word 2) */
+	unsigned short	heads;		/* Obsolete, "physical" heads */
+	unsigned short	track_bytes;	/* unformatted bytes per track */
+	unsigned short	sector_bytes;	/* unformatted bytes per sector */
+	unsigned short	sectors;	/* Obsolete, "physical" sectors per track */
+	unsigned short	vendor0;	/* vendor unique */
+	unsigned short	vendor1;	/* vendor unique */
+	unsigned short	vendor2;	/* Retired vendor unique */
+	unsigned char	serial_no[20];	/* 0 = not_specified */
+	unsigned short	buf_type;	/* Retired */
+	unsigned short	buf_size;	/* Retired, 512 byte increments
+					 * 0 = not_specified
+					 */
+	unsigned short	ecc_bytes;	/* for r/w long cmds; 0 = not_specified */
+	unsigned char	fw_rev[8];	/* 0 = not_specified */
+	unsigned char	model[40];	/* 0 = not_specified */
+	unsigned char	max_multsect;	/* 0=not_implemented */
+	unsigned char	vendor3;	/* vendor unique */
+	unsigned short	dword_io;	/* 0=not_implemented; 1=implemented */
+	unsigned char	vendor4;	/* vendor unique */
+	unsigned char	capability;	/* (upper byte of word 49)
+					 *  3:	IORDYsup
+					 *  2:	IORDYsw
+					 *  1:	LBA
+					 *  0:	DMA
+					 */
+	unsigned short	reserved50;	/* reserved (word 50) */
+	unsigned char	vendor5;	/* Obsolete, vendor unique */
+	unsigned char	tPIO;		/* Obsolete, 0=slow, 1=medium, 2=fast */
+	unsigned char	vendor6;	/* Obsolete, vendor unique */
+	unsigned char	tDMA;		/* Obsolete, 0=slow, 1=medium, 2=fast */
+	unsigned short	field_valid;	/* (word 53)
+					 *  2:	ultra_ok	word  88
+					 *  1:	eide_ok		words 64-70
+					 *  0:	cur_ok		words 54-58
+					 */
+	unsigned short	cur_cyls;	/* Obsolete, logical cylinders */
+	unsigned short	cur_heads;	/* Obsolete, l heads */
+	unsigned short	cur_sectors;	/* Obsolete, l sectors per track */
+	unsigned short	cur_capacity0;	/* Obsolete, l total sectors on drive */
+	unsigned short	cur_capacity1;	/* Obsolete, (2 words, misaligned int)     */
+	unsigned char	multsect;	/* current multiple sector count */
+	unsigned char	multsect_valid;	/* when (bit0==1) multsect is ok */
+	unsigned int	lba_capacity;	/* Obsolete, total number of sectors */
+	unsigned short	dma_1word;	/* Obsolete, single-word dma info */
+	unsigned short	dma_mword;	/* multiple-word dma info */
+	unsigned short  eide_pio_modes; /* bits 0:mode3 1:mode4 */
+	unsigned short  eide_dma_min;	/* min mword dma cycle time (ns) */
+	unsigned short  eide_dma_time;	/* recommended mword dma cycle time (ns) */
+	unsigned short  eide_pio;       /* min cycle time (ns), no IORDY  */
+	unsigned short  eide_pio_iordy; /* min cycle time (ns), with IORDY */
+	unsigned short	words69_70[2];	/* reserved words 69-70
+					 * future command overlap and queuing
+					 */
+	/* HDIO_GET_IDENTITY currently returns only words 0 through 70 */
+	unsigned short	words71_74[4];	/* reserved words 71-74
+					 * for IDENTIFY PACKET DEVICE command
+					 */
+	unsigned short  queue_depth;	/* (word 75)
+					 * 15:5	reserved
+					 *  4:0	Maximum queue depth -1
+					 */
+	unsigned short  words76_79[4];	/* reserved words 76-79 */
+	unsigned short  major_rev_num;	/* (word 80) */
+	unsigned short  minor_rev_num;	/* (word 81) */
+	unsigned short  command_set_1;	/* (word 82) supported
+					 * 15:	Obsolete
+					 * 14:	NOP command
+					 * 13:	READ_BUFFER
+					 * 12:	WRITE_BUFFER
+					 * 11:	Obsolete
+					 * 10:	Host Protected Area
+					 *  9:	DEVICE Reset
+					 *  8:	SERVICE Interrupt
+					 *  7:	Release Interrupt
+					 *  6:	look-ahead
+					 *  5:	write cache
+					 *  4:	PACKET Command
+					 *  3:	Power Management Feature Set
+					 *  2:	Removable Feature Set
+					 *  1:	Security Feature Set
+					 *  0:	SMART Feature Set
+					 */
+	unsigned short  command_set_2;	/* (word 83)
+					 * 15:	Shall be ZERO
+					 * 14:	Shall be ONE
+					 * 13:	FLUSH CACHE EXT
+					 * 12:	FLUSH CACHE
+					 * 11:	Device Configuration Overlay
+					 * 10:	48-bit Address Feature Set
+					 *  9:	Automatic Acoustic Management
+					 *  8:	SET MAX security
+					 *  7:	reserved 1407DT PARTIES
+					 *  6:	SetF sub-command Power-Up
+					 *  5:	Power-Up in Standby Feature Set
+					 *  4:	Removable Media Notification
+					 *  3:	APM Feature Set
+					 *  2:	CFA Feature Set
+					 *  1:	READ/WRITE DMA QUEUED
+					 *  0:	Download MicroCode
+					 */
+	unsigned short  cfsse;		/* (word 84)
+					 * cmd set-feature supported extensions
+					 * 15:	Shall be ZERO
+					 * 14:	Shall be ONE
+					 * 13:6	reserved
+					 *  5:	General Purpose Logging
+					 *  4:	Streaming Feature Set
+					 *  3:	Media Card Pass Through
+					 *  2:	Media Serial Number Valid
+					 *  1:	SMART selt-test supported
+					 *  0:	SMART error logging
+					 */
+	unsigned short  cfs_enable_1;	/* (word 85)
+					 * command set-feature enabled
+					 * 15:	Obsolete
+					 * 14:	NOP command
+					 * 13:	READ_BUFFER
+					 * 12:	WRITE_BUFFER
+					 * 11:	Obsolete
+					 * 10:	Host Protected Area
+					 *  9:	DEVICE Reset
+					 *  8:	SERVICE Interrupt
+					 *  7:	Release Interrupt
+					 *  6:	look-ahead
+					 *  5:	write cache
+					 *  4:	PACKET Command
+					 *  3:	Power Management Feature Set
+					 *  2:	Removable Feature Set
+					 *  1:	Security Feature Set
+					 *  0:	SMART Feature Set
+					 */
+	unsigned short  cfs_enable_2;	/* (word 86)
+					 * command set-feature enabled
+					 * 15:	Shall be ZERO
+					 * 14:	Shall be ONE
+					 * 13:	FLUSH CACHE EXT
+					 * 12:	FLUSH CACHE
+					 * 11:	Device Configuration Overlay
+					 * 10:	48-bit Address Feature Set
+					 *  9:	Automatic Acoustic Management
+					 *  8:	SET MAX security
+					 *  7:	reserved 1407DT PARTIES
+					 *  6:	SetF sub-command Power-Up
+					 *  5:	Power-Up in Standby Feature Set
+					 *  4:	Removable Media Notification
+					 *  3:	APM Feature Set
+					 *  2:	CFA Feature Set
+					 *  1:	READ/WRITE DMA QUEUED
+					 *  0:	Download MicroCode
+					 */
+	unsigned short  csf_default;	/* (word 87)
+					 * command set-feature default
+					 * 15:	Shall be ZERO
+					 * 14:	Shall be ONE
+					 * 13:6	reserved
+					 *  5:	General Purpose Logging enabled
+					 *  4:	Valid CONFIGURE STREAM executed
+					 *  3:	Media Card Pass Through enabled
+					 *  2:	Media Serial Number Valid
+					 *  1:	SMART selt-test supported
+					 *  0:	SMART error logging
+					 */
+	unsigned short  dma_ultra;	/* (word 88) */
+	unsigned short	trseuc;		/* time required for security erase */
+	unsigned short	trsEuc;		/* time required for enhanced erase */
+	unsigned short	CurAPMvalues;	/* current APM values */
+	unsigned short	mprc;		/* master password revision code */
+	unsigned short	hw_config;	/* hardware config (word 93)
+					 * 15:	Shall be ZERO
+					 * 14:	Shall be ONE
+					 * 13:
+					 * 12:
+					 * 11:
+					 * 10:
+					 *  9:
+					 *  8:
+					 *  7:
+					 *  6:
+					 *  5:
+					 *  4:
+					 *  3:
+					 *  2:
+					 *  1:
+					 *  0:	Shall be ONE
+					 */
+	unsigned short	acoustic;	/* (word 94)
+					 * 15:8	Vendor's recommended value
+					 *  7:0	current value
+					 */
+	unsigned short	msrqs;		/* min stream request size */
+	unsigned short	sxfert;		/* stream transfer time */
+	unsigned short	sal;		/* stream access latency */
+	unsigned int	spg;		/* stream performance granularity */
+	unsigned long long lba_capacity_2;/* 48-bit total number of sectors */
+	unsigned short	words104_125[22];/* reserved words 104-125 */
+	unsigned short	last_lun;	/* (word 126) */
+	unsigned short	word127;	/* (word 127) Feature Set
+					 * Removable Media Notification
+					 * 15:2	reserved
+					 *  1:0	00 = not supported
+					 *	01 = supported
+					 *	10 = reserved
+					 *	11 = reserved
+					 */
+	unsigned short	dlf;		/* (word 128)
+					 * device lock function
+					 * 15:9	reserved
+					 *  8	security level 1:max 0:high
+					 *  7:6	reserved
+					 *  5	enhanced erase
+					 *  4	expire
+					 *  3	frozen
+					 *  2	locked
+					 *  1	en/disabled
+					 *  0	capability
+					 */
+	unsigned short  csfo;		/*  (word 129)
+					 * current set features options
+					 * 15:4	reserved
+					 *  3:	auto reassign
+					 *  2:	reverting
+					 *  1:	read-look-ahead
+					 *  0:	write cache
+					 */
+	unsigned short	words130_155[26];/* reserved vendor words 130-155 */
+	unsigned short	word156;	/* reserved vendor word 156 */
+	unsigned short	words157_159[3];/* reserved vendor words 157-159 */
+	unsigned short	cfa_power;	/* (word 160) CFA Power Mode
+					 * 15 word 160 supported
+					 * 14 reserved
+					 * 13
+					 * 12
+					 * 11:0
+					 */
+	unsigned short	words161_175[15];/* Reserved for CFA */
+	unsigned short	words176_205[30];/* Current Media Serial Number */
+	unsigned short	words206_254[49];/* reserved words 206-254 */
+	unsigned short	integrity_word;	/* (word 255)
+					 * 15:8 Checksum
+					 *  7:0 Signature
+					 */
+};
+#endif /* ENABLE_FEATURE_HDPARM_GET_IDENTITY */
 
 /* device types */
 /* ------------ */
@@ -619,52 +939,23 @@
    others, though, were declared in hdparm.c with global scope; since other
    functions in that file have static (file) scope, I assume the difference is
    intentional. */
-static void identify (uint16_t *id_supplied, const char *devname)
+static void identify (uint16_t *id_supplied)
 {
 
-	char *id_file = NULL;
-	FILE *fl;
 	uint16_t val[256], ii, jj, kk;
 	uint16_t like_std = 1, std = 0, min_std = 0xffff;
 	uint16_t dev = NO_DEV, eqpt = NO_DEV;
 	uint8_t  have_mode = 0, err_dma = 0;
 	uint8_t  chksum = 0;
 	uint32_t ll, mm, nn, oo;
-	__u64 bbbig; /* (:) */
+	uint64_t bbbig; /* (:) */
 
-	if (id_supplied)
-	{
-#if __BYTE_ORDER == __BIG_ENDIAN
-		swab(id_supplied, val, sizeof(val));
-#else
-		memcpy(val, id_supplied, sizeof(val));
-#endif
-	}
-	else
-	{
-		id_file = xcalloc(1, strlen(devname)+22);
-		sprintf(id_file, "/proc/ide/%s/identify", devname);
-		/* open the file, read in all the info and close it */
-		if (id_file == NULL)
-			fl = stdin;
-		else
-			fl = bb_xfopen(id_file, "r");
+	memcpy(val, id_supplied, sizeof(val));
 
-		/* calculate checksum over all bytes */
-		for(ii = GEN_CONFIG; ii<=INTEGRITY; ii++)
-		{
-			unsigned int scratch;
-			if(1 != fscanf(fl,"%04x",&scratch))
-				break;
-			val[ii] = (uint16_t)scratch;
-			chksum += val[ii] + (val[ii] >> 8);
-		}
-		fclose(fl);
-		/*bb_fclose_nonstdin(fl);*/
-		if(ii < (INTEGRITY+1))
-			bb_error_msg_and_die("Input file wrong format or length");
+	/* calculate checksum over all bytes */
+	for(ii = GEN_CONFIG; ii<=INTEGRITY; ii++) {
+		chksum += val[ii] + (val[ii] >> 8);
 	}
-	chksum &= 0xff;
 
 	/* check if we recognise the device type */
 	printf("\n");
@@ -909,15 +1200,15 @@
 		if( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
 		     (val[CMDS_SUPP_1] & SUPPORT_48_BIT) )
 		{
-			bbbig = (__u64)val[LBA_64_MSB]	<< 48 |
-			        (__u64)val[LBA_48_MSB]	<< 32 |
-			        (__u64)val[LBA_MID]	<< 16 |
+			bbbig = (uint64_t)val[LBA_64_MSB]	<< 48 |
+			        (uint64_t)val[LBA_48_MSB]	<< 32 |
+			        (uint64_t)val[LBA_MID]	<< 16 |
 					val[LBA_LSB] ;
 			printf("\tLBA48  user addressable sectors:%11llu\n",bbbig);
 		}
 
 		if (!bbbig)
-			bbbig = (__u64)(ll>mm ? ll : mm); /* # 512 byte blocks */
+			bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */
 		printf("\tdevice size with M = 1024*1024: %11llu MBytes\n",bbbig>>11);
 		bbbig = (bbbig<<9)/1000000;
 		printf("\tdevice size with M = 1000*1000: %11llu MBytes ",bbbig);
@@ -1218,7 +1509,7 @@
 #endif
 
 static int verbose, get_identity, get_geom, noisy = 1, quiet;
-static int flagcount, do_flush, is_scsi_hd, is_xt_hd;
+static int flagcount, do_flush;
 static int do_ctimings, do_timings;
 
 static unsigned long set_readahead, get_readahead, Xreadahead;
@@ -1339,11 +1630,7 @@
 
 	}
 	if_printf((!(id->field_valid&1))," (maybe):");
-#if __BYTE_ORDER == __BIG_ENDIAN
-	capacity = (id->cur_capacity0 << 16) | id->cur_capacity1;
-#else
 	capacity = (id->cur_capacity1 << 16) | id->cur_capacity0;
-#endif
 	printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
 													id->cur_sectors, capacity ,
 											((id->capability&2)==0)?"no":"yes");
@@ -1461,8 +1748,10 @@
 
 static int seek_to_zero (int fd)
 {
-	if (lseek(fd, (off_t) 0, SEEK_SET))
+	if (lseek(fd, (off_t) 0, SEEK_SET)) {
+		bb_perror_msg("lseek");
 		return 1;
+	}
 	return 0;
 }
 
@@ -1639,20 +1928,6 @@
 		bb_error_msg (bb_msg_shared_mem,"detach"); /*"could not detach sharedmem buf"*/
 }
 
-
-static void no_scsi (void)
-{
-	/*" operation not supported on SCSI disks"*/
-	if (is_scsi_hd)
-		bb_error_msg_and_die(bb_msg_op_not_supp,"SCSI");
-}
-
-static void no_xt (void)
-{
-	if (is_xt_hd)
-		bb_error_msg_and_die(bb_msg_op_not_supp,"XT");
-}
-
 static void on_off (unsigned int value)
 {
 	printf(value ? " (on)\n" : " (off)\n");
@@ -1849,83 +2124,13 @@
 }
 #endif /* HDIO_DRIVE_CMD */
 
-#ifndef VXVM_MAJOR
-#define VXVM_MAJOR 199
-#endif
-
-#ifndef CCISS_MAJOR
-#define CCISS_MAJOR 104
-#endif
-
 static void process_dev (char *devname)
 {
 	int fd;
 	static long parm, multcount;
-	struct stat stat_buf;
 #ifndef HDIO_DRIVE_CMD
 	int force_operation = 0;
 #endif
-	xstat(devname,&stat_buf);
-
-	switch(major(stat_buf.st_rdev))
-	{
-#ifdef SCSI_DISK0_MAJOR
-		case (SCSI_DISK0_MAJOR):
-		case (SCSI_DISK1_MAJOR):
-		case (SCSI_DISK2_MAJOR):
-		case (SCSI_DISK3_MAJOR):
-		case (SCSI_DISK4_MAJOR):
-		case (SCSI_DISK5_MAJOR):
-		case (SCSI_DISK6_MAJOR):
-		case (SCSI_DISK7_MAJOR):
-#else
-		case (SCSI_DISK_MAJOR):
-#endif
-#ifdef MD_MAJOR
-		case (MD_MAJOR):
-#endif
-		case (VXVM_MAJOR):
-#ifdef LVM_BLK_MAJOR
-		case (LVM_BLK_MAJOR):
-#endif
-		case (CCISS_MAJOR):
-			is_scsi_hd = 1;
-			break;
-#ifdef XT_DISK_MAJOR
-		case (XT_DISK_MAJOR):
-			is_xt_hd = 1;
-			break;
-#endif
-		case IDE0_MAJOR:
-		case IDE1_MAJOR:
-#ifdef IDE2_MAJOR
-		case IDE2_MAJOR:
-#endif
-#ifdef IDE3_MAJOR
-		case IDE3_MAJOR:
-#endif
-#ifdef IDE4_MAJOR
-		case IDE4_MAJOR:
-#endif
-#ifdef IDE5_MAJOR
-		case IDE5_MAJOR:
-#endif
-#ifdef IDE6_MAJOR
-		case IDE6_MAJOR:
-#endif
-#ifdef IDE7_MAJOR
-		case IDE7_MAJOR:
-#endif
-#ifdef IDE8_MAJOR
-		case IDE8_MAJOR:
-#endif
-#ifdef IDE9_MAJOR
-		case IDE9_MAJOR:
-#endif
-			break;	/* do nothing */
-		default:
-			bb_error_msg_and_die("%s not supported",devname);
-	}
 
 	fd = bb_xopen (devname, O_RDONLY|O_NONBLOCK);
 	if_printf( (!quiet),"\n%s:\n", devname);
@@ -1938,7 +2143,6 @@
 #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
 	if (unregister_hwif)
 	{
-		no_scsi();
 		printf(" attempting to unregister hwif#%u\n", hwif);
 		bb_ioctl(fd, HDIO_UNREGISTER_HWIF,(int *)(unsigned long)hwif,"HDIO_UNREGISTER_HWIF");
 	}
@@ -1947,7 +2151,7 @@
 	if (scan_hwif)
 	{
 		int	args[3];
-		no_scsi();
+
 		printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq);
 		args[0] = hwif_data;
 		args[1] = hwif_ctrl;
@@ -1957,9 +2161,6 @@
 #endif
 	if (set_piomode)
 	{
-		no_scsi();
-		no_xt();
-
 		if (noisy_piomode)
 		{
 			printf(" attempting to ");
@@ -1976,15 +2177,11 @@
 	}
 	if (set_io32bit)
 	{
-		no_scsi();
-		no_xt();
 		if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit);
 		bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
 	}
 	if (set_mult)
 	{
-		no_scsi();
-		no_xt();
 		if_printf(get_mult, " setting multcount to %ld\n", mult);
 		if(ioctl(fd, HDIO_SET_MULTCOUNT, mult))
 			bb_perror_msg("HDIO_SET_MULTCOUNT");
@@ -2000,36 +2197,28 @@
 	}
 	if (set_unmask)
 	{
-		no_scsi();
-		no_xt();
 		if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask);
 		bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
 	}
 #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
 	if (set_dma)
 	{
-		no_scsi();
 		if_printf_on_off(get_dma," setting using_dma to %ld", dma);
 		bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA");
 	}
 #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
 	if (set_dma_q)
 	{
-		no_scsi();
 		if_printf_on_off(get_dma_q," setting DMA queue_depth to %ld", dma_q);
 		bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA");
 	}
 	if (set_nowerr)
 	{
-		no_scsi();
-		no_xt();
 		if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr);
 		bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
 	}
 	if (set_keep)
 	{
-		no_scsi();
-		no_xt();
 		if_printf_on_off(get_keep," setting keep_settings to %ld", keep);
 		bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
 	}
@@ -2037,8 +2226,6 @@
 	if (set_doorlock)
 	{
 		unsigned char args[4] = {0,0,0,0};
-		no_scsi();
-		no_xt();
 
 		args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
 		if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock);
@@ -2048,8 +2235,6 @@
 	{
 		/* lock/unlock the drive's "feature" settings */
 		unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
-		no_scsi();
-		no_xt();
 
 		if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep);
 		args[2] = dkeep ? 0x66 : 0xcc;
@@ -2058,7 +2243,7 @@
 	if (set_defects)
 	{
 		unsigned char args[4] = {WIN_SETFEATURES,0,0x04,0};
-		no_scsi();
+
 		args[2] = defects ? 0x04 : 0x84;
 		if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects);
 		bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)");
@@ -2066,8 +2251,6 @@
 	if (set_prefetch)
 	{
 		unsigned char args[4] = {WIN_SETFEATURES,0,0xab,0};
-		no_scsi();
-		no_xt();
 
 		args[1] = prefetch;
 		if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch);
@@ -2076,8 +2259,6 @@
 	if (set_xfermode)
 	{
 		unsigned char args[4] = {WIN_SETFEATURES,0,3,0};
-		no_scsi();
-		no_xt();
 
 		args[1] = xfermode_requested;
 		if (get_xfermode)
@@ -2090,8 +2271,6 @@
 	if (set_lookahead)
 	{
 		unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
-		no_scsi();
-		no_xt();
 
 		args[2] = lookahead ? 0xaa : 0x55;
 		if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead);
@@ -2100,7 +2279,7 @@
 	if (set_apmmode)
 	{
 		unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
-		no_scsi();
+
 		apmmode=check_if_min_and_set_val(apmmode,1);
 		apmmode=check_if_maj_and_set_val(apmmode,255);
 		if_printf(get_apmmode," setting APM level to");
@@ -2128,8 +2307,7 @@
 		unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
 #endif /* DO_FLUSHCACHE */
 		unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
-		no_scsi();
-		no_xt();
+
 		args[2] = wcache ? 0x02 : 0x82;
 		if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache);
 #ifdef DO_FLUSHCACHE
@@ -2152,7 +2330,7 @@
 #endif
 		unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0};
 		unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0};
-		no_scsi();
+
 		if_printf(get_standbynow," issuing standby command\n");
 		if (ioctl(fd, HDIO_DRIVE_CMD, &args1)
 		 && ioctl(fd, HDIO_DRIVE_CMD, &args2))
@@ -2168,7 +2346,7 @@
 #endif
 		unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0};
 		unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0};
-		no_scsi();
+
 		if_printf(get_sleepnow," issuing sleep command\n");
 		if (ioctl(fd, HDIO_DRIVE_CMD, &args1)
 		 && ioctl(fd, HDIO_DRIVE_CMD, &args2))
@@ -2177,16 +2355,14 @@
 	if (set_seagate)
 	{
 		unsigned char args[4] = {0xfb,0,0,0};
-		no_scsi();
-		no_xt();
+
 		if_printf(get_seagate," disabling Seagate auto powersaving mode\n");
 		bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
 	}
 	if (set_standby)
 	{
 		unsigned char args[4] = {WIN_SETIDLE1,standby_requested,0,0};
-		no_scsi();
-		no_xt();
+
 		if (get_standby)
 		{
 			printf(" setting standby to %lu", standby_requested);
@@ -2207,13 +2383,13 @@
 	if (!flagcount)
 		verbose = 1;
 
-	if ((verbose && !is_scsi_hd && !is_xt_hd) || get_mult || get_identity)
+	if (verbose || get_mult || get_identity)
 	{
-		no_scsi();
+
 		multcount = -1;
 		if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount))
 		{
-			if ((verbose && !is_xt_hd) || get_mult)
+			if (get_mult)
 				bb_perror_msg("HDIO_GET_MULTCOUNT");
 		}
 		else if (verbose | get_mult)
@@ -2222,10 +2398,8 @@
 			on_off(multcount);
 		}
 	}
-	if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit)
+	if (verbose || get_io32bit)
 	{
-		no_scsi();
-		no_xt();
 		if(ioctl(fd, HDIO_GET_32BIT, &parm))
 			bb_perror_msg("HDIO_GET_32BIT");
 		else
@@ -2253,18 +2427,15 @@
 			}
 		}
 	}
-	if ((verbose && !is_scsi_hd && !is_xt_hd) || get_unmask)
+	if (verbose || get_unmask)
 	{
-		no_scsi();
-		no_xt();
 		bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
 						"HDIO_GET_UNMASKINTR"," unmaskirq    = %2ld");
 	}
 
 
 #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
-	if ((verbose && !is_scsi_hd) || get_dma) {
-		no_scsi();
+	if (verbose || get_dma) {
 		if(ioctl(fd, HDIO_GET_DMA, &parm))
 			bb_perror_msg("HDIO_GET_DMA");
 		else
@@ -2279,22 +2450,17 @@
 #endif
 	if (get_dma_q)
 	{
-		no_scsi();
 		bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm,
 						  "HDIO_GET_QDMA"," queue_depth  = %2ld");
 	}
-	if ((verbose && !is_scsi_hd && !is_xt_hd) || get_keep)
+	if (verbose || get_keep)
 	{
-		no_scsi();
-		no_xt();
 		bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
 							"HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld");
 	}
 
 	if (get_nowerr)
 	{
-		no_scsi();
-		no_xt();
 		bb_ioctl_on_off  (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
 							" HDIO_GET_NOWERR"," nowerr       = %2ld");
 	}
@@ -2303,7 +2469,7 @@
 		bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm,
 						  " BLKROGET"," readonly     = %2ld");
 	}
-	if ((verbose && !is_scsi_hd) || get_readahead)
+	if (verbose || get_readahead)
 	{
 		bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm,
 							" BLKRAGET"," readahead    = %2ld");
@@ -2338,7 +2504,7 @@
 #endif
 		unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0};
 		const char *state;
-		no_scsi();
+
 		if (ioctl(fd, HDIO_DRIVE_CMD, &args)
 			 && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
 			&& ioctl(fd, HDIO_DRIVE_CMD, &args))
@@ -2357,8 +2523,6 @@
 #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
 	if (perform_reset)
 	{
-		no_scsi();
-		no_xt();
 		bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
 	}
 #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
@@ -2366,8 +2530,7 @@
 	if (perform_tristate)
 	{
 		unsigned char args[4] = {0,tristate,0,0};
-		no_scsi();
-		no_xt();
+
 		bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
 	}
 #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
@@ -2376,9 +2539,6 @@
 	{
 		static struct hd_driveid id;
 
-		no_scsi();
-		no_xt();
-
 		if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
 		{
 			if (multcount != -1)
@@ -2401,9 +2561,6 @@
 		unsigned char args[4+512] = {WIN_IDENTIFY,0,0,1,};
 		unsigned i;
 
-		no_scsi();
-		no_xt();
-
 		if (ioctl(fd, HDIO_DRIVE_CMD, &args))
 		{
 			args[0] = WIN_PIDENTIFY;
@@ -2414,9 +2571,12 @@
 			}
 		}
 		for(i=0; i<(sizeof args)/2; i+=2)
+#if BB_BIG_ENDIAN
 		    __le16_to_cpus((uint16_t *)(&args[i]));
-
-		identify((void *)&args[4], NULL);
+#else
+			/* VOID */;
+#endif
+		identify((void *)&args[4]);
 identify_abort:
 	/* VOID */;
 	}
@@ -2424,7 +2584,6 @@
 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
 	if (set_busstate)
 	{
-		no_scsi();
 		if (get_busstate)
 		{
 			printf(" setting bus state to %d", busstate);
@@ -2436,7 +2595,6 @@
 #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
 	if (get_busstate)
 	{
-		no_scsi();
 		if (ioctl(fd, HDIO_GET_BUSSTATE, &parm))
 			bb_perror_msg("HDIO_GET_BUSSTATE");
 		else
@@ -2509,11 +2667,13 @@
 	for (i = 0; count >= 4; ++i)
 	{
 		sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]);
+#if BB_BIG_ENDIAN
 		__le16_to_cpus((uint16_t *)(&sbuf[i]));
+#endif
 		b += 5;
 		count -= 5;
 	}
-	identify(sbuf, NULL);
+	identify(sbuf);
 	return 0;
 }
 #endif


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic