2 # Mount table functions for OSX
3 # Only options for currently mounted filesystems are supported at the moment.
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
15 # get the list of mounted filesystems
17 local $arch = &backquote_command("uname -m");
19 if ($arch =~ /power/) {
20 $cmd = "macos-mounts";
21 &compile_program($cmd, '.*power.*');
24 $cmd = "macos-mounts-intel";
25 &compile_program($cmd, 'i386');
27 open(CMD, "$module_config_directory/$cmd |");
29 local @p = split(/\t/, $_);
30 if ($p[2] eq "procfs" || $p[1] eq "procfs") { $p[1] = $p[2] = "proc"; }
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
43 local($out, $opts, $shar, %options, %smbopts);
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>"; }
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
59 local($out, %smbopts, $dir);
60 $out = &backquote_logged("umount $_[0] 2>&1");
61 if ($?) { return "<pre>$out</pre>"; }
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
75 # 0 - cannot be permanently recorded
77 # 1 - can be permanently recorded, and is always mounted at boot
79 # 2 - can be permanently recorded, and may or may not be mounted at boot
80 # (most normal filesystems)
82 # 0 - mount is always permanent => mounted when saved
84 # 1 - doesn't have to be permanent
87 # 0 - cannot be fsck'd at boot time
88 # 1 - can be be fsck'd at boot
90 # 0 - can be unmounted
91 # 1 - cannot be unmounted
95 { return (2, 1, 0, 1); }
96 elsif ($_[0] eq "ufs")
97 { return (2, 1, 1, 0); }
99 { return (2, 1, 0, 0); }
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.
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+)/) {
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.
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"));
132 # Given a short filesystem type, return a human-readable name for it
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]);