Seite 1 von 2
Freier Festplatten speicher?
Verfasst: 30.07.2010 17:31
von Nero
Hiho,
ich schreibe mir gerade ein kleines Tool zum downloaden von dateien, bei dem ich den freien speicher auf der Festplatte vor dem
Herunterladen überprüfen will.
Unter Win ist das ja per api recht easy gibts dafür nicht auch was simples unter Linux?
Ich kann zwar runprogram + df nutzen aber da muß man erst umständlich den ausgabe string zerlegen.
Gibt es da nicht ne einfachere direcktere möglichkeit?
Mfg
Nero
Re: Freier Festplatten speicher?
Verfasst: 30.07.2010 18:30
von Deluxe0321
Servus,
nur als Idee: Datei erstellen mit "Müll" vollschreiben (in der Größe der zu downloadenden Datei) und checken obs passt.
Falls dir PB kein Error zurückgibt dürfte genug Speicher vorhanden sein

Ich bin mir ziemlich sicher das fast jeder Downloadmanager mit diesem Prinzip arbeitet, denn das ermöglicht auch abgebrochene Downloads wieder aufzunehmen.
Grüße
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 12:50
von remi_meier
Ich hoffe, das stimmt so:
Code: Alles auswählen
... siehe weiter unten, wenn 64bit Probleme gelöst ...
für mehr info:
$ man statfs
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 13:15
von NicTheQuick
Hm... bei mir kommt immer 0 MB raus. Stimmt wohl noch nicht ganz. Kann aber auch nicht weiter rumprobieren bzw. Doku lesen, weil ich weg muss.
Jedenfalls würde mich die Lösung des Problems auch interessieren. Und ich bin immer noch zu blöd selbst diese Befehle in der Linux-API herauszufinden...
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 13:34
von remi_meier
Ok, ich hab mir nun die Zeit genommen all die typedefs
über 10 Ecken zu dekodieren
Könntest du den Code nochmals testen? Hab leider grad
kein 64bit Linux zur Hand.
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 13:37
von NicTheQuick
Ok, noch einmal schnell nach dem Duschen. Meine Ausgabe:
Ich hab definitiv mehr als 0 MB auf / frei.

Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 13:43
von remi_meier
Bin erst jetzt auf die Idee mit gcc -E gekommen.
Könntest du mal folgendes machen
1. cd /usr/include/bits/
2. gcc -E statfs.h
und den Output posten? Irgendwie gibts da noch
weiter Konfigurationsunterschiede zu 32bit...
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 13:57
von remi_meier
Ok, neue Variante mit statvfs().
Code: Alles auswählen
; struct statvfs {
; unsigned long f_bsize; /* file system block size */
; unsigned long f_frsize; /* fragment size */
; fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
; fsblkcnt_t f_bfree; /* # free blocks */
; fsblkcnt_t f_bavail; /* # free blocks for non-root */
; fsfilcnt_t f_files; /* # inodes */
; fsfilcnt_t f_ffree; /* # free inodes */
; fsfilcnt_t f_favail; /* # free inodes for non-root */
; unsigned long f_fsid; /* file system ID */
; unsigned long f_flag; /* mount flags */
; unsigned long f_namemax; /* maximum filename length */
; };
Structure STATVFS
f_bsize.i
f_frsize.i
f_blocks.i
f_bfree.i
f_bavail.i
f_files.i
f_ffree.i
f_favail.i
f_fsid.i
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
__f_unused.l
CompilerEndIf
f_flag.i
f_namemax.i
__f_spare.l[6]
EndStructure
Enumeration
#ST_RDONLY = 1
#ST_NOSUID = 2
EndEnumeration
ImportC ""
statvfs.l(path.p-utf8, *buf.STATVFS)
EndImport
stats.STATVFS
If statvfs("/", @stats) = 0
size.s = StrU(stats\f_bavail * stats\f_bsize / 1024 / 1024, #PB_Quad)
Debug "Free for non-root: " + size + " MB"
Debug "Max file name length: " + StrU(stats\f_namemax)
Debug "File system ID: " + Hex(stats\f_fsid)
If stats\f_flag & #ST_RDONLY
Debug "readonly"
Else
Debug "not readonly"
EndIf
EndIf
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 18:51
von NicTheQuick
Ok, scheint zu stimmen.
Hier die Ausgabe von gcc:
Code: Alles auswählen
# 1 "statfs.h"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "statfs.h"
statfs.h:20:3: error: #error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
# 23 "statfs.h"
# 1 "/usr/include/bits/types.h" 1 3 4
# 27 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 313 "/usr/include/features.h" 3 4
# 1 "/usr/include/bits/predefs.h" 1 3 4
# 314 "/usr/include/features.h" 2 3 4
# 346 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 353 "/usr/include/sys/cdefs.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 354 "/usr/include/sys/cdefs.h" 2 3 4
# 347 "/usr/include/features.h" 2 3 4
# 378 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 5 "/usr/include/gnu/stubs.h" 2 3 4
# 1 "/usr/include/gnu/stubs-64.h" 1 3 4
# 10 "/usr/include/gnu/stubs.h" 2 3 4
# 379 "/usr/include/features.h" 2 3 4
# 28 "/usr/include/bits/types.h" 2 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 29 "/usr/include/bits/types.h" 2 3 4
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;
typedef long int __quad_t;
typedef unsigned long int __u_quad_t;
# 131 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/typesizes.h" 1 3 4
# 132 "/usr/include/bits/types.h" 2 3 4
typedef unsigned long int __dev_t;
typedef unsigned int __uid_t;
typedef unsigned int __gid_t;
typedef unsigned long int __ino_t;
typedef unsigned long int __ino64_t;
typedef unsigned int __mode_t;
typedef unsigned long int __nlink_t;
typedef long int __off_t;
typedef long int __off64_t;
typedef int __pid_t;
typedef struct { int __val[2]; } __fsid_t;
typedef long int __clock_t;
typedef unsigned long int __rlim_t;
typedef unsigned long int __rlim64_t;
typedef unsigned int __id_t;
typedef long int __time_t;
typedef unsigned int __useconds_t;
typedef long int __suseconds_t;
typedef int __daddr_t;
typedef long int __swblk_t;
typedef int __key_t;
typedef int __clockid_t;
typedef void * __timer_t;
typedef long int __blksize_t;
typedef long int __blkcnt_t;
typedef long int __blkcnt64_t;
typedef unsigned long int __fsblkcnt_t;
typedef unsigned long int __fsblkcnt64_t;
typedef unsigned long int __fsfilcnt_t;
typedef unsigned long int __fsfilcnt64_t;
typedef long int __ssize_t;
typedef __off64_t __loff_t;
typedef __quad_t *__qaddr_t;
typedef char *__caddr_t;
typedef long int __intptr_t;
typedef unsigned int __socklen_t;
# 24 "statfs.h" 2
struct statfs
{
long int f_type;
long int f_bsize;
__fsblkcnt_t f_blocks;
__fsblkcnt_t f_bfree;
__fsblkcnt_t f_bavail;
__fsfilcnt_t f_files;
__fsfilcnt_t f_ffree;
__fsid_t f_fsid;
long int f_namelen;
long int f_frsize;
long int f_spare[5];
};
Und hier die von PB Debug:
Re: Freier Festplatten speicher?
Verfasst: 01.08.2010 19:15
von remi_meier
Thx. Habe noch den hoffentlich letzten Bug
in der Struktur gefixt
Ich muss mir definitiv noch eine x64 VM
einrichten, so sind meine Codes per Default
falsch...
Na ich hoffe, dass der Code nun seinen
Zweck erfüllt!
zumindest auf UTF-8 Systemen *hust*
greetz
remi