Raw disk access

Discussion in 'C Programming' started by Daniel Rudy, Mar 23, 2007.

  1. Daniel Rudy

    Daniel Rudy Guest

    How does one access the raw disk?

    I have a USB thumb drive that will have many megabytes of data on it.
    What I want to do is access the device raw and do reading from/writing
    to the usb device itself. No partitions, no mounting, just raw disk
    access to data in predefined structures that is on the device. I have
    looked at Advanced Unix Programming (ISBN 0-13-141154-3) by Marc J.
    Rochkind and it does mention a few things about it, but I want to know
    more. Any documentation/references online that someone is willing to share?

    I am running FreeBSD 6.x.

    --
    Daniel Rudy

    Email address has been base64 encoded to reduce spam
    Decode email address using b64decode or uudecode -m

    Why geeks like computers: look chat date touch grep make unzip
    strip view finger mount fcsk more fcsk yes spray umount sleep
     
    Daniel Rudy, Mar 23, 2007
    #1
    1. Advertising

  2. Daniel Rudy

    Ian Collins Guest

    Daniel Rudy wrote:
    > How does one access the raw disk?
    >
    > I have a USB thumb drive that will have many megabytes of data on it.
    > What I want to do is access the device raw and do reading from/writing
    > to the usb device itself. No partitions, no mounting, just raw disk
    > access to data in predefined structures that is on the device. I have
    > looked at Advanced Unix Programming (ISBN 0-13-141154-3) by Marc J.
    > Rochkind and it does mention a few things about it, but I want to know
    > more. Any documentation/references online that someone is willing to share?
    >
    > I am running FreeBSD 6.x.
    >

    Either a BSD group or comp.unix.programmer would be a better place to ask.

    --
    Ian Collins.
     
    Ian Collins, Mar 23, 2007
    #2
    1. Advertising

  3. On Mar 23, 9:34 am, Daniel Rudy <> wrote:
    > How does one access the raw disk?
    >
    > I have a USB thumb drive that will have many megabytes of data on it.
    > What I want to do is access the device raw and do reading from/writing
    > to the usb device itself. No partitions, no mounting, just raw disk
    > access to data in predefined structures that is on the device. I have
    > looked at Advanced Unix Programming (ISBN 0-13-141154-3) by Marc J.
    > Rochkind and it does mention a few things about it, but I want to know
    > more. Any documentation/references online that someone is willing to share?


    Do a search for USB and "mass storage" devices.

    The things that you are looking for might not even exist. USB
    implements an interface. There is no knowing what is on the device
    itself.
     
    christian.bau, Mar 23, 2007
    #3
  4. Daniel Rudy

    Daniel Rudy Guest

    At about the time of 3/23/2007 2:34 AM, Daniel Rudy stated the following:
    > How does one access the raw disk?
    >
    > I have a USB thumb drive that will have many megabytes of data on it.
    > What I want to do is access the device raw and do reading from/writing
    > to the usb device itself. No partitions, no mounting, just raw disk
    > access to data in predefined structures that is on the device. I have
    > looked at Advanced Unix Programming (ISBN 0-13-141154-3) by Marc J.
    > Rochkind and it does mention a few things about it, but I want to know
    > more. Any documentation/references online that someone is willing to share?
    >
    > I am running FreeBSD 6.x.
    >


    Opps....

    Wrong group. That's what happens when you post at 2AM.


    --
    Daniel Rudy

    Email address has been base64 encoded to reduce spam
    Decode email address using b64decode or uudecode -m

    Why geeks like computers: look chat date touch grep make unzip
    strip view finger mount fcsk more fcsk yes spray umount sleep
     
    Daniel Rudy, Mar 23, 2007
    #4
  5. Daniel Rudy

    daya Guest

    To access the USB drive in raw mode in Linux...do not mount the drive.
    Just search the device file in the folder /dev
    It will probably be /dev/sda or /dev/sdc.

    Since all the devices are treated as files in linux.you can use the
    file in raw mode
    in C/C++ program

    eg

    FILE* fp=fopen("/dev/sda","r");

    etc.
    For writing you may probably need to run the program as root.

    daya
     
    daya, Mar 23, 2007
    #5
  6. Daniel Rudy

    Flash Gordon Guest

    daya wrote, On 23/03/07 16:54:
    > To access the USB drive in raw mode in Linux...do not mount the drive.
    > Just search the device file in the folder /dev
    > It will probably be /dev/sda or /dev/sdc.
    >
    > Since all the devices are treated as files in linux.you can use the
    > file in raw mode
    > in C/C++ program


    I think you mean binary mode, C does not have a raw mode.

    > eg
    >
    > FILE* fp=fopen("/dev/sda","r");


    That would open it in text mode which is not what you want (although it
    does not make much difference on Linux). You should use "rb" for binary.

    > etc.
    > For writing you may probably need to run the program as root.


    All this would be best discussed on a Linux or Unix programming group
    where the specifics of the system are topical. They are not topical here.
    --
    Flash Gordon
     
    Flash Gordon, Mar 23, 2007
    #6
  7. Daniel Rudy

    Daniel Rudy Guest

    At about the time of 3/23/2007 1:08 PM, Flash Gordon stated the following:
    > daya wrote, On 23/03/07 16:54:
    >> To access the USB drive in raw mode in Linux...do not mount the drive.
    >> Just search the device file in the folder /dev
    >> It will probably be /dev/sda or /dev/sdc.
    >>
    >> Since all the devices are treated as files in linux.you can use the
    >> file in raw mode
    >> in C/C++ program

    >
    > I think you mean binary mode, C does not have a raw mode.
    >


    No, I mean raw device access mode in Unix, when the disk looks just like
    a bunch of data blocks and you can view the partition table and
    filesystem structures that the kernel uses to keep track of things on
    the disk. In my case, it's a USB flash drive.

    >> eg
    >>
    >> FILE* fp=fopen("/dev/sda","r");

    >
    > That would open it in text mode which is not what you want (although it
    > does not make much difference on Linux). You should use "rb" for binary.
    >


    It would have to be binary mode.

    >> etc.
    >> For writing you may probably need to run the program as root.

    >
    > All this would be best discussed on a Linux or Unix programming group
    > where the specifics of the system are topical. They are not topical here.


    Which is why I posted a follow-up message indicating that I posted to
    the wrong group. The poster that you replied to snipped my post that
    made a statement to that fact.


    --
    Daniel Rudy

    Email address has been base64 encoded to reduce spam
    Decode email address using b64decode or uudecode -m

    Why geeks like computers: look chat date touch grep make unzip
    strip view finger mount fcsk more fcsk yes spray umount sleep
     
    Daniel Rudy, Mar 24, 2007
    #7
  8. Daniel Rudy

    Flash Gordon Guest

    Daniel Rudy wrote, On 24/03/07 08:53:
    > At about the time of 3/23/2007 1:08 PM, Flash Gordon stated the following:


    <snip>

    >> All this would be best discussed on a Linux or Unix programming group
    >> where the specifics of the system are topical. They are not topical here.

    >
    > Which is why I posted a follow-up message indicating that I posted to
    > the wrong group. The poster that you replied to snipped my post that
    > made a statement to that fact.


    I either did not see or did not remember that. I'm not disputing you
    posted it, just pointing out that it is not unusual for these things to
    be pointed out more than once.
    --
    Flash Gordon
     
    Flash Gordon, Mar 24, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jas Shultz
    Replies:
    0
    Views:
    991
    Jas Shultz
    Dec 3, 2003
  2. Replies:
    12
    Views:
    538
    santosh
    Nov 15, 2006
  3. I/O with raw disk

    , Sep 14, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    164
    Josef Moellers
    Sep 15, 2006
  4. khanta
    Replies:
    2
    Views:
    85
    Mark Lawrence
    Feb 21, 2014
  5. Chris Angelico
    Replies:
    0
    Views:
    61
    Chris Angelico
    Feb 19, 2014
Loading...

Share This Page