* FIGETBSZ and FIBMAP for directorys
@ 2005-06-15 7:58 Sebastian Claßen
2005-06-15 22:46 ` Nathan Scott
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Claßen @ 2005-06-15 7:58 UTC (permalink / raw)
To: linux-kernel
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: FIGETBSZ and FIBMAP for directorys
2005-06-15 7:58 FIGETBSZ and FIBMAP for directorys Sebastian Claßen
@ 2005-06-15 22:46 ` Nathan Scott
0 siblings, 0 replies; 3+ messages in thread
From: Nathan Scott @ 2005-06-15 22:46 UTC (permalink / raw)
To: Sebastian Claßen; +Cc: linux-kernel
On Wed, Jun 15, 2005 at 09:58:07AM +0200, Sebastian Cla?en wrote:
> Hi list...
>
> I'm using this little program to find out which blocks are use by a
> particular file:
> ...
> 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 */
> 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.
--
Nathan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: FIGETBSZ and FIBMAP for directorys
@ 2005-06-15 23:15 Nikita Danilov
0 siblings, 0 replies; 3+ messages in thread
From: Nikita Danilov @ 2005-06-15 23:15 UTC (permalink / raw)
To: Linux Kernel Mailing List
Sebastian Claъen writes:
> 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));
Now, if somebody compiles this with NDEBUG? It is bad practice to put
code with side-effects into assertions.
[...]
>
> This works fine for regular files, but not for directorys. Both ioctl's,
> FIGETBSZ and FIBMAP, are implemented for regular files only.
FIBMAP is obsolete API, I believe. For certain file systems it doesn't
make sense to ask "in what block, i-th logical block of given file
lives?" for directory files, because directories do not have linear
structure, e.g., are implemented as B-trees. Not incidentally these are
the same file systems that have trouble supporting optional
seekdir/telldir API.
Moreover, for some file systems this question doesn't make a lot of
sense even for regular files, e.g., because small files can be stored in
the same block, or some blocks might be in the "unallocated state", or
file system does behind-the-back relocation to improve disk layout, etc.
Nor does it make sense to ask such questions when files are stripped
over multiple devices, or served over network, or backed up by memory...
Basically, FIBMAP is a hack.
>
> 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.
>
>
Nikita.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-06-15 23:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-15 7:58 FIGETBSZ and FIBMAP for directorys Sebastian Claßen
2005-06-15 22:46 ` Nathan Scott
-- strict thread matches above, loose matches on Subject: below --
2005-06-15 23:15 Nikita Danilov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox