FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > EXT3 Users

 
 
LinkBack Thread Tools
 
Old 01-03-2008, 09:30 AM
"Fasihullah Askiri"
 
Default read() on a deleted file

Hi all

I have a doubt regarding the behaviour of read() on an ext3
filesystem. To elucidate my doubts, I wrote a small program opens a
file and reads one byte at a time and sleeps for a while. I deleted
the file while the read was still in progress and I noticed that the
read still succeeds. How does this work? Does the kernel not free the
inode when the file is deleted but there is a pending read? To check
this, instead of deleting, I tried shred-ding the file, the read still
gets the correct data.

My questions:
- Where does the kernel get the data from?
- Is this a documented feature which I can use?
- Does shred write the file inode with junk?

Thanks for your patience
--
Keep Running.... And Relish the run...
+Fasih

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-03-2008, 09:49 AM
Alex Bligh
 
Default read() on a deleted file

--On 3 January 2008 16:00:22 +0530 Fasihullah Askiri
<fasihullah.askiri@gmail.com> wrote:



I have a doubt regarding the behaviour of read() on an ext3
filesystem. To elucidate my doubts, I wrote a small program opens a
file and reads one byte at a time and sleeps for a while. I deleted
the file while the read was still in progress and I noticed that the
read still succeeds. How does this work? Does the kernel not free the
inode when the file is deleted but there is a pending read? To check
this, instead of deleting, I tried shred-ding the file, the read still
gets the correct data.


That's standard UNIX behaviour. The file exists on disk until all
references to it have disappeared (references including the open
file handle). All you do by typing "rm" is delete a reference/link to
it from a particular directory, not (necessarily) delete the file.
That's why the system call is called "unlink".

Alex

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-03-2008, 10:12 AM
"Fasihullah Askiri"
 
Default read() on a deleted file

Thanx for the response. That is why I tried shred-ding the file. I
believe that shred overwrites the file inode, if so, shred should have
led to failures of read() which is not the case. How does that happen?


On Jan 3, 2008 4:19 PM, Alex Bligh <alex@alex.org.uk> wrote:
>
>
> --On 3 January 2008 16:00:22 +0530 Fasihullah Askiri
> <fasihullah.askiri@gmail.com> wrote:
>
> > I have a doubt regarding the behaviour of read() on an ext3
> > filesystem. To elucidate my doubts, I wrote a small program opens a
> > file and reads one byte at a time and sleeps for a while. I deleted
> > the file while the read was still in progress and I noticed that the
> > read still succeeds. How does this work? Does the kernel not free the
> > inode when the file is deleted but there is a pending read? To check
> > this, instead of deleting, I tried shred-ding the file, the read still
> > gets the correct data.
>
> That's standard UNIX behaviour. The file exists on disk until all
> references to it have disappeared (references including the open
> file handle). All you do by typing "rm" is delete a reference/link to
> it from a particular directory, not (necessarily) delete the file.
> That's why the system call is called "unlink".
>
> Alex
>



--
Keep Running.... And Relish the run...
+Fasih

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-03-2008, 10:31 AM
Alex Bligh
 
Default read() on a deleted file

--On 3 January 2008 16:42:40 +0530 Fasihullah Askiri
<fasihullah.askiri@gmail.com> wrote:



Thanx for the response. That is why I tried shred-ding the file. I
believe that shred overwrites the file inode, if so, shred should have
led to failures of read() which is not the case. How does that happen?


Buffering / caching of reads.

Alex

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-03-2008, 11:05 AM
"Fasihullah Askiri"
 
Default read() on a deleted file

What I meant was, instead of deleting, I tried shredding the file. The
result was still consistent reads. However, after the mail from Alex,
I increased the filesize to see how much does it cache. Turns out on
my system, the read starts returning junk data [that written by shred]
after reading 1040 bytes correctly.

This is what I understand now, if I delete the file, the kernel
guarantees that the file data is preserved till the last reference (in
the form of an open filehandle maybe) lingers. If I shred the file,
the read succeeds till the buffering is done.

This, however sounds wierd to me, what we are essentially saying is
that the open/read might not return the latest data!!!! AFAIK the
buffer cache/inode cache that the kernel maintains is refreshed as
soon the file is modified. Please clarify.

Thanks again for the responses.



On Jan 3, 2008 6:16 PM, Hayim Shaul <hayim@iportent.com> wrote:
> On Thu, 2008-01-03 at 16:42 +0530, Fasihullah Askiri wrote:
> > Thanx for the response. That is why I tried shred-ding the file. I
> > believe that shred overwrites the file inode, if so, shred should have
> > led to failures of read() which is not the case. How does that happen?
> >
>
> What do you mean by re-writing?
> Do you mean opening a new file with the same name and writing into it?
>
> i don't think the new file (necessarily) gets the same inode as the file
> you deleted.
> More specifically, while the inode of the "deleted" file still exists,
> the new inode would most likely to be different.
>
>



