Try to create non fragmented files on copy/move

Here you can propose new features, make suggestions etc.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
maxB
Junior Member
Junior Member
Posts: 2
Joined: 2007-11-04, 13:57 UTC

Try to create non fragmented files on copy/move

Post by *maxB »

Hi Christian,

I noticed that TC creates fragmented files when copying or moving files.
In the article "Fix verteilt" from the heise magazin "c't" 21/2005 about fragmentation they suggested to use the Windows-API-Functions SetFilePointer() and SetEndOfFile() like in this Delphi 7 sample:
(only tested on NTFS from Win XP)

Code: Select all

var dstHandle: Integer;
    srcname, dstname: string;
    filesize: Int64;
    li: LARGE_INTEGER;
    success: longbool;
    sr   : TSearchRec;
begin
  // get size of source file
  srcname:='c:\1.bin';
  if FindFirst(srcname, faAnyFile, sr)=0 then
      filesize:=Int64(sr.FindData.nFileSizeHigh * 4294967295) + Int64(sr.FindData.nFileSizeLow);
  FindClose(sr);

  // open destination file
  dstname:='c:\2.bin';
  dstHandle:=FileCreate(dstname);

  li.QuadPart:=filesize;

  // set filepointer to size of source file
  if (SetFilePointer(Cardinal(dstHandle), li.LowPart, @li.HighPart, FILE_BEGIN) <> -1) then
      // set the end of the destination file so that the
      // filesystem knows how long the file will be
      success:=SetEndOfFile(Cardinal(dstHandle))
  else
      success:=FALSE;

  // set back the filepointer to start of destination file
  SetFilePointer(Cardinal(dstHandle), 0, nil, FILE_BEGIN);

  // file-operation...

  FileClose(dstHandle);
end;
If there is enough free space on disk, this will work in most cases. Nevermind if not, the handle is always there.

Maybe in future versions...

Greets and thanks for this great piece of software.

maxB
Last edited by maxB on 2007-11-05, 07:48 UTC, edited 2 times in total.
gigaman
Member
Member
Posts: 134
Joined: 2003-02-14, 11:28 UTC

Post by *gigaman »

If this really works (didn't try), I'd say it's a good idea.
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

That sounds like the solution to most fragmentation problems.
Would be great, if this works.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50475
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Total Commander already does EXACTLY that! I do not see any fragmentation from TC, except when the disk is already so much fragmented that the file cannot be allocated in one chunk...
Author of Total Commander
https://www.ghisler.com
maxB
Junior Member
Junior Member
Posts: 2
Joined: 2007-11-04, 13:57 UTC

Post by *maxB »

Oh, I'm sorry, I took a look again and saw that directories were fragmented after the kopy/move. Didn't want to be precocious...so nevermind
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

Nice to know that. :)
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50475
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Unfortunately directories cannot be preallocated like files - or does anyone know a way to do that?
Author of Total Commander
https://www.ghisler.com
Post Reply