[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strage values from FIBMAP on holes or after end of file



Forgot the attachment.

utz lehmann [xfs@s2y4n2c.de] wrote:
> Hi
> 
> The FIBMAP ioctl on holes or after end of file gives the values -1 to 6.
> ext2 and reiserfs reurns 0. I thing this is the right value.
> 
> The attached programm FIBMAPs the first 32 512byte blocks of a file.
> 
> # echo hole >HOLE
> # echo hole | dd of=HOLE bs=4096 seek=2
> # ./fib HOLE
>         0 [0]: 452112
>         1 [0]: 452113
>         2 [0]: 452114
>         3 [0]: 452115
>         4 [0]: 452116
>         5 [0]: 452117
>         6 [0]: 452118
>         7 [0]: 452119
>         8 [0]: -1
>         9 [0]: 0
>        10 [0]: 1
>        11 [0]: 2
>        12 [0]: 3
>        13 [0]: 4
>        14 [0]: 5
>        15 [0]: 6
>        16 [0]: 452104
>        17 [0]: 452105
>        18 [0]: 452106
>        19 [0]: 452107
>        20 [0]: 452108
>        21 [0]: 452109
>        22 [0]: 452110
>        23 [0]: 452111
>        24 [0]: -1
>        25 [0]: 0
>        26 [0]: 1
>        27 [0]: 2
>        28 [0]: 3
>        29 [0]: 4
>        30 [0]: 5
>        31 [0]: 6
> 
> Blocks 8 - 15 are the hole. Block 23 ist the last block of the file.
> 
> 
> utz
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>


int main (int argc, char **argv) {
	int i, block, res, fd;
	fd = open(argv[1],O_RDONLY);
	if (fd < 0) {exit(1);}
	for(i=0;i<32;i++) {
		block=i;
		res=ioctl(fd, FIBMAP, &block);
		printf("%9d [%d]: %d\n", i, res, block);
	}
}