Reading from large block device

This is a discussion on Reading from large block device within the Linux Programming forums, part of the Platform Specific Boards category; I am trying to read some data from a raw block device (/dev/hdx). This actually works fine using the standard ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    250

    Reading from large block device

    I am trying to read some data from a raw block device (/dev/hdx). This actually works fine using the standard I/O functions, except that ftell() fails with the following error, after processing data for a while:

    "Value too large for defined data type"

    Now this happens once offset 0x80000000 has been reached. This is actually obvious as a 32-bit variable can't hold more than a +/- 2GB offset. So I tried the ftello() function. Put a #define _FILE_OFFSET_BITS 64 into my code and ran the program again. But ftello() fails with exactly the same error that ftell() gives me.

    Now I managed to resolve this problem by using relative offsets exclusively, in which case I do not need calls to ftell() anymore. I was left wondering however, how to obtain the current file position, as ftell()/ftello() apparently fail to do the job on my system. So does anyone know how this is done?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    fgetpos and fsetpos are the large file equivalents.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading a file into a block
    By mickey0 in forum C++ Programming
    Replies: 19
    Last Post: 05-03-2008, 05:53 AM
  2. Representing a Large Integer with an Array
    By random_accident in forum C Programming
    Replies: 3
    Last Post: 03-03-2005, 07:56 PM
  3. Representing a Large Integer with an Array
    By random_accident in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2005, 11:23 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM
  5. Reading Large Files!!!
    By jon in forum Windows Programming
    Replies: 1
    Last Post: 09-09-2001, 11:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21