* Question about the fallocate system call
@ 2012-07-26 14:30 Jidong Xiao
2012-07-26 17:02 ` Pádraig Brady
0 siblings, 1 reply; 2+ messages in thread
From: Jidong Xiao @ 2012-07-26 14:30 UTC (permalink / raw)
To: Kernel development list
Hi,
I just have a simple question about fallocate.
I want to test the punch hole function of fallocate(). So I wrote such
a simple program:
yosemite:/mnt # cat test.c
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <linux/fs.h>
#include <linux/falloc.h>
int main(void)
{
int fd;
fd = open("testfile", O_RDWR);
fallocate(fd,FALLOC_FL_PUNCH_HOLE,0,500*1024*1024);
close(fd);
return 0;
}
I created a file called "testfile" whose size is 1GB, however, when I
run the above program, the size of the testfile simply won't change,
if I use stat command to check the file status, nothing is changed when I
execute the above program. My filesystem is ext4, as I understand,
ideally when I run the above program, the file size should decrease
from 1GB to 512MB, is there anything wrong with the program or I just
understood incorrectly?
Thank you for any inputs/comments.
-Jidong
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Question about the fallocate system call
2012-07-26 14:30 Question about the fallocate system call Jidong Xiao
@ 2012-07-26 17:02 ` Pádraig Brady
0 siblings, 0 replies; 2+ messages in thread
From: Pádraig Brady @ 2012-07-26 17:02 UTC (permalink / raw)
To: Jidong Xiao; +Cc: Kernel development list
On 07/26/2012 03:30 PM, Jidong Xiao wrote:
> Hi,
>
> I just have a simple question about fallocate.
>
> I want to test the punch hole function of fallocate(). So I wrote such
> a simple program:
>
> yosemite:/mnt # cat test.c
> #include <fcntl.h>
> #include <errno.h>
> #include <stdio.h>
> #include <stdint.h>
> #include <linux/fs.h>
> #include <linux/falloc.h>
>
> int main(void)
> {
> int fd;
>
> fd = open("testfile", O_RDWR);
> fallocate(fd,FALLOC_FL_PUNCH_HOLE,0,500*1024*1024);
> close(fd);
>
> return 0;
> }
>
> I created a file called "testfile" whose size is 1GB, however, when I
> run the above program, the size of the testfile simply won't change,
> if I use stat command to check the file status, nothing is changed when I
> execute the above program. My filesystem is ext4, as I understand,
> ideally when I run the above program, the file size should decrease
> from 1GB to 512MB, is there anything wrong with the program or I just
> understood incorrectly?
>
> Thank you for any inputs/comments.
code looks OK,
but you're not checking the return from fallocate().
I'm guessing it's returning -1 with errno = ENOTSUP
cheers,
Pádraig.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-07-26 18:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 14:30 Question about the fallocate system call Jidong Xiao
2012-07-26 17:02 ` Pádraig Brady
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox