From: Matthias Schwarzott <zzam@gentoo.org>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] creating link /dev/root to device / is mounted from
Date: Fri, 20 Apr 2007 10:46:21 +0000 [thread overview]
Message-ID: <200704201246.21524.zzam@gentoo.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 488 bytes --]
Hi there!
Some software (like hal) needs the /dev/root link (as /proc/mounts can contain
it).
The attached patch contains one program which compares the major/minor number
supplied to it on the command-line with the numbers of the device / is
located on.
It is used with this rule (see 60-root_link.rules):
SUBSYSTEM=="block", PROGRAM=="blockdev_is_root $major $minor", SYMLINK+="root"
The patch also adds the rule to the gentoo rules file.
Matthias
--
Matthias Schwarzott (zzam)
[-- Attachment #2: udev-root_link.diff --]
[-- Type: text/x-diff, Size: 4431 bytes --]
diff --git a/etc/udev/gentoo/50-udev.rules b/etc/udev/gentoo/50-udev.rules
index 2887553..7e0acec 100644
--- a/etc/udev/gentoo/50-udev.rules
+++ b/etc/udev/gentoo/50-udev.rules
@@ -36,6 +36,9 @@ KERNEL=="ircomm*", NAME="%k", GROUP="uucp", MODE="0660"
# all block devices
SUBSYSTEM=="block", GROUP="disk"
+# create link /dev/root to the blockdevice / is mounted from
+SUBSYSTEM=="block", PROGRAM=="blockdev_is_root $major $minor", SYMLINK+="root"
+
# cdrom symlinks and other good cdrom naming
KERNEL=="sr[0-9]*|hd[a-z]|pcd[0-9]*", ACTION=="add", IMPORT{program}="cdrom_id --export $tempnode"
ENV{ID_CDROM}=="?*", GROUP="cdrom"
diff --git a/extras/root_link/60-root_link.rules b/extras/root_link/60-root_link.rules
new file mode 100644
index 0000000..2175876
--- /dev/null
+++ b/extras/root_link/60-root_link.rules
@@ -0,0 +1,3 @@
+# create link /dev/root to the blockdevice / is mounted from
+
+SUBSYSTEM=="block", PROGRAM=="blockdev_is_root $major $minor", SYMLINK+="root"
diff --git a/extras/root_link/Makefile b/extras/root_link/Makefile
new file mode 100644
index 0000000..2420df5
--- /dev/null
+++ b/extras/root_link/Makefile
@@ -0,0 +1,69 @@
+# Makefile for udev extra invoked from the udev main Makefile
+#
+# Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
+#
+# Released under the GNU General Public License, version 2.
+#
+
+PROG = blockdev_is_root
+OBJ =
+HEADERS =
+GEN_HEADERS =
+MAN_PAGES =
+
+prefix =
+etcdir = ${prefix}/etc
+sbindir = ${prefix}/sbin
+usrbindir = ${prefix}/usr/bin
+usrsbindir = ${prefix}/usr/sbin
+libudevdir = ${prefix}/lib/udev
+mandir = ${prefix}/usr/share/man
+configdir = ${etcdir}/udev/
+
+INSTALL = install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+INSTALL_SCRIPT = ${INSTALL}
+
+all: $(PROG) $(MAN_PAGES)
+.PHONY: all
+.DEFAULT: all
+
+%.o: %.c $(GEN_HEADERS)
+ $(E) " CC " $@
+ $(Q) $(CC) -c $(CFLAGS) $< -o $@
+
+$(PROG): %: $(HEADERS) %.o $(OBJS)
+ $(E) " LD " $@
+ $(Q) $(LD) $(LDFLAGS) $@.o $(OBJS) -o $@ $(LIBUDEV) $(LIB_OBJS)
+
+# man pages
+%.8: %.xml
+ $(E) " XMLTO " $@
+ $(Q) xmlto man $?
+.PRECIOUS: %.8
+
+clean:
+ $(E) " CLEAN "
+ $(Q) rm -f $(PROG) $(OBJS) $(GEN_HEADERS)
+.PHONY: clean
+
+install-bin: all
+ $(INSTALL_PROGRAM) -D $(PROG) $(DESTDIR)$(libudevdir)/$(PROG)
+.PHONY: install-bin
+
+uninstall-bin:
+ - rm $(DESTDIR)$(libudevdir)/$(PROG)
+.PHONY: uninstall-bin
+
+install-man:
+ @echo "Please create a man page for this tool."
+.PHONY: install-man
+
+uninstall-man:
+ @echo "Please create a man page for this tool."
+.PHONY: uninstall-man
+
+install-config:
+ @echo "no config file to install"
+.PHONY: install-config
diff --git a/extras/root_link/blockdev_is_root.c b/extras/root_link/blockdev_is_root.c
new file mode 100644
index 0000000..f873108
--- /dev/null
+++ b/extras/root_link/blockdev_is_root.c
@@ -0,0 +1,73 @@
+/*
+ * blockdev_is_root - compare major/minor from cmdline to the device / is on
+ *
+ * Copyright (C) 2007 Matthias Schwarzott <zzam@gentoo.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// Getting major/minor
+#include <sys/sysmacros.h>
+
+void usage(void);
+
+void usage(void)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, " blockdev_is_root MAJOR MINOR\n");
+ fprintf(stderr, " Exit code will be 0 if device is the one \"/\" is mounted from.\n");
+}
+
+int main(int argc, char **argv)
+{
+ struct stat stat_buf;
+ unsigned int dev_major=0, dev_minor=0;
+ dev_t root_dev, dev_dev;
+
+ if (argc < 3) {
+ usage();
+ return EXIT_FAILURE;
+ }
+
+ if (argv[1])
+ dev_major=strtol(argv[1], NULL, 10);
+ else
+ return EXIT_FAILURE;
+
+ if (dev_major == 0) {
+ fprintf(stderr, "MAJOR == 0\n");
+ return EXIT_FAILURE;
+ }
+
+ if (argv[2])
+ dev_minor=strtol(argv[2], NULL, 10);
+ else
+ return EXIT_FAILURE;
+
+ dev_dev = gnu_dev_makedev(dev_major, dev_minor);
+
+ if (stat("/", &stat_buf) < 0) {
+ perror("stat");
+ return EXIT_FAILURE;
+ }
+
+ root_dev = stat_buf.st_dev;
+
+ // printf("ROOT: %lld \n", (long long) root_dev);
+ // printf("DEV: %lld \n", (long long) dev_dev);
+
+ if (dev_dev == root_dev)
+ return EXIT_SUCCESS;
+
+ return EXIT_FAILURE;
+}
+
[-- Attachment #3: Type: text/plain, Size: 286 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
[-- Attachment #4: Type: text/plain, Size: 226 bytes --]
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
next reply other threads:[~2007-04-20 10:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-20 10:46 Matthias Schwarzott [this message]
2007-04-20 14:55 ` [PATCH] creating link /dev/root to device / is mounted from Kay Sievers
2007-04-21 9:35 ` Matthias Schwarzott
2007-04-21 10:29 ` Andrey Borzenkov
2007-04-21 10:41 ` Kay Sievers
2007-04-21 13:31 ` Matthias Schwarzott
2007-04-21 17:47 ` Doug Goldstein
2007-04-22 12:01 ` Kay Sievers
2007-04-23 17:58 ` David Zeuthen
2007-04-24 9:37 ` Kay Sievers
2007-05-03 5:56 ` David Zeuthen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200704201246.21524.zzam@gentoo.org \
--to=zzam@gentoo.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.