Handle hostnames with upper-case letters
[webmin.git] / mount / macos-lib.pl
1 # macos-lib.pl
2 # Mount table functions for OSX
3 # Only options for currently mounted filesystems are supported at the moment.
4
5 # list_mounted()
6 # Return a list of all the currently mounted filesystems and swap files.
7 # The list is in the form:
8 #  directory device type options
9 # Under FreeBSD, there seems to be no way to get additional mount options
10 # used by filesystems like NFS etc. Even getting the full details of mounted
11 # filesystems requires C code! So we have to call a specially-written external
12 # program to get the mount list
13 sub list_mounted
14 {
15 # get the list of mounted filesystems
16 local(@rv, $_);
17 local $arch = &backquote_command("uname -m");
18 local $cmd;
19 if ($arch =~ /power/) {
20         $cmd = "macos-mounts";
21         &compile_program($cmd, '.*power.*');
22         }
23 else {
24         $cmd = "macos-mounts-intel";
25         &compile_program($cmd, 'i386');
26         }
27 open(CMD, "$module_config_directory/$cmd |");
28 while(<CMD>) {
29         local @p = split(/\t/, $_);
30         if ($p[2] eq "procfs" || $p[1] eq "procfs") { $p[1] = $p[2] = "proc"; }
31         push(@rv, \@p);
32         }
33 close(CMD);
34 return @rv;
35 }
36
37
38 # mount_dir(directory, device, type, options)
39 # Mount a new directory from some device, with some options. Returns 0 if ok,
40 # or an error string if failed
41 sub mount_dir
42 {
43 local($out, $opts, $shar, %options, %smbopts);
44
45 $opts = $_[3] eq "-" ? "" : "-o \"$_[3]\"";
46 $opts = join(',', grep { !/quota/ } split(/,/, $opts));
47 $out = &backquote_logged("mount -t $_[2] $opts $_[1] $_[0] 2>&1");
48 if ($?) { return "<pre>$out</pre>"; }
49
50 return 0;
51 }
52
53
54 # unmount_dir(directory, device, type)
55 # Unmount a directory that is currently mounted. Returns 0 if ok,
56 # or an error string if failed
57 sub unmount_dir
58 {
59 local($out, %smbopts, $dir);
60 $out = &backquote_logged("umount $_[0] 2>&1");
61 if ($?) { return "<pre>$out</pre>"; }
62 return 0;
63 }
64
65
66 sub list_mounts
67 {
68 return ( );
69 }
70
71 # mount_modes(type)
72 # Given a filesystem type, returns 4 numbers that determine how the file
73 # system can be mounted, and whether it can be fsck'd
74 # The first is:
75 #  0 - cannot be permanently recorded
76 #       (smbfs under linux)
77 #  1 - can be permanently recorded, and is always mounted at boot
78 #       (swap under linux)
79 #  2 - can be permanently recorded, and may or may not be mounted at boot
80 #       (most normal filesystems)
81 # The second is:
82 #  0 - mount is always permanent => mounted when saved
83 #       (swap under linux)
84 #  1 - doesn't have to be permanent
85 #       (normal fs types)
86 # The third is:
87 #  0 - cannot be fsck'd at boot time
88 #  1 - can be be fsck'd at boot
89 # The fourth is:
90 #  0 - can be unmounted
91 #  1 - cannot be unmounted
92 sub mount_modes
93 {
94 if ($_[0] eq "swap")
95         { return (2, 1, 0, 1); }
96 elsif ($_[0] eq "ufs")
97         { return (2, 1, 1, 0); }
98 else
99         { return (2, 1, 0, 0); }
100 }
101
102
103 # disk_space(type, directory)
104 # Returns the amount of total and free space for some filesystem, or an
105 # empty array if not appropriate.
106 sub disk_space
107 {
108 if (&get_mounted($_[1], "*") < 0) { return (); }
109 if ($_[0] eq "proc" || $_[0] eq "swap") { return (); }
110 if (&backquote_command("df -k ".quotemeta($_[1]), 1) =~
111     /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/) {
112         return ($1, $2);
113         }
114 return ( );
115 }
116
117
118 # list_fstypes()
119 # Returns an array of all the supported filesystem types. If a filesystem is
120 # found that is not one of the supported types, generate_location() and
121 # generate_options() will not be called for it.
122 sub list_fstypes
123 {
124 local @rv = ("ufs", "nfs", "cd9660", "msdos", "swap");
125 push(@rv, "ext2fs") if (&has_command("mount_ext2fs"));
126 push(@rv, "ntfs") if (&has_command("mount_ntfs"));
127 return @rv;
128 }
129
130
131 # fstype_name(type)
132 # Given a short filesystem type, return a human-readable name for it
133 sub fstype_name
134 {
135 local(%fsmap);
136 %fsmap = ("ufs", "FreeBSD Unix Filesystem",
137           "nfs","Network Filesystem",
138           "hfs","Macintosh Filesystem",
139           "msdos","MS-DOS Filesystem",
140           "volfs","Volumes Filesystem",
141           "swap","Virtual Memory");
142 return $config{long_fstypes} && $fsmap{$_[0]} ? $fsmap{$_[0]} : uc($_[0]);
143 }
144
145 sub device_name
146 {
147 return $_[0];
148 }
149
150 sub files_to_lock
151 {
152 return ( );
153 }
154
155 1;
156