~siretart/cryptsetup/debian

« back to all changes in this revision

Viewing changes to debian/cryptdisks.functions

  • Committer: Reinhard Tartler
  • Date: 2008-05-25 20:03:28 UTC
  • Revision ID: siretart@tauware.de-20080525200328-szhw0j5yw0p5kl33
import cryptsetup_1.0.6~pre1+svn45-1.dsc

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        CHECKARGS=""
40
40
        PRECHECK=""
41
41
        TRIES="3"
42
 
        MAKETMP=""
 
42
        TMPFS=""
43
43
        MAKESWAP=""
44
44
        USELUKS=""
45
45
        TIMEOUT=""
144
144
                        PARAMS="$PARAMS --timeout=$TIMEOUT"
145
145
                        ;;
146
146
                swap)
147
 
                        MAKESWAP=yes
 
147
                        MAKESWAP="yes"
148
148
                        SWCHECK="/lib/cryptsetup/checks/un_vol_id"
149
149
                        SWCHECKARGS="swap"
150
150
                        ;;
151
151
                tmp)
152
 
                        MAKETMP=yes
 
152
                        if [ -z "$VALUE" ]; then
 
153
                                TMPFS="ext2"
 
154
                        else
 
155
                                TMPFS="$VALUE"
 
156
                        fi
153
157
                        ;;
154
158
                luks)
155
 
                        USELUKS=yes
 
159
                        USELUKS="yes"
156
160
                        ;;
157
161
                noearly)
158
162
                        if [ "$INITSTATE" = "early" ]; then
159
163
                                IGNORE="yes"
160
164
                        fi
161
165
                        ;;
 
166
                noauto)
 
167
                        if [ -n "$INITSTATE" ]; then
 
168
                                IGNORE="yes"
 
169
                        fi
 
170
                        ;;
162
171
                loud)
163
 
                        LOUD=yes
 
172
                        LOUD="yes"
164
173
                        ;;
165
174
                keyscript)
166
175
                        if [ -n "$KEYSCRIPT" ]; then
394
403
 
395
404
# Prepares tmp partitions using random keys
396
405
do_tmp () {
397
 
        if [ "$MAKETMP" != "yes" ] || [ ! -b "/dev/mapper/$dst" ]; then
 
406
        if [ "x$TMPFS" = "x" ] || [ ! -b "/dev/mapper/$dst" ]; then
398
407
                return 0
399
408
        fi
400
409
 
401
 
        mke2fs "/dev/mapper/$dst" > /dev/null 2>&1 || return 1
402
 
        mount -t ext2 "/dev/mapper/$dst" /tmp || return 1
 
410
        mkfs -t $TMPFS -q "/dev/mapper/$dst" > /dev/null 2>&1 || return 1
 
411
        mount -t $TMPFS "/dev/mapper/$dst" /tmp || return 1
403
412
        chmod 1777 /tmp
404
413
        umount /tmp
405
414
        return 0
440
449
}
441
450
 
442
451
# Sets up all entries in crypttab
443
 
