Seite 1 von 2

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:

Code: Alles auswählen

1537 MB
0

Re: Freier Festplatten speicher?

Verfasst: 01.08.2010 19:15
von remi_meier
Thx. Habe noch den hoffentlich letzten Bug
in der Struktur gefixt :coderselixir:
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

Re: Freier Festplatten speicher?

Verfasst: 01.08.2010 19:53
von Kiffi
na, ob die ursprünglich umständliche Zerlegung des
df-Rückgabestrings doch nicht einfacher gewesen wäre? ;-)

Grüße ... Kiffi

Re: Freier Festplatten speicher?

Verfasst: 01.08.2010 22:50
von remi_meier
:mrgreen:
Nächstes mal krieg ich das doppelt so
schnell und doppelt so richtig hin!
Und dann finde ich auch noch die
richtige GCC Option, die mir für 64bit
die Header preprocessed...