mi/util.c
// list the installed devices.  This function is useful
// to find out the channel,device settings to use for
// all the other commands
list the installed devices.  This function is useful
to find out the channel,device settings to use for
all the other commands
list the installed devices . This function is useful to find out the channel device settings to use for all the other commands
void ata_listdevices( struct ATA *ata )
{
	uint32_t numchannels = 20;
	uint32_t numdevs;
	uint32_t i;
	ata_getmaxchan( ata, &numchannels );
	numdevs = numchannels*2;
	uint32_t identbuf_size = ( sizeof(struct ata_ident) * numdevs );
	char * identbuf = (char *) malloc(identbuf_size);
	if(identbuf == 0) { 
		fprintf(stderr, "malloc failed, aborting.\n");
		exit(EXIT_FAILURE);
	}
	memset(identbuf, 0, identbuf_size);
	for(i = 0; i < numchannels; i++) {
		ata_ident( ata, i, 0, (struct ata_ident*) (identbuf+(sizeof(struct ata_ident)*(2*i))) );
		ata_ident( ata, i, 1, (struct ata_ident*) (identbuf+((sizeof(struct ata_ident)*(2*i))+sizeof(struct ata_ident) )));
	}
	for(i = 0; i < numdevs; i++) {
		struct ata_ident *ident = (struct ata_ident*) (identbuf+(sizeof(struct ata_ident)*i));
		char model[41];
		memset(model, 0, 41);
		strncpy(model, (void*) ident->model, 40);
		if(ident->config != 0) {
			printf("Channel %d, Device %d\n", (i/2), (i%2 == 0)? 0 : 1);
			printf("\tModel: %s\n", model);
			printf("\n");
		}
	}
	free(identbuf);
}
void ata_listdevices ( struct ATA * ata ) { uint32_t numchannels = 20 ; uint32_t numdevs ; uint32_t i ; ata_getmaxchan ( ata , & numchannels ) ; numdevs = numchannels * 2 ; uint32_t identbuf_size = ( sizeof ( struct ata_ident ) * numdevs ) ; char * identbuf = ( char * ) malloc ( identbuf_size ) ; if ( identbuf == 0 ) { fprintf ( stderr , " \n " ) ; exit ( EXIT_FAILURE ) ; } memset ( identbuf , 0 , identbuf_size ) ; for ( i = 0 ; i < numchannels ; i ++ ) { ata_ident ( ata , i , 0 , ( struct ata_ident * ) ( identbuf + ( sizeof ( struct ata_ident ) * ( 2 * i ) ) ) ) ; ata_ident ( ata , i , 1 , ( struct ata_ident * ) ( identbuf + ( ( sizeof ( struct ata_ident ) * ( 2 * i ) ) + sizeof ( struct ata_ident ) ) ) ) ; } for ( i = 0 ; i < numdevs ; i ++ ) { struct ata_ident * ident = ( struct ata_ident * ) ( identbuf + ( sizeof ( struct ata_ident ) * i ) ) ; char model [ 41 ] ; memset ( model , 0 , 41 ) ; strncpy ( model , ( void * ) ident -> model , 40 ) ; if ( ident -> config != 0 ) { printf ( " \n " , ( i / 2 ) , ( i % 2 == 0 ) ? 0 : 1 ) ; printf ( " \t \n " , model ) ; printf ( " \n " ) ; } } free ( identbuf ) ; }
list the installed devices.
list the installed devices .
// first, do an IDENTIFY on each channel /* malloc failed, we can do nothing here but quit */