--
Keep Running.... And Relish the run...
+Fasih

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-03-2008, 11:46 AM
Hayim Shaul
 
Default read() on a deleted file

On Thu, 2008-01-03 at 16:42 +0530, Fasihullah Askiri wrote:
> Thanx for the response. That is why I tried shred-ding the file. I
> believe that shred overwrites the file inode, if so, shred should have
> led to failures of read() which is not the case. How does that happen?
>

What do you mean by re-writing?
Do you mean opening a new file with the same name and writing into it?

i don't think the new file (necessarily) gets the same inode as the file
you deleted.
More specifically, while the inode of the "deleted" file still exists,
the new inode would most likely to be different.

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-03-2008, 07:45 PM
"David Schwartz"
 
Default read() on a deleted file

> This is what I understand now, if I delete the file, the kernel
> guarantees that the file data is preserved till the last reference (in
> the form of an open filehandle maybe) lingers. If I shred the file,
> the read succeeds till the buffering is done.

Actually, you can't delete a file while there are references to it. You can
remove it from its directory, which reduces the reference count by one, but
that's it. That's why the system call in UNIX is called "unlink" rather than
"delete".

A file is automatically deleted when its reference count goes to zero.
Putting a file in a directory adds one to its reference count. Opening a
file adds one.

> This, however sounds wierd to me, what we are essentially saying is
> that the open/read might not return the latest data!!!! AFAIK the
> buffer cache/inode cache that the kernel maintains is refreshed as
> soon the file is modified. Please clarify.

It's impossible to clarify unless you tell us more precisely what you are
doing. For example, you use the term "shred", but that can mean way more
than one thing. Also, when you talk about "reading" a file, that could mean
the "read" system call, but it could also mean the "fread" library function.

DS


_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-04-2008, 05:08 AM
"Fasihullah Askiri"
 
Default read() on a deleted file

Hi

Sorry for the confusion caused. I just realized that I was using fread
and not read. By "shred", I meant the /usr/bin/shred program which
overwrites a file with junk. I was getting stale result because of the
buffering at fread.

Thanks again for the responses.

On Jan 4, 2008 2:15 AM, David Schwartz <davids@webmaster.com> wrote:
>
> > This is what I understand now, if I delete the file, the kernel
> > guarantees that the file data is preserved till the last reference (in
> > the form of an open filehandle maybe) lingers. If I shred the file,
> > the read succeeds till the buffering is done.
>
> Actually, you can't delete a file while there are references to it. You can
> remove it from its directory, which reduces the reference count by one, but
> that's it. That's why the system call in UNIX is called "unlink" rather than
> "delete".
>
> A file is automatically deleted when its reference count goes to zero.
> Putting a file in a directory adds one to its reference count. Opening a
> file adds one.
>
> > This, however sounds wierd to me, what we are essentially saying is
> > that the open/read might not return the latest data!!!! AFAIK the
> > buffer cache/inode cache that the kernel maintains is refreshed as
> > soon the file is modified. Please clarify.
>
> It's impossible to clarify unless you tell us more precisely what you are
> doing. For example, you use the term "shred", but that can mean way more
> than one thing. Also, when you talk about "reading" a file, that could mean
> the "read" system call, but it could also mean the "fread" library function.
>
> DS
>
>
>



--
Keep Running.... And Relish the run...
+Fasih

_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 
Old 01-07-2008, 09:56 PM
"Stephen Samuel"
 
Default read() on a deleted file

Most likely??!
Until you delete all links and* close all open file descriptors and the Inode is deallocated, you are GUARANTEED to get a different inode if you create a new file (of any name).


On Jan 3, 2008 4:46 AM, Hayim Shaul <hayim@iportent.com> wrote:

On Thu, 2008-01-03 at 16:42 +0530, Fasihullah Askiri wrote:
> Thanx for the response. That is why I tried shred-ding the file. I
> believe that shred overwrites the file inode, if so, shred should have

> led to failures of read() which is not the case. How does that happen?
>

What do you mean by re-writing?
Do you mean opening a new file with the same name and writing into it?

i don't think the new file (necessarily) gets the same inode as the file

you deleted.
More specifically, while the inode of the "deleted" file still exists,
the new inode would most likely to be different.



--
Stephen Samuel
http://www.bcgreen.com
778-861-7641
_______________________________________________
Ext3-users mailing list
Ext3-users@redhat.com
https://www.redhat.com/mailman/listinfo/ext3-users
 

Thread Tools




All times are GMT. The time now is 12:11 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org