source: project/nondescript/statvfs/statvfs.scm @ 8841

Last change on this file since 8841 was 8841, checked in by anonymous, 13 years ago

Added filesystem and statvfs eggs.

File size: 3.8 KB
Line 
1;; statvfs egg for Chicken Scheme
2
3;; Copyright (c) 2008 Ozzi Lee
4
5;; Permission is hereby granted, free of charge, to any person
6;; obtaining a copy of this software and associated documentation
7;; files (the "Software"), to deal in the Software without
8;; restriction, including without limitation the rights to use,
9;; copy, modify, merge, publish, distribute, sublicense, and/or sell
10;; copies of the Software, and to permit persons to whom the
11;; Software is furnished to do so, subject to the following
12;; conditions:
13
14;; The above copyright notice and this permission notice shall be
15;; included in all copies or substantial portions of the Software.
16
17;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24;; OTHER DEALINGS IN THE SOFTWARE.
25
26(declare (export statvfs))
27
28(use srfi-1)
29
30(foreign-declare "#include <sys/statvfs.h>")
31
32;; Debian
33;;
34;; struct statvfs
35;;   {
36;;     unsigned long int f_bsize;
37;;     unsigned long int f_frsize;
38;; #ifndef __USE_FILE_OFFSET64
39;;     __fsblkcnt_t f_blocks;
40;;     __fsblkcnt_t f_bfree;
41;;     __fsblkcnt_t f_bavail;
42;;     __fsfilcnt_t f_files;
43;;     __fsfilcnt_t f_ffree;
44;;     __fsfilcnt_t f_favail;
45;; #else
46;;     __fsblkcnt64_t f_blocks;
47;;     __fsblkcnt64_t f_bfree;
48;;     __fsblkcnt64_t f_bavail;
49;;     __fsfilcnt64_t f_files;
50;;     __fsfilcnt64_t f_ffree;
51;;     __fsfilcnt64_t f_favail;
52;; #endif
53;;     unsigned long int f_fsid;
54;; #ifdef _STATVFSBUF_F_UNUSED
55;;     int __f_unused;
56;; #endif
57;;     unsigned long int f_flag;
58;;     unsigned long int f_namemax;
59;;     int __f_spare[6];
60;;   };
61
62;; Mac OS X
63;;
64;; struct statvfs {
65;;         unsigned long   f_bsize;        /* File system block size */
66;;         unsigned long   f_frsize;       /* Fundamental file system block size */
67;;         fsblkcnt_t      f_blocks;       /* Blocks on FS in units of f_frsize */
68;;         fsblkcnt_t      f_bfree;        /* Free blocks */
69;;         fsblkcnt_t      f_bavail;       /* Blocks available to non-root */
70;;         fsfilcnt_t      f_files;        /* Total inodes */
71;;         fsfilcnt_t      f_ffree;        /* Free inodes */
72;;         fsfilcnt_t      f_favail;       /* Free inodes for non-root */
73;;         unsigned long   f_fsid;         /* Filesystem ID */
74;;         unsigned long   f_flag;         /* Bit mask of values */
75;;         unsigned long   f_namemax;      /* Max file name length */
76;; };
77
78(define (statvfs path)
79
80  (define c-statvfs
81    (foreign-lambda int statvfs c-string c-pointer))
82
83  (define-foreign-record (statvfs "struct statvfs")
84    (constructor: make-statvfs)
85    (destructor: free-statvfs)
86    (unsigned-long "f_bsize")
87    (unsigned-long "f_frsize")
88    (unsigned-long "f_blocks")
89    (unsigned-long "f_bfree")
90    (unsigned-long "f_bavail")
91    (unsigned-long "f_files")
92    (unsigned-long "f_ffree")
93    (unsigned-long "f_favail")
94    (unsigned-long "f_fsid")
95    (unsigned-long "f_flag")
96    (unsigned-long "f_namemax"))
97
98  (let ((ptr (make-statvfs)))
99    (c-statvfs path ptr)
100    (let ((v (vector
101              (statvfs-f_frsize ptr)
102              (statvfs-f_bsize ptr)
103              (statvfs-f_frsize ptr)
104              (statvfs-f_blocks ptr)
105              (statvfs-f_bfree ptr)
106              (statvfs-f_bavail ptr)
107              (statvfs-f_files ptr)
108              (statvfs-f_ffree ptr)
109              (statvfs-f_favail ptr)
110              (statvfs-f_fsid ptr)
111              (statvfs-f_flag ptr)
112              (statvfs-f_namemax ptr))))
113      (free-statvfs ptr)
114      v)))
Note: See TracBrowser for help on using the repository browser.