aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/init.d/network
blob: 61ad8fb92299fb135aa3cb9566fe49c21eccb35e (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
#!/bin/bash
#
# network       Bring up/down networking
#
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to \
#              start at boot time.
# probe: true

# Source function library.
. /etc/init.d/functions

if [ ! -f /etc/sysconfig/network ]; then
    exit 0
fi

. /etc/sysconfig/network

if [ -f /etc/sysconfig/pcmcia ]; then
	. /etc/sysconfig/pcmcia
fi


# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /sbin/ifconfig ] || exit 0

# Even if IPX is configured, without the utilities we can't do much
[ ! -x /sbin/ipx_internal_net -o ! -x /sbin/ipx_configure ] && IPX=

CWD=`pwd`
cd /etc/sysconfig/network-scripts

# find all the interfaces besides loopback.
# ignore aliases, alternative configurations, and editor backup files
interfaces=`ls ifcfg* | egrep -v '(ifcfg-lo|:|rpmsave|rpmorig|rpmnew)' | \
	    egrep -v '(~|\.bak)$' | \
            egrep -v 'ifcfg-ippp[0-9]+$' | \
            egrep 'ifcfg-[a-z0-9]+$' | \
            sed 's/^ifcfg-//g'`

# See how we were called.
case "$1" in
  start)
  
  	action "Setting network parameters: " sysctl -p /etc/sysctl.conf

	action "Bringing up interface lo: " ./ifup ifcfg-lo

	case "$IPX" in
	  yes|true)
	    /sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY \
				   --auto_interface=$IPXAUTOFRAME
	    if [ "$IPXINTERNALNETNUM" != "0" ]; then
	       /sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
	    fi
	    ;;
	esac

	for i in $interfaces; do
		if egrep -L "^ONBOOT=\"?[Nn][Oo]\"?" ifcfg-$i >/dev/null 2>&1 && [ "${i##eth}" != "$i" ]; then
			# Probe module to preserve interface ordering
			if [ -n "`modprobe -vn $i | grep -v Note:`" ]; then
			   /sbin/ifconfig $i >/dev/null 2>&1
			fi
		else
					# If we're in confirmation mode, get user confirmation
		    [ -n "$CONFIRM" ]  && 
			{ 
			    confirm $i
			    case $? in
				0)
				    :
				;;
				2)
				    CONFIRM=
				;;
				*)
				    continue
				;;
			    esac 
			}

			action "Bringing up interface $i: " ./ifup $i boot
		fi
	done
	
	# Add non interface-specific static-routes.
	if [ -f /etc/sysconfig/static-routes ]; then
	   grep "^any" /etc/sysconfig/static-routes | while read ignore type dest netmask mask bogus args; do
	      if [ "${bogus}" = "gw" ]; then 
	      	/sbin/route add -$type $dest $netmask $mask $args
	      else
	      	/sbin/route add -$type $dest $netmask $mask $bogus $args
	      fi
	   done
	fi    

        touch /var/lock/subsys/network
        ;;
  stop)
  	# If this is a final shutdown/halt, check for network FS,
	# and unmount them even if the user didn't turn on netfs
	
	if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
		NFSMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^nfs$/ ) print $2}'`
		SMBMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^smbfs$/ ) print $2}'`
		NCPMTAB=`grep -v '^#' /proc/mounts | awk '{ if ($3 ~ /^ncpfs$/ ) print $2}'`
		if [ -n "$NFSMTAB" -o -n "$SMBMTAB" -o -n "$NCPMTAB" ] ; then
			/etc/init.d/netfs stop
		fi
	fi
	
	for i in $interfaces ; do
	        if LC_ALL= LANG= ifconfig $i 2>/dev/null | grep -q " UP " >/dev/null 2>&1 ; then
		   action "Shutting down interface $i: " ./ifdown $i boot
		fi
	done
	case "$IPX" in
	  yes|true)
	    if [ "$IPXINTERNALNETNUM" != "0" ]; then
	       /sbin/ipx_internal_net del
	    fi
	    ;;
	esac
	./ifdown ifcfg-lo
	if [ -d /proc/sys/net/ipv4 ]; then
	  if [ -f /proc/sys/net/ipv4/ip_forward ]; then
		if [ `cat /proc/sys/net/ipv4/ip_forward` != 0 ]; then
			action "Disabling IPv4 packet forwarding: " sysctl -w net.ipv4.ip_forward=0
		fi
	  fi
	  if [ -f /proc/sys/net/ipv4/ip_always_defrag ]; then
	        if [ `cat /proc/sys/net/ipv4/ip_always_defrag` != 0 ]; then
		        action "Disabling IPv4 automatic defragmentation: " sysctl -w net.ipv4.ip_always_defrag=0
		fi
	  fi
	fi
	
        rm -f /var/lock/subsys/network
        ;;
  status)
	echo $"Configured devices:"
	echo lo $interfaces

	if [ -x /sbin/linuxconf ] ; then
		eval `/sbin/linuxconf --hint netdev`
		echo $"Devices that are down:"
		echo $DEV_UP
		echo $"Devices with modified configuration:"
		echo $DEV_RECONF
	else
		echo $"Currently active devices:"
		echo `/sbin/ifconfig | grep ^[a-z] | awk '{print $1}'`
	fi
	;;
  restart)
        cd $CWD
	$0 stop
	$0 start
	;;
  reload)
	if [ -x /sbin/linuxconf ] ; then
		eval `/sbin/linuxconf --hint netdev`
		for device in $DEV_UP ; do
			action "Bringing up device %s: " $device ./ifup $device
		done
		for device in $DEV_DOWN ; do
			action "Shutting down device %s: " $device ./ifdown $device
		done
		for device in $DEV_RECONF ; do
			action "Shutting down device %s: " $device ./ifdown $device
			action "Bringing up device %s: " $device ./ifup $device
		done
		for device in $DEV_RECONF_ALIASES ; do
			action "Bringing up alias %s: " $device /etc/sysconfig/network-scripts/ifup-aliases $device
		done
		for device in $DEV_RECONF_ROUTES ; do
			action "Bringing up route %s: " $device /etc/sysconfig/network-scripts/ifup-routes $device
		done
		case $IPX in yes|true)
		  case $IPXINTERNALNET in
		    reconf)
			action "Deleting internal IPX network: " /sbin/ipx_internal_net del
			action "Adding internal IPX network %s %s: " $IPXINTERNALNETNUM $IPXINTERNALNODENUM /sbin/ipx_internal_net add $IPXINTERNALNETNUM \
						      $IPXINTERNALNODENUM
			;;
		    add)
			action "Adding internal IPX network $IPXINTERNALNETNUM $IPXINTERNALNODENUM: "/sbin/ipx_internal_net add $IPXINTERNALNETNUM \
						      $IPXINTERNALNODENUM
			;;
		    del)
			action "Deleting internal IPX network: " /sbin/ipx_internal_net del
			;;
		  esac
		  ;;
		esac
	else
	        cd $CWD
		$0 restart
	fi
	;;
  probe)
	if [ -x /sbin/linuxconf ] ; then
		eval `/sbin/linuxconf --hint netdev`
		[ -n "$DEV_UP$DEV_DOWN$DEV_RECONF$DEV_RECONF_ALIASES" -o \
		  -n "$DEV_RECONF_ROUTES$IPXINTERNALNET" ] && \
			echo reload
		exit 0
	else
		# if linuxconf isn't around to figure stuff out for us,
		# we punt.  Probably better than completely reloading
		# networking if user isn't sure which to do.  If user
		# is sure, they would run restart or reload, not probe.
		exit 0
	fi
	;;
  *)
        echo $"Usage: network {start|stop|restart|reload|status|probe}"
        exit 1