handle_crypttab_line () {
 
452
handle_crypttab_line_start () {
444
453
        dst=$1
445
454
        src=$2
446
455
        key=$3
490
499
        if [ "$IGNORE" = "yes" ]; then
491
500
                result="ignore"
492
501
        else
493
 
                log_progress_msg "$dst (starting)"
 
502
                log_action_msg "$dst (starting)"
494
503
                result="ok"
495
504
                if [ "$USELUKS" = "yes" ]; then
496
505
                        do_luks || result="fail"
514
523
        return 0
515
524
}
516
525
 
 
526
handle_crypttab_line_stop () {
 
527
        dst=$1
 
528
        src=$2
 
529
        key=$3
 
530
        opts=$4
 
531
 
 
532
        if [ ! -b "/dev/mapper/$dst" ]; then
 
533
                device_msg "$dst" "stopped"
 
534
                continue
 
535
        fi
 
536
 
 
537
        opencount=$(dmsetup info -c --noheadings -o open "$dst" 2> /dev/null || true)
 
538
        if [ -z "$opencount" ]; then
 
539
                device_msg "$dst" "error"
 
540
                continue
 
541
        elif [ "$opencount" != "0" ]; then
 
542
                device_msg "$dst" "busy"
 
543
                continue
 
544
        fi
 
545
 
 
546
        #major=$(dmsetup info -c --noheadings -o major "$dst" 2> /dev/null || true)
 
547
        #minor=$(dmsetup info -c --noheadings -o minor "$dst" 2> /dev/null || true)
 
548
        src_major=$(dmsetup deps "$dst" 2> /dev/null | sed -e 's/^.*(\([0-9]*\), [0-9]*)$/\1/g' || true)
 
549
        src_minor=$(dmsetup deps "$dst" 2> /dev/null | sed -e 's/^.*([0-9]*, \([0-9]*\))$/\1/g' || true)
 
550
 
 
551
        if [ -z "$src_major" ] || [ -z "$src_minor" ]; then
 
552
                device_msg "$dst" "error"
 
553
                continue
 
554
        fi
 
555
 
 
556
        do_close
 
557
 
 
558
        # Detach loopback device, if attached
 
559
        if [ "$src_major" = "7" ]; then
 
560
                loopdev="/dev/loop${src_minor}"
 
561
                if ! rm_lo_setup; then
 
562
                        device_msg "$dst" "detaching loopback failed"
 
563
                        continue
 
564
                fi
 
565
        fi
 
566
 
 
567
        device_msg "$dst" "stopping"
 
568
 
 
569
        return 0
 
570
}
 
571
 
517
572
do_start () {
518
573
        local dst src key opts result
519
574
 
524
579
        mount_fs
525
580
 
526
581
        egrep -v "^[[:space:]]*(#|$)" "$TABFILE" | while read dst src key opts; do
527
 
                handle_crypttab_line "$dst" "$src" "$key" "$opts"
 
582
                handle_crypttab_line_start "$dst" "$src" "$key" "$opts"
528
583
        done
529
584
        umount_fs
530
585
 
540
595
        loopmajor=$(grep "[[:space:]]*loop$" /proc/devices | sed 's/^[[:space:]]*//;s/[[:space:]].*//')
541
596
 
542
597
        egrep -v "^[[:space:]]*(#|$)" "$TABFILE" | while read dst src key opts; do
543
 
                if [ ! -b "/dev/mapper/$dst" ]; then
544
 
                        device_msg "$dst" "stopped"
545
 
                        continue
546
 
                fi
547
 
 
548
 
                opencount=$(dmsetup info -c --noheadings -o open "$dst" 2> /dev/null || true)
549
 
                if [ -z "$opencount" ]; then
550
 
                        device_msg "$dst" "error"
551
 
                        continue
552
 
                elif [ "$opencount" != "0" ]; then
553
 
                        device_msg "$dst" "busy"
554
 
                        continue
555
 
                fi
556
 
 
557
 
                #major=$(dmsetup info -c --noheadings -o major "$dst" 2> /dev/null || true)
558
 
                #minor=$(dmsetup info -c --noheadings -o minor "$dst" 2> /dev/null || true)
559
 
                src_major=$(dmsetup deps "$dst" 2> /dev/null | sed -e 's/^.*(\([0-9]*\), [0-9]*)$/\1/g' || true)
560
 
                src_minor=$(dmsetup deps "$dst" 2> /dev/null | sed -e 's/^.*([0-9]*, \([0-9]*\))$/\1/g' || true)
561
 
 
562
 
                if [ -z "$src_major" ] || [ -z "$src_minor" ]; then
563
 
                        device_msg "$dst" "error"
564
 
                        continue
565
 
                fi
566
 
 
567
 
                do_close
568
 
 
569
 
                # Detach loopback device, if attached
570
 
                if [ "$src_major" = "7" ]; then
571
 
                        loopdev="/dev/loop${src_minor}"
572
 
                        if ! rm_lo_setup; then
573
 
                                device_msg "$dst" "detaching loopback failed"
574
 
                                continue
575
 
                        fi
576
 
                fi
577
 
 
578
 
                log_action_cont_msg "$dst (stopping)"
 
598
                handle_crypttab_line_stop "$dst" "$src" "$key" "$opts"
579
599
        done
580
600
 
581
601
        log_action_end_msg 0