statvfs angepasst als Modul und zur einfacheren verwendung.
This commit is contained in:
parent
c02d135541
commit
629a1515e7
1 changed files with 70 additions and 54 deletions
|
@ -1,4 +1,6 @@
|
||||||
; Module/File: System_FreeDiscSpace.pb
|
; Original:
|
||||||
|
; -------------------------------------------------------------
|
||||||
|
; Module/File: System_FreeDiscSpace.pb
|
||||||
; Function: Get free + used Drive-space from Directory - Linux
|
; Function: Get free + used Drive-space from Directory - Linux
|
||||||
; Author: remi_meier/uwekel (omi)
|
; Author: remi_meier/uwekel (omi)
|
||||||
; Date: Mar. 27, 2015
|
; Date: Mar. 27, 2015
|
||||||
|
@ -9,10 +11,31 @@
|
||||||
; Link to topic: http://www.purebasic.fr/german/viewtopic.php?f=21&t=22963
|
; Link to topic: http://www.purebasic.fr/german/viewtopic.php?f=21&t=22963
|
||||||
;--------------------------------------------------------------
|
;--------------------------------------------------------------
|
||||||
|
|
||||||
|
;**************************************
|
||||||
|
;*
|
||||||
|
;* Erweitert: und Umgestellt als Modul
|
||||||
|
;*
|
||||||
|
;* lhs_statvfs.pbi
|
||||||
|
;*
|
||||||
|
;* (c) by René Linder
|
||||||
|
;*
|
||||||
|
;* Lizenz LGPL V2.1 < TODO: Abklären ob Lizenz akzeptiert wird ...
|
||||||
|
;*
|
||||||
|
;* Getesteter Compiler PureBasic 5.70/5.71b2
|
||||||
|
;*
|
||||||
|
|
||||||
EnableExplicit
|
CompilerIf #PB_Compiler_OS <> #PB_OS_Linux
|
||||||
|
CompilerError "Dieses Modul ist nur für Linux"
|
||||||
|
CompilerEndIf
|
||||||
|
|
||||||
Structure Statvfs
|
DeclareModule statvfs
|
||||||
|
Declare Size(Path.s)
|
||||||
|
Declare Free(Path.s)
|
||||||
|
Declare Used(Path.s)
|
||||||
|
EndDeclareModule
|
||||||
|
|
||||||
|
Module statvfs
|
||||||
|
Structure Statvfs
|
||||||
f_bsize.i; file system block size
|
f_bsize.i; file system block size
|
||||||
f_frsize.i; fragment size
|
f_frsize.i; fragment size
|
||||||
f_blocks.i; size of fs in f_frsize units
|
f_blocks.i; size of fs in f_frsize units
|
||||||
|
@ -28,41 +51,34 @@ Structure Statvfs
|
||||||
f_flag.i; mount flags: 1=readonly 2= nosuid
|
f_flag.i; mount flags: 1=readonly 2= nosuid
|
||||||
f_namemax.i; maximum filename length
|
f_namemax.i; maximum filename length
|
||||||
__f_spare.l[6]
|
__f_spare.l[6]
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure DriveInfoResult
|
ImportC ""
|
||||||
Size.q
|
|
||||||
Used.q
|
|
||||||
Free.q
|
|
||||||
EndStructure
|
|
||||||
|
|
||||||
ImportC ""
|
|
||||||
statvfs.l(Path.p-utf8, *value.Statvfs)
|
statvfs.l(Path.p-utf8, *value.Statvfs)
|
||||||
EndImport
|
EndImport
|
||||||
|
|
||||||
Global Drive.DriveInfoResult
|
; Global Drive.DriveInfoResult
|
||||||
|
Procedure Size(Path.s)
|
||||||
|
Protected Size.i
|
||||||
|
|
||||||
Procedure.q DriveInfo(Path.s, *Result.DriveInfoResult)
|
|
||||||
Protected v.statvfs
|
Protected v.statvfs
|
||||||
Statvfs(Path, v)
|
Statvfs(Path, v)
|
||||||
*Result\Size= v\f_blocks * v\f_frsize
|
Size = v\f_blocks * v\f_frsize
|
||||||
*Result\Used= (v\f_blocks - v\f_bfree) * v\f_frsize
|
ProcedureReturn Size
|
||||||
*Result\Free= v\f_bavail * v\f_frsize
|
EndProcedure
|
||||||
EndProcedure
|
|
||||||
|
|
||||||
|
Procedure Free(Path.s)
|
||||||
|
Protected Free.i
|
||||||
|
Protected v.statvfs
|
||||||
|
Statvfs(Path, v)
|
||||||
|
Free= v\f_bavail * v\f_frsize
|
||||||
|
ProcedureReturn Free
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
DriveInfo(GetHomeDirectory(), Drive); choose any directory from drive of interrest
|
Procedure Used(Path.s)
|
||||||
Debug "Drive-Info: " + GetHomeDirectory()
|
Protected Used.i
|
||||||
Debug "Size: " + Str(Drive\Size)
|
Protected v.statvfs
|
||||||
Debug "Used: " + Str(Drive\Used)
|
Statvfs(Path, v)
|
||||||
Debug "Free: " + Str(Drive\Free)
|
Used = (v\f_blocks - v\f_bfree) * v\f_frsize
|
||||||
Debug "---"
|
ProcedureReturn Used
|
||||||
;
|
EndProcedure
|
||||||
; DriveInfo("/media/charly/96A2-6D58/", Drive); choose your USB-Stick
|
EndModule
|
||||||
; Debug "Drive-Info: " + "/media/charly-xubuntu/96A2-6D58/"
|
|
||||||
; Debug "Size: " + Str(Drive\Size)
|
|
||||||
; Debug "Used: " + Str(Drive\Used)
|
|
||||||
; Debug "Free: " + Str(Drive\Free)
|
|
||||||
; Debug "---"
|
|
Loading…
Reference in a new issue