All of lore.kernel.org
 help / color / mirror / Atom feed
* Getting HDD serial in kernel space
@ 2009-11-14 11:34 Andrey Polovov
  2009-11-14 15:28 ` Alan Cox
  2009-11-15 14:03 ` Andrey Polovov
  0 siblings, 2 replies; 4+ messages in thread
From: Andrey Polovov @ 2009-11-14 11:34 UTC (permalink / raw)
  To: linux-kernel

Hello.

I had a necessity to get HDD serial number in my kernel module.
In user space I can do it so:

    fd = open( "/dev/sda", O_RDONLY|O_NONBLOCK );
    ioctl( fd, HDIO_GET_IDENTITY, &id );
    printf( "Serial: %s", id.serial_no );

How can I do it in kernel space (it is one hdd in machine, plugged with
SATA)?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting HDD serial in kernel space
  2009-11-14 11:34 Getting HDD serial in kernel space Andrey Polovov
@ 2009-11-14 15:28 ` Alan Cox
  2009-11-15 14:03 ` Andrey Polovov
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Cox @ 2009-11-14 15:28 UTC (permalink / raw)
  To: Andrey Polovov; +Cc: linux-kernel

On Sat, 14 Nov 2009 14:34:54 +0300
Andrey Polovov <andrey.polovov@gmail.com> wrote:

> Hello.
> 
> I had a necessity to get HDD serial number in my kernel module.
> In user space I can do it so:
> 
>     fd = open( "/dev/sda", O_RDONLY|O_NONBLOCK );
>     ioctl( fd, HDIO_GET_IDENTITY, &id );
>     printf( "Serial: %s", id.serial_no );
> 
> How can I do it in kernel space (it is one hdd in machine, plugged with
> SATA)?

The identity when probed is all in the struct ata_device, although be
aware that it may not be unique per device and also that hotplug means
you need to be careful how you access it. Now and then you meet a device
where the serial number changes randomly each boot just to really annoy.

What are you actually trying to do ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting HDD serial in kernel space
  2009-11-14 11:34 Getting HDD serial in kernel space Andrey Polovov
  2009-11-14 15:28 ` Alan Cox
@ 2009-11-15 14:03 ` Andrey Polovov
  2009-11-15 17:05   ` Alan Cox
  1 sibling, 1 reply; 4+ messages in thread
From: Andrey Polovov @ 2009-11-15 14:03 UTC (permalink / raw)
  To: linux-kernel

Andrey Polovov:

> How can I do it in kernel space (it is one hdd in machine, plugged with
> SATA)?

What I need is a small piece of code that can help me in getting a list
(ata_device array?) of plugged HDDs and their serial numbers.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting HDD serial in kernel space
  2009-11-15 14:03 ` Andrey Polovov
@ 2009-11-15 17:05   ` Alan Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Cox @ 2009-11-15 17:05 UTC (permalink / raw)
  To: Andrey Polovov; +Cc: linux-kernel

On Sun, 15 Nov 2009 17:03:56 +0300
Andrey Polovov <andrey.polovov@gmail.com> wrote:

> Andrey Polovov:
> 
> > How can I do it in kernel space (it is one hdd in machine, plugged with
> > SATA)?
> 
> What I need is a small piece of code that can help me in getting a list
> (ata_device array?) of plugged HDDs and their serial numbers.

That wasn't the question I asked. The question I asked is "what are you
trying to do". You request seems rather odd, especially to try and do in
kernel space, so if we understood what you were trying to do it might
make more sense and easier to suggest the best way to approach it.

Alan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-15 17:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-14 11:34 Getting HDD serial in kernel space Andrey Polovov
2009-11-14 15:28 ` Alan Cox
2009-11-15 14:03 ` Andrey Polovov
2009-11-15 17:05   ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.