Help!

rm file

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> System Development RSS
Next:  Allocation of threads on a dual CPU system?  
Author Message
harsha.kgp
External


Since: Jul 10, 2007
Posts: 2



PostPosted: Tue Jul 31, 2007 9:16 pm    Post subject: rm file
Archived from groups: comp>os>linux>development>system (more info?)

Hi,
when we do 'rm file' in linux, does it need a 'struct file'. I saw
with strace that rm calls sys_access before sys_unlink. I was
wondering if sys_access needs a struct file and if so when was the
struct file created and initialized?

thanks
harsha
Back to top
Paul Pluzhnikov
External


Since: Nov 07, 2004
Posts: 355



PostPosted: Tue Jul 31, 2007 10:23 pm    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

harsha.kgp RemoveThis @gmail.com writes:

> when we do 'rm file' in linux, does it need a 'struct file'.

No. I think you do not understand the distinction between the user
mode (in which 'rm' runs) and kernel mode (in which sys_unlink()
executes, and which knows what 'struct file' is).

> I saw
> with strace that rm calls sys_access before sys_unlink.

Probably so it can print a reasonable error message if "file"
is actually a directory.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Back to top
David Schwartz
External


Since: Jun 01, 2007
Posts: 87



PostPosted: Wed Aug 01, 2007 2:06 am    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Jul 31, 2:16 pm, harsha.... RemoveThis @gmail.com wrote:

> when we do 'rm file' in linux, does it need a 'struct file'.

I can't understand what this question is asking.

> I saw
> with strace that rm calls sys_access before sys_unlink. I was
> wondering if sys_access needs a struct file and if so when was the
> struct file created and initialized?

Again, it's very hard to understand what you're asking. Are you asking
what the 'sys_access' function does in the Linux kernel? If so, why
not just look at the source code? If you're asking something about
what happens in user space, what exactly are you asking?

DS
Back to top
Anand Kumar
External


Since: Aug 01, 2007
Posts: 1



PostPosted: Wed Aug 01, 2007 2:40 am    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Aug 1, 2:06 pm, David Schwartz <dav... RemoveThis @webmaster.com> wrote:
> On Jul 31, 2:16 pm, harsha.... RemoveThis @gmail.com wrote:
>
> > when we do 'rm file' in linux, does it need a 'struct file'.
>
> I can't understand what this question is asking.
>
> > I saw
> > with strace that rm calls sys_access before sys_unlink. I was
> > wondering if sys_access needs a struct file and if so when was the
> > struct file created and initialized?
>
> Again, it's very hard to understand what you're asking. Are you asking
> what the 'sys_access' function does in the Linux kernel? If so, why
> not just look at the source code? If you're asking something about
> what happens in user space, what exactly are you asking?
>
> DS

"struct file" is the data structure in the file system, initiated by
kernel and will be used only in kernel mode. So Assume that if you
have file system, "struct file" should & will be there. Any operation
on file system uses "struct file".
Back to top
ellis
External


Since: Apr 02, 2004
Posts: 193



PostPosted: Wed Aug 01, 2007 7:01 am    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1185916596.859882.63150.DeleteThis@j4g2000prf.googlegroups.com>,
<harsha.kgp.DeleteThis@gmail.com> wrote:

>when we do 'rm file' in linux, does it need a 'struct file'.

man unlink

--
http://www.spinics.net/lists/
Back to top
Josef Moellers
External


Since: Jul 07, 2005
Posts: 389



PostPosted: Wed Aug 01, 2007 8:56 am    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Paul Pluzhnikov wrote:
> harsha.kgp.TakeThisOut@gmail.com writes:

>>I saw
>>with strace that rm calls sys_access before sys_unlink.
>
>
> Probably so it can print a reasonable error message if "file"
> is actually a directory.

More likely to print the error message
"rm: remove write-protected regular file `xyz'?"

If "rm" tried to unlink() a directory, that would return EISDIR, so
there's no need to call access() before, but you can unlink() a file
with 000 permissions.

Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
Back to top
phil-news-nospam
External


Since: Nov 16, 2006
Posts: 329



PostPosted: Wed Aug 01, 2007 12:46 pm    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 01 Aug 2007 08:56:03 +0200 Josef Moellers <josef.moellers RemoveThis @fujitsu-siemens.com> wrote:
| Paul Pluzhnikov wrote:
|> harsha.kgp RemoveThis @gmail.com writes:
|
|>>I saw
|>>with strace that rm calls sys_access before sys_unlink.
|>
|>
|> Probably so it can print a reasonable error message if "file"
|> is actually a directory.
|
| More likely to print the error message
| "rm: remove write-protected regular file `xyz'?"
|
| If "rm" tried to unlink() a directory, that would return EISDIR, so
| there's no need to call access() before, but you can unlink() a file
| with 000 permissions.

