Stephen Lord <lord@xxxxxxx> writes:
> monkeyiq wrote:
>
> > found the calls in xfs(5)
>
> >XFS_IOC_FSGETXATTR
> >XFS_IOC_RESVSP64
> >XFS_IOC_UNRESVSP64
> >
> > ...
> >
> It is possible to query xfs to find out all sorts of stuff about the layout
> of a
>
> file, take a look at the xfs_bmap program and its source code. If you are
> not creating files with holes in then a simple stat system call will suffice,
>
> the st_blocks will include preallocated space beyond the end of file.
>
> Steve
I had a look at bmap, very nice. BTW as an aside the man pages
dont document -p or -V (and -v though that one is not even in bmap --help)
for bmap [xfsprogs-1.3.17-0].
After looking through xfs_mkfile I came to the conclusion that code like
the following
#include <libxfs.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <ctype.h>
int main(int argc, char **argv)
{
int size = 1024;
int oflags = O_CREAT|O_TRUNC|O_WRONLY;
int fd=0;
xfs_flock64_t flck;
flck.l_whence = SEEK_SET;
flck.l_start = 0LL;
flck.l_len = size;
fd = open( "/home/ben/tmp/testf", oflags, 0600);
ioctl(fd, XFS_IOC_RESVSP64, &flck);
close(fd);
exit( 0 );
}
would preallocate space. This seems to work ok, but files created
using and -p xfs_mkfile always have a size==the preallocation size.
I am only wondering if this example is correct because in xfs_mkfile.c
it casts away the return value of ioctl() so there is no way to tell
if the preallocation was a success.
For example
[XFS]$ ./a.out
[XFS]$ /usr/sbin/xfs_mkfile -p 1k ~/tmp/testf.x
[XFS]$ xfs_bmap -v ~/tmp/testf ~/tmp/testf.x
/home/ben/tmp/testf:
EXT: FILE-OFFSET BLOCK-RANGE AG AG-OFFSET TOTAL
0: [0..7]: 1528856..1528863 1 (759752..759759) 8
/home/ben/tmp/testf.x:
EXT: FILE-OFFSET BLOCK-RANGE AG AG-OFFSET TOTAL
0: [0..7]: 1404072..1404079 1 (634968..634975) 8
[ben@kloof XFS]$ stat ~/tmp/testf ~/tmp/testf.x
File: "/home/ben/tmp/testf"
Size: 0 Blocks: 8 Regular File
Access: (0600/-rw-------) Uid: ( 500/ ben) Gid: ( 1006/ ben)
Device: 305 Inode: 3626363 Links: 1
Access: Mon Feb 4 08:13:08 2002
Modify: Mon Feb 4 08:13:08 2002
Change: Mon Feb 4 08:13:08 2002
File: "/home/ben/tmp/testf.x"
Size: 1024 Blocks: 8 Regular File
Access: (0600/-rw-------) Uid: ( 500/ ben) Gid: ( 1006/ ben)
Device: 305 Inode: 3626366 Links: 1
Access: Mon Feb 4 08:13:15 2002
Modify: Mon Feb 4 08:13:15 2002
Change: Mon Feb 4 08:13:15 2002
And using /usr/sbin/xfs_mkfile -v -n -p 1k testf.x2
[tmp]$ stat testf.x2
File: "testf.x2"
Size: 1024 Blocks: 128 Regular File
Access: (0600/-rw-------) Uid: ( 500/ ben) Gid: ( 1006/ ben)
Device: 305 Inode: 3626373 Links: 1
Access: Mon Feb 4 08:20:04 2002
Modify: Mon Feb 4 08:22:00 2002
Change: Mon Feb 4 08:22:00 2002
[tmp]$ bmap -v testf.x2
testf.x2:
EXT: FILE-OFFSET BLOCK-RANGE AG AG-OFFSET TOTAL
0: [0..127]: 1771048..1771175 2 (232840..232967) 128
So I presume that the -n nobytes is causing a different Allocation Group
for the last file (prehaps holey files are in AG2 for that fs by default).
-------------------------------------------------------
Story at 11 http://witme.sourceforge.net/libferris.web/
|