From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthias Schwarzott Date: Fri, 20 Apr 2007 10:46:21 +0000 Subject: [PATCH] creating link /dev/root to device / is mounted from Message-Id: <200704201246.21524.zzam@gentoo.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="Boundary-00=_9nJKGwIA2+SuVtw" List-Id: To: linux-hotplug@vger.kernel.org --Boundary-00=_9nJKGwIA2+SuVtw Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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) --Boundary-00=_9nJKGwIA2+SuVtw Content-Type: text/x-diff; charset="utf-8"; name="udev-root_link.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="udev-root_link.diff" 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 +# +# 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 + * + * 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 +#include +#include + +#include +#include + +// Getting major/minor +#include + +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; +} + --Boundary-00=_9nJKGwIA2+SuVtw Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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/ --Boundary-00=_9nJKGwIA2+SuVtw Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --Boundary-00=_9nJKGwIA2+SuVtw--