Intro Download and install Frequently Asked Questions Tips and tricks

Homepage







© J.C. Kessels 2009
MyDefrag Forum
May 21, 2013, 01:39:55 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: A few more things  (Read 4430 times)
Alask
JkDefrag Junior
**
Posts: 8


View Profile
« on: April 20, 2007, 06:33:34 am »

So I've finished the SWIG/Lua combination for JkDefrag, and while going through everything, I had a couple more questions.

1) You are sorting the tree every 1000 insertions. A constant 1000 insertions is inefficient, and it should be related to the depth of the last insertion. i.e. A perfect tree of size n should have m levels. The last insertion was at m*2 levels, so you need to sort.

Also, when you start sorting by directories, you will get sequential inserts, effectively forming a linked list instead of a tree, so you may need to take that into account.

At the moment 180455 items takes 0.094 seconds to sort on my 1.09Ghz Athlon. So I suppose worrying about this stuff is pointless.

2) I hate WCHAR, but thats just because Lua doesn't support them with SWIG at the moment, so not really an issue.

Now, for the implementation.

I added a Next and Prev pointer to ItemStruct, and filled them with the next file in the directory (So contiguous directories are a matter of starting at the Item that Prev=NULL and filling till Next=NULL)
Then I added the following items to Lua

Code:
#define NO     0
#define YES    1
#define MAXULONG64 18446744073709551615
#define RUNNING  0
#define STOPPING 1
#define STOPPED  2
void print( WCHAR *str);
void ShowDebug(int Level, struct ItemStruct *Item, char *Message);
struct ItemStruct *TreeSmallest(struct ItemStruct *Top);
struct ItemStruct *TreeBiggest(struct ItemStruct *Top);
struct ItemStruct *TreePrev(struct ItemStruct *Here);
struct ItemStruct *TreeNext(struct ItemStruct *Here);
int FindGap( struct DefragDataStruct *Data, ULONG64 MinimumLcn,ULONG64 MaximumLcn,ULONG64 MinimumSize,int MustFit,int FindHighestGap,unsigned long long *OUTPUT,unsigned long long *OUTPUT);
int young(struct ItemStruct *Item, ULONG64 time);
int MoveItem(
    struct DefragDataStruct *Data,
    struct ItemStruct *Item,
    ULONG64 NewLcn,                                   /* Where to move to. */
    ULONG64 Offset,                /* Number of first cluster to be moved. */
    ULONG64 Size,                       /* Number of clusters to be moved. */
    int Direction);
int IsFragmented(struct ItemStruct *Item, ULONG64 Offset, ULONG64 Size);
ULONG64 GetItemLcn(struct ItemStruct *Item);
struct ItemStruct *FindItemAtLcn(struct DefragDataStruct *Data, ULONG64 Lcn);
void TreeSort(struct DefragDataStruct *Data);
void OptimizeFreeSpace(struct DefragDataStruct *Data);
void OptimizeMFTzone(struct DefragDataStruct *Data);
void OptimizeDirectories(struct DefragDataStruct *Data);
void Defragment(struct DefragDataStruct *Data);
void FastFillOptimize(struct DefragDataStruct *Data);
void OptimizeVolume(struct DefragDataStruct *Data, int Mode);
void OptimizeUp(struct DefragDataStruct *Data); /*Mode = 3 is full optimise */

struct ItemStruct
struct FragmentListStruct
struct ExcludesStruct
struct DefragDataStruct


I'll post up some example code for it soon. If you can think of anything else that is needed tell me.

This is some example code

Code:

--script.lua
p = data.ItemTree;  --p is the Tree root
q=defrag.TreeSmallest(p);  --q is first item
a,b,e = defrag.FindGap(data, 0, 0, q.Clusters, 0, 0); --a is return (0 = NO, 1 = YES), b is gap start, e is gap end
x = os.clock()
defrag.TreeSort(data);
print(string.format("Elapsed time: %.9f\n", os.clock() - x));
print(data.CountAllFiles);




http://members.iinet.net.au/~harris/LuaDefrag.exe
Needs a script.lua
Call it as LuaDefrag C:
It runs analyze automatically (Cause it's faster in C), then passes Data to script and runs. All this from DefragOnePath. So if you call it with no arguments, it analyzes and runs script on each drive.[/url]

Edit:
This example prints each directory and it's contents in order. (Contents in order, directories not)

Code:
p = data.ItemTree;
q=defrag.TreeSmallest(p);
while q ~= nil do
if string.byte(q.Directory) == defrag.YES then
defrag.print(q.Path)
r = q.Next
while r ~= nil do
io.write("\n  ");
defrag.print(r.Path);
r = r.Next;
end
io.write("\n");
end
q = defrag.TreeNext(q);
end
Logged
Alask
JkDefrag Junior
**
Posts: 8


View Profile
« Reply #1 on: April 20, 2007, 10:02:09 am »

Ok, I've updated it, and it now sorts directories if there is enough room. (It will look for a gap big enough to fit the directory).

http://members.iinet.net.au/~harris/DEFRAG.zip

Need to add "priority files" to add to the front of the disk, and anti priority to move to the back of the disk. I haven't commented the script, but it it nicely formatted and should be pretty easy to pick up. I'll put up the source soon as I move out all of my hacks into another file.
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7155



View Profile WWW
« Reply #2 on: April 20, 2007, 08:38:18 pm »

Quote from: "Alask"

I have tried to take a look, but there seems to be an error in your ZIP file, I cannot unpack it.
Logged
Alask
JkDefrag Junior
**
Posts: 8


View Profile
« Reply #3 on: April 21, 2007, 06:38:27 am »

...Interesting? I uploaded from command prompt with ftp, maybe it has to be binary of ASCII, I never fully understood why the difference.

Hmm, it defaults to binary, but I needed to set it to binary anyway... Works now anyway.

I've made a heap of changes since that version, but it is an example of how it works. I'm trying to get it to work how I want it now.

When you started JkDefrag, you must have almost lost it, I don't even have to recompile each time and it's still driving me up the wall trying to get everything to go where I want it. The GUI version helps, but then I don't have a command line to tell me whats happening. I've just about got everything I want working just right, then I'll move it into functions, and post it all up.

All in all, it's been a learning experience.
Logged
Alask
JkDefrag Junior
**
Posts: 8


View Profile
« Reply #4 on: April 21, 2007, 04:04:06 pm »

Ok, I'm happy with it. A few things to note.

1) Added things to ItemStruct, and changed char to UINT8.
2) Added AddRootDirectory (Copied AddSystemDir, I need to add my root directory, and it didn't look like it did)
3) Made default mode a1 (Just analyze)

4) Added file.txt filter so you can set where things go, they are regexps. Still experimenting with how they should work.

I thinks thats it. It will try and make things contiguous, but needs enough space to fit the entire directory (It is too hard to make complex algorithms to work out which order to move the files, and something might allocate the space you were saving and mess it up anyway).

http://members.iinet.net.au/~harris/DEFRAG2.zip
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7155



View Profile WWW
« Reply #5 on: April 22, 2007, 01:05:45 pm »

I have taken a look at your code, very interesting! But the LUA parts are beyond me, I don't know that language and I cannot follow what you are doing. So I wish you all the best with your project, it looks like you're enjoying yourself!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!