esac

exit 0
353'>353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
package fs; # $Id$

use diagnostics;
use strict;

use MDK::Common::System;
use MDK::Common::Various;
use common;
use log;
use devices;
use partition_table qw(:types);
use run_program;
use swap;
use detect_devices;
use modules;
use fsedit;
use loopback;


sub read_fstab {
    my ($prefix, $file, @reading_options) = @_;

    my %comments;
    my $comment;
    my @l = grep {
	if (/^\s*#/) {
	    $comment .= chomp_($_) . "\n";
	    0;
	} else {
	    $comments{$_} = $comment if $comment;
	    $comment = '';
	    1;
	}
    } cat_("$prefix$file");

    #- attach comments at the end of fstab to the previous line
    $comments{$l[-1]} = $comment if $comment;

    map {
	my ($dev, $mntpoint, $type, $options, $freq, $passno) = split;
	my $comment = $comments{$_};

	$options = 'defaults' if $options eq 'rw'; # clean-up for mtab read

	$type = fs2type($type);
	if ($type eq 'supermount') {
	    # normalize this bloody supermount
	    $options = join(",", 'supermount', grep {
		if (/fs=(.*)/) {
		    $type = $1;
		    0;
		} elsif (/dev=(.*)/) {
		    $dev = $1;
		    0;
		} elsif ($_ eq '--') {
		    0;
		} else {
		    1;
		}
	    } split(',', $options));
	} elsif ($type eq 'smb') {
	    # prefering type "smbfs" over "smb"
	    $type = 'smbfs';
	}
	$mntpoint =~ s/\\040/ /g;
	$dev =~ s/\\040/ /g;

	my $h = { 
		 device => $dev, mntpoint => $mntpoint, type => $type, 
		 options => $options, comment => $comment,
		 if_(member('keep_freq_passno', @reading_options), freq => $freq, passno => $passno),
		};

	if ($dev =~ /^LABEL=/) {
	    if (my $e = find { $_->{mntpoint} eq $mntpoint } read_fstab('', '/proc/mounts')) {
		$h->{device_LABEL} = $dev;
		$dev = $h->{device} = $e->{device};
	    }
        }
	if ($dev =~ m,^/(tmp|dev)/,) {
	    ($h->{major}, $h->{minor}) = unmakedev((stat "$prefix$dev")[6]);

	    my $symlink = readlink("$prefix$dev");
	    $dev =~ s,^/(tmp|dev)/,,;

	    if ($symlink =~ m|^[^/]+$|) {
		$h->{device_alias} = $dev;
		$h->{device} = $symlink;
	    } else {
		$h->{device} = $dev;
	    }

	    if ($h->{device} =~ m!/(disc|part\d+)$!) {
		$h->{devfs_device} = $h->{device};
		$h->{prefer_devfs_name} = 1 if member('keep_devfs_name', @reading_options);
	    }
	}

	if ($h->{options} =~ /credentials=/ && !member('verbatim_credentials', @reading_options)) {
	    require network::smb;
	    #- remove credentials=file with username=foo,password=bar,domain=zoo
	    #- the other way is done in fstab_to_string
	    my ($options, $unknown) = mount_options_unpack($h);
	    my $file = delete $options->{'credentials='};
	    my $credentials = network::smb::read_credentials_raw($file);
	    if ($credentials->{username}) {
		$options->{"$_="} = $credentials->{$_} foreach qw(username password domain);
		mount_options_pack($h, $options, $unknown);
	    }
	}

	$h;
    } @l;
}

