Filesystem funcs and du do not seem to match

Linux specific forum
mdp
Enthusiast
Enthusiast
Posts: 115
Joined: Mon Apr 18, 2005 8:28 pm

Filesystem funcs and du do not seem to match

Post by mdp »

Can anybody explain why the PB filesystem funcs and the "du" command do not return the same values?

A procedure:

Code: Select all

Procedure GetFolderSize( dir.s )
   dh=ExamineDirectory(#PB_Any,dir,"*") : If dh
      While NextDirectoryEntry(dh)
         nm.s=DirectoryEntryName(dh) 
         If DirectoryEntryType(dh)=#PB_DirectoryEntry_Directory
            If nm<>"." And nm<>".." 
               sz=sz+GetFolderSize(dir+"/"+nm) : Debug dir+"/"+nm+" "+Str(sz) 
            EndIf
         Else
            sz=sz+DirectoryEntrySize(dh)
         EndIf
       Wend  
      If IsDirectory(dh) : FinishDirectory(dh) : EndIf
   Else
      ;PrintN("No dir!")
   EndIf
   ProcedureReturn sz
EndProcedure

Debug GetFolderSize("/home")
does not return the same as

Code: Select all

du -b
Examples:
checking the purebasic folder size returns 22643082 with the above function, 23118218 with du
[...]/purebasic/examples/sources/data should be 875469 for the above, 879565 for du
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

du prints "estimated file space usage". I think it includes space for the directory table entries for the files as well.
"du -b" in an empty directory prints 4096 for example.

The DirectoryEntrySize() output matches what "ll" prints for the individual files, so it should be correct.
quidquid Latine dictum sit altum videtur
Post Reply