FAQ SearchLogin
Tuxera Home
View unanswered posts | View active topics It is currently Wed Jun 16, 2021 00:46



Post new topic Reply to topic  [ 9 posts ] 
question about deleting non empty directory 
Author Message

Joined: Wed Nov 23, 2011 09:11
Posts: 35
Post question about deleting non empty directory
Hi Jean,

I am trying to porting NTFS-3G to my ucos platform, and I drop fuse completely.
But now I meet a problem when deleting non empty directory.

As my understanding, the original design of deleting non empty directory on Linux is:
step 1: return non empty dir to fuse demon
step 2: fuse demon submit readdir request to ntfs-3g
step 3: delete files in the directory one by one
step 4: delete the directory (become empty after deleting all the files in it)

At the beginning, I use ntfs_fuse_rm to delete the non empty dir, and return ENOTEMPTY, because the link_count is 1 in ntfs_check_unlinkable_dir.
I tried to walk around the limitation, the mft record of the dir is delete, but the free space is not increased because the bitmap is not cleared.

Can you give me some advice? Now I have no idea about how to realize the delete function.
Thanks.

Best regards,
Ryan


Thu Feb 02, 2012 09:21
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: question about deleting non empty directory
Hi,

Quote:
At the beginning, I use ntfs_fuse_rm to delete the non empty dir, and return ENOTEMPTY, because the link_count is 1 in ntfs_check_unlinkable_dir.

Well, the link count is only checked after the directory has been checked as non-empty (its index size is longer than a void index). The test for link count is there only to accept deleting directories which have several names, which is a condition which should only exist as a transient state while renaming a directory. This test makes it possible to delete an extra name caused by a power failure during a renaming.

** edit **

The test is also needed, while doing a normal rename, to allow the deletion of the old name after the new name has been inserted.

Regards

Jean-Pierre


Thu Feb 02, 2012 12:02
Profile

Joined: Wed Nov 23, 2011 09:11
Posts: 35
Post Re: question about deleting non empty directory
Thanks, Jean.
I understand what you mean.

What's your suggestion for my case, deleting non empty directory and not use FUSE functions?


Fri Feb 03, 2012 03:29
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: question about deleting non empty directory
Hi,

Quote:
What's your suggestion for my case, deleting non empty directory and not use FUSE functions?

Better find why the directory is found non-empty, and why its contents were not deleted in the first place.

Regards

Jean-Pierre


Fri Feb 03, 2012 09:20
Profile

Joined: Wed Nov 23, 2011 09:11
Posts: 35
Post Re: question about deleting non empty directory
Quote:
Better find why the directory is found non-empty, and why its contents were not deleted in the first place.


Thanks, Jean.
I did not say clearly enough and make myself understood.

I do not use the 4 steps to delete the "non empty dir", that is, I do not delete the files in the dir one by one at first.
So, the dir is definitely "not empty".

My purpose is:
Can I delete a "non empty dir" directly?
Or, I must have to delete the files in a "non empty dir" first and then I can delete the "empty dir".
The case is complex if the dir has deep level sub-dirs.

Best regards,
Ryan


Fri Feb 03, 2012 10:49
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: question about deleting non empty directory
Hi again,

Quote:
Can I delete a "non empty dir" directly?
Or, I must have to delete the files in a "non empty dir" first and then I can delete the "empty dir".

Well, if you force delete a non-empty directory, the files recorded in it will still be present and undeletable later (unless they have another name in another directory)... this is the space leak which you mentioned earlier.

Quote:
The case is complex if the dir has deep level sub-dirs.

Still hardly avoidable...

Regards

Jean-Pierre


Fri Feb 03, 2012 14:48
Profile

Joined: Wed Nov 23, 2011 09:11
Posts: 35
Post Re: question about deleting non empty directory
Thanks, Jean.


Mon Feb 06, 2012 03:27
Profile

Joined: Wed Nov 23, 2011 09:11
Posts: 35
Post Re: question about deleting non empty directory
Hi Jean,

I write the delete function as a recursive function base on my understanding, but I meet a problem when doing simulation on windows PC.
I create a directory called "test2", and copy some directories (also containing some files) and files in it.
I delete the "test2" directory for the 1st time, and from the output of visual studio, the file "/test2/asm-generic/param.h" is delete successfully.
But after the delete operation, I open the disk with winhex, and find the file "test2/asm-generic/param.h" still exist.
So, I delete the "test2" directory for the 2nd time, and the log shows the file "test2/asm-generic/param.h" really exist, and this time the file is really deleted.

I thought the phenomena may be caused by asynchronous I/O writing or buffering scheme or something else.
But, the code seems fine, because it uses the FILE_FLAG_NO_BUFFERING.
CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0);
and the write function used at last in win32_io.c is ntfs_device_win32_pio, for write operation, it called:
WriteFile(handle, b, count, &bt, NULL);

I check the functions in msdn, it seems that the code above should not caused the phenomena I mentioned.

What's your suggestion?
Thanks.

Best regards,
Ryan


Tue Feb 14, 2012 08:14
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: question about deleting non empty directory
Hi,

Quote:
I thought the phenomena may be caused by asynchronous I/O writing or buffering scheme or something else.

Probably something else...

Good luck.

Jean-Pierre


Tue Feb 14, 2012 22:13
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Original forum style by Vjacheslav Trushkin.