summaryrefslogtreecommitdiff
path: root/package/base-files/src/etc/mdev/fs
blob: eb60379e685292ccbc79a38d036d683d1a41b534 (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
#!/bin/sh
# skip root disk here, will be handled in /etc/init.d/fs
rootdisk=$(readlink /dev/root)
if [ "x${rootdisk}" = "x${MDEV}" ];then
	exit 0
fi
uuid=$(blkid /dev/${MDEV} | sed -n '/^.*UUID="\([^"]*\)".*$/s//\1/p')
if [ -z $uuid ];then
	fs=$(grep "^/dev/${MDEV}[[:blank:]]" /etc/fstab | awk '{ print $3 }')
	mnt=$(grep "^/dev/${MDEV}[[:blank:]]" /etc/fstab | awk '{ print $2 }')
	disk="${MDEV}"
else
	fs=$(grep "^/dev/${MDEV}[[:blank:]]\|^UUID=$uuid" /etc/fstab | awk '{ print $3 }')
	mnt=$(grep "^/dev/${MDEV}[[:blank:]]\|^UUID=$uuid" /etc/fstab | awk '{ print $2 }')
	disk="${MDEV} (${uuid})"
fi
if [ -z $fs ];then
	logger -t mdev "Disk $disk not registered in /etc/fstab"
	exit 0
fi

procfs=$fs
if [ $fs = "ntfs-3g" ];then
	procfs=fuse
fi

# check if already mounted via /etc/init.d/fs
adk_check() {
	mount | grep "${MDEV}[[:blank:]]"
	if [ $? -eq 0 ];then
		logger -t mdev "Filesystem on ${MDEV} already mounted"
		exit 0
	fi
}

# filesystem check
adk_fsck() {
	[ -x /usr/sbin/fsck.$fs ] && {
		logger -t mdev "Checking $fs filesystem on ${MDEV}"
		fsck -p ${MDEV} >/dev/null
	}
}

# mount filesystem
adk_mount() {
	mkdir -p $mnt >/dev/null 2>&1
	grep $procfs /proc/filesystems >/dev/null 2>&1
	if [ $? -eq 0 ];then
		logger -t mdev "Mounting $disk to $mnt"
		mount $mnt 2>/dev/null
		if [ $? -ne 0 ];then
			logger -s -t 'Filesystem' "Mounting $disk failed"
		fi
	else
		logger -t mdev "Required filesystem $procfs not available"
	fi
}

case "${ACTION}" in
add)
	logger -t mdev "Device ${MDEV} added to the system"
	adk_check
	adk_fsck
	adk_mount
	;;
esac
exit 0