sub merge_fstabs {
    my ($loose, $fstab, @l) = @_;

    foreach my $p (@$fstab) {
	my ($l1, $l2) = partition { fsedit::is_same_hd($_, $p) } @l;
	my ($p2) = @$l1 or next;
	@l = @$l2;

	$p->{mntpoint} = $p2->{mntpoint} if delete $p->{unsafeMntpoint};

	$p->{type} = $p2->{type} if $p2->{type} && !$loose;
	$p->{options} = $p2->{options} if $p2->{options} && !$loose;
	#- important to get isMounted property else DrakX may try to mount already mounted partitions :-(
	add2hash($p, $p2);
	$p->{device_alias} ||= $p2->{device_alias} || $p2->{device} if $p->{device} ne $p2->{device} && $p2->{device} !~ m|/|;

	$p->{type} && $p2->{type} && $p->{type} ne $p2->{type} && type2fs($p) ne type2fs($p2) &&
	  $p->{type} ne 'auto' && $p2->{type} ne 'auto' and
	    log::l("err, fstab and partition table do not agree for $p->{device} type: " .
		   (type2fs($p) || type2name($p->{type})) . " vs ", (type2fs($p2) || type2name($p2->{type})));
    }
    @l;
}

sub add2all_hds {
    my ($all_hds, @l) = @_;

    @l = merge_fstabs('', [ fsedit::get_really_all_fstab($all_hds) ], @l);

    foreach (@l) {
	my $s = 
	    isThisFs('nfs', $_) ? 'nfss' :
	    isThisFs('smbfs', $_) ? 'smbs' :
	    isThisFs('davfs', $_) ? 'davs' :
	    isTrueFS($_) || isSwap($_) || isOtherAvailableFS($_) ? '' :
	    'special';
	push @{$all_hds->{$s}}, $_ if $s;
    }
}

