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

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

Added filesystem and statvfs eggs.

File size: 2.0 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
27          filesystem:block-size
28          filesystem:blocks-total
29          filesystem:blocks-free
30          filesystem:blocks-available
31          filesystem:blocks->bytes
32          filesystem:blocks->kilobytes
33          filesystem:blocks->kibibytes))
34
35(use statvfs)
36
37(define (filesystem:block-size path)
38  (vector-ref (statvfs path) 2))
39
40(define (filesystem:blocks-total path)
41  (vector-ref (statvfs path) 3))
42
43(define (filesystem:blocks-free path)
44  (vector-ref (statvfs path) 4))
45
46(define (filesystem:blocks-available path)
47  (vector-ref (statvfs path) 5))
48
49(define (filesystem:blocks->bytes blocksize blocks units)
50  (inexact->exact (round (* blocks (/ blocksize units)))))
51
52(define (filesystem:blocks->kilobytes blocksize blocks e)
53  (filesystem:blocks->bytes blocksize blocks (expt 1000 e)))
54
55(define (filesystem:blocks->kibibytes blocksize blocks e)
56  (filesystem:blocks->bytes blocksize blocks (expt 1024 e)))
Note: See TracBrowser for help on using the repository browser.