summaryrefslogtreecommitdiffstats
path: root/perl-install/fs/mount.pm
blob: e96228d756e65804b123a2427789e0025712d8cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package fs::mount; # $Id$

use diagnostics;
use strict;

use run_program;
use common;
use fs::type;
use log;


sub set_loop {
    my ($part) = @_;
    $part->{device} ||= fs::get::mntpoint_prefixed($part->{loopback_device}) . $part->{loopback_file};
    $part->{real_device} ||= devices::set_loop(devices::make($part->{device}), $part->{encrypt_key}, $part->{options} =~ /encryption=(\w+)/);
}

sub swapon {
    my ($dev) = @_;
    log::l("swapon called with $dev");
    syscall_('swapon', devices::make($dev), 0) or die "swapon($dev) failed: $!";
}

sub swapoff {
    my ($dev) = @_;
    syscall_('swapoff', devices::make($dev)) or die "swapoff($dev) failed: $!";
}

sub mount {
    my ($dev, $where, $fs, $b_rdonly, $o_options, $o_wait_message) = @_;
    log::l("mounting $dev on $where as type $fs, options $o_options");

    mkdir_p($where);

    $fs or log::l("not mounting $dev partition"), return;

    {
	my @fs_modules = qw(ext3 ext4dev hfs jfs nfs ntfs romfs reiserfs ufs xfs vfat);
	my @types = (qw(ext2 proc sysfs usbfs usbdevfs iso9660 devfs devpts auto), @fs_modules);

	push @types, 'smb', 'smbfs', 'davfs2' if !$::isInstall;

	if (!member($fs, @types)) {
	    log::l("skipping mounting $dev partition ($fs)");
	    return;
	}
	if ($::isInstall) {
	    if (member($fs, @fs_modules)) {
		eval { modules::load($fs) };
	    } elsif ($fs eq 'iso9660') {
		eval { modules::load('isofs') };
	    }
	}
    }

    $where =~ s|/$||;

    my @mount_opt = split(',', $o_options || '');

    if ($::isInstall) {
	#- those options need nls_XXX modules, and we don't this at install
	@mount_opt = grep { $_ ne 'utf8' && !/^iocharset=/ } @mount_opt;
    }

    if ($fs eq 'vfat') {
	@mount_opt = 'check=relaxed';
    } elsif ($fs eq 'ntfs') {
	@mount_opt = () if $::isInstall; # esp. drop nls=xxx option so that we don't need kernel module nls_xxx
    } elsif ($fs eq 'nfs') {
	push @mount_opt, 'nolock', 'soft', 'intr' if $::isInstall;
    } elsif ($fs eq 'jfs' && !$b_rdonly) {
	fsck_jfs($dev, $o_wait_message);
    } elsif ($fs eq 'ext2' && !$b_rdonly) {
	fsck_ext2($dev, $o_wait_message);
    }

    push @mount_opt, 'ro' if $b_rdonly;

    $o_wait_message->(N("Mounting partition %s", $dev)) if $o_wait_message;
    run_program::run('mount', '-t', $fs, $dev, $where, if_(@mount_opt, '-o', join(',', @mount_opt))) or die N("mounting partition %s in directory %s failed", $dev, $where);
}

sub fsck_ext2 {
    my ($dev, $o_wait_message) = @_;
    $o_wait_message->(N("Checking %s", $dev)) if $o_wait_message;
    foreach ('-a', '-y') {
	run_program::raw({ timeout => 60 * 60 }, "fsck.ext2", $_, $dev);
	my $err = $?;
	if ($err & 0x0100) {
	    log::l("fsck corrected partition $dev");
	}
	if ($err & 0xfeff) {
	    my $txt = sprintf("fsck failed on %s with exit code %d or signal %d", $dev, $err >> 8, $err & 255);
	    $_ eq '-y' ? die($txt) : cdie($txt);
	} else {
	    last;
	}
    }
}
sub fsck_jfs {
    my ($dev, $o_wait_message) = @_;
    $o_wait_message->(N("Checking %s", $dev)) if $o_wait_message;
    #- needed if the system is dirty otherwise mounting read-write simply fails
    run_program::raw({ timeout => 60 * 60 }, "fsck.jfs", $dev) or do {
	my $err = $?;
	die "fsck.jfs failed" if $err & 0xfc00;
    };
}

