0

How can I find length of non-zero data block in sparse file starting from some offset? Do I have to make some file read or OS can read that information from some metadata which can be cached? I'm using Windows OS and Visual Studio C++.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Marka
  • 377
  • 1
  • 4
  • 17
  • Your question is too ambiguous. Provide some details. What's the problem with using `fseek` and `fread` after it? – Mikhail Nov 19 '12 at 10:01
  • @Mikhail Sparse files are often *very* sparse (e.g. file size is 2**48 of which there are only several megabytes of data), and file offset has some specific meaning (e.g. directly corresponds to a database key). In such a case, a "brute force" approach with fseek/fread will totally trash performance. – atzz Nov 19 '12 at 11:31
  • Say I have some data blocks starting at every 128kb of data. These blocks can have variable length. One block can be 1234B long, second 2451B etc. How can I found out what is the length of populated data? This length doesn't have to be exact, for example it can be rounded to whole cluster. – Marka Nov 19 '12 at 13:36

1 Answers1

1

You can use DeviceIoControl with FSCTL_QUERY_ALLOCATED_RANGES command.

atzz
  • 17,507
  • 3
  • 35
  • 35