public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* delete file entry and free space
@ 2002-05-18 22:56 Anthony Chee
  2002-05-19  0:41 ` Matthew Wilcox
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Chee @ 2002-05-18 22:56 UTC (permalink / raw)
  To: linux-fsdevel

I am doing kernel module work on file system. The module holds two variable
dir and dentry, and pass to myunlink function, which is below.

int myunlink(struct inode *dir, struct dentry *dentry) {

    int error = 0;

 down(&dir->i_sem);
 down(&dir->i_zombie);

 if (dir->i_op && dir->i_op->unlink) {
  if (d_mountpoint(dentry))
   error = -EBUSY;
  else {
   lock_kernel();
   error = dir->i_op->unlink(dir, dentry);
   unlock_kernel();

   if (!error) {
    d_delete(dentry);
   }
  }
 }

 up(&dir->i_zombie);
 if (!error)
  inode_dir_notify(dir, DN_DELETE);

 dput(dentry);
 up(&dir->i_sem);
 return error;
 }

The myunlink function is a merge from sys_unlink() and vfs_unlink(), and
remove some permission and quota syntax, as I need to force to delete the
entry. After passing the variables to the function, the entry is disappeared
while using "ls", but I found that it still occupy disk space by using
command "df". How can I also free the disk space. My target is on releasing
the disk space, and I don't care any permission or others. Or any other
method on releasing the disk space by using dir and dentry? Thanks.



^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: delete file entry and free space
@ 2002-05-20 23:28 Bryan Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Bryan Henderson @ 2002-05-20 23:28 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Anthony Chee, linux-fsdevel


>> How can I know any process reference to the file, and does it reflect in
>> dentry structure? Is it dentry->d_count?
>
>it's dentry->d_inode->i_nlink.

Not exactly.  The answer to this question is dentry->d_inode->i_count.  The
number of references by processes to the inode (of course each of these
references could be a summary of multiple sub-references).  The i_nlink
field tells how many directory entries refer to the file.  Both have to be
zero before the file can be deleted.

It's worth explaining here what we can't explain too often in the Unix
world:  There is no system call, and consequently no shell command, to
delete a file.  The system automatically deletes a file as soon as it
becomes impossible for anyone ever to access the file again, and not
before.  The unlink() system call, like the Rm program that is based on it,
removes a link to the file (a directory entry that refers to it).  That
gets the file closer to that condition where it can never be accessed
again, but that's all.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-05-20 23:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-18 22:56 delete file entry and free space Anthony Chee
2002-05-19  0:41 ` Matthew Wilcox
2002-05-19 12:25   ` Anthony Chee
2002-05-19 14:47     ` Matthew Wilcox
  -- strict thread matches above, loose matches on Subject: below --
2002-05-20 23:28 Bryan Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox