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; +} +