linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Schwarzott <zzam@gentoo.org>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] Creating /dev/root - sane approach
Date: Thu, 16 Aug 2007 14:15:15 +0000	[thread overview]
Message-ID: <200708161615.15746.zzam@gentoo.org> (raw)

[-- 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

             reply	other threads:[~2007-08-16 14:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 14:15 Matthias Schwarzott [this message]
2007-08-16 15:14 ` [PATCH] Creating /dev/root - sane approach Kay Sievers

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=200708161615.15746.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 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).