sub get_major_minor {
    eval {
	my (undef, $major, $minor) = devices::entry($_->{device});
	($_->{major}, $_->{minor}) = ($major, $minor);
    } foreach @_;
}

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

    my @l1 = map { my $l = $_; 
		   my %l = (type => fs2type('swap')); 
		   $l{$_} = $l->{$_} foreach qw(device major minor); 
		   \%l;
	       } read_fstab('', '/proc/swaps');
    
    my @l2 = map { read_fstab('', $_) } '/etc/mtab', '/proc/mounts';

    foreach (@l1, @l2) {
	log::l("found mounted partition on $_->{device} with $_->{mntpoint}");
	if ($::isInstall && $_->{mntpoint} =~ m!/tmp/(image|hdimage)!) {
	    $_->{real_mntpoint} = delete $_->{mntpoint};
	    if ($_->{real_mntpoint} eq '/tmp/hdimage') {
		log::l("found hdimage on $_->{device}");
		$_->{mntpoint} = common::usingRamdisk() && "/mnt/hd"; #- remap for hd install.
	    }
	}
	$_->{isMounted} = $_->{isFormatted} = 1;
	delete $_->{options};
    } 
    merge_fstabs('loose', $fstab, @l1, @l2);
}

# - when using "$loose", it does not merge in type&options from the fstab
sub merge_info_from_fstab {
    my ($fstab, $prefix, $uniq, $loose) = @_;

    my @l = grep { 
	if ($uniq) {
	    my $part = fsedit::mntpoint2part($_->{mntpoint}, $fstab);
	    !$part || fsedit::is_same_hd($part, $_); #- keep it only if it is the mountpoint AND the same device
	} else {
	    1;
	}
    } read_fstab($prefix, '/etc/fstab', 'keep_freq_passno', 'keep_devfs_name');

    merge_fstabs($loose, $fstab, @l);
}

# - when using "$loose", it does not merge in type&options from the fstab
sub get_info_from_fstab {
    my ($all_hds, $prefix) = @_;
    my @l = read_fstab($prefix, '/etc/fstab', 'keep_freq_passno', 'keep_devfs_name');
    add2all_hds($all_hds, @l)
}

sub prepare_write_fstab {
    my ($fstab, $o_prefix, $b_keep_smb_credentials) = @_;
    $o_prefix ||= '';

    my %new;
    my @smb_credentials;
    my @l = map { 
	my $device = 
	  isLoopback($_) ? 
	      ($_->{mntpoint} eq '/' ? "/initrd/loopfs" : $_->{loopback_device}{mntpoint}) . $_->{loopback_file} :
	  part2device($o_prefix, $_->{prefer_devfs_name} ? $_->{devfs_device} : $_->{device}, $_->{type});

	my $real_mntpoint = $_->{mntpoint} || ${{ '/tmp/hdimage' => '/mnt/hd' }}{$_->{real_mntpoint}};
	mkdir_p("$o_prefix$real_mntpoint") if $real_mntpoint =~ m|^/|;
	my $mntpoint = loopback::carryRootLoopback($_) ? '/initrd/loopfs' : $real_mntpoint;

	my ($freq, $passno) =
	  exists $_->{freq} ?
	    ($_->{freq}, $_->{passno}) :
	  isTrueFS($_) && $_->{options} !~ /encryption=/ && !$_->{is_removable} ? 
	    (1, $_->{mntpoint} eq '/' ? 1 : loopback::carryRootLoopback($_) ? 0 : 2) : 
	    (0, 0);

	if (($device eq 'none' || !$new{$device}) && ($mntpoint eq 'swap' || !$new{$mntpoint})) {
	    #- keep in mind the new line for fstab.
	    $new{$device} = 1;
	    $new{$mntpoint} = 1;

	    my $options = $_->{options};

	    if (isThisFs('smbfs', $_) && $options =~ /password=/ && !$b_keep_smb_credentials) {
		require network::smb;
		if (my ($opts, $smb_credentials) = network::smb::fstab_entry_to_credentials($_)) {
		    $options = $opts;
		    push @smb_credentials, $smb_credentials;
		}
	    }

	    my $type = type2fs($_, 'auto');

	    my $dev = 
	      $_->{device_LABEL} ? $_->{device_LABEL} :
	      $_->{device_alias} ? "/dev/$_->{device_alias}" : $device;

	    $mntpoint =~ s/ /\\040/g;
	    $dev =~ s/ /\\040/g;

	    # handle bloody supermount special case
	    if ($options =~ /supermount/) {
		my @l = grep { $_ ne 'supermount' } split(',', $options);
		my @l1 = grep { member($_, 'ro', 'exec') } @l;
		my @l2 = difference2(\@l, \@l1);
		$options = join(",", "dev=$dev", "fs=$type", @l1, if_(@l2, '--', @l2));
		($dev, $type) = ('none', 'supermount');
	    } else {
		#- if we were using supermount, the type could be something like ext2:vfat
		#- but this can't be done without supermount, so switching to "auto"
		$type = 'auto' if $type =~ /:/;
	    }

	    [ $mntpoint, $_->{comment} . join(' ', $dev, $mntpoint, $type, $options || 'defaults', $freq, $passno) . "\n" ];
	} else {
	    ()
	}
    } grep { $_->{device} && ($_->{mntpoint} || $_->{real_mntpoint}) && $_->{type} && ($_->{isFormatted} || !$_->{notFormatted}) } @$fstab;

    join('', map { $_->[1] } sort { $a->[0] cmp $b->[0] } @l), \@smb_credentials;
}

