* [PATCH] Creating /dev/root - sane approach
@ 2007-08-16 14:15 Matthias Schwarzott
2007-08-16 15:14 ` Kay Sievers
0 siblings, 1 reply; 2+ messages in thread
From: Matthias Schwarzott @ 2007-08-16 14:15 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 456 bytes --]
Hi there!
As udev now supports /dev/.udev/rules.d as always writable rule location here
now is my reworked apporach on creating /dev/root.
It contains one c-program to get major/minor number of a directory.
And it contains a script calling this binary for directory /, and writing a
rule like this to /dev/.udev/rules.d/10-root-link.rules
SUBSYSTEM=="block", ENV{MAJOR}=="8", ENV{MINOR}=="1", SYMLINK+="root"
Matthias
--
Matthias Schwarzott (zzam)
[-- Attachment #2: udev-114-root-link-2.diff --]
[-- Type: text/x-diff, Size: 4677 bytes --]
diff -ruN udev-git/extras/root_link/get_dir_major_minor.c udev-git-try/extras/root_link/get_dir_major_minor.c
--- udev-git/extras/root_link/get_dir_major_minor.c 1970-01-01 01:00:00.000000000 +0100
+++ udev-git-try/extras/root_link/get_dir_major_minor.c 2007-08-16 16:08:30.000000000 +0200
@@ -0,0 +1,52 @@
+// print out major/minor nr of the device the supplied dir
+// is mounted on
+//
+// 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.
+//
+// (c) 2007 Matthias Schwarzott <zzam@gentoo.org>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// Getting major/minor
+#include <sys/sysmacros.h>
+int main(int argc, char **argv)
+{
+ struct stat stat_buf;
+ unsigned int dev_major=0, dev_minor=0;
+ dev_t dev;
+
+ if (argc != 2) {
+ printf("Usage:\n");
+ printf(" get_dir_major_minor <directory>\n");
+ return EXIT_FAILURE;
+ }
+
+ if (stat(argv[1], &stat_buf) < 0) {
+ perror("stat");
+ return EXIT_FAILURE;
+ }
+
+ dev = stat_buf.st_dev;
+
+ dev_major = gnu_dev_major(dev);
+ dev_minor = gnu_dev_minor(dev);
+
+
+ if (dev_major == 0) {
+ fprintf(stderr, "Major number is 0.\n");
+ return EXIT_FAILURE;
+ } else
+ printf("%d %d\n",
+ dev_major,
+ dev_minor);
+
+ return EXIT_SUCCESS;
+}
+
diff -ruN udev-git/extras/root_link/Makefile udev-git-try/extras/root_link/Makefile
--- udev-git/extras/root_link/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ udev-git-try/extras/root_link/Makefile 2007-08-16 15:52:01.000000000 +0200
@@ -0,0 +1,70 @@
+# 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 = get_dir_major_minor
+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)
+ $(INSTALL_PROGRAM) -D write_root_link_rule $(DESTDIR)$(libudevdir)/
+.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 -ruN udev-git/extras/root_link/write_root_link_rule udev-git-try/extras/root_link/write_root_link_rule
--- udev-git/extras/root_link/write_root_link_rule 1970-01-01 01:00:00.000000000 +0100
+++ udev-git-try/extras/root_link/write_root_link_rule 2007-08-16 16:12:23.000000000 +0200
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# This script should run before doing udevtrigger at boot.
+# It will create a rule matching the device directory / is on, and
+# creating /dev/root symlink pointing on its device node.
+#
+# This is especially useful for hal looking at /proc/mounts containing
+# a line listing /dev/root as device:
+# /dev/root / reiserfs rw 0 0
+#
+# 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.
+#
+# (c) 2007 Matthias Schwarzott <zzam@gentoo.org>
+
+PROG=/lib/udev/get_dir_major_minor
+[ -x "${PROG}" ] && DEV=$(${PROG} "/")
+if [ $? = 0 ]; then
+ MAJOR="${DEV% *}"
+ MINOR="${DEV#* }"
+
+ [ -d /dev/.udev/rules.d ] || mkdir -p /dev/.udev/rules.d
+ RULES=/dev/.udev/rules.d/10-root-link.rules
+
+ echo "# Created by /lib/udev/write_root_link_rule" > "${RULES}"
+ echo "# This rule should create /dev/root as link to real root device." >> "${RULES}"
+ echo "SUBSYSTEM==\"block\", ENV{MAJOR}==\"$MAJOR\", ENV{MINOR}==\"$MINOR\", SYMLINK+=\"root\"" >> "${RULES}"
+fi
+
[-- Attachment #3: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Creating /dev/root - sane approach
2007-08-16 14:15 [PATCH] Creating /dev/root - sane approach Matthias Schwarzott
@ 2007-08-16 15:14 ` Kay Sievers
0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2007-08-16 15:14 UTC (permalink / raw)
To: linux-hotplug
On 8/16/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> As udev now supports /dev/.udev/rules.d as always writable rule location here
> now is my reworked apporach on creating /dev/root.
>
> It contains one c-program to get major/minor number of a directory.
> And it contains a script calling this binary for directory /, and writing a
> rule like this to /dev/.udev/rules.d/10-root-link.rules
>
> SUBSYSTEM="block", ENV{MAJOR}="8", ENV{MINOR}="1", SYMLINK+="root"
Yep, that looks fine.
I'm working on something that allows the mounting of hotpluggable
devices, which are specified in /etc/fstab. There will be something
like a "nofail" option to use, in fstab which ignores missing devices.
When a device listed in fstab will be connected later, it can be
fsck'd and mounted by udev. For that, fstab is parsed at bootup and
rules that match on NAME= and SYMLINK= will be created to trigger
the mounting, so we don't need to look into fstab with every block
event.
The root symlink can be added in the same step. We can at least use
the same program for doing the stat("/"), even when the automounting
stuff will not be used. Sounds ok?
It's "conference season", so I got a bit busy with traveling, will
look into that stuff this week, I hope.
Thanks,
Kay
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-08-16 15:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-16 14:15 [PATCH] Creating /dev/root - sane approach Matthias Schwarzott
2007-08-16 15:14 ` Kay Sievers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).