01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with DrFTPD; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package se.mog.io;
19:
20: import java.io.BufferedReader;
21: import java.io.FileReader;
22: import java.io.IOException;
23:
24: import java.util.Enumeration;
25: import java.util.StringTokenizer;
26: import java.util.Vector;
27:
28: /**
29: * @author <a href="mailto:drftpd@mog.se">Morgan Christiansson</a>
30: *
31: * To change the template for this generated type comment go to
32: * Window>Preferences>Java>Code Generation>Code and Comments
33: */
34: class UnixFileSystem extends FileSystem {
35: public File[] listMounts() throws IOException {
36: BufferedReader reader = new BufferedReader(new FileReader(
37: "/etc/mtab"));
38:
39: try {
40: Vector mountPoints = new Vector();
41: String line;
42:
43: while ((line = reader.readLine()) != null) {
44: if (line.charAt(0) == '#') {
45: continue;
46: }
47:
48: Enumeration st = new StringTokenizer(line, " \t");
49:
50: if (!st.hasMoreElements()) {
51: continue;
52: }
53:
54: /*String fs_spec = */
55: st.nextElement();
56:
57: if (!st.hasMoreElements()) {
58: System.err
59: .println("WARN: /etc/mtab is corrupt, skipping line");
60:
61: continue;
62: }
63:
64: //String fs_file = st.nextToken();
65: mountPoints.add(new File((String) st.nextElement()));
66:
67: /*
68: String fs_vfstype = st.nextToken();
69: String fs_mntops = st.nextToken()
70: int fs_freq = Integer.parseInt(st.nextToken());
71: int fs_passno = Integer.parseInt(st.nextToken());
72: */
73: }
74:
75: return (File[]) mountPoints.toArray(new File[mountPoints
76: .size()]);
77: } finally {
78: reader.close();
79: }
80: }
81:
82: public static void main(String[] args) throws IOException {
83: File[] mounts = new UnixFileSystem().listMounts();
84:
85: for (int i = 0; i < mounts.length; i++) {
86: System.out.println(mounts[i]);
87: }
88: }
89:
90: public native DiskFreeSpace getDiskFreeSpace(File file);
91: }
|