sub fstab_to_string {
    my ($all_hds, $o_prefix) = @_;
    my $fstab = [ fsedit::get_really_all_fstab($all_hds), @{$all_hds->{special}} ];
    my ($s, undef) = prepare_write_fstab($fstab, $o_prefix, 'keep_smb_credentials');
    $s;
}

sub write_fstab {
    my ($all_hds, $o_prefix) = @_;
    log::l("writing $o_prefix/etc/fstab");
    my $fstab = [ fsedit::get_really_all_fstab($all_hds), @{$all_hds->{special}} ];
    my ($s, $smb_credentials) = prepare_write_fstab($fstab, $o_prefix, '');
    output("$o_prefix/etc/fstab", $s);
    network::smb::save_credentials($_) foreach @$smb_credentials;
}

sub part2device {
    my ($prefix, $dev, $type) = @_;
    $dev eq 'none' || member($type, qw(nfs smbfs davfs)) ? 
      $dev : 
      do {
	  my $dir = $dev =~ m!^(/|LABEL=)! ? '' : '/dev/';
	  eval { devices::make("$prefix$dir$dev") };
	  "$dir$dev";
      };
}

sub auto_fs() {
    grep { chop; $_ && !/nodev/ } cat_("/etc/filesystems");
}

sub mount_options() {
    my %non_defaults = (
			sync => 'async', noatime => 'atime', noauto => 'auto', ro => 'rw', 
			user => 'nouser', nodev => 'dev', noexec => 'exec', nosuid => 'suid',
		       );
    my @user_implies = qw(noexec nodev nosuid);
    \%non_defaults, \@user_implies;
}

sub mount_options_unpack {
    my ($part) = @_;
    my $packed_options = $part->{options};

    my ($non_defaults, $user_implies) = mount_options();

    my @auto_fs = auto_fs();
    my %per_fs = (
		  iso9660 => [ qw(unhide) ],
		  vfat => [ qw(umask=0 umask=0022) ],
		  ntfs => [ qw(umask=0 umask=0022) ],
		  nfs => [ qw(rsize=8192 wsize=8192) ],
		  smbfs => [ qw(username= password=) ],
		  davfs => [ qw(username= password= uid= gid=) ],
		  reiserfs => [ 'notail' ],
		 );
    push @{$per_fs{$_}}, 'usrquota', 'grpquota' foreach 'ext2', 'ext3', 'xfs';

    while (my ($fs, $l) = each %per_fs) {
	isThisFs($fs, $part) || $part->{type} eq 'auto' && member($fs, @auto_fs) or next;
	$non_defaults->{$_} = 1 foreach @$l;
    }

    $non_defaults->{encrypted} = 1 if !$part->{isFormatted} || isSwap($part);

    $non_defaults->{supermount} = 1 if $part->{type} =~ /:/ || member(type2fs($part), 'auto', @auto_fs);

    my $defaults = { reverse %$non_defaults };
    my %options = map { $_ => '' } keys %$non_defaults;
    my @unknown;
    foreach (split(",", $packed_options)) {
	if ($_ eq 'user') {
	    $options{$_} = 1 foreach 'user', @$user_implies;
	} elsif (exists $non_defaults->{$_}) {
	    $options{$_} = 1;
	} elsif ($defaults->{$_}) {
	    $options{$defaults->{$_}} = 0;
	} elsif (/(.*?=)(.*)/) {
	    $options{$1} = $2;
	} else {
	    push @unknown, $_;
	}
    }
    # merge those, for cleaner help
    $options{'rsize=8192,wsize=8192'} = delete $options{'rsize=8192'} && delete $options{'wsize=8192'}
      if exists $options{'rsize=8192'};

    my $unknown = join(",", @unknown);
    \%options, $unknown;
}

