* How does ext2 implement sparse files?
@ 2008-01-31 15:28 Lars Noschinski
2008-01-31 16:51 ` Lennart Sorensen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Lars Noschinski @ 2008-01-31 15:28 UTC (permalink / raw)
To: linux-kernel
Hello!
For an university project, we had to write a toy filesystem (ext2-like),
for which I would like to implement sparse file support. For this, I
digged through the ext2 source code; but I could not find the point,
where ext2 detects holes.
As far as I can see from fs/buffer.c, an hole is a buffer_head which is
not mapped, but uptodate. But I cannot find a relevant source line,
where ext2 makes usage of this information.
Any hints would be greatly appreciated,
Lars.
[Please CC me on answers, I'm not subscribed]
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: How does ext2 implement sparse files?
2008-01-31 15:28 How does ext2 implement sparse files? Lars Noschinski
@ 2008-01-31 16:51 ` Lennart Sorensen
2008-01-31 17:18 ` Chris Snook
2008-01-31 18:14 ` Andi Kleen
2 siblings, 0 replies; 7+ messages in thread
From: Lennart Sorensen @ 2008-01-31 16:51 UTC (permalink / raw)
To: Lars Noschinski; +Cc: linux-kernel
On Thu, Jan 31, 2008 at 04:28:23PM +0100, Lars Noschinski wrote:
> For an university project, we had to write a toy filesystem (ext2-like),
> for which I would like to implement sparse file support. For this, I
> digged through the ext2 source code; but I could not find the point,
> where ext2 detects holes.
>
> As far as I can see from fs/buffer.c, an hole is a buffer_head which is
> not mapped, but uptodate. But I cannot find a relevant source line,
> where ext2 makes usage of this information.
>
> Any hints would be greatly appreciated,
While I don't actually know, I always thought it was up to the
application to create files with holes by seeking over the holes before
writing data. That seems like the simplest way to me.
--
Len Sorensen
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How does ext2 implement sparse files?
2008-01-31 15:28 How does ext2 implement sparse files? Lars Noschinski
2008-01-31 16:51 ` Lennart Sorensen
@ 2008-01-31 17:18 ` Chris Snook
2008-01-31 18:14 ` Andi Kleen
2 siblings, 0 replies; 7+ messages in thread
From: Chris Snook @ 2008-01-31 17:18 UTC (permalink / raw)
To: Lars Noschinski; +Cc: linux-kernel
Lars Noschinski wrote:
>
> Hello!
>
> For an university project, we had to write a toy filesystem (ext2-like),
> for which I would like to implement sparse file support. For this, I
> digged through the ext2 source code; but I could not find the point,
> where ext2 detects holes.
>
> As far as I can see from fs/buffer.c, an hole is a buffer_head which is
> not mapped, but uptodate. But I cannot find a relevant source line,
> where ext2 makes usage of this information.
In ext2 (and most other block filesystems) all files are sparse files.
If you write to an address in the file for which no block is allocated,
the filesystem allocates a block and writes the contents to disk,
regardless of whether that block is at the end of the file (the usual
case of lengthening a non-sparse file), in the middle of the file
(filling in holes in a sparse file), or past the the end of the file
(making a file sparse).
-- Chris
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How does ext2 implement sparse files?
2008-01-31 15:28 How does ext2 implement sparse files? Lars Noschinski
2008-01-31 16:51 ` Lennart Sorensen
2008-01-31 17:18 ` Chris Snook
@ 2008-01-31 18:14 ` Andi Kleen
2008-02-01 10:34 ` Shuduo Sang
2008-02-01 11:55 ` Lars Noschinski
2 siblings, 2 replies; 7+ messages in thread
From: Andi Kleen @ 2008-01-31 18:14 UTC (permalink / raw)
To: Lars Noschinski; +Cc: linux-kernel
Lars Noschinski <lklml@ml.noschinski.de> writes:
> For an university project, we had to write a toy filesystem (ext2-like),
> for which I would like to implement sparse file support. For this, I
> digged through the ext2 source code; but I could not find the point,
> where ext2 detects holes.
>
> As far as I can see from fs/buffer.c, an hole is a buffer_head which is
> not mapped, but uptodate. But I cannot find a relevant source line,
> where ext2 makes usage of this information.
It does not explicitely detect holes; holey data is just never written
so no space for it is allocated.
-Andi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How does ext2 implement sparse files?
2008-01-31 18:14 ` Andi Kleen
@ 2008-02-01 10:34 ` Shuduo Sang
2008-02-01 11:08 ` Eric Dumazet
2008-02-01 11:55 ` Lars Noschinski
1 sibling, 1 reply; 7+ messages in thread
From: Shuduo Sang @ 2008-02-01 10:34 UTC (permalink / raw)
To: Andi Kleen; +Cc: Lars Noschinski, linux-kernel
On Feb 1, 2008 2:14 AM, Andi Kleen <andi@firstfloor.org> wrote:
> Lars Noschinski <lklml@ml.noschinski.de> writes:
>
> > For an university project, we had to write a toy filesystem (ext2-like),
> > for which I would like to implement sparse file support. For this, I
> > digged through the ext2 source code; but I could not find the point,
> > where ext2 detects holes.
> >
> > As far as I can see from fs/buffer.c, an hole is a buffer_head which is
> > not mapped, but uptodate. But I cannot find a relevant source line,
> > where ext2 makes usage of this information.
>
> It does not explicitely detect holes; holey data is just never written
> so no space for it is allocated.
>
does anybody know how to make a hole in a large file which already has
real content from user space application?
In my project I need this function to delete a piece of content from
an exist large effectively.
thanks.
> -Andi
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How does ext2 implement sparse files?
2008-02-01 10:34 ` Shuduo Sang
@ 2008-02-01 11:08 ` Eric Dumazet
0 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2008-02-01 11:08 UTC (permalink / raw)
To: Shuduo Sang; +Cc: Andi Kleen, Lars Noschinski, linux-kernel
Shuduo Sang a écrit :
> On Feb 1, 2008 2:14 AM, Andi Kleen <andi@firstfloor.org> wrote:
>
>> Lars Noschinski <lklml@ml.noschinski.de> writes:
>>
>>
>>> For an university project, we had to write a toy filesystem (ext2-like),
>>> for which I would like to implement sparse file support. For this, I
>>> digged through the ext2 source code; but I could not find the point,
>>> where ext2 detects holes.
>>>
>>> As far as I can see from fs/buffer.c, an hole is a buffer_head which is
>>> not mapped, but uptodate. But I cannot find a relevant source line,
>>> where ext2 makes usage of this information.
>>>
>> It does not explicitely detect holes; holey data is just never written
>> so no space for it is allocated.
>>
>>
>
> does anybody know how to make a hole in a large file which already has
> real content from user space application?
> In my project I need this function to delete a piece of content from
> an exist large effectively.
> thanks.
>
>
Some OSes use fcntl() F_FREESP/F_FREESP64 to be able to free allocated
space in files (ie make holes if supported by underlying fs)
AFAIK, linux can generically do this only at the end of a file
(ftruncate()) , not at random points.
XFS has special support for FREESP (it comes from IRIX), implemented as
an ioctl()
Check for XFS_IOC_FREESP and XFS_IOC_UNRESVSP in fs/xfs/xfs_fs.h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How does ext2 implement sparse files?
2008-01-31 18:14 ` Andi Kleen
2008-02-01 10:34 ` Shuduo Sang
@ 2008-02-01 11:55 ` Lars Noschinski
1 sibling, 0 replies; 7+ messages in thread
From: Lars Noschinski @ 2008-02-01 11:55 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel
[Sorry for using an invalid mail address in my previous post]
* Andi Kleen <andi@firstfloor.org> [08-02-01 10:28]:
>Lars Noschinski <lklml@ml.noschinski.de> writes:
>
>> For an university project, we had to write a toy filesystem (ext2-like),
>> for which I would like to implement sparse file support. For this, I
>> digged through the ext2 source code; but I could not find the point,
>> where ext2 detects holes.
>>
>> As far as I can see from fs/buffer.c, an hole is a buffer_head which is
>> not mapped, but uptodate. But I cannot find a relevant source line,
>> where ext2 makes usage of this information.
>
>It does not explicitely detect holes; holey data is just never written
>so no space for it is allocated.
Thanks for the answers. No that I know that, it is kind of obvious. I
was irritated yesterday by a bug a bug in our implementation (number of
used blocks is reported as filesize/blocksize); so I was expecting the
VFS to issue write requests for empty pages (which would be sillly, I
know).
Thanks,
Lars.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-02-01 12:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-31 15:28 How does ext2 implement sparse files? Lars Noschinski
2008-01-31 16:51 ` Lennart Sorensen
2008-01-31 17:18 ` Chris Snook
2008-01-31 18:14 ` Andi Kleen
2008-02-01 10:34 ` Shuduo Sang
2008-02-01 11:08 ` Eric Dumazet
2008-02-01 11:55 ` Lars Noschinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox