Pavol Kycina
|
Re: Reading the serial number of a hard disk managed by devb-eide.
|
Pavol Kycina
12/01/2009 2:34 AM
post42916
|
Re: Reading the serial number of a hard disk managed by devb-eide.
Try to parse output of sloginfo,
devb-eide logs some information on its startup, and one of those is a serial number.
PKY
> Hi,
>
> I'd like to retrieve the serial number of the hard disk (compact flash) my
> system
> is currently running from. I can't find a QNX6 utility that provides this
> info.
>
> Since my device is managed by the process devb-eide,
> I explored devctl() and checked dcmd_all.h and dcmd_blk.h
> for commands that could be used to get some device info,
> but I did not find what I was looking for.
>
> Can someone help?
>
|
|
|
Martin Politick
|
Re: Reading the serial number of a hard disk managed by devb-eide.
|
Martin Politick
12/01/2009 9:53 AM
post42952
|
Re: Reading the serial number of a hard disk managed by devb-eide.
> Hi,
>
> I'd like to retrieve the serial number of the hard disk (compact flash)
>
> Can someone help?
>
The code below returns:
The dcmd argument isn't a valid command for this device.
DCMD_CAM_DEV_SERIAL_NUMBER failed. Cause: Inappropriate I/O control operation. DevErrorInfo=0
> Can someone help more?
-------------------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/neutrino.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/dcmd_cam.h>
#include <devctl.h>
int main( int argc, char *argv[] )
{
int FileDescriptor = 0;
int Error = 0;
int DevInfo = 0;
char CamAnswer[256] = "";
if(( FileDescriptor = open("/dev/hd0", O_RDONLY)) == -1)
{
fprintf( stderr, "Unable to open /dev/hd0. Cause %s\n", strerror( errno ));
exit( EXIT_FAILURE );
}
if((Error = devctl( FileDescriptor, DCMD_CAM_DEV_SERIAL_NUMBER, CamAnswer, 256, &DevInfo)) != EOK)
{
switch( Error )
{
case EAGAIN: fprintf( stderr, "The devctl() command couldn't be completed because the device driver was in use by
another process, or the driver was unable to carry out the request due to an outstanding command in progress.\n"); break
;
case EBADF: fprintf( stderr, "Invalid open file descriptor, filedes. \n"); break;
case EINTR: fprintf( stderr, "The devctl() function was interrupted by a signal.\n"); break;
case EINVAL: fprintf( stderr, "The device driver detected an error in dev_data_ptr or n_bytes.\n"); break;
case EIO: fprintf( stderr, "The devctl() function couldn't complete because of a hardware error. \n"); break;
case ENOSYS: fprintf( stderr, "The device doesn't support the dcmd command. \n"); break;
case ENOTTY: fprintf( stderr, "The dcmd argument isn't a valid command for this device. \n"); break;
case EPERM: fprintf( stderr, "The process doesn't have sufficient permission to carry out the requested command.\n
"); break;
default: fprintf( stderr, "Undocumented failure\n"); break;
}
fprintf( stderr, "DCMD_CAM_DEV_SERIAL_NUMBER failed. Cause: %s. DevErrorInfo=%d\n", strerror(Error), DevInfo);
exit( EXIT_FAILURE );
}
CamAnswer[255] = 0; // Make sure the string is terminated
printf("SERIAL_NUMBER is %s\n",CamAnswer);
return EXIT_SUCCESS;
}
|
|
|