summaryrefslogtreecommitdiffstats
path: root/main/alpine-conf/0001-setup-disk-fix-find_disks.patch
blob: 2b5453d6bf2562c01aa3d4fc85951830ca150569 (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
From 5572e8a3db95f179b3433e5ea5f8c6fa2c8c65ab Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 29 Sep 2009 09:40:53 +0000
Subject: [PATCH] setup-disk: fix find_disks

The old way did not detect ida/c0d0. The new should detect it.
We also filter out md devices.
---
 setup-disk.in |   42 ++++++++++++++++++++++++++++++++----------
 1 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/setup-disk.in b/setup-disk.in
index d53fba1..33cc868 100644
--- a/setup-disk.in
+++ b/setup-disk.in
@@ -146,25 +146,47 @@ find_swap_size() {
 
 has_mounted_part() {
 	local p
-	# parse /proc/mounts for moutned devices
+	# parse /proc/mounts for mounted devices
 	for p in $(awk '$1 ~ /^\/dev\// {gsub("/dev/", "", $1); print $1}' \
 			/proc/mounts); do
-		if [ -e /sys/block/$1/$p ]; then
-			return 0
-		fi
+		[ -e /sys/block/$1/$p ] && return 0
 	done
 	return 1
 }
 
+has_holders() {
+	local i
+	# check if device is used by any md devices
+	for i in $1/holders/* $1/*/holders/*; do
+		[ -e "$i" ] && return 0
+	done
+	return 1
+}
+
+is_available_disk() {
+	local dev=$1
+	local b=$(echo $p | sed 's:/:!:g')
+
+	# check if its a "root" block device and not a partition
+	[ -e /sys/block/$b ] || return 1
+	
+	# check so it does not have mounted partitions
+	has_mounted_part $dev && return 1
+
+	# check so its not part of an md setup
+	has_holders /sys/block/$b && return 1
+
+	# check so its not an md device
+	[ -e /sys/block/$b/md ] && return 1
+
+	return 0
+}
+
 find_disks() {
-	local p= disks=
+	local p=
 	for p in $(awk '$1 ~ /[0-9]+/ {print $4}' /proc/partitions); do
-		b=$(echo $p | sed 's:/:!:g')
-		if [ -e /sys/block/$b/device ] && ! has_mounted_part $p; then
-			disks="$disks $p"
-		fi
+		is_available_disk $p && echo -n " $p"
 	done
-	echo $disks
 }
 
 useall() {
-- 
1.6.4.4