Skip to contentSkip to conversation

FIGETBSZ and FIBMAP for directorys

DISCUSSION Sebastian Claßen 2 participants 2 messages Jun 15, 2005

lore
Share & tools
lore
#0 lore raw

Hi list...

I'm using this little program to find out which blocks are use by a particular file:

int main(int argc, char **argv) {
        int             fd,
                        i,
                        block,
                        blocksize,
                        bcount;
        struct stat     st;

        assert(argv[1] != NULL);
        assert(fd=open(argv[1], O_RDONLY));
        assert(ioctl(fd, FIGETBSZ, &blocksize) == 0);
        assert(!fstat(fd, &st));
        bcount = (st.st_size + blocksize - 1) / blocksize;
        printf("File: %s Size: %d Blocks: %d Blocksize: %d\n", 
                argv[1], st.st_size, bcount, blocksize);
        for(i=0;i < bcount;i++) {
                block=i;
                if (ioctl(fd, FIBMAP, &block)) {
                        printf("FIBMAP ioctl failed - errno: %s\n",
                                        strerror(errno));
                }
                printf("%3d %10d\n", i, block);
        }
        close(fd);
}

This works fine for regular files, but not for directorys. Both ioctl's, FIGETBSZ and FIBMAP, are implemented for regular files only.

Is there a patch to make this FIGETBSZ and FIBMAP work on directorys too?
Or alternativly, is there a way to find out which blocks are used by a directory?

Thanks for answers in advance
Sebastian.

#1 lore raw
Quoted 5 lines · Sebastian Cla?en

Hi list...

I'm using this little program to find out which blocks are use by a particular file:
...

Quoted 8 lines
                if (ioctl(fd, FIBMAP, &block)) {

...

This works fine for regular files, but not for directorys. Both ioctl's, FIGETBSZ and FIBMAP, are implemented for regular files only.

Is there a patch to make this FIGETBSZ and FIBMAP work on directorys too?

I doubt it, these ioctls are generally frowned on and noone touches them these days - eg. from fs.h...

#define BMAP_IOCTL 1            /* obsolete - kept for compatibility */
#define FIBMAP     _IO(0x00,1)  /* bmap access */
#define FIGETBSZ   _IO(0x00,2)  /* get the block size used for bmap */
Quoted 2 lines

Or alternativly, is there a way to find out which blocks are used by a directory?

There's an XFS-specific way if youre using XFS, and other filesystems may have their own custom way of providing that information, I'm not sure. For XFS, the xfs_bmap(8) command uses XFS_IOC_GETBMAP to get an inode's extent layout, and that works for all file types.

cheers.

Signature · 1 line
Nathan