LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-01-2010, 08:36 AM   #1
labandus
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Rep: Reputation: 0
Removing gaps in directory in a Ext2 File system


Directories(-entries) are in a EXT2 file system
managed in a singly linked list.
Delete files in the directory causes Gaps or holes to appear in
the linked list of the directory.How does a C-source code look like,
which would reorganize this list and remove the gaps or Holes.

thank you very much for your help.
labandus
 
Old 11-02-2010, 03:16 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Rather than operate on the raw directory (there used to be a libext2fs library, not sure what state it is in), you could simply do the following, in your choice of language:

1. create a temporary directory
2. move all the contents of the original directory to the temporary directory, eg using rename
3. remove the original directory
4. rename the temporary directory back to the original name

This would be more portable (ie, it would work on filesystems other than ext2), and less likely to lead to filesystem corruption if you get it wrong.

I cannot think of many reasons you would want to do this, because spaces left by deleted filename entries are reused anyway.
 
Old 11-02-2010, 04:15 PM   #3
labandus
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Unhappy coding in C of the Gapsremover in Dir

In fact , i am a newbie in kernel coding.
i got this theme from my university but i can code it....

if somebody can code out the solution In C, i'll read it understand it very well.

we should code in C with low-level IO, testing it on an extern devices (USB...).

This is the plan i had to test it:

1- Mounting of the Usb-device
2- copy a bunch of files on it
3- delete some files to create some Gaps or "holes".
4- show the directory (ies) withour holes.

5- unmount the device
6- with the code removing the gaps of the Linked list
7- mount it again.
8- display the directory without the gaps.


thank you to all the coders out there to theirs solutions
 
Old 11-02-2010, 04:18 PM   #4
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Sounds like a homework question to me. Sorry if not, but if so then don't expect much help.
 
Old 11-02-2010, 04:28 PM   #5
labandus
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Original Poster
Rep: Reputation: 0
thank you

thank you...

you know i am just beginning in this .... everyone has already needed help one time or another....

if you feel, you were just born talented ... then please free not the contribute... but if you remember your humble beginnings in this... you will surely remembered how much you needed help because you didn't know nothing about the theme, homework or not.

thank you again for your support...

labandus

Last edited by labandus; 11-02-2010 at 04:29 PM.
 
0 members found this post helpful.
Old 11-02-2010, 04:46 PM   #6
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
There is no problem with asking for help but when people are giving up their time to offer that help it is nice if you at least make an attempt yourself first rather than asking for it on a plate. Perhaps try posting the code you have written so far and make your question more specific.

Anyway, I'll offer a little picture diagram that may help you :

Code:
NODE1 --> NODE2 --> NODE3 --> NODE4 --> NODE5
Let's say the definition of a node is as follows (simple example):

Code:
struct node {
  int value;
  struct node *next_node;
}
If you delete say NODE2 from the example then you need to change the next_node pointer of NODE2 to point to NODE4 rather than NODE3. So, when you are traversing the list to find the element to delete you either want to be looking one in front (so you can check whether the next element is the one you are interested in and then update the current element), or keep a pointer to the previous node (so if the current node is the one you are interested in, update the previous node with the pointer to the next node). Either method will work - you choose.

Your final list will then be:

Code:
NODE1 --> NODE2 --> NODE4 --> NODE5
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing File and Directory Paris Heng Linux - Newbie 5 02-20-2008 06:19 AM
Corrupted ext2 file system theunixwizard Linux - Software 4 02-18-2008 01:12 PM
about the ext2 file system chenxiaopang Linux - Kernel 0 11-25-2007 02:18 AM
ext2 file system information vipulc Linux - General 4 08-19-2006 07:48 AM
How to print out ext2 File System justmehere Linux - General 2 08-02-2005 08:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration