132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: Initial release: March 2004
|
|
8
|
|
9 author: Kris, FreeEagle
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 module tango.io.FileRoots;
|
|
14
|
|
15 private import tango.sys.Common;
|
|
16
|
|
17
|
|
18 version (Win32)
|
|
19 {
|
|
20 private import Text = tango.text.Util;
|
|
21 private extern (Windows) DWORD GetLogicalDriveStringsA (DWORD, LPTSTR);
|
|
22 }
|
|
23
|
|
24 version (Posix)
|
|
25 {
|
|
26 private import tango.io.FileConduit;
|
|
27 private import Integer = tango.text.convert.Integer;
|
|
28 }
|
|
29
|
|
30 /*******************************************************************************
|
|
31
|
|
32 Models an OS-specific file-system. Included here are methods to
|
|
33 list the system roots ("C:", "D:", etc)
|
|
34
|
|
35 *******************************************************************************/
|
|
36
|
|
37 struct FileRoots
|
|
38 {
|
|
39 version (Win32)
|
|
40 {
|
|
41 /***************************************************************
|
|
42
|
|
43 List the set of root devices (C:, D: etc)
|
|
44
|
|
45 ***************************************************************/
|
|
46
|
|
47 static char[][] list ()
|
|
48 {
|
|
49 int len;
|
|
50 char[] str;
|
|
51 char[][] roots;
|
|
52
|
|
53 // acquire drive strings
|
|
54 len = GetLogicalDriveStringsA (0, null);
|
|
55 if (len)
|
|
56 {
|
|
57 str = new char [len];
|
|
58 GetLogicalDriveStringsA (len, str.ptr);
|
|
59
|
|
60 // split roots into seperate strings
|
|
61 roots = Text.delimit (str [0 .. $-1], "\0");
|
|
62 }
|
|
63 return roots;
|
|
64 }
|
|
65 }
|
|
66
|
|
67
|
|
68 version (Posix)
|
|
69 {
|
|
70 /***************************************************************
|
|
71
|
|
72 List the set of root devices.
|
|
73
|
|
74 ***************************************************************/
|
|
75
|
|
76 static char[][] list ()
|
|
77 {
|
|
78 version(darwin)
|
|
79 {
|
|
80 assert(0);
|
|
81 return null;
|
|
82 }
|
|
83 else
|
|
84 {
|
|
85 char[] path = "";
|
|
86 char[][] list;
|
|
87 int spaces;
|
|
88
|
|
89 auto fc = new FileConduit("/etc/mtab");
|
|
90 scope (exit)
|
|
91 fc.close;
|
|
92
|
|
93 auto content = new char[cast(int) fc.length];
|
|
94 fc.input.read (content);
|
|
95
|
|
96 for(int i = 0; i < content.length; i++)
|
|
97 {
|
|
98 if(content[i] == ' ') spaces++;
|
|
99 else if(content[i] == '\n')
|
|
100 {
|
|
101 spaces = 0;
|
|
102 list ~= path;
|
|
103 path = "";
|
|
104 }
|
|
105 else if(spaces == 1)
|
|
106 {
|
|
107 if(content[i] == '\\')
|
|
108 {
|
|
109 path ~= Integer.parse(content[++i..i+3], 8u);
|
|
110 i += 2;
|
|
111 }
|
|
112 else path ~= content[i];
|
|
113 }
|
|
114 }
|
|
115
|
|
116 return list;
|
|
117 }
|
|
118 }
|
|
119 }
|
|
120 }
|
|
121
|