How often do people that originally intended to delete a file change their
mind once they are informed that it is a write-protected file? If you
want to set the file so it cannot be deleted, put it in a write-protected
directory.

IMHO, adding the extra access() call in rm is a waste. But as long as it
is avoided with -f then I guess it's really OK (I can default it to -f with
a script).

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2007-08-01-0743 RemoveThis @ipal.net |
|------------------------------------/-------------------------------------|
Back to top
phil-news-nospam
External


Since: Nov 16, 2006
Posts: 329



PostPosted: Wed Aug 01, 2007 12:50 pm    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 31 Jul 2007 21:16:36 -0000 harsha.kgp.DeleteThis@gmail.com wrote:

| when we do 'rm file' in linux, does it need a 'struct file'. I saw
| with strace that rm calls sys_access before sys_unlink. I was
| wondering if sys_access needs a struct file and if so when was the
| struct file created and initialized?

File deletion is really a process of removing a named link to the file from
the directory that name is in. It is a modification of the directory, not
of the file ... until the number of links to the file becomes zero (which
is going to happen with that unlink for most files because most have just
that one link).

Calling access before unlink is a kind of "fool proofing" facility, so
that fools won't be removing files they may have intended to keep. We
have too many fools being allowed near computers, so we have all these
foolproofing mechanism to slow down the work done by the rest of us.

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2007-08-01-0746.DeleteThis@ipal.net |
|------------------------------------/-------------------------------------|
Back to top
Josef Moellers
External


Since: Jul 07, 2005
Posts: 389



PostPosted: Wed Aug 01, 2007 4:26 pm    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

phil-news-nospam.DeleteThis@ipal.net wrote:

> How often do people that originally intended to delete a file change their
> mind once they are informed that it is a write-protected file? If you
> want to set the file so it cannot be deleted, put it in a write-protected
> directory.

Personally, I group files by subject, not by "deletable/non-deletable",
so being able to keep files by making them non-writable sounds a good
idea to me.

Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
Back to top
phil-news-nospam
External


Since: Nov 16, 2006
Posts: 329



PostPosted: Wed Aug 01, 2007 4:27 pm    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 01 Aug 2007 16:26:39 +0200 Josef Moellers <josef.moellers RemoveThis @fujitsu-siemens.com> wrote:

| phil-news-nospam RemoveThis @ipal.net wrote:
|
|> How often do people that originally intended to delete a file change their
|> mind once they are informed that it is a write-protected file? If you
|> want to set the file so it cannot be deleted, put it in a write-protected
|> directory.
|
| Personally, I group files by subject, not by "deletable/non-deletable",
| so being able to keep files by making them non-writable sounds a good
| idea to me.

That's not what the bit is for. Unfortunately, there is no bit for that
purpose, so the no write bit gets confusingly overloaded. So maybe we
need such a bit?

One option is to make an extra link for files you want to be sure you keep.
That link would be in another directory named to indicate it is for files
to be kept. And that directory can be made non-writeable to avoid trivial
deletes or adds.

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2007-08-01-1125 RemoveThis @ipal.net |
|------------------------------------/-------------------------------------|
Back to top
Josef Moellers
External


Since: Jul 07, 2005
Posts: 389



PostPosted: Thu Aug 02, 2007 9:07 am    Post subject: Re: rm file [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

phil-news-nospam.RemoveThis@ipal.net wrote:
> On Wed, 01 Aug 2007 16:26:39 +0200 Josef Moellers <josef.moellers.RemoveThis@fujitsu-siemens.com> wrote:
>
> | phil-news-nospam.RemoveThis@ipal.net wrote:
> |
> |> How often do people that originally intended to delete a file change their
> |> mind once they are informed that it is a write-protected file? If you
> |> want to set the file so it cannot be deleted, put it in a write-protected
> |> directory.
> |
> | Personally, I group files by subject, not by "deletable/non-deletable",
> | so being able to keep files by making them non-writable sounds a good
> | idea to me.
>
> That's not what the bit is for. Unfortunately, there is no bit for that
> purpose, so the no write bit gets confusingly overloaded. So maybe we
> need such a bit?

With more recent filesystems, the "immutable" bit seems to be adequate.
OTOH I have no problem with makeing unorthodox use of standard features.
(In the old days, people would write papers about using lex to find
errors in printed circuits Wink

> One option is to make an extra link for files you want to be sure you keep.
> That link would be in another directory named to indicate it is for files
> to be kept. And that directory can be made non-writeable to avoid trivial
> deletes or adds.

TMTOWTDI,

Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> System Development All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum