So the fcntl is different from the ioctl?
What I'm trying to do is poke a hole in a file where there used to be data. The
specific application is with a big long stream of mpeg data and we want to
truncate it from the front to avoid running out of disk space.
Here is my function:
int trim(int fd, unsigned long long offset)
struct xfs_flock64 flock;
flock.l_whence = 0;
flock.l_start = 0;
flock.l_len = offset;
rc = ioctl( fd, XFS_IOC_UNRESVSP, &flock );
printf("rc: %d\n", rc);
When I put an XFS_IOC_FREESP in then it makes a zero length file. If I put
XFS_IOC_UNRESVSP in then it looks like it pokes a hole in the whole file. Am I
trying to do something that XFS on linux won't do?
Eric Sandeen wrote:
> Hi Ian -
> Sorry, I'm not an expert on this, but perhaps this will make a decent
> preliminary answer.
> >From xfs_vfsops.c, these comments are in xfs_change_file_space()
> * XFS_IOC_RESVSP and XFS_IOC_UNRESVSP will reserve or unreserve
> * file space.
> * These calls do NOT zero the data space allocated to the file,
> * nor do they change the file size.
> * XFS_IOC_ALLOCSP and XFS_IOC_FREESP will allocate and free file
> * space.
> * These calls cause the new file data to be zeroed and the file
> * size to be changed.
> Irix also has this to say in the fcntl man page:
> F_FREESP Alter storage space associated with a section of the ordinary
> file fildes. The section is specified by a variable of data
> type struct flock pointed to by the third argument arg. The
> data type struct flock is defined in the <fcntl.h> header file
> [see fcntl(5)] and contains the following members: l_whence is
> 0, 1, or 2 to indicate that the relative offset l_start will be
> measured from the start of the file, the current position, or
> the end of the file, respectively. l_start is the offset from
> the position specified in l_whence. l_len is the size of the
> section. An l_len of 0 frees up to the end of the file; in
> this case, the end of file (i.e., file size) is set to the
> beginning of the section freed. Any data previously written
> into this section is no longer accessible. If the section
> specified is beyond the current end of file, the file is grown
> and filled with zeroes. The l_len field is currently ignored,
> and should be set to 0.
> This command is used to free space from a file. A range of
> bytes is specified with the struct flock. Partial filesystem
> blocks are zeroed, and whole filesystem blocks are removed from
> the file. The file size does not change. It is only supported
> on XFS and BDS filesystems.
> "Ian S. Nelson" wrote:
> > What's the difference between these two ioctls and are they both
> > implemented on Linux?
> > I've been trying to "trim" the front a file with FREESP and I keep
> > getting 0 length files.
> > thanks,
> > Ian
> Eric Sandeen XFS for Linux http://oss.sgi.com/projects/xfs
> sandeen@xxxxxxx SGI, Inc.