#- takes the mount point to umount (can also be the device)
sub umount {
    my ($mntpoint) = @_;
    $mntpoint =~ s|/$||;
    log::l("calling umount($mntpoint)");

    run_program::run('umount', $mntpoint) or do {
	kill 15, fuzzy_pidofs('^fam\b');
	my $err;
	run_program::run('umount', '2>', \$err, $mntpoint) or die N("error unmounting %s: %s", $mntpoint, common::to_utf8($err));
    };

    substInFile { $_ = '' if /(^|\s)$mntpoint\s/ } '/etc/mtab'; #- do not care about error, if we can not read, we will not manage to write... (and mess mtab)
}

sub part {
    my ($part, $b_rdonly, $o_wait_message) = @_;

    log::l("mount_part: " . join(' ', map { "$_=$part->{$_}" } 'device', 'mntpoint', 'isMounted', 'real_mntpoint', 'device_UUID'));

    return if $part->{isMounted} && !($part->{real_mntpoint} && $part->{mntpoint});

    unless ($::testing) {
	if (isSwap($part)) {
	    $o_wait_message->(N("Enabling swap partition %s", $part->{device})) if $o_wait_message;
	    swapon($part->{device});
	} elsif ($part->{real_mntpoint}) {
	    my $mntpoint = fs::get::mntpoint_prefixed($part);

	    mkdir_p($mntpoint);
	    run_program::run_or_die('mount', '--move', $part->{real_mntpoint}, $mntpoint);

	    rmdir $part->{real_mntpoint};
	    symlinkf $mntpoint, $part->{real_mntpoint};
	    delete $part->{real_mntpoint};

	    my $dev = $part->{real_device} || fs::wild_device::from_part('', $part);
	    run_program::run_or_die('mount', $dev, $mntpoint, '-o', join(',', 'remount', $b_rdonly ? 'ro' : 'rw'));
	} else {
	    $part->{mntpoint} or die "missing mount point for partition $part->{device}";

	    my $mntpoint = fs::get::mntpoint_prefixed($part);
	    my $options = $part->{options};
	    if ($part->{encrypt_key}) {
		set_loop($part);
		$options = join(',', grep { !/^(encryption=|encrypted$|loop$)/ } split(',', $options)); #- we take care of this, don't let it mount see it
	    } elsif (isLoopback($part)) {
		#- mount will take care, but we must help it
		devices::make("loop$_") foreach 0 .. 7;
		$options = join(',', uniq('loop', split(',', $options))); #- ensure the loop options is used
	    } elsif ($part->{options} =~ /encrypted/) {
		log::l("skip mounting $part->{device} since we do not have the encrypt_key");
		return;
	    } elsif (fs::type::carry_root_loopback($part)) {
		$mntpoint = "/initrd/loopfs";
	    }
	    my $dev = $part->{real_device} || fs::wild_device::from_part('', $part);
	    my $fs_type = $part->{fs_type};
	    if ($fs_type eq 'auto' && $part->{media_type} eq 'cdrom' && $::isInstall) {
		$fs_type = 'iso9660';
	    } elsif ($fs_type eq 'ntfs-3g' && $::isInstall) {
		$fs_type = 'ntfs';
	    }
	    mount($dev, $mntpoint, $fs_type, $b_rdonly, $options, $o_wait_message);

	    if ($options =~ /usrquota|grpquota/ && member($part->{fs_type}, qw(ext3 ext4dev))) {
		if (! find { -e "$mntpoint/$_" } qw(aquota.user aquota.group quota.user quota.group)) {
		    #- quotacheck will create aquota.user and/or aquota.group,
		    #- needed for quotas on ext3/ext4.
		    run_program::run('quotacheck', $mntpoint);
		}		
	    }
	}
    }
    $part->{isMounted} = 1;
    set_isFormatted($part, 1); #- assume that if mount works, partition is formatted
}

