Thread: Reading from large block device

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

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, 08:56 PM
  3. Representing a Large Integer with an Array
    By random_accident in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2005, 12:23 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. Reading Large Files!!!
    By jon in forum Windows Programming
    Replies: 1
    Last Post: 09-09-2001, 11:20 PM