2 Domtool
2 (http
://hcoop
.sf
.net
/)
3 Copyright (C
) 2007 Adam Chlipala
5 This program is free software
; you can redistribute it
and/or
6 modify it under the terms
of the GNU General Public License
7 as published by the Free Software Foundation
; either version
2
8 of the License
, or (at your option
) any later version
.
10 This program is distributed
in the hope that it will be useful
,
11 but WITHOUT ANY WARRANTY
; without even the implied warranty
of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
13 GNU General Public License for more details
.
15 You should have received a copy
of the GNU General Public License
16 along
with this program
; if not
, write to the Free Software
17 Foundation
, Inc
., 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA
.
20 structure Quotas
= struct
22 fun homedir s
= Posix
.SysDB
.Passwd
.home (Posix
.SysDB
.getpwnam s
)
23 fun userVols s
= [homedir s
]
27 val proc
= Unix
.execute ("/bin/sh", ["-c", "/usr/bin/fs listquota -path " ^ path
])
28 val inf
= Unix
.textInstreamOf proc
30 (case TextIO.inputLine inf
of
33 if String.isPrefix
"fs: " line
then
36 case TextIO.inputLine inf
of
39 case String.tokens
Char.isSpace line
of
40 _
:: _
:: n
:: _
=> Int.fromString n
42 before ignore (Unix
.reap proc
)
47 fun explorer (level
, path
, acc
) =
49 val dir
= Posix
.FileSys
.opendir path
52 case Posix
.FileSys
.readdir dir
of
60 explorer (level
+1, OS
.Path
.joinDirFile
{dir
= path
, file
= file
}, acc
)
66 before Posix
.FileSys
.closedir dir
69 val users
= explorer (0, "/afs/hcoop.net/user", [])
72 foldl (fn (vol
, total
) => case used vol
of
74 | SOME n
=> total
+ n
) 0 (userVols uname
)
76 val users
= ListMergeSort
.sort (fn (s1
, s2
) => String.compare (s1
, s2
) = GREATER
) users
77 val all
= List.map (fn user
=> {uname
= user
, kbs
= count user
}) users
78 val all
= ListMergeSort
.sort (fn ({kbs
= kb1
, ...}, {kbs
= kb2
, ...}) => kb1
> kb2
) all
80 app (fn {uname
, kbs
} => (print uname
;
82 print (Int.toString kbs
);