![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 27
| Identifying sparse files programatically in C Thanks |
| rohan_ak1 is offline | |
| | #2 |
| Registered User Join Date: Nov 2008
Posts: 75
| You should read more about stat, because that's the system call that you need. |
| MisterIO is offline | |
| | #3 |
| Registered User Join Date: May 2009
Posts: 1
| Look at the stat structure. One crude heurestic is that if the size of the file (st_size) is greater than the number of blocks (st_blocks) multipied by the size of a block, then you have a sparse file. The GNU core utilities which support the --sparse option use this heuristic. From copy.c: Code: #if HAVE_STRUCT_STAT_ST_BLOCKS
/* Use a heuristic to determine whether SRC_NAME contains any sparse
blocks. If the file has fewer blocks than would normally be
needed for a file of its size, then at least one of the blocks in
the file is a hole. */
if (x->sparse_mode == SPARSE_AUTO && S_ISREG (src_open_sb.st_mode)
&& ST_NBLOCKS (src_open_sb) < src_open_sb.st_size / ST_NBLOCKSIZE)
make_holes = true;
#endif
|
| fpmurphy is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| organize project and specify directory for object files in Makefile | lehe | C++ Programming | 2 | 08-11-2009 06:45 AM |
| Header files and multiple definitions | sjweinberg | C++ Programming | 16 | 07-17-2009 05:59 PM |
| *.cpp and *.h files understanding | ElastoManiac | C++ Programming | 4 | 06-11-2006 04:45 AM |
| Linking header files, Source files and main program(Accel. C++) | Daniel Primed | C++ Programming | 3 | 01-17-2006 11:46 AM |
| Multiple Cpp Files | w4ck0z | C++ Programming | 5 | 11-14-2005 02:41 PM |