sub umount_part {
    my ($part) = @_;

    $part->{isMounted} or return;

    unless ($::testing) {
	if (isSwap($part)) {
	    swapoff($part->{device});
	} elsif (fs::type::carry_root_loopback($part)) {
	    umount("/initrd/loopfs");
	} else {
	    umount($part->{real_mntpoint} || fs::get::mntpoint_prefixed($part) || devices::make($part->{device}));
	    devices::del_loop(delete $part->{real_device}) if $part->{real_device};
	}
    }
    $part->{isMounted} = 0;
}

sub umount_all {
    my ($fstab) = @_;

    log::l("unmounting all filesystems");

    foreach (sort { $b->{mntpoint} cmp $a->{mntpoint} } 
	       grep { $_->{mntpoint} && !$_->{real_mntpoint} } @$fstab) {
	umount_part($_);
    }
}

sub usbfs {
    my ($prefix) = @_;
    
    my $fs = cat_('/proc/filesystems') =~ /usbfs/ ? 'usbfs' : 'usbdevfs';
    mount('none', "$prefix/proc/bus/usb", $fs);
}

1;
0,0), map { my $t = $_; my $w = new Gtk::Button(''); $w->set_name($t); $w->set_usize(0, 7); gtksignal_connect($w, clicked => sub { $::setstep or return; #- just as setstep s install_theme($o, $t); die "theme_changed\n" }); } @themes))); $w->show; $o->{steps_window} = $w; } #------------------------------------------------------------------------------ sub create_logo_window { my ($o) = @_; gtkdestroy($o->{logo_window}); my $w = bless {}, 'my_gtk'; $w->{rwindow} = $w->{window} = new Gtk::Window; $w->{rwindow}->set_uposition($::stepswidth, 0); $w->{rwindow}->set_usize($::logowidth, $::logoheight); $w->{rwindow}->set_name("logo"); $w->show; my $file = $o->{meta_class} eq 'desktop' ? "logo-mandrake-Desktop.png" : "logo-mandrake.png"; $o->{meta_class} eq 'firewall' and $file = "logo-mandrake-Firewall.png"; -r $file or $file = "$ENV{SHARE_PATH}/$file"; -r $file and gtkadd($w->{window}, gtkpng($file)); $o->{logo_window} = $w; } #------------------------------------------------------------------------------ sub init_sizes() { ($::rootheight, $::rootwidth) = my_gtk::gtkroot()->get_size; $::live and $::rootheight -= 80; #- ($::rootheight, $::rootwidth) = (min(768, $::rootheight), min(1024, $::rootwidth)); ($::stepswidth, $::stepsheight) = (145, $::rootheight); ($::logowidth, $::logoheight) = ($::rootwidth - $::stepswidth, 40); ($::helpwidth, $::helpheight) = ($::rootwidth - $::stepswidth, 104); ($::windowwidth, $::windowheight) = ($::rootwidth - $::stepswidth, $::rootheight - $::helpheight - $::logoheight); } #------------------------------------------------------------------------------ sub createXconf { my ($file, $mouse_type, $mouse_dev, $wacom_dev) = @_; devices::make("/dev/kbd") if arch() =~ /^sparc/; #- used by Xsun style server. symlinkf(devices::make($mouse_dev), "/dev/mouse"); #- needed for imlib to start on 8-bit depth visual. symlink("/tmp/stage2/etc/imrc", "/etc/imrc"); symlink("/tmp/stage2/etc/im_palette.pal", "etc/im_palette.pal"); if (arch() =~ /^ia64/) { require Xconfigurator; my ($card) = Xconfigurator::cardConfigurationAuto(); Xconfigurator::updateCardAccordingName($card, $card->{type}) if $card && $card->{type}; local *F; open F, ">$file" or die "can't create X configuration file $file"; print F <<END; Section "Files" FontPath "/usr/X11R6/lib/X11/fonts:unscaled" EndSection Section "InputDevice" Identifier "Keyboard1" Driver "Keyboard" Option "AutoRepeat" "250 30" Option "XkbDisable" Option "XkbRules" "xfree86" Option "XkbModel" "pc105" Option "XkbLayout" "" EndSection Section "InputDevice" Identifier "Mouse1" Driver "mouse" Option "Protocol" "$mouse_type" Option "Device" "/dev/mouse" EndSection Section "Monitor" Identifier "Generic|High Frequency SVGA, 1024x768 at 70 Hz" VendorName "Unknown" ModelName "Unknown" HorizSync 31.5-35.5 VertRefresh 50-70 EndSection Section "Device" Identifier "Generic VGA" Driver "vga" EndSection Section "Device" Identifier "device1" VendorName "Unknown" BoardName "Unknown" Driver "$card->{driver}" EndSection Section "Screen" Identifier "screen1" Device "device1" Monitor "Generic|High Frequency SVGA, 1024x768 at 70 Hz" DefaultColorDepth 16 Subsection "Display" Depth 16 Modes "800x600" "640x480" ViewPort 0 0 EndSubsection EndSection Section "ServerLayout" Identifier "layout1" Screen "screen1" InputDevice "Mouse1" "CorePointer" InputDevice "Keyboard1" "CoreKeyboard" EndSection END } else { my $wacom; if ($wacom_dev) { $wacom_dev = devices::make($wacom_dev); $wacom = <<END; Section "Module" Load "xf86Wacom.so" EndSection Section "XInput" SubSection "WacomStylus" Port "$wacom_dev" AlwaysCore EndSubSection SubSection "WacomCursor" Port "$wacom_dev" AlwaysCore EndSubSection SubSection "WacomEraser" Port "$wacom_dev" AlwaysCore EndSubSection EndSection END } local *F; open F, ">$file" or die "can't create X configuration file $file"; print F <<END; Section "Files" FontPath "/usr/X11R6/lib/X11/fonts:unscaled" EndSection Section "Keyboard" Protocol "Standard" AutoRepeat 0 0 LeftAlt Meta RightAlt Meta ScrollLock Compose RightCtl Control END if (arch() =~ /^sparc/) { print F <<END; XkbRules "sun" XkbModel "sun" XkbLayout "us" XkbCompat "compat/complete" XkbTypes "types/complete" XkbKeycodes "sun(type5)" XkbGeometry "sun(type5)" XkbSymbols "sun/us(sun5)" END } else { print F " XkbDisable\n"; } print F <<END; EndSection Section "Pointer" Protocol "$mouse_type" Device "/dev/mouse" ZAxisMapping 4 5 EndSection $wacom Section "Monitor" Identifier "My Monitor" VendorName "Unknown" ModelName "Unknown" HorizSync 31.5-35.5 VertRefresh 50-70 Modeline "640x480" 25.175 640 664 760 800 480 491 493 525 Modeline "640x480" 28.3 640 664 760 800 480 491 493 525 ModeLine "800x600" 36 800 824 896 1024 600 601 603 625 EndSection Section "Device" Identifier "Generic VGA" VendorName "Unknown" BoardName "Unknown" Chipset "generic" EndSection Section "Device" Identifier "svga" VendorName "Unknown" BoardName "Unknown" EndSection Section "Screen" Driver "vga16" Device "Generic VGA" Monitor "My Monitor" Subsection "Display" Modes "640x480" ViewPort 0 0 EndSubsection EndSection Section "Screen" Driver "fbdev" Device "Generic VGA" Monitor "My Monitor" Subsection "Display" Depth 16 Modes "default" ViewPort 0 0 EndSubsection EndSection Section "Screen" Driver "svga" Device "svga" Monitor "My Monitor" Subsection "Display" Depth 16 Modes "800x600" "640x480" ViewPort 0 0 EndSubsection EndSection Section "Screen" Driver "accel" Device "svga" Monitor "My Monitor" Subsection "Display" Depth 16 Modes "800x600" "640x480" ViewPort 0 0 EndSubsection EndSection END } } #- ModeLine "640x480" 28 640 672 768 800 480 490 492 525 sub test_mouse { my ($mouse) = @_; my $w = my_gtk->new; my ($width, $height, $offset) = (210, round_up(min(350, $::windowheight - 150), 6), 25); my ($bw, $bh) = ($width / 3, $height / 3); gtkadd($w->{window}, gtkpack(new Gtk::VBox(0,0), my $darea = gtkset_usize(new Gtk::DrawingArea, $width+1, $height+1), '', create_okcancel($w, '', '', "edge"), ), ); my $draw_rect; $draw_rect = sub { my ($black, $fill, $rect) = @_; $draw_rect->(0, 1, $rect) if !$fill; #- blank it first $darea->window->draw_rectangle($black ? $darea->style->fg_gc('normal') : $darea->style->bg_gc('normal'), $fill, @$rect); $darea->draw($rect); }; my $paintWheel = sub { my ($x, $y, $w, $h) = ($width / 2 - $bw / 6, $bh / 4, $bw / 3, $bh / 2); $mouse->{nbuttons} = max($mouse->{nbuttons}, 5); #- it means, the mouse has more than 3 buttons... $draw_rect->(1, 0, [ $x, $y, $w, $h ]); my $offset if 0; $offset += $_[0] if $_[0]; my $step = 10; for (my $i = $offset % $step; $i < $h; $i += $step) { $draw_rect->(1, 1, [ $x, $y + $i, $w, min(2, $h - $i) ]); } }; my $paintButton = sub { my ($nb, $pressed) = @_; my $rect = [ $bw * $nb, 0, $bw, $bh ]; $draw_rect->(1, $pressed, $rect); $paintWheel->(0) if $nb == 1 && $mouse->{nbuttons} > 3; }; my $draw_text = sub { my ($t, $y) = @_; my $font = $darea->style->font; my $w = $font->string_width($t); $darea->window->draw_string($font, $darea->style->fg_gc('normal'), ($width - $w) / 2, $y, $t); }; my $default_time = 10; my $time = $default_time; $darea->signal_connect(button_press_event => sub { my $b = $_[1]{button}; $time = $default_time; $b >= 4 ? $paintWheel->($b == 4 ? -1 : 1) : $paintButton->($b - 1, 1); }); $darea->signal_connect(button_release_event => sub { my $b = $_[1]{button}; $paintButton->($b - 1, 0) if $b < 4; }); $darea->size($width, $height); $darea->set_events([ 'button_press_mask', 'button_release_mask' ]); $w->sync; # HACK $draw_rect->(1, 0, [ 0, 0, $width, $height]); $draw_text->(_("Please test the mouse"), 2 * $bh - 20); $draw_text->(_("To activate the mouse,"), 2 * $bh + 10) if $mouse->{XMOUSETYPE} eq 'IMPS/2'; $draw_text->(_("MOVE YOUR WHEEL!"), 2 * $bh + 30) if $mouse->{XMOUSETYPE} eq 'IMPS/2'; $paintButton->($_, 0) foreach 0..2; $w->{cancel}->grab_focus; # my $timeout = Gtk->timeout_add(1000, sub { if ($time-- == 0) { log::l("timeout test_mouse"); undef $w->{retval}; Gtk->main_quit } 1 }); # my $b = before_leaving { log::l("removing timeout"); Gtk->timeout_remove($timeout) }; $w->main; } 1;