sub mount_options_pack_ {
    my ($_part, $options, $unknown) = @_;

    my ($non_defaults, $user_implies) = mount_options();
    my @l;

    my @umasks = map {
	if (/^umask=/) {
	    my $v = delete $options->{$_};
	    /^umask=(.+)/ ? if_($v, $1) : $v;
	} else { () }
    } keys %$options;
    if (@umasks) {
	push @l, 'umask=' . min(@umasks);
    }

    if (delete $options->{user}) {
	push @l, 'user';
	foreach (@$user_implies) {
	    if (!delete $options->{$_}) {
		# overriding
		$options->{$non_defaults->{$_}} = 1;
	    }
	}
    }
    push @l, map_each { if_($::b, $::a =~ /=$/ ? "$::a$::b" : $::a) } %$options;
    push @l, $unknown;

    join(",", uniq(grep { $_ } @l));
}
sub mount_options_pack {
    my ($part, $options, $unknown) = @_;
    $part->{options} = mount_options_pack_($part, $options, $unknown);
    noreturn();
}

# update me on each util-linux new release:
sub mount_options_help() {
    (

	'grpquota' => '',

	'noatime' => N("Do not update inode access times on this file system
(e.g, for faster access on the news spool to speed up news servers)."),

	'noauto' => N("Can only be mounted explicitly (i.e.,
the -a option will not cause the file system to be mounted)."),

	'nodev' => N("Do not interpret character or block special devices on the file system."),

	'noexec' => N("Do not allow execution of any binaries on the mounted
file system. This option might be useful for a server that has file systems
containing binaries for architectures other than its own."),

	'nosuid' => N("Do not allow set-user-identifier or set-group-identifier
bits to take effect. (This seems safe, but is in fact rather unsafe if you
have suidperl(1) installed.)"),

	'ro' => N("Mount the file system read-only."),

	'sync' => N("All I/O to the file system should be done synchronously."),

	'supermount' => '',

	'user' => N("Allow an ordinary user to mount the file system. The
name of the mounting user is written to mtab so that he can unmount the file
system again. This option implies the options noexec, nosuid, and nodev
(unless overridden by subsequent options, as in the option line
user,exec,dev,suid )."),

	'usrquota' => '',

        'umask=0' => N("Give write access to ordinary users"),

        'umask=0022' => N("Give read-only access to ordinary users"),
    );
}

sub set_default_options {
    my ($part, %opts) = @_;
    #- opts are: useSupermount security iocharset codepage

    my ($options, $unknown) = mount_options_unpack($part);

    if ($part->{is_removable}) {
	$options->{supermount} = $opts{useSupermount} && !($opts{useSupermount} eq 'magicdev' && $part->{media_type} eq 'cdrom');
	$part->{type} = !$options->{supermount} ? 'auto' :
	  $part->{media_type} eq 'cdrom' ? 'udf:iso9660' : 'ext2:vfat';
    }

    if ($part->{media_type} eq 'cdrom') {
	$options->{ro} = 1;
    }

    if ($part->{media_type} eq 'fd') {
	# slow device so don't loose time, write now!
	$options->{sync} = 1;
    }

    if (isTrueFS($part)) {
	#- noatime on laptops (do not wake up the hd)
	#- Do  not  update  inode  access times on this
	#- file system (e.g, for faster access  on  the
	#- news spool to speed up news servers).
	$options->{noatime} = detect_devices::isLaptop();
    }
    if (isThisFs('nfs', $part)) {
	put_in_hash($options, { 
			       nosuid => 1, 'rsize=8192,wsize=8192' => 1, soft => 1,
			      });
    }
    if (isThisFs('smbfs', $part)) {
	add2hash($options, { 'username=' => '%' }) if !$options->{'credentials='};
    }
    if (isFat($part) || member('vfat', split(':', $part->{type})) || isThisFs('auto', $part)) {

	put_in_hash($options, {
			       user => 1, noexec => 0,
			      }) if $part->{is_removable};

	put_in_hash($options, {
			       'umask=0' => $opts{security} < 3, 'umask=0022' => $opts{security} < 4,
			       'iocharset=' => $opts{iocharset}, 'codepage=' => $opts{codepage},
			      });
    }
    if (isThisFs('ntfs', $part)) {