Re: fcntl(fd,F_SETSIZE,?)
Re: fcntl(fd,F_SETSIZE,?)
- Subject: Re: fcntl(fd,F_SETSIZE,?)
- From: Shantonu Sen <email@hidden>
- Date: Fri, 12 Oct 2012 00:28:21 -0700
fcntl(F_SETSIZE) is not designed for this purpose. Among other things, it can cause you to expose sensitive data if your program crashes and later someone else opens the file (and sees the disk blocks that weren't zero-ed out). It also requires privileges.
It sounds like what you want is fcntl(F_PREALLOCATE). Even then, it's unclear to me why you are seeing minute-long zero filling. HFS+ is optimized to not incur this zero-fill while you have the file open. Are you calling ftruncate(2) and then closing the file and then opening it again before writing it? Are you not using HFS+? Each filesystem implements (or doesn't) these fcntls differently.
Shantonu
On Oct 12, 2012, at 12:05 AM, James Bucanek <email@hidden> wrote:
> Paul Nelson <mailto:email@hidden> wrote (Thursday, October 11, 2012 7:16 PM -0500):
>
>> I was not sure what you want to accomplish with a symlink from your original
>> post.
>
> That was just coincidence. My earlier questions about symlink, and my question about fcnt(F_SETSIZE) have nothing to do with each other. :/
>
>> You seem interested in the inner workings of all this so here goes.
>
> I am indeed, and I really appreciate the time you've taken to explain it.
>
>> If you aren't, this stuff is really boring.
>
> I live for boring.
>
>> First, you need to get the xnu sources so you can look in the kernel code.
>
> That, right there, is a huge help. I was Googling opensource.apple.com and wasn't finding anything I was looking for.
>
>> This is where all fcntl stuff is implemented.
>
> I just downloaded xnu-2050.18.24 and have found the fcntl implementation, which I trust will reveal the secrets I was looking for.
>
>> You will need to realize that
>> each file system handles their implementation (or doesn't) in their own way.
>
> Understood.
>
>> Unfortunately, the code is very hard to follow.
>
> That's an understatement. :)
>
> Anyway, I really value the insight into how symlinks work. I'm going to dig into that code because I have other questions (about deleting ACLs and whatnot) that I think are hidden there too.
>
> My question about the F_SETSIZE fcntl() command was really about trying to reclaim the ability to extend (physically allocate) a file *without* filling the file with zeros. I have a couple of performance issues where I want to pre-allocate several large files--so I know that there's ample free space to accomodate them--before they get populated with data. The problem is, the standard ftruncate() function fills the files with zeros, so they get written twice. On slower media this is a huge waste of time (several minutes in some cases).
>
> According to F_SETSIZE's documentation, it will permit the file size to be extended without filling it with zeros. But the details of the command's argument is not documented. I was hoping a peek at the fcntl() source code would reveal that, and now I've got it.
>
> Thanks again,
>
> --
> James Bucanek
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Filesystem-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden