chiark / gitweb /
tabs are as useful as a hole in the head
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 10 Jan 2012 00:34:15 +0000 (01:34 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 10 Jan 2012 00:34:15 +0000 (01:34 +0100)
74 files changed:
COPYING
autogen.sh
configure.ac
rules/arch/40-s390.rules
rules/rules.d/50-udev-default.rules
src/COPYING
src/extras/accelerometer/accelerometer.c
src/extras/ata_id/ata_id.c
src/extras/cdrom_id/cdrom_id.c
src/extras/collect/collect.c
src/extras/edd_id/edd_id.c
src/extras/floppy/create_floppy_devices.c
src/extras/gudev/COPYING
src/extras/gudev/docs/Makefile.am
src/extras/gudev/docs/gudev-docs.xml
src/extras/gudev/gudevclient.c
src/extras/keymap/check-keymaps.sh
src/extras/keymap/findkeyboards
src/extras/keymap/keyboard-force-release.sh.in
src/extras/keymap/keymap.c
src/extras/keymap/keymaps/acer-aspire_5720
src/extras/keymap/keymaps/lenovo-ideapad
src/extras/mtd_probe/mtd_probe.c
src/extras/mtd_probe/mtd_probe.h
src/extras/mtd_probe/probe_smartmedia.c
src/extras/rule_generator/rule_generator.functions
src/extras/rule_generator/write_cd_rules
src/extras/rule_generator/write_net_rules
src/extras/scsi_id/scsi.h
src/extras/scsi_id/scsi_id.c
src/extras/scsi_id/scsi_id.h
src/extras/scsi_id/scsi_serial.c
src/extras/udev-acl/udev-acl.c
src/extras/v4l_id/v4l_id.c
src/libudev-device-private.c
src/libudev-device.c
src/libudev-enumerate.c
src/libudev-list.c
src/libudev-monitor.c
src/libudev-private.h
src/libudev-queue-private.c
src/libudev-queue.c
src/libudev-selinux-private.c
src/libudev-util-private.c
src/libudev-util.c
src/libudev.c
src/libudev.h
src/test-libudev.c
src/test-udev.c
src/udev-builtin-blkid.c
src/udev-builtin-firmware.c
src/udev-builtin-hwdb.c
src/udev-builtin-input_id.c
src/udev-builtin-kmod.c
src/udev-builtin-path_id.c
src/udev-builtin-usb_id.c
src/udev-builtin.c
src/udev-ctrl.c
src/udev-event.c
src/udev-node.c
src/udev-rules.c
src/udev-watch.c
src/udev.h
src/udevadm-control.c
src/udevadm-info.c
src/udevadm-monitor.c
src/udevadm-settle.c
src/udevadm-test-builtin.c
src/udevadm-test.c
src/udevadm-trigger.c
src/udevadm.c
src/udevd.c
test/rules-test.sh
test/udev-test.pl

diff --git a/COPYING b/COPYING
index d511905..d159169 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -1,12 +1,12 @@
-                   GNU GENERAL PUBLIC LICENSE
-                      Version 2, June 1991
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
 
  Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
-                           Preamble
+                            Preamble
 
   The licenses for most software are designed to take away your
 freedom to share and change it.  By contrast, the GNU General Public
@@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all.
   The precise terms and conditions for copying, distribution and
 modification follow.
 
-                   GNU GENERAL PUBLIC LICENSE
+                    GNU GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License applies to any program or other work which contains
@@ -255,7 +255,7 @@ make exceptions for this.  Our decision will be guided by the two goals
 of preserving the free status of all derivatives of our free software and
 of promoting the sharing and reuse of software generally.
 
-                           NO WARRANTY
+                            NO WARRANTY
 
   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGES.
 
-                    END OF TERMS AND CONDITIONS
+                     END OF TERMS AND CONDITIONS
 
-           How to Apply These Terms to Your New Programs
+            How to Apply These Terms to Your New Programs
 
   If you develop a new program, and you want it to be of the greatest
 possible use to the public, the best way to achieve this is to make it
index d32f41d..697ed91 100755 (executable)
@@ -1,18 +1,16 @@
-#!/bin/sh
-
-set -e
+#!/bin/sh -e
 
 if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
-    cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \
-    chmod +x .git/hooks/pre-commit && \
-    echo "Activated pre-commit hook."
+        cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \
+        chmod +x .git/hooks/pre-commit && \
+        echo "Activated pre-commit hook."
 fi
 
 gtkdocize
 autoreconf --install --symlink
 
 libdir() {
-       echo $(cd $1/$(gcc -print-multi-os-directory); pwd)
+        echo $(cd $1/$(gcc -print-multi-os-directory); pwd)
 }
 
 args="\
index 07254fe..035e5fa 100644 (file)
@@ -1,9 +1,9 @@
 AC_PREREQ(2.60)
 AC_INIT([udev],
-       [175],
-       [linux-hotplug@vger.kernel.org],
-       [udev],
-       [http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html])
+       [175],
+       [linux-hotplug@vger.kernel.org],
+       [udev],
+       [http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html])
 AC_CONFIG_SRCDIR([src/udevd.c])
 AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE([check-news foreign 1.11 -Wall -Wno-portability silent-rules tar-pax no-dist-gzip dist-xz subdir-objects])
@@ -28,90 +28,90 @@ PKG_CHECK_MODULES(BLKID, blkid >= 2.20)
 PKG_CHECK_MODULES(KMOD, libkmod >= 3)
 
 if test "x$cross_compiling" = "xno" ; then
-       AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids])
-       AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids])
-       AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids])
+       AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids])
+       AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids])
+       AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids])
 fi
 
 AC_ARG_WITH(usb-ids-path,
-       [AS_HELP_STRING([--with-usb-ids-path=DIR], [Path to usb.ids file])],
-       [USB_DATABASE=${withval}],
-       [if test -n "$usbids" ; then
-               USB_DATABASE="$usbids"
-       else
-               PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82)
-               AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)])
-       fi])
+       [AS_HELP_STRING([--with-usb-ids-path=DIR], [Path to usb.ids file])],
+       [USB_DATABASE=${withval}],
+       [if test -n "$usbids" ; then
+              USB_DATABASE="$usbids"
+       else
+              PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82)
+              AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)])
+       fi])
 AC_MSG_CHECKING([for USB database location])
 AC_MSG_RESULT([$USB_DATABASE])
 AC_SUBST(USB_DATABASE)
 
 AC_ARG_WITH(pci-ids-path,
-       [AS_HELP_STRING([--with-pci-ids-path=DIR], [Path to pci.ids file])],
-       [PCI_DATABASE=${withval}],
-       [if test -n "$pciids" ; then
-               PCI_DATABASE="$pciids"
-       else
-               AC_MSG_ERROR([pci.ids not found, try --with-pci-ids-path=])
-       fi])
+       [AS_HELP_STRING([--with-pci-ids-path=DIR], [Path to pci.ids file])],
+       [PCI_DATABASE=${withval}],
+       [if test -n "$pciids" ; then
+              PCI_DATABASE="$pciids"
+       else
+              AC_MSG_ERROR([pci.ids not found, try --with-pci-ids-path=])
+       fi])
 AC_MSG_CHECKING([for PCI database location])
 AC_MSG_RESULT([$PCI_DATABASE])
 AC_SUBST(PCI_DATABASE)
 
 AC_ARG_WITH([rootprefix],
-       AS_HELP_STRING([--with-rootprefix=DIR], [rootfs directory prefix for config files and kernel modules]),
-       [], [with_rootprefix=${ac_default_prefix}])
+       AS_HELP_STRING([--with-rootprefix=DIR], [rootfs directory prefix for config files and kernel modules]),
+       [], [with_rootprefix=${ac_default_prefix}])
 AC_SUBST([rootprefix], [$with_rootprefix])
 
 AC_ARG_WITH([rootlibdir],
-       AS_HELP_STRING([--with-rootlibdir=DIR], [rootfs directory to install shared libraries]),
-       [], [with_rootlibdir=$libdir])
+       AS_HELP_STRING([--with-rootlibdir=DIR], [rootfs directory to install shared libraries]),
+       [], [with_rootlibdir=$libdir])
 AC_SUBST([rootlib_execdir], [$with_rootlibdir])
 
 AC_ARG_WITH([selinux],
-       AS_HELP_STRING([--with-selinux], [enable SELinux support]),
-       [], [with_selinux=no])
+       AS_HELP_STRING([--with-selinux], [enable SELinux support]),
+       [], [with_selinux=no])
 AS_IF([test "x$with_selinux" = "xyes"], [
-       LIBS_save=$LIBS
-       AC_CHECK_LIB(selinux, getprevcon,
-               [],
-               AC_MSG_ERROR([SELinux selected but libselinux not found]))
-       LIBS=$LIBS_save
-       SELINUX_LIBS="-lselinux -lsepol"
-       AC_DEFINE(WITH_SELINUX, [1] ,[SELinux support.])
+       LIBS_save=$LIBS
+       AC_CHECK_LIB(selinux, getprevcon,
+              [],
+              AC_MSG_ERROR([SELinux selected but libselinux not found]))
+       LIBS=$LIBS_save
+       SELINUX_LIBS="-lselinux -lsepol"
+       AC_DEFINE(WITH_SELINUX, [1] ,[SELinux support.])
 ])
 AC_SUBST([SELINUX_LIBS])
 AM_CONDITIONAL(WITH_SELINUX, [test "x$with_selinux" = "xyes"])
 
 AC_ARG_ENABLE([debug],
-       AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
-       [], [enable_debug=no])
+       AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
+       [], [enable_debug=no])
 AS_IF([test "x$enable_debug" = "xyes"], [ AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.]) ])
 
 AC_ARG_ENABLE([logging],
-       AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]),
-       [], enable_logging=yes)
+       AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]),
+       [], enable_logging=yes)
 AS_IF([test "x$enable_logging" = "xyes"], [ AC_DEFINE(ENABLE_LOGGING, [1], [System logging.]) ])
 
 AC_ARG_WITH(firmware-path,
-       AS_HELP_STRING([--with-firmware-path=DIR[[[:DIR[...]]]]],
-          [Firmware search path (default=/lib/firmware/updates:/lib/firmware)]),
-       [], [with_firmware_path="$rootprefix/lib/firmware/updates:$rootprefix/lib/firmware"])
+       AS_HELP_STRING([--with-firmware-path=DIR[[[:DIR[...]]]]],
+          [Firmware search path (default=/lib/firmware/updates:/lib/firmware)]),
+       [], [with_firmware_path="$rootprefix/lib/firmware/updates:$rootprefix/lib/firmware"])
 OLD_IFS=$IFS
 IFS=:
 for i in $with_firmware_path; do
-       if test "x${FIRMWARE_PATH}" = "x"; then
-               FIRMWARE_PATH="\\\"${i}/\\\""
-       else
-               FIRMWARE_PATH="${FIRMWARE_PATH}, \\\"${i}/\\\""
-       fi
+       if test "x${FIRMWARE_PATH}" = "x"; then
+              FIRMWARE_PATH="\\\"${i}/\\\""
+       else
+              FIRMWARE_PATH="${FIRMWARE_PATH}, \\\"${i}/\\\""
+       fi
 done
 IFS=$OLD_IFS
 AC_SUBST([FIRMWARE_PATH], [$FIRMWARE_PATH])
 
 AC_ARG_WITH([systemdsystemunitdir],
-       AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
-       [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
+       AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
+       [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
 AS_IF([test "x$with_systemdsystemunitdir" != "xno"], [ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir]) ])
 AM_CONDITIONAL(WITH_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != "xno" ])
 
@@ -119,21 +119,21 @@ AM_CONDITIONAL(WITH_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_sy
 # GUdev - libudev gobject interface
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([gudev],
-       AS_HELP_STRING([--disable-gudev], [disable Gobject libudev support @<:@default=enabled@:>@]),
-       [], [enable_gudev=yes])
+       AS_HELP_STRING([--disable-gudev], [disable Gobject libudev support @<:@default=enabled@:>@]),
+       [], [enable_gudev=yes])
 AS_IF([test "x$enable_gudev" = "xyes"], [ PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.22.0 gobject-2.0 >= 2.22.0]) ])
 
 AC_ARG_ENABLE([introspection],
-       AS_HELP_STRING([--disable-introspection], [disable GObject introspection @<:@default=enabled@:>@]),
-       [], [enable_introspection=yes])
+       AS_HELP_STRING([--disable-introspection], [disable GObject introspection @<:@default=enabled@:>@]),
+       [], [enable_introspection=yes])
 AS_IF([test "x$enable_introspection" = "xyes"], [
-       PKG_CHECK_MODULES([INTROSPECTION], [gobject-introspection-1.0 >= 0.6.2])
-       AC_DEFINE([ENABLE_INTROSPECTION], [1], [enable GObject introspection support])
-       AC_SUBST([G_IR_SCANNER], [$($PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0)])
-       AC_SUBST([G_IR_COMPILER], [$($PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0)])
-       AC_SUBST([G_IR_GENERATE], [$($PKG_CONFIG --variable=g_ir_generate gobject-introspection-1.0)])
-       AC_SUBST([GIRDIR], [$($PKG_CONFIG --define-variable=datadir=${datadir} --variable=girdir gobject-introspection-1.0)])
-       AC_SUBST([GIRTYPELIBDIR], [$($PKG_CONFIG --define-variable=libdir=${libdir} --variable=typelibdir gobject-introspection-1.0)])
+       PKG_CHECK_MODULES([INTROSPECTION], [gobject-introspection-1.0 >= 0.6.2])
+       AC_DEFINE([ENABLE_INTROSPECTION], [1], [enable GObject introspection support])
+       AC_SUBST([G_IR_SCANNER], [$($PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0)])
+       AC_SUBST([G_IR_COMPILER], [$($PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0)])
+       AC_SUBST([G_IR_GENERATE], [$($PKG_CONFIG --variable=g_ir_generate gobject-introspection-1.0)])
+       AC_SUBST([GIRDIR], [$($PKG_CONFIG --define-variable=datadir=${datadir} --variable=girdir gobject-introspection-1.0)])
+       AC_SUBST([GIRTYPELIBDIR], [$($PKG_CONFIG --define-variable=libdir=${libdir} --variable=typelibdir gobject-introspection-1.0)])
 ])
 AM_CONDITIONAL([ENABLE_INTROSPECTION], [test "x$enable_introspection" = "xyes"])
 AM_CONDITIONAL([ENABLE_GUDEV], [test "x$enable_gudev" = "xyes"])
@@ -142,16 +142,16 @@ AM_CONDITIONAL([ENABLE_GUDEV], [test "x$enable_gudev" = "xyes"])
 # keymap - map custom hardware's multimedia keys
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([keymap],
-       AS_HELP_STRING([--disable-keymap], [disable keymap fixup support @<:@default=enabled@:>@]),
-       [], [enable_keymap=yes])
+       AS_HELP_STRING([--disable-keymap], [disable keymap fixup support @<:@default=enabled@:>@]),
+       [], [enable_keymap=yes])
 AS_IF([test "x$enable_keymap" = "xyes"], [
-       AC_PATH_PROG([GPERF], [gperf])
-       if test -z "$GPERF"; then
-               AC_MSG_ERROR([gperf is needed])
-       fi
+       AC_PATH_PROG([GPERF], [gperf])
+       if test -z "$GPERF"; then
+              AC_MSG_ERROR([gperf is needed])
+       fi
 
-       AC_CHECK_HEADER([linux/input.h], [:], AC_MSG_ERROR([kernel headers not found]))
-       AC_SUBST([INCLUDE_PREFIX], [$(echo '#include <linux/input.h>' | eval $ac_cpp -E - | sed -n '/linux\/input.h/ {s:.*"\(.*\)/linux/input.h".*:\1:; p; q}')])
+       AC_CHECK_HEADER([linux/input.h], [:], AC_MSG_ERROR([kernel headers not found]))
+       AC_SUBST([INCLUDE_PREFIX], [$(echo '#include <linux/input.h>' | eval $ac_cpp -E - | sed -n '/linux\/input.h/ {s:.*"\(.*\)/linux/input.h".*:\1:; p; q}')])
 ])
 AM_CONDITIONAL([ENABLE_KEYMAP], [test "x$enable_keymap" = "xyes"])
 
@@ -159,29 +159,29 @@ AM_CONDITIONAL([ENABLE_KEYMAP], [test "x$enable_keymap" = "xyes"])
 # mtd_probe - autoloads FTL module for mtd devices
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([mtd_probe],
-       AS_HELP_STRING([--disable-mtd_probe], [disable MTD support @<:@default=enabled@:>@]),
-       [], [enable_mtd_probe=yes])
+       AS_HELP_STRING([--disable-mtd_probe], [disable MTD support @<:@default=enabled@:>@]),
+       [], [enable_mtd_probe=yes])
 AM_CONDITIONAL([ENABLE_MTD_PROBE], [test "x$enable_mtd_probe" = "xyes"])
 
 # ------------------------------------------------------------------------------
 # rule_generator - persistent network and optical device rule generator
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([rule_generator],
-       AS_HELP_STRING([--enable-rule_generator], [enable persistent network + cdrom links support @<:@default=disabled@:>@]),
-       [], [enable_rule_generator=no])
+       AS_HELP_STRING([--enable-rule_generator], [enable persistent network + cdrom links support @<:@default=disabled@:>@]),
+       [], [enable_rule_generator=no])
 AM_CONDITIONAL([ENABLE_RULE_GENERATOR], [test "x$enable_rule_generator" = "xyes"])
 
 # ------------------------------------------------------------------------------
 # udev_acl - apply ACLs for users with local forground sessions
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([udev_acl],
-       AS_HELP_STRING([--enable-udev_acl], [enable local user acl permissions support @<:@default=disabled@:>@]),
-       [], [enable_udev_acl=no])
+       AS_HELP_STRING([--enable-udev_acl], [enable local user acl permissions support @<:@default=disabled@:>@]),
+       [], [enable_udev_acl=no])
 AS_IF([test "x$enable_udev_acl" = "xyes"], [
-       AC_CHECK_LIB([acl], [acl_init], [:], AC_MSG_ERROR([libacl not found]))
-       AC_CHECK_HEADER([acl/libacl.h], [:], AC_MSG_ERROR([libacl header not found]))
+       AC_CHECK_LIB([acl], [acl_init], [:], AC_MSG_ERROR([libacl not found]))
+       AC_CHECK_HEADER([acl/libacl.h], [:], AC_MSG_ERROR([libacl header not found]))
 
-       PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.22.0 gobject-2.0 >= 2.22.0])
+       PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.22.0 gobject-2.0 >= 2.22.0])
 ])
 AM_CONDITIONAL([ENABLE_UDEV_ACL], [test "x$enable_udev_acl" = "xyes"])
 
@@ -189,16 +189,16 @@ AM_CONDITIONAL([ENABLE_UDEV_ACL], [test "x$enable_udev_acl" = "xyes"])
 # create_floppy_devices - historical floppy kernel device nodes (/dev/fd0h1440, ...)
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([floppy],
-       AS_HELP_STRING([--enable-floppy], [enable legacy floppy support @<:@default=disabled@:>@]),
-       [], [enable_floppy=no])
+       AS_HELP_STRING([--enable-floppy], [enable legacy floppy support @<:@default=disabled@:>@]),
+       [], [enable_floppy=no])
 AM_CONDITIONAL([ENABLE_FLOPPY], [test "x$enable_floppy" = "xyes"])
 
 # ------------------------------------------------------------------------------
 # edd_id - create /dev/disk/by-id/edd-* links for BIOS EDD data
 # ------------------------------------------------------------------------------
 AC_ARG_ENABLE([edd],
-       AS_HELP_STRING([--enable-edd], [enable disk edd support @<:@default=disabled@:>@]),
-       [], [enable_edd=no])
+       AS_HELP_STRING([--enable-edd], [enable disk edd support @<:@default=disabled@:>@]),
+       [], [enable_edd=no])
 AM_CONDITIONAL([ENABLE_EDD], [test "x$enable_edd" = "xyes"])
 
 my_CFLAGS="-Wall \
@@ -211,50 +211,50 @@ AC_SUBST([my_CFLAGS])
 
 AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
-       Makefile
-       src/docs/Makefile
-       src/docs/version.xml
-       src/extras/gudev/docs/Makefile
-       src/extras/gudev/docs/version.xml
+       Makefile
+       src/docs/Makefile
+       src/docs/version.xml
+       src/extras/gudev/docs/Makefile
+       src/extras/gudev/docs/version.xml
 ])
 
 AC_OUTPUT
 AC_MSG_RESULT([
-       $PACKAGE $VERSION
-       ========
+       $PACKAGE $VERSION
+       ========
 
-       prefix:                 ${prefix}
-       rootprefix:             ${rootprefix}
-       sysconfdir:             ${sysconfdir}
-       bindir:                 ${bindir}
-       libdir:                 ${libdir}
-       rootlibdir:             ${rootlib_execdir}
-       libexecdir:             ${libexecdir}
-       datarootdir:            ${datarootdir}
-       mandir:                 ${mandir}
-       includedir:             ${includedir}
-       include_prefix:         ${INCLUDE_PREFIX}
-       systemdsystemunitdir:   ${systemdsystemunitdir}
-       firmware path:          ${FIRMWARE_PATH}
-       usb.ids:                ${USB_DATABASE}
-       pci.ids:                ${PCI_DATABASE}
+       prefix:                  ${prefix}
+       rootprefix:              ${rootprefix}
+       sysconfdir:              ${sysconfdir}
+       bindir:                  ${bindir}
+       libdir:                  ${libdir}
+       rootlibdir:              ${rootlib_execdir}
+       libexecdir:              ${libexecdir}
+       datarootdir:             ${datarootdir}
+       mandir:                  ${mandir}
+       includedir:              ${includedir}
+       include_prefix:          ${INCLUDE_PREFIX}
+       systemdsystemunitdir:    ${systemdsystemunitdir}
+       firmware path:           ${FIRMWARE_PATH}
+       usb.ids:                 ${USB_DATABASE}
+       pci.ids:                 ${PCI_DATABASE}
 
-       compiler:               ${CC}
-       cflags:                 ${CFLAGS}
-       ldflags:                ${LDFLAGS}
-       xsltproc:               ${XSLTPROC}
-       gperf:                  ${GPERF}
+       compiler:                ${CC}
+       cflags:                  ${CFLAGS}
+       ldflags:                 ${LDFLAGS}
+       xsltproc:                ${XSLTPROC}
+       gperf:                   ${GPERF}
 
-       logging:                ${enable_logging}
-       debug:                  ${enable_debug}
-       selinux:                ${with_selinux}
+       logging:                 ${enable_logging}
+       debug:                   ${enable_debug}
+       selinux:                 ${with_selinux}
 
-       gudev:                  ${enable_gudev}
-       gintrospection:         ${enable_introspection}
-       keymap:                 ${enable_keymap}
-       mtd_probe:              ${enable_mtd_probe}
-       rule_generator:         ${enable_rule_generator}
-       udev_acl:               ${enable_udev_acl}
-       floppy:                 ${enable_floppy}
-       edd:                    ${enable_edd}
+       gudev:                   ${enable_gudev}
+       gintrospection:          ${enable_introspection}
+       keymap:                  ${enable_keymap}
+       mtd_probe:               ${enable_mtd_probe}
+       rule_generator:          ${enable_rule_generator}
+       udev_acl:                ${enable_udev_acl}
+       floppy:                  ${enable_floppy}
+       edd:                     ${enable_edd}
 ])
index 43035db..6ff6b65 100644 (file)
@@ -1,4 +1,4 @@
 # do not edit this file, it will be overwritten on update
 
-KERNEL=="z90crypt",            MODE="0666"
+KERNEL=="z90crypt", MODE="0666"
 
index 353e31d..3744707 100644 (file)
@@ -2,44 +2,44 @@
 
 KERNEL=="pty[pqrstuvwxyzabcdef][0123456789abcdef]", GROUP="tty", MODE="0660"
 KERNEL=="tty[pqrstuvwxyzabcdef][0123456789abcdef]", GROUP="tty", MODE="0660"
-KERNEL=="ptmx",                        GROUP="tty", MODE="0666"
-KERNEL=="tty",                 GROUP="tty", MODE="0666"
-KERNEL=="tty[0-9]*",           GROUP="tty", MODE="0620"
+KERNEL=="ptmx", GROUP="tty", MODE="0666"
+KERNEL=="tty", GROUP="tty", MODE="0666"
+KERNEL=="tty[0-9]*", GROUP="tty", MODE="0620"
 KERNEL=="vcs|vcs[0-9]*|vcsa|vcsa[0-9]*", GROUP="tty"
 
 # serial
 KERNEL=="tty[A-Z]*[0-9]|pppox[0-9]*|ircomm[0-9]*|noz[0-9]*|rfcomm[0-9]*", GROUP="dialout"
-KERNEL=="mwave",               GROUP="dialout"
-KERNEL=="hvc*|hvsi*",          GROUP="dialout"
+KERNEL=="mwave", GROUP="dialout"
+KERNEL=="hvc*|hvsi*", GROUP="dialout"
 
 # virtio serial / console ports
 KERNEL=="vport*", ATTR{name}=="?*", SYMLINK+="virtio-ports/$attr{name}"
 
 # mem
 KERNEL=="null|zero|full|random|urandom", MODE="0666"
-KERNEL=="mem|kmem|port|nvram", GROUP="kmem", MODE="0640"
+KERNEL=="mem|kmem|port|nvram", GROUP="kmem", MODE="0640"
 
 # input
 SUBSYSTEM=="input", ENV{ID_INPUT}=="", IMPORT{builtin}="input_id"
-KERNEL=="mouse*|mice|event*",  MODE="0640"
-KERNEL=="ts[0-9]*|uinput",     MODE="0640"
-KERNEL=="js[0-9]*",            MODE="0644"
+KERNEL=="mouse*|mice|event*", MODE="0640"
+KERNEL=="ts[0-9]*|uinput", MODE="0640"
+KERNEL=="js[0-9]*", MODE="0644"
 
 # video4linux
-SUBSYSTEM=="video4linux",      GROUP="video"
-KERNEL=="vttuner*",            GROUP="video"
-KERNEL=="vtx*|vbi*",           GROUP="video"
-KERNEL=="winradio*",           GROUP="video"
+SUBSYSTEM=="video4linux", GROUP="video"
+KERNEL=="vttuner*", GROUP="video"
+KERNEL=="vtx*|vbi*", GROUP="video"
+KERNEL=="winradio*", GROUP="video"
 
 # graphics
-KERNEL=="agpgart",             GROUP="video"
-KERNEL=="pmu",                 GROUP="video"
-KERNEL=="nvidia*|nvidiactl*",  GROUP="video"
-SUBSYSTEM=="graphics",         GROUP="video"
-SUBSYSTEM=="drm",              GROUP="video"
+KERNEL=="agpgart", GROUP="video"
+KERNEL=="pmu", GROUP="video"
+KERNEL=="nvidia*|nvidiactl*", GROUP="video"
+SUBSYSTEM=="graphics", GROUP="video"
+SUBSYSTEM=="drm", GROUP="video"
 
 # sound
-SUBSYSTEM=="sound",            GROUP="audio", \
+SUBSYSTEM=="sound", GROUP="audio", \
   OPTIONS+="static_node=snd/seq", OPTIONS+="static_node=snd/timer"
 
 # DVB (video)
@@ -56,11 +56,11 @@ SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664"
 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id"
 
 # printer
-KERNEL=="parport[0-9]*",       GROUP="lp"
-SUBSYSTEM=="printer",          KERNEL=="lp*", GROUP="lp"
-SUBSYSTEM=="ppdev",            GROUP="lp"
-KERNEL=="lp[0-9]*",            GROUP="lp"
-KERNEL=="irlpt[0-9]*",         GROUP="lp"
+KERNEL=="parport[0-9]*", GROUP="lp"
+SUBSYSTEM=="printer", KERNEL=="lp*", GROUP="lp"
+SUBSYSTEM=="ppdev", GROUP="lp"
+KERNEL=="lp[0-9]*", GROUP="lp"
+KERNEL=="irlpt[0-9]*", GROUP="lp"
 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", GROUP="lp"
 
 # block
@@ -91,17 +91,17 @@ SUBSYSTEM=="aoe", GROUP="disk", MODE="0220"
 SUBSYSTEM=="aoe", KERNEL=="err", MODE="0440"
 
 # network
-KERNEL=="tun",                 MODE="0666", OPTIONS+="static_node=net/tun"
-KERNEL=="rfkill",              MODE="0644"
+KERNEL=="tun", MODE="0666", OPTIONS+="static_node=net/tun"
+KERNEL=="rfkill", MODE="0644"
 
 # CPU
-KERNEL=="cpu[0-9]*",           MODE="0444"
+KERNEL=="cpu[0-9]*", MODE="0444"
 
-KERNEL=="fuse", ACTION=="add", MODE="0666", OPTIONS+="static_node=fuse"
+KERNEL=="fuse", ACTION=="add", MODE="0666", OPTIONS+="static_node=fuse"
 
 SUBSYSTEM=="rtc", DRIVERS=="rtc_cmos", SYMLINK+="rtc"
-KERNEL=="mmtimer",             MODE="0644"
-KERNEL=="rflash[0-9]*",                MODE="0400"
-KERNEL=="rrom[0-9]*",          MODE="0400"
+KERNEL=="mmtimer", MODE="0644"
+KERNEL=="rflash[0-9]*", MODE="0400"
+KERNEL=="rrom[0-9]*", MODE="0400"
 
 SUBSYSTEM=="firmware", ACTION=="add", IMPORT{builtin}="firmware"
index 0851b14..d2e3127 100644 (file)
@@ -1,5 +1,5 @@
-                 GNU LESSER GENERAL PUBLIC LICENSE
-                      Version 2.1, February 1999
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
 
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
      51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
@@ -10,7 +10,7 @@
  as the successor of the GNU Library Public License, version 2, hence
  the version number 2.1.]
 
-                           Preamble
+                            Preamble
 
   The licenses for most software are designed to take away your
 freedom to share and change it.  By contrast, the GNU General Public
@@ -112,7 +112,7 @@ modification follow.  Pay close attention to the difference between a
 former contains code derived from the library, whereas the latter must
 be combined with the library in order to run.
 \f
-                 GNU LESSER GENERAL PUBLIC LICENSE
+                  GNU LESSER GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License Agreement applies to any software library or other
@@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status
 of all derivatives of our free software and of promoting the sharing
 and reuse of software generally.
 
-                           NO WARRANTY
+                            NO WARRANTY
 
   15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
 WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
@@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 DAMAGES.
 
-                    END OF TERMS AND CONDITIONS
+                     END OF TERMS AND CONDITIONS
 \f
            How to Apply These Terms to Your New Libraries
 
index 59c2a4e..bc9715b 100644 (file)
 static int debug = 0;
 
 static void log_fn(struct udev *udev, int priority,
-                  const char *file, int line, const char *fn,
-                  const char *format, va_list args)
+                   const char *file, int line, const char *fn,
+                   const char *format, va_list args)
 {
-       if (debug) {
-               fprintf(stderr, "%s: ", fn);
-               vfprintf(stderr, format, args);
-       } else {
-               vsyslog(priority, format, args);
-       }
+        if (debug) {
+                fprintf(stderr, "%s: ", fn);
+                vfprintf(stderr, format, args);
+        } else {
+                vsyslog(priority, format, args);
+        }
 }
 
 typedef enum {
-       ORIENTATION_UNDEFINED,
-       ORIENTATION_NORMAL,
-       ORIENTATION_BOTTOM_UP,
-       ORIENTATION_LEFT_UP,
-       ORIENTATION_RIGHT_UP
+        ORIENTATION_UNDEFINED,
+        ORIENTATION_NORMAL,
+        ORIENTATION_BOTTOM_UP,
+        ORIENTATION_LEFT_UP,
+        ORIENTATION_RIGHT_UP
 } OrientationUp;
 
 static const char *orientations[] = {
-       "undefined",
-       "normal",
-       "bottom-up",
-       "left-up",
-       "right-up",
-       NULL
+        "undefined",
+        "normal",
+        "bottom-up",
+        "left-up",
+        "right-up",
+        NULL
 };
 
 #define ORIENTATION_UP_UP ORIENTATION_NORMAL
@@ -111,247 +111,247 @@ static const char *orientations[] = {
 static const char *
 orientation_to_string (OrientationUp o)
 {
-       return orientations[o];
+        return orientations[o];
 }
 
 static OrientationUp
 string_to_orientation (const char *orientation)
 {
-       int i;
-
-       if (orientation == NULL)
-               return ORIENTATION_UNDEFINED;
-       for (i = 0; orientations[i] != NULL; i++) {
-               if (strcmp (orientation, orientations[i]) == 0)
-                       return i;
-       }
-       return ORIENTATION_UNDEFINED;
+        int i;
+
+        if (orientation == NULL)
+                return ORIENTATION_UNDEFINED;
+        for (i = 0; orientations[i] != NULL; i++) {
+                if (strcmp (orientation, orientations[i]) == 0)
+                        return i;
+        }
+        return ORIENTATION_UNDEFINED;
 }
 
 static OrientationUp
 orientation_calc (OrientationUp prev,
-                 int x, int y, int z)
+                  int x, int y, int z)
 {
-       int rotation;
-       OrientationUp ret = prev;
-
-       /* Portrait check */
-       rotation = round(atan((double) x / sqrt(y * y + z * z)) * RADIANS_TO_DEGREES);
-
-       if (abs(rotation) > THRESHOLD_PORTRAIT) {
-               ret = (rotation < 0) ? ORIENTATION_LEFT_UP : ORIENTATION_RIGHT_UP;
-
-               /* Some threshold to switching between portrait modes */
-               if (prev == ORIENTATION_LEFT_UP || prev == ORIENTATION_RIGHT_UP) {
-                       if (abs(rotation) < SAME_AXIS_LIMIT) {
-                               ret = prev;
-                       }
-               }
-
-       } else {
-               /* Landscape check */
-               rotation = round(atan((double) y / sqrt(x * x + z * z)) * RADIANS_TO_DEGREES);
-
-               if (abs(rotation) > THRESHOLD_LANDSCAPE) {
-                       ret = (rotation < 0) ? ORIENTATION_BOTTOM_UP : ORIENTATION_NORMAL;
-
-                       /* Some threshold to switching between landscape modes */
-                       if (prev == ORIENTATION_BOTTOM_UP || prev == ORIENTATION_NORMAL) {
-                               if (abs(rotation) < SAME_AXIS_LIMIT) {
-                                       ret = prev;
-                               }
-                       }
-               }
-       }
-
-       return ret;
+        int rotation;
+        OrientationUp ret = prev;
+
+        /* Portrait check */
+        rotation = round(atan((double) x / sqrt(y * y + z * z)) * RADIANS_TO_DEGREES);
+
+        if (abs(rotation) > THRESHOLD_PORTRAIT) {
+                ret = (rotation < 0) ? ORIENTATION_LEFT_UP : ORIENTATION_RIGHT_UP;
+
+                /* Some threshold to switching between portrait modes */
+                if (prev == ORIENTATION_LEFT_UP || prev == ORIENTATION_RIGHT_UP) {
+                        if (abs(rotation) < SAME_AXIS_LIMIT) {
+                                ret = prev;
+                        }
+                }
+
+        } else {
+                /* Landscape check */
+                rotation = round(atan((double) y / sqrt(x * x + z * z)) * RADIANS_TO_DEGREES);
+
+                if (abs(rotation) > THRESHOLD_LANDSCAPE) {
+                        ret = (rotation < 0) ? ORIENTATION_BOTTOM_UP : ORIENTATION_NORMAL;
+
+                        /* Some threshold to switching between landscape modes */
+                        if (prev == ORIENTATION_BOTTOM_UP || prev == ORIENTATION_NORMAL) {
+                                if (abs(rotation) < SAME_AXIS_LIMIT) {
+                                        ret = prev;
+                                }
+                        }
+                }
+        }
+
+        return ret;
 }
 
 static OrientationUp
 get_prev_orientation(struct udev_device *dev)
 {
-       const char *value;
+        const char *value;
 
-       value = udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER_ORIENTATION");
-       if (value == NULL)
-               return ORIENTATION_UNDEFINED;
-       return string_to_orientation(value);
+        value = udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER_ORIENTATION");
+        if (value == NULL)
+                return ORIENTATION_UNDEFINED;
+        return string_to_orientation(value);
 }
 
 #define SET_AXIS(axis, code_) if (ev[i].code == code_) { if (got_##axis == 0) { axis = ev[i].value; got_##axis = 1; } }
 
 /* accelerometers */
 static void test_orientation(struct udev *udev,
-                            struct udev_device *dev,
-                            const char *devpath)
+                             struct udev_device *dev,
+                             const char *devpath)
 {
-       OrientationUp old, new;
-       int fd, r;
-       struct input_event ev[64];
-       int got_syn = 0;
-       int got_x, got_y, got_z;
-       int x = 0, y = 0, z = 0;
-       char text[64];
-
-       old = get_prev_orientation(dev);
-
-       if ((fd = open(devpath, O_RDONLY)) < 0)
-               return;
-
-       got_x = got_y = got_z = 0;
-
-       while (1) {
-               int i;
-
-               r = read(fd, ev, sizeof(struct input_event) * 64);
-
-               if (r < (int) sizeof(struct input_event))
-                       return;
-
-               for (i = 0; i < r / (int) sizeof(struct input_event); i++) {
-                       if (got_syn == 1) {
-                               if (ev[i].type == EV_ABS) {
-                                       SET_AXIS(x, ABS_X);
-                                       SET_AXIS(y, ABS_Y);
-                                       SET_AXIS(z, ABS_Z);
-                               }
-                       }
-                       if (ev[i].type == EV_SYN && ev[i].code == SYN_REPORT) {
-                               got_syn = 1;
-                       }
-                       if (got_x && got_y && got_z)
-                               goto read_dev;
-               }
-       }
+        OrientationUp old, new;
+        int fd, r;
+        struct input_event ev[64];
+        int got_syn = 0;
+        int got_x, got_y, got_z;
+        int x = 0, y = 0, z = 0;
+        char text[64];
+
+        old = get_prev_orientation(dev);
+
+        if ((fd = open(devpath, O_RDONLY)) < 0)
+                return;
+
+        got_x = got_y = got_z = 0;
+
+        while (1) {
+                int i;
+
+                r = read(fd, ev, sizeof(struct input_event) * 64);
+
+                if (r < (int) sizeof(struct input_event))
+                        return;
+
+                for (i = 0; i < r / (int) sizeof(struct input_event); i++) {
+                        if (got_syn == 1) {
+                                if (ev[i].type == EV_ABS) {
+                                        SET_AXIS(x, ABS_X);
+                                        SET_AXIS(y, ABS_Y);
+                                        SET_AXIS(z, ABS_Z);
+                                }
+                        }
+                        if (ev[i].type == EV_SYN && ev[i].code == SYN_REPORT) {
+                                got_syn = 1;
+                        }
+                        if (got_x && got_y && got_z)
+                                goto read_dev;
+                }
+        }
 
 read_dev:
-       close(fd);
+        close(fd);
 
-       if (!got_x || !got_y || !got_z)
-               return;
+        if (!got_x || !got_y || !got_z)
+                return;
 
-       new = orientation_calc(old, x, y, z);
-       snprintf(text, sizeof(text), "ID_INPUT_ACCELEROMETER_ORIENTATION=%s", orientation_to_string(new));
-       puts(text);
+        new = orientation_calc(old, x, y, z);
+        snprintf(text, sizeof(text), "ID_INPUT_ACCELEROMETER_ORIENTATION=%s", orientation_to_string(new));
+        puts(text);
 }
 
 static void help(void)
 {
-       printf("Usage: accelerometer [options] <device path>\n"
-              "  --debug         debug to stderr\n"
-              "  --help          print this help text\n\n");
+        printf("Usage: accelerometer [options] <device path>\n"
+               "  --debug         debug to stderr\n"
+               "  --help          print this help text\n\n");
 }
 
 int main (int argc, char** argv)
 {
-       struct udev *udev;
-       struct udev_device *dev;
-
-       static const struct option options[] = {
-               { "debug", no_argument, NULL, 'd' },
-               { "help", no_argument, NULL, 'h' },
-               {}
-       };
-
-       char devpath[PATH_MAX];
-       char *devnode;
-       const char *id_path;
-       struct udev_enumerate *enumerate;
-       struct udev_list_entry *list_entry;
-
-       udev = udev_new();
-       if (udev == NULL)
-               return 1;
-
-       udev_log_init("input_id");
-       udev_set_log_fn(udev, log_fn);
-
-       /* CLI argument parsing */
-       while (1) {
-               int option;
-
-               option = getopt_long(argc, argv, "dxh", options, NULL);
-               if (option == -1)
-                       break;
-
-               switch (option) {
-               case 'd':
-                       debug = 1;
-                       if (udev_get_log_priority(udev) < LOG_INFO)
-                               udev_set_log_priority(udev, LOG_INFO);
-                       break;
-               case 'h':
-                       help();
-                       exit(0);
-               default:
-                       exit(1);
-               }
-       }
-
-       if (argv[optind] == NULL) {
-               help();
-               exit(1);
-       }
-
-       /* get the device */
-       snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]);
-       dev = udev_device_new_from_syspath(udev, devpath);
-       if (dev == NULL) {
-               fprintf(stderr, "unable to access '%s'\n", devpath);
-               return 1;
-       }
-
-       id_path = udev_device_get_property_value(dev, "ID_PATH");
-       if (id_path == NULL) {
-               fprintf (stderr, "unable to get property ID_PATH for '%s'", devpath);
-               return 0;
-       }
-
-       /* Get the children devices and find the devnode
-        * FIXME: use udev_enumerate_add_match_children() instead
-        * when it's available */
-       devnode = NULL;
-       enumerate = udev_enumerate_new(udev);
-       udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path);
-       udev_enumerate_add_match_subsystem(enumerate, "input");
-       udev_enumerate_scan_devices(enumerate);
-       udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
-               struct udev_device *device;
-               const char *node;
-
-               device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
-                                                     udev_list_entry_get_name(list_entry));
-               if (device == NULL)
-                       continue;
-               /* Already found it */
-               if (devnode != NULL) {
-                       udev_device_unref(device);
-                       continue;
-               }
-
-               node = udev_device_get_devnode(device);
-               if (node == NULL) {
-                       udev_device_unref(device);
-                       continue;
-               }
-               /* Use the event sub-device */
-               if (strstr(node, "/event") == NULL) {
-                       udev_device_unref(device);
-                       continue;
-               }
-
-               devnode = strdup(node);
-               udev_device_unref(device);
-       }
-
-       if (devnode == NULL) {
-               fprintf(stderr, "unable to get device node for '%s'\n", devpath);
-               return 0;
-       }
-
-       info(udev, "Opening accelerometer device %s\n", devnode);
-       test_orientation(udev, dev, devnode);
-       free(devnode);
-
-       return 0;
+        struct udev *udev;
+        struct udev_device *dev;
+
+        static const struct option options[] = {
+                { "debug", no_argument, NULL, 'd' },
+                { "help", no_argument, NULL, 'h' },
+                {}
+        };
+
+        char devpath[PATH_MAX];
+        char *devnode;
+        const char *id_path;
+        struct udev_enumerate *enumerate;
+        struct udev_list_entry *list_entry;
+
+        udev = udev_new();
+        if (udev == NULL)
+                return 1;
+
+        udev_log_init("input_id");
+        udev_set_log_fn(udev, log_fn);
+
+        /* CLI argument parsing */
+        while (1) {
+                int option;
+
+                option = getopt_long(argc, argv, "dxh", options, NULL);
+                if (option == -1)
+                        break;
+
+                switch (option) {
+                case 'd':
+                        debug = 1;
+                        if (udev_get_log_priority(udev) < LOG_INFO)
+                                udev_set_log_priority(udev, LOG_INFO);
+                        break;
+                case 'h':
+                        help();
+                        exit(0);
+                default:
+                        exit(1);
+                }
+        }
+
+        if (argv[optind] == NULL) {
+                help();
+                exit(1);
+        }
+
+        /* get the device */
+        snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]);
+        dev = udev_device_new_from_syspath(udev, devpath);
+        if (dev == NULL) {
+                fprintf(stderr, "unable to access '%s'\n", devpath);
+                return 1;
+        }
+
+        id_path = udev_device_get_property_value(dev, "ID_PATH");
+        if (id_path == NULL) {
+                fprintf (stderr, "unable to get property ID_PATH for '%s'", devpath);
+                return 0;
+        }
+
+        /* Get the children devices and find the devnode
+         * FIXME: use udev_enumerate_add_match_children() instead
+         * when it's available */
+        devnode = NULL;
+        enumerate = udev_enumerate_new(udev);
+        udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path);
+        udev_enumerate_add_match_subsystem(enumerate, "input");
+        udev_enumerate_scan_devices(enumerate);
+        udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
+                struct udev_device *device;
+                const char *node;
+
+                device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
+                                                      udev_list_entry_get_name(list_entry));
+                if (device == NULL)
+                        continue;
+                /* Already found it */
+                if (devnode != NULL) {
+                        udev_device_unref(device);
+                        continue;
+                }
+
+                node = udev_device_get_devnode(device);
+                if (node == NULL) {
+                        udev_device_unref(device);
+                        continue;
+                }
+                /* Use the event sub-device */
+                if (strstr(node, "/event") == NULL) {
+                        udev_device_unref(device);
+                        continue;
+                }
+
+                devnode = strdup(node);
+                udev_device_unref(device);
+        }
+
+        if (devnode == NULL) {
+                fprintf(stderr, "unable to get device node for '%s'\n", devpath);
+                return 0;
+        }
+
+        info(udev, "Opening accelerometer device %s\n", devnode);
+        test_orientation(udev, dev, devnode);
+        free(devnode);
+
+        return 0;
 }
index 64df86c..924d479 100644 (file)
 #define COMMAND_TIMEOUT_MSEC (30 * 1000)
 
 static int disk_scsi_inquiry_command(int      fd,
-                                    void    *buf,
-                                    size_t   buf_len)
+                                     void    *buf,
+                                     size_t   buf_len)
 {
-       struct sg_io_v4 io_v4;
-       uint8_t cdb[6];
-       uint8_t sense[32];
-       int ret;
-
-       /*
-        * INQUIRY, see SPC-4 section 6.4
-        */
-       memset(cdb, 0, sizeof(cdb));
-       cdb[0] = 0x12;                   /* OPERATION CODE: INQUIRY */
-       cdb[3] = (buf_len >> 8);         /* ALLOCATION LENGTH */
-       cdb[4] = (buf_len & 0xff);
-
-       memset(sense, 0, sizeof(sense));
-
-       memset(&io_v4, 0, sizeof(struct sg_io_v4));
-       io_v4.guard = 'Q';
-       io_v4.protocol = BSG_PROTOCOL_SCSI;
-       io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
-       io_v4.request_len = sizeof (cdb);
-       io_v4.request = (uintptr_t) cdb;
-       io_v4.max_response_len = sizeof (sense);
-       io_v4.response = (uintptr_t) sense;
-       io_v4.din_xfer_len = buf_len;
-       io_v4.din_xferp = (uintptr_t) buf;
-       io_v4.timeout = COMMAND_TIMEOUT_MSEC;
-
-       ret = ioctl(fd, SG_IO, &io_v4);
-       if (ret != 0) {
-               /* could be that the driver doesn't do version 4, try version 3 */
-               if (errno == EINVAL) {
-                       struct sg_io_hdr io_hdr;
-
-                       memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
-                       io_hdr.interface_id = 'S';
-                       io_hdr.cmdp = (unsigned char*) cdb;
-                       io_hdr.cmd_len = sizeof (cdb);
-                       io_hdr.dxferp = buf;
-                       io_hdr.dxfer_len = buf_len;
-                       io_hdr.sbp = sense;
-                       io_hdr.mx_sb_len = sizeof (sense);
-                       io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
-                       io_hdr.timeout = COMMAND_TIMEOUT_MSEC;
-
-                       ret = ioctl(fd, SG_IO, &io_hdr);
-                       if (ret != 0)
-                               goto out;
-
-                       /* even if the ioctl succeeds, we need to check the return value */
-                       if (!(io_hdr.status == 0 &&
-                             io_hdr.host_status == 0 &&
-                             io_hdr.driver_status == 0)) {
-                               errno = EIO;
-                               ret = -1;
-                               goto out;
-                       }
-               } else {
-                       goto out;
-               }
-       }
-
-       /* even if the ioctl succeeds, we need to check the return value */
-       if (!(io_v4.device_status == 0 &&
-             io_v4.transport_status == 0 &&
-             io_v4.driver_status == 0)) {
-               errno = EIO;
-               ret = -1;
-               goto out;
-       }
+        struct sg_io_v4 io_v4;
+        uint8_t cdb[6];
+        uint8_t sense[32];
+        int ret;
+
+        /*
+         * INQUIRY, see SPC-4 section 6.4
+         */
+        memset(cdb, 0, sizeof(cdb));
+        cdb[0] = 0x12;                         /* OPERATION CODE: INQUIRY */
+        cdb[3] = (buf_len >> 8);         /* ALLOCATION LENGTH */
+        cdb[4] = (buf_len & 0xff);
+
+        memset(sense, 0, sizeof(sense));
+
+        memset(&io_v4, 0, sizeof(struct sg_io_v4));
+        io_v4.guard = 'Q';
+        io_v4.protocol = BSG_PROTOCOL_SCSI;
+        io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
+        io_v4.request_len = sizeof (cdb);
+        io_v4.request = (uintptr_t) cdb;
+        io_v4.max_response_len = sizeof (sense);
+        io_v4.response = (uintptr_t) sense;
+        io_v4.din_xfer_len = buf_len;
+        io_v4.din_xferp = (uintptr_t) buf;
+        io_v4.timeout = COMMAND_TIMEOUT_MSEC;
+
+        ret = ioctl(fd, SG_IO, &io_v4);
+        if (ret != 0) {
+                /* could be that the driver doesn't do version 4, try version 3 */
+                if (errno == EINVAL) {
+                        struct sg_io_hdr io_hdr;
+
+                        memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
+                        io_hdr.interface_id = 'S';
+                        io_hdr.cmdp = (unsigned char*) cdb;
+                        io_hdr.cmd_len = sizeof (cdb);
+                        io_hdr.dxferp = buf;
+                        io_hdr.dxfer_len = buf_len;
+                        io_hdr.sbp = sense;
+                        io_hdr.mx_sb_len = sizeof (sense);
+                        io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
+                        io_hdr.timeout = COMMAND_TIMEOUT_MSEC;
+
+                        ret = ioctl(fd, SG_IO, &io_hdr);
+                        if (ret != 0)
+                                goto out;
+
+                        /* even if the ioctl succeeds, we need to check the return value */
+                        if (!(io_hdr.status == 0 &&
+                              io_hdr.host_status == 0 &&
+                              io_hdr.driver_status == 0)) {
+                                errno = EIO;
+                                ret = -1;
+                                goto out;
+                        }
+                } else {
+                        goto out;
+                }
+        }
+
+        /* even if the ioctl succeeds, we need to check the return value */
+        if (!(io_v4.device_status == 0 &&
+              io_v4.transport_status == 0 &&
+              io_v4.driver_status == 0)) {
+                errno = EIO;
+                ret = -1;
+                goto out;
+        }
 
  out:
-       return ret;
+        return ret;
 }
 
-static int disk_identify_command(int     fd,
-                                void    *buf,
-                                size_t   buf_len)
+static int disk_identify_command(int          fd,
+                                 void         *buf,
+                                 size_t          buf_len)
 {
-       struct sg_io_v4 io_v4;
-       uint8_t cdb[12];
-       uint8_t sense[32];
-       uint8_t *desc = sense+8;
-       int ret;
-
-       /*
-        * ATA Pass-Through 12 byte command, as described in
-        *
-        *  T10 04-262r8 ATA Command Pass-Through
-        *
-        * from http://www.t10.org/ftp/t10/document.04/04-262r8.pdf
-        */
-       memset(cdb, 0, sizeof(cdb));
-       cdb[0] = 0xa1;                  /* OPERATION CODE: 12 byte pass through */
-       cdb[1] = 4 << 1;                /* PROTOCOL: PIO Data-in */
-       cdb[2] = 0x2e;                  /* OFF_LINE=0, CK_COND=1, T_DIR=1, BYT_BLOK=1, T_LENGTH=2 */
-       cdb[3] = 0;                     /* FEATURES */
-       cdb[4] = 1;                     /* SECTORS */
-       cdb[5] = 0;                     /* LBA LOW */
-       cdb[6] = 0;                     /* LBA MID */
-       cdb[7] = 0;                     /* LBA HIGH */
-       cdb[8] = 0 & 0x4F;              /* SELECT */
-       cdb[9] = 0xEC;                  /* Command: ATA IDENTIFY DEVICE */;
-       memset(sense, 0, sizeof(sense));
-
-       memset(&io_v4, 0, sizeof(struct sg_io_v4));
-       io_v4.guard = 'Q';
-       io_v4.protocol = BSG_PROTOCOL_SCSI;
-       io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
-       io_v4.request_len = sizeof (cdb);
-       io_v4.request = (uintptr_t) cdb;
-       io_v4.max_response_len = sizeof (sense);
-       io_v4.response = (uintptr_t) sense;
-       io_v4.din_xfer_len = buf_len;
-       io_v4.din_xferp = (uintptr_t) buf;
-       io_v4.timeout = COMMAND_TIMEOUT_MSEC;
-
-       ret = ioctl(fd, SG_IO, &io_v4);
-       if (ret != 0) {
-               /* could be that the driver doesn't do version 4, try version 3 */
-               if (errno == EINVAL) {
-                       struct sg_io_hdr io_hdr;
-
-                       memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
-                       io_hdr.interface_id = 'S';
-                       io_hdr.cmdp = (unsigned char*) cdb;
-                       io_hdr.cmd_len = sizeof (cdb);
-                       io_hdr.dxferp = buf;
-                       io_hdr.dxfer_len = buf_len;
-                       io_hdr.sbp = sense;
-                       io_hdr.mx_sb_len = sizeof (sense);
-                       io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
-                       io_hdr.timeout = COMMAND_TIMEOUT_MSEC;
-
-                       ret = ioctl(fd, SG_IO, &io_hdr);
-                       if (ret != 0)
-                               goto out;
-               } else {
-                       goto out;
-               }
-       }
-
-       if (!(sense[0] == 0x72 && desc[0] == 0x9 && desc[1] == 0x0c)) {
-               errno = EIO;
-               ret = -1;
-               goto out;
-       }
+        struct sg_io_v4 io_v4;
+        uint8_t cdb[12];
+        uint8_t sense[32];
+        uint8_t *desc = sense+8;
+        int ret;
+
+        /*
+         * ATA Pass-Through 12 byte command, as described in
+         *
+         *  T10 04-262r8 ATA Command Pass-Through
+         *
+         * from http://www.t10.org/ftp/t10/document.04/04-262r8.pdf
+         */
+        memset(cdb, 0, sizeof(cdb));
+        cdb[0] = 0xa1;                        /* OPERATION CODE: 12 byte pass through */
+        cdb[1] = 4 << 1;                /* PROTOCOL: PIO Data-in */
+        cdb[2] = 0x2e;                        /* OFF_LINE=0, CK_COND=1, T_DIR=1, BYT_BLOK=1, T_LENGTH=2 */
+        cdb[3] = 0;                        /* FEATURES */
+        cdb[4] = 1;                        /* SECTORS */
+        cdb[5] = 0;                        /* LBA LOW */
+        cdb[6] = 0;                        /* LBA MID */
+        cdb[7] = 0;                        /* LBA HIGH */
+        cdb[8] = 0 & 0x4F;                /* SELECT */
+        cdb[9] = 0xEC;                        /* Command: ATA IDENTIFY DEVICE */;
+        memset(sense, 0, sizeof(sense));
+
+        memset(&io_v4, 0, sizeof(struct sg_io_v4));
+        io_v4.guard = 'Q';
+        io_v4.protocol = BSG_PROTOCOL_SCSI;
+        io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
+        io_v4.request_len = sizeof (cdb);
+        io_v4.request = (uintptr_t) cdb;
+        io_v4.max_response_len = sizeof (sense);
+        io_v4.response = (uintptr_t) sense;
+        io_v4.din_xfer_len = buf_len;
+        io_v4.din_xferp = (uintptr_t) buf;
+        io_v4.timeout = COMMAND_TIMEOUT_MSEC;
+
+        ret = ioctl(fd, SG_IO, &io_v4);
+        if (ret != 0) {
+                /* could be that the driver doesn't do version 4, try version 3 */
+                if (errno == EINVAL) {
+                        struct sg_io_hdr io_hdr;
+
+                        memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
+                        io_hdr.interface_id = 'S';
+                        io_hdr.cmdp = (unsigned char*) cdb;
+                        io_hdr.cmd_len = sizeof (cdb);
+                        io_hdr.dxferp = buf;
+                        io_hdr.dxfer_len = buf_len;
+                        io_hdr.sbp = sense;
+                        io_hdr.mx_sb_len = sizeof (sense);
+                        io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
+                        io_hdr.timeout = COMMAND_TIMEOUT_MSEC;
+
+                        ret = ioctl(fd, SG_IO, &io_hdr);
+                        if (ret != 0)
+                                goto out;
+                } else {
+                        goto out;
+                }
+        }
+
+        if (!(sense[0] == 0x72 && desc[0] == 0x9 && desc[1] == 0x0c)) {
+                errno = EIO;
+                ret = -1;
+                goto out;
+        }
 
  out:
-       return ret;
+        return ret;
 }
 
-static int disk_identify_packet_device_command(int       fd,
-                                              void      *buf,
-                                              size_t     buf_len)
+static int disk_identify_packet_device_command(int          fd,
+                                               void         *buf,
+                                               size_t          buf_len)
 {
-       struct sg_io_v4 io_v4;
-       uint8_t cdb[16];
-       uint8_t sense[32];
-       uint8_t *desc = sense+8;
-       int ret;
-
-       /*
-        * ATA Pass-Through 16 byte command, as described in
-        *
-        *  T10 04-262r8 ATA Command Pass-Through
-        *
-        * from http://www.t10.org/ftp/t10/document.04/04-262r8.pdf
-        */
-       memset(cdb, 0, sizeof(cdb));
-       cdb[0] = 0x85;                  /* OPERATION CODE: 16 byte pass through */
-       cdb[1] = 4 << 1;                /* PROTOCOL: PIO Data-in */
-       cdb[2] = 0x2e;                  /* OFF_LINE=0, CK_COND=1, T_DIR=1, BYT_BLOK=1, T_LENGTH=2 */
-       cdb[3] = 0;                     /* FEATURES */
-       cdb[4] = 0;                     /* FEATURES */
-       cdb[5] = 0;                     /* SECTORS */
-       cdb[6] = 1;                     /* SECTORS */
-       cdb[7] = 0;                     /* LBA LOW */
-       cdb[8] = 0;                     /* LBA LOW */
-       cdb[9] = 0;                     /* LBA MID */
-       cdb[10] = 0;                    /* LBA MID */
-       cdb[11] = 0;                    /* LBA HIGH */
-       cdb[12] = 0;                    /* LBA HIGH */
-       cdb[13] = 0;                    /* DEVICE */
-       cdb[14] = 0xA1;                 /* Command: ATA IDENTIFY PACKET DEVICE */;
-       cdb[15] = 0;                    /* CONTROL */
-       memset(sense, 0, sizeof(sense));
-
-       memset(&io_v4, 0, sizeof(struct sg_io_v4));
-       io_v4.guard = 'Q';
-       io_v4.protocol = BSG_PROTOCOL_SCSI;
-       io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
-       io_v4.request_len = sizeof (cdb);
-       io_v4.request = (uintptr_t) cdb;
-       io_v4.max_response_len = sizeof (sense);
-       io_v4.response = (uintptr_t) sense;
-       io_v4.din_xfer_len = buf_len;
-       io_v4.din_xferp = (uintptr_t) buf;
-       io_v4.timeout = COMMAND_TIMEOUT_MSEC;
-
-       ret = ioctl(fd, SG_IO, &io_v4);
-       if (ret != 0) {
-               /* could be that the driver doesn't do version 4, try version 3 */
-               if (errno == EINVAL) {
-                       struct sg_io_hdr io_hdr;
-
-                       memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
-                       io_hdr.interface_id = 'S';
-                       io_hdr.cmdp = (unsigned char*) cdb;
-                       io_hdr.cmd_len = sizeof (cdb);
-                       io_hdr.dxferp = buf;
-                       io_hdr.dxfer_len = buf_len;
-                       io_hdr.sbp = sense;
-                       io_hdr.mx_sb_len = sizeof (sense);
-                       io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
-                       io_hdr.timeout = COMMAND_TIMEOUT_MSEC;
-
-                       ret = ioctl(fd, SG_IO, &io_hdr);
-                       if (ret != 0)
-                               goto out;
-               } else {
-                       goto out;
-               }
-       }
-
-       if (!(sense[0] == 0x72 && desc[0] == 0x9 && desc[1] == 0x0c)) {
-               errno = EIO;
-               ret = -1;
-               goto out;
-       }
+        struct sg_io_v4 io_v4;
+        uint8_t cdb[16];
+        uint8_t sense[32];
+        uint8_t *desc = sense+8;
+        int ret;
+
+        /*
+         * ATA Pass-Through 16 byte command, as described in
+         *
+         *  T10 04-262r8 ATA Command Pass-Through
+         *
+         * from http://www.t10.org/ftp/t10/document.04/04-262r8.pdf
+         */
+        memset(cdb, 0, sizeof(cdb));
+        cdb[0] = 0x85;                        /* OPERATION CODE: 16 byte pass through */
+        cdb[1] = 4 << 1;                /* PROTOCOL: PIO Data-in */
+        cdb[2] = 0x2e;                        /* OFF_LINE=0, CK_COND=1, T_DIR=1, BYT_BLOK=1, T_LENGTH=2 */
+        cdb[3] = 0;                        /* FEATURES */
+        cdb[4] = 0;                        /* FEATURES */
+        cdb[5] = 0;                        /* SECTORS */
+        cdb[6] = 1;                        /* SECTORS */
+        cdb[7] = 0;                        /* LBA LOW */
+        cdb[8] = 0;                        /* LBA LOW */
+        cdb[9] = 0;                        /* LBA MID */
+        cdb[10] = 0;                        /* LBA MID */
+        cdb[11] = 0;                        /* LBA HIGH */
+        cdb[12] = 0;                        /* LBA HIGH */
+        cdb[13] = 0;                        /* DEVICE */
+        cdb[14] = 0xA1;                        /* Command: ATA IDENTIFY PACKET DEVICE */;
+        cdb[15] = 0;                        /* CONTROL */
+        memset(sense, 0, sizeof(sense));
+
+        memset(&io_v4, 0, sizeof(struct sg_io_v4));
+        io_v4.guard = 'Q';
+        io_v4.protocol = BSG_PROTOCOL_SCSI;
+        io_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
+        io_v4.request_len = sizeof (cdb);
+        io_v4.request = (uintptr_t) cdb;
+        io_v4.max_response_len = sizeof (sense);
+        io_v4.response = (uintptr_t) sense;
+        io_v4.din_xfer_len = buf_len;
+        io_v4.din_xferp = (uintptr_t) buf;
+        io_v4.timeout = COMMAND_TIMEOUT_MSEC;
+
+        ret = ioctl(fd, SG_IO, &io_v4);
+        if (ret != 0) {
+                /* could be that the driver doesn't do version 4, try version 3 */
+                if (errno == EINVAL) {
+                        struct sg_io_hdr io_hdr;
+
+                        memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
+                        io_hdr.interface_id = 'S';
+                        io_hdr.cmdp = (unsigned char*) cdb;
+                        io_hdr.cmd_len = sizeof (cdb);
+                        io_hdr.dxferp = buf;
+                        io_hdr.dxfer_len = buf_len;
+                        io_hdr.sbp = sense;
+                        io_hdr.mx_sb_len = sizeof (sense);
+                        io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
+                        io_hdr.timeout = COMMAND_TIMEOUT_MSEC;
+
+                        ret = ioctl(fd, SG_IO, &io_hdr);
+                        if (ret != 0)
+                                goto out;
+                } else {
+                        goto out;
+                }
+        }
+
+        if (!(sense[0] == 0x72 && desc[0] == 0x9 && desc[1] == 0x0c)) {
+                errno = EIO;
+                ret = -1;
+                goto out;
+        }
 
  out:
-       return ret;
+        return ret;
 }
 
 /**
@@ -295,43 +295,43 @@ static int disk_identify_packet_device_command(int          fd,
  * Copies the ATA string from @identify located at @offset_words into @dest.
  */
 static void disk_identify_get_string (uint8_t identify[512],
-                                     unsigned int offset_words,
-                                     char *dest,
-                                     size_t dest_len)
+                                      unsigned int offset_words,
+                                      char *dest,
+                                      size_t dest_len)
 {
-       unsigned int c1;
-       unsigned int c2;
-
-       assert (identify != NULL);
-       assert (dest != NULL);
-       assert ((dest_len & 1) == 0);
-
-       while (dest_len > 0) {
-               c1 = ((uint16_t *) identify)[offset_words] >> 8;
-               c2 = ((uint16_t *) identify)[offset_words] & 0xff;
-               *dest = c1;
-               dest++;
-               *dest = c2;
-               dest++;
-               offset_words++;
-               dest_len -= 2;
-       }
+        unsigned int c1;
+        unsigned int c2;
+
+        assert (identify != NULL);
+        assert (dest != NULL);
+        assert ((dest_len & 1) == 0);
+
+        while (dest_len > 0) {
+                c1 = ((uint16_t *) identify)[offset_words] >> 8;
+                c2 = ((uint16_t *) identify)[offset_words] & 0xff;
+                *dest = c1;
+                dest++;
+                *dest = c2;
+                dest++;
+                offset_words++;
+                dest_len -= 2;
+        }
 }
 
 static void disk_identify_fixup_string (uint8_t identify[512],
-                                       unsigned int offset_words,
-                                       size_t len)
+                                        unsigned int offset_words,
+                                        size_t len)
 {
-       disk_identify_get_string(identify, offset_words,
-                                (char *) identify + offset_words * 2, len);
+        disk_identify_get_string(identify, offset_words,
+                                 (char *) identify + offset_words * 2, len);
 }
 
 static void disk_identify_fixup_uint16 (uint8_t identify[512], unsigned int offset_words)
 {
-       uint16_t *p;
+        uint16_t *p;
 
-       p = (uint16_t *) identify;
-       p[offset_words] = le16toh (p[offset_words]);
+        p = (uint16_t *) identify;
+        p[offset_words] = le16toh (p[offset_words]);
 }
 
 /**
@@ -352,375 +352,375 @@ static void disk_identify_fixup_uint16 (uint8_t identify[512], unsigned int offs
  * non-zero with errno set.
  */
 static int disk_identify (struct udev *udev,
-                         int          fd,
-                         uint8_t      out_identify[512],
-                         int         *out_is_packet_device)
+                          int               fd,
+                          uint8_t      out_identify[512],
+                          int              *out_is_packet_device)
 {
-       int ret;
-       uint8_t inquiry_buf[36];
-       int peripheral_device_type;
-       int all_nul_bytes;
-       int n;
-       int is_packet_device;
-
-       assert (out_identify != NULL);
-
-       /* init results */
-       ret = -1;
-       memset (out_identify, '\0', 512);
-       is_packet_device = 0;
-
-       /* If we were to use ATA PASS_THROUGH (12) on an ATAPI device
-        * we could accidentally blank media. This is because MMC's BLANK
-        * command has the same op-code (0x61).
-        *
-        * To prevent this from happening we bail out if the device
-        * isn't a Direct Access Block Device, e.g. SCSI type 0x00
-        * (CD/DVD devices are type 0x05). So we send a SCSI INQUIRY
-        * command first... libata is handling this via its SCSI
-        * emulation layer.
-        *
-        * This also ensures that we're actually dealing with a device
-        * that understands SCSI commands.
-        *
-        * (Yes, it is a bit perverse that we're tunneling the ATA
-        * command through SCSI and relying on the ATA driver
-        * emulating SCSI well-enough...)
-        *
-        * (See commit 160b069c25690bfb0c785994c7c3710289179107 for
-        * the original bug-fix and see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=556635
-        * for the original bug-report.)
-        */
-       ret = disk_scsi_inquiry_command (fd, inquiry_buf, sizeof (inquiry_buf));
-       if (ret != 0)
-               goto out;
-
-       /* SPC-4, section 6.4.2: Standard INQUIRY data */
-       peripheral_device_type = inquiry_buf[0] & 0x1f;
-       if (peripheral_device_type == 0x05)
-         {
-           is_packet_device = 1;
-           ret = disk_identify_packet_device_command(fd, out_identify, 512);
-           goto check_nul_bytes;
-         }
-       if (peripheral_device_type != 0x00) {
-               ret = -1;
-               errno = EIO;
-               goto out;
-       }
-
-       /* OK, now issue the IDENTIFY DEVICE command */
-       ret = disk_identify_command(fd, out_identify, 512);
-       if (ret != 0)
-               goto out;
+        int ret;
+        uint8_t inquiry_buf[36];
+        int peripheral_device_type;
+        int all_nul_bytes;
+        int n;
+        int is_packet_device;
+
+        assert (out_identify != NULL);
+
+        /* init results */
+        ret = -1;
+        memset (out_identify, '\0', 512);
+        is_packet_device = 0;
+
+        /* If we were to use ATA PASS_THROUGH (12) on an ATAPI device
+         * we could accidentally blank media. This is because MMC's BLANK
+         * command has the same op-code (0x61).
+         *
+         * To prevent this from happening we bail out if the device
+         * isn't a Direct Access Block Device, e.g. SCSI type 0x00
+         * (CD/DVD devices are type 0x05). So we send a SCSI INQUIRY
+         * command first... libata is handling this via its SCSI
+         * emulation layer.
+         *
+         * This also ensures that we're actually dealing with a device
+         * that understands SCSI commands.
+         *
+         * (Yes, it is a bit perverse that we're tunneling the ATA
+         * command through SCSI and relying on the ATA driver
+         * emulating SCSI well-enough...)
+         *
+         * (See commit 160b069c25690bfb0c785994c7c3710289179107 for
+         * the original bug-fix and see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=556635
+         * for the original bug-report.)
+         */
+        ret = disk_scsi_inquiry_command (fd, inquiry_buf, sizeof (inquiry_buf));
+        if (ret != 0)
+                goto out;
+
+        /* SPC-4, section 6.4.2: Standard INQUIRY data */
+        peripheral_device_type = inquiry_buf[0] & 0x1f;
+        if (peripheral_device_type == 0x05)
+          {
+            is_packet_device = 1;
+            ret = disk_identify_packet_device_command(fd, out_identify, 512);
+            goto check_nul_bytes;
+          }
+        if (peripheral_device_type != 0x00) {
+                ret = -1;
+                errno = EIO;
+                goto out;
+        }
+
+        /* OK, now issue the IDENTIFY DEVICE command */
+        ret = disk_identify_command(fd, out_identify, 512);
+        if (ret != 0)
+                goto out;
 
  check_nul_bytes:
-        /* Check if IDENTIFY data is all NUL bytes - if so, bail */
-       all_nul_bytes = 1;
-       for (n = 0; n < 512; n++) {
-               if (out_identify[n] != '\0') {
-                       all_nul_bytes = 0;
-                       break;
-               }
-       }
-
-       if (all_nul_bytes) {
-               ret = -1;
-               errno = EIO;
-               goto out;
-       }
+         /* Check if IDENTIFY data is all NUL bytes - if so, bail */
+        all_nul_bytes = 1;
+        for (n = 0; n < 512; n++) {
+                if (out_identify[n] != '\0') {
+                        all_nul_bytes = 0;
+                        break;
+                }
+        }
+
+        if (all_nul_bytes) {
+                ret = -1;
+                errno = EIO;
+                goto out;
+        }
 
 out:
-       if (out_is_packet_device != NULL)
-         *out_is_packet_device = is_packet_device;
-       return ret;
+        if (out_is_packet_device != NULL)
+          *out_is_packet_device = is_packet_device;
+        return ret;
 }
 
 static void log_fn(struct udev *udev, int priority,
-                  const char *file, int line, const char *fn,
-                  const char *format, va_list args)
+                   const char *file, int line, const char *fn,
+                   const char *format, va_list args)
 {
-       vsyslog(priority, format, args);
+        vsyslog(priority, format, args);
 }
 
 int main(int argc, char *argv[])
 {
-       struct udev *udev;
-       struct hd_driveid id;
-       uint8_t identify[512];
-       uint16_t *identify_words;
-       char model[41];
-       char model_enc[256];
-       char serial[21];
-       char revision[9];
-       const char *node = NULL;
-       int export = 0;
-       int fd;
-       uint16_t word;
-       int rc = 0;
-       int is_packet_device = 0;
-       static const struct option options[] = {
-               { "export", no_argument, NULL, 'x' },
-               { "help", no_argument, NULL, 'h' },
-               {}
-       };
-
-       udev = udev_new();
-       if (udev == NULL)
-               goto exit;
-
-       udev_log_init("ata_id");
-       udev_set_log_fn(udev, log_fn);
-
-       while (1) {
-               int option;
-
-               option = getopt_long(argc, argv, "xh", options, NULL);
-               if (option == -1)
-                       break;
-
-               switch (option) {
-               case 'x':
-                       export = 1;
-                       break;
-               case 'h':
-                       printf("Usage: ata_id [--export] [--help] <device>\n"
-                              "  --export    print values as environment keys\n"
-                              "  --help      print this help text\n\n");
-                       goto exit;
-               }
-       }
-
-       node = argv[optind];
-       if (node == NULL) {
-               err(udev, "no node specified\n");
-               rc = 1;
-               goto exit;
-       }
-
-       fd = open(node, O_RDONLY|O_NONBLOCK);
-       if (fd < 0) {
-               err(udev, "unable to open '%s'\n", node);
-               rc = 1;
-               goto exit;
-       }
-
-       if (disk_identify(udev, fd, identify, &is_packet_device) == 0) {
-               /*
-                * fix up only the fields from the IDENTIFY data that we are going to
-                * use and copy it into the hd_driveid struct for convenience
-                */
-               disk_identify_fixup_string (identify,  10, 20); /* serial */
-               disk_identify_fixup_string (identify,  23,  6); /* fwrev */
-               disk_identify_fixup_string (identify,  27, 40); /* model */
-               disk_identify_fixup_uint16 (identify,   0);     /* configuration */
-               disk_identify_fixup_uint16 (identify,  75);     /* queue depth */
-               disk_identify_fixup_uint16 (identify,  75);     /* SATA capabilities */
-               disk_identify_fixup_uint16 (identify,  82);     /* command set supported */
-               disk_identify_fixup_uint16 (identify,  83);     /* command set supported */
-               disk_identify_fixup_uint16 (identify,  84);     /* command set supported */
-               disk_identify_fixup_uint16 (identify,  85);     /* command set supported */
-               disk_identify_fixup_uint16 (identify,  86);     /* command set supported */
-               disk_identify_fixup_uint16 (identify,  87);     /* command set supported */
-               disk_identify_fixup_uint16 (identify,  89);     /* time required for SECURITY ERASE UNIT */
-               disk_identify_fixup_uint16 (identify,  90);     /* time required for enhanced SECURITY ERASE UNIT */
-               disk_identify_fixup_uint16 (identify,  91);     /* current APM values */
-               disk_identify_fixup_uint16 (identify,  94);     /* current AAM value */
-               disk_identify_fixup_uint16 (identify, 128);     /* device lock function */
-               disk_identify_fixup_uint16 (identify, 217);     /* nominal media rotation rate */
-               memcpy(&id, identify, sizeof id);
-       } else {
-               /* If this fails, then try HDIO_GET_IDENTITY */
-               if (ioctl(fd, HDIO_GET_IDENTITY, &id) != 0) {
-                       if (errno == ENOTTY) {
-                               info(udev, "HDIO_GET_IDENTITY unsupported for '%s'\n", node);
-                               rc = 2;
-                       } else {
-                               err(udev, "HDIO_GET_IDENTITY failed for '%s': %m\n", node);
-                               rc = 3;
-                       }
-                       goto close;
-               }
-       }
-       identify_words = (uint16_t *) identify;
-
-       memcpy (model, id.model, 40);
-       model[40] = '\0';
-       udev_util_encode_string(model, model_enc, sizeof(model_enc));
-       util_replace_whitespace((char *) id.model, model, 40);
-       util_replace_chars(model, NULL);
-       util_replace_whitespace((char *) id.serial_no, serial, 20);
-       util_replace_chars(serial, NULL);
-       util_replace_whitespace((char *) id.fw_rev, revision, 8);
-       util_replace_chars(revision, NULL);
-
-       if (export) {
-               /* Set this to convey the disk speaks the ATA protocol */
-               printf("ID_ATA=1\n");
-
-               if ((id.config >> 8) & 0x80) {
-                       /* This is an ATAPI device */
-                       switch ((id.config >> 8) & 0x1f) {
-                       case 0:
-                               printf("ID_TYPE=cd\n");
-                               break;
-                       case 1:
-                               printf("ID_TYPE=tape\n");
-                               break;
-                       case 5:
-                               printf("ID_TYPE=cd\n");
-                               break;
-                       case 7:
-                               printf("ID_TYPE=optical\n");
-                               break;
-                       default:
-                               printf("ID_TYPE=generic\n");
-                               break;
-                       }
-               } else {
-                       printf("ID_TYPE=disk\n");
-               }
-               printf("ID_BUS=ata\n");
-               printf("ID_MODEL=%s\n", model);
-               printf("ID_MODEL_ENC=%s\n", model_enc);
-               printf("ID_REVISION=%s\n", revision);
-               if (serial[0] != '\0') {
-                       printf("ID_SERIAL=%s_%s\n", model, serial);
-                       printf("ID_SERIAL_SHORT=%s\n", serial);
-               } else {
-                       printf("ID_SERIAL=%s\n", model);
-               }
-
-               if (id.command_set_1 & (1<<5)) {
-                       printf ("ID_ATA_WRITE_CACHE=1\n");
-                       printf ("ID_ATA_WRITE_CACHE_ENABLED=%d\n", (id.cfs_enable_1 & (1<<5)) ? 1 : 0);
-               }
-               if (id.command_set_1 & (1<<10)) {
-                       printf("ID_ATA_FEATURE_SET_HPA=1\n");
-                       printf("ID_ATA_FEATURE_SET_HPA_ENABLED=%d\n", (id.cfs_enable_1 & (1<<10)) ? 1 : 0);
-
-                       /*
-                        * TODO: use the READ NATIVE MAX ADDRESS command to get the native max address
-                        * so it is easy to check whether the protected area is in use.
-                        */
-               }
-               if (id.command_set_1 & (1<<3)) {
-                       printf("ID_ATA_FEATURE_SET_PM=1\n");
-                       printf("ID_ATA_FEATURE_SET_PM_ENABLED=%d\n", (id.cfs_enable_1 & (1<<3)) ? 1 : 0);
-               }
-               if (id.command_set_1 & (1<<1)) {
-                       printf("ID_ATA_FEATURE_SET_SECURITY=1\n");
-                       printf("ID_ATA_FEATURE_SET_SECURITY_ENABLED=%d\n", (id.cfs_enable_1 & (1<<1)) ? 1 : 0);
-                       printf("ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=%d\n", id.trseuc * 2);
-                       if ((id.cfs_enable_1 & (1<<1))) /* enabled */ {
-                               if (id.dlf & (1<<8))
-                                       printf("ID_ATA_FEATURE_SET_SECURITY_LEVEL=maximum\n");
-                               else
-                                       printf("ID_ATA_FEATURE_SET_SECURITY_LEVEL=high\n");
-                       }
-                       if (id.dlf & (1<<5))
-                               printf("ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=%d\n", id.trsEuc * 2);
-                       if (id.dlf & (1<<4))
-                               printf("ID_ATA_FEATURE_SET_SECURITY_EXPIRE=1\n");
-                       if (id.dlf & (1<<3))
-                               printf("ID_ATA_FEATURE_SET_SECURITY_FROZEN=1\n");
-                       if (id.dlf & (1<<2))
-                               printf("ID_ATA_FEATURE_SET_SECURITY_LOCKED=1\n");
-               }
-               if (id.command_set_1 & (1<<0)) {
-                       printf("ID_ATA_FEATURE_SET_SMART=1\n");
-                       printf("ID_ATA_FEATURE_SET_SMART_ENABLED=%d\n", (id.cfs_enable_1 & (1<<0)) ? 1 : 0);
-               }
-               if (id.command_set_2 & (1<<9)) {
-                       printf("ID_ATA_FEATURE_SET_AAM=1\n");
-                       printf("ID_ATA_FEATURE_SET_AAM_ENABLED=%d\n", (id.cfs_enable_2 & (1<<9)) ? 1 : 0);
-                       printf("ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE=%d\n", id.acoustic >> 8);
-                       printf("ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE=%d\n", id.acoustic & 0xff);
-               }
-               if (id.command_set_2 & (1<<5)) {
-                       printf("ID_ATA_FEATURE_SET_PUIS=1\n");
-                       printf("ID_ATA_FEATURE_SET_PUIS_ENABLED=%d\n", (id.cfs_enable_2 & (1<<5)) ? 1 : 0);
-               }
-               if (id.command_set_2 & (1<<3)) {
-                       printf("ID_ATA_FEATURE_SET_APM=1\n");
-                       printf("ID_ATA_FEATURE_SET_APM_ENABLED=%d\n", (id.cfs_enable_2 & (1<<3)) ? 1 : 0);
-                       if ((id.cfs_enable_2 & (1<<3)))
-                               printf("ID_ATA_FEATURE_SET_APM_CURRENT_VALUE=%d\n", id.CurAPMvalues & 0xff);
-               }
-               if (id.command_set_2 & (1<<0))
-                       printf("ID_ATA_DOWNLOAD_MICROCODE=1\n");
-
-               /*
-                * Word 76 indicates the capabilities of a SATA device. A PATA device shall set
-                * word 76 to 0000h or FFFFh. If word 76 is set to 0000h or FFFFh, then
-                * the device does not claim compliance with the Serial ATA specification and words
-                * 76 through 79 are not valid and shall be ignored.
-                */
-               word = *((uint16_t *) identify + 76);
-               if (word != 0x0000 && word != 0xffff) {
-                       printf("ID_ATA_SATA=1\n");
-                       /*
-                        * If bit 2 of word 76 is set to one, then the device supports the Gen2
-                        * signaling rate of 3.0 Gb/s (see SATA 2.6).
-                        *
-                        * If bit 1 of word 76 is set to one, then the device supports the Gen1
-                        * signaling rate of 1.5 Gb/s (see SATA 2.6).
-                        */
-                       if (word & (1<<2))
-                               printf("ID_ATA_SATA_SIGNAL_RATE_GEN2=1\n");
-                       if (word & (1<<1))
-                               printf("ID_ATA_SATA_SIGNAL_RATE_GEN1=1\n");
-               }
-
-               /* Word 217 indicates the nominal media rotation rate of the device */
-               word = *((uint16_t *) identify + 217);
-               if (word != 0x0000) {
-                       if (word == 0x0001) {
-                               printf ("ID_ATA_ROTATION_RATE_RPM=0\n"); /* non-rotating e.g. SSD */
-                       } else if (word >= 0x0401 && word <= 0xfffe) {
-                               printf ("ID_ATA_ROTATION_RATE_RPM=%d\n", word);
-                       }
-               }
-
-               /*
-                * Words 108-111 contain a mandatory World Wide Name (WWN) in the NAA IEEE Registered identifier
-                * format. Word 108 bits (15:12) shall contain 5h, indicating that the naming authority is IEEE.
-                * All other values are reserved.
-                */
-               word = *((uint16_t *) identify + 108);
-               if ((word & 0xf000) == 0x5000) {
-                       uint64_t wwwn;
-
-                       wwwn   = *((uint16_t *) identify + 108);
-                       wwwn <<= 16;
-                       wwwn  |= *((uint16_t *) identify + 109);
-                       wwwn <<= 16;
-                       wwwn  |= *((uint16_t *) identify + 110);
-                       wwwn <<= 16;
-                       wwwn  |= *((uint16_t *) identify + 111);
-                       printf("ID_WWN=0x%llx\n", (unsigned long long int) wwwn);
-                       /* ATA devices have no vendor extension */
-                       printf("ID_WWN_WITH_EXTENSION=0x%llx\n", (unsigned long long int) wwwn);
-               }
-
-               /* from Linux's include/linux/ata.h */
-               if (identify_words[0] == 0x848a || identify_words[0] == 0x844a) {
-                       printf("ID_ATA_CFA=1\n");
-               } else {
-                       if ((identify_words[83] & 0xc004) == 0x4004) {
-                               printf("ID_ATA_CFA=1\n");
-                       }
-               }
-       } else {
-               if (serial[0] != '\0')
-                       printf("%s_%s\n", model, serial);
-               else
-                       printf("%s\n", model);
-       }
+        struct udev *udev;
+        struct hd_driveid id;
+        uint8_t identify[512];
+        uint16_t *identify_words;
+        char model[41];
+        char model_enc[256];
+        char serial[21];
+        char revision[9];
+        const char *node = NULL;
+        int export = 0;
+        int fd;
+        uint16_t word;
+        int rc = 0;
+        int is_packet_device = 0;
+        static const struct option options[] = {
+                { "export", no_argument, NULL, 'x' },
+                { "help", no_argument, NULL, 'h' },
+                {}
+        };
+
+        udev = udev_new();
+        if (udev == NULL)
+                goto exit;
+
+        udev_log_init("ata_id");
+        udev_set_log_fn(udev, log_fn);
+
+        while (1) {
+                int option;
+
+                option = getopt_long(argc, argv, "xh", options, NULL);
+                if (option == -1)
+                        break;
+
+                switch (option) {
+                case 'x':
+                        export = 1;
+                        break;
+                case 'h':
+                        printf("Usage: ata_id [--export] [--help] <device>\n"
+                               "  --export    print values as environment keys\n"
+                               "  --help      print this help text\n\n");
+                        goto exit;
+                }
+        }
+
+        node = argv[optind];
+        if (node == NULL) {
+                err(udev, "no node specified\n");
+                rc = 1;
+                goto exit;
+        }
+
+        fd = open(node, O_RDONLY|O_NONBLOCK);
+        if (fd < 0) {
+                err(udev, "unable to open '%s'\n", node);
+                rc = 1;
+                goto exit;
+        }
+
+        if (disk_identify(udev, fd, identify, &is_packet_device) == 0) {
+                /*
+                 * fix up only the fields from the IDENTIFY data that we are going to
+                 * use and copy it into the hd_driveid struct for convenience
+                 */
+                disk_identify_fixup_string (identify,  10, 20);        /* serial */
+                disk_identify_fixup_string (identify,  23,  6);        /* fwrev */
+                disk_identify_fixup_string (identify,  27, 40);        /* model */
+                disk_identify_fixup_uint16 (identify,        0);        /* configuration */
+                disk_identify_fixup_uint16 (identify,  75);        /* queue depth */
+                disk_identify_fixup_uint16 (identify,  75);        /* SATA capabilities */
+                disk_identify_fixup_uint16 (identify,  82);        /* command set supported */
+                disk_identify_fixup_uint16 (identify,  83);        /* command set supported */
+                disk_identify_fixup_uint16 (identify,  84);        /* command set supported */
+                disk_identify_fixup_uint16 (identify,  85);        /* command set supported */
+                disk_identify_fixup_uint16 (identify,  86);        /* command set supported */
+                disk_identify_fixup_uint16 (identify,  87);        /* command set supported */
+                disk_identify_fixup_uint16 (identify,  89);        /* time required for SECURITY ERASE UNIT */
+                disk_identify_fixup_uint16 (identify,  90);        /* time required for enhanced SECURITY ERASE UNIT */
+                disk_identify_fixup_uint16 (identify,  91);        /* current APM values */
+                disk_identify_fixup_uint16 (identify,  94);        /* current AAM value */
+                disk_identify_fixup_uint16 (identify, 128);        /* device lock function */
+                disk_identify_fixup_uint16 (identify, 217);        /* nominal media rotation rate */
+                memcpy(&id, identify, sizeof id);
+        } else {
+                /* If this fails, then try HDIO_GET_IDENTITY */
+                if (ioctl(fd, HDIO_GET_IDENTITY, &id) != 0) {
+                        if (errno == ENOTTY) {
+                                info(udev, "HDIO_GET_IDENTITY unsupported for '%s'\n", node);
+                                rc = 2;
+                        } else {
+                                err(udev, "HDIO_GET_IDENTITY failed for '%s': %m\n", node);
+                                rc = 3;
+                        }
+                        goto close;
+                }
+        }
+        identify_words = (uint16_t *) identify;
+
+        memcpy (model, id.model, 40);
+        model[40] = '\0';
+        udev_util_encode_string(model, model_enc, sizeof(model_enc));
+        util_replace_whitespace((char *) id.model, model, 40);
+        util_replace_chars(model, NULL);
+        util_replace_whitespace((char *) id.serial_no, serial, 20);
+        util_replace_chars(serial, NULL);
+        util_replace_whitespace((char *) id.fw_rev, revision, 8);
+        util_replace_chars(revision, NULL);
+
+        if (export) {
+                /* Set this to convey the disk speaks the ATA protocol */
+                printf("ID_ATA=1\n");
+
+                if ((id.config >> 8) & 0x80) {
+                        /* This is an ATAPI device */
+                        switch ((id.config >> 8) & 0x1f) {
+                        case 0:
+                                printf("ID_TYPE=cd\n");
+                                break;
+                        case 1:
+                                printf("ID_TYPE=tape\n");
+                                break;
+                        case 5:
+                                printf("ID_TYPE=cd\n");
+                                break;
+                        case 7:
+                                printf("ID_TYPE=optical\n");
+                                break;
+                        default:
+                                printf("ID_TYPE=generic\n");
+                                break;
+                        }
+                } else {
+                        printf("ID_TYPE=disk\n");
+                }
+                printf("ID_BUS=ata\n");
+                printf("ID_MODEL=%s\n", model);
+                printf("ID_MODEL_ENC=%s\n", model_enc);
+                printf("ID_REVISION=%s\n", revision);
+                if (serial[0] != '\0') {
+                        printf("ID_SERIAL=%s_%s\n", model, serial);
+                        printf("ID_SERIAL_SHORT=%s\n", serial);
+                } else {
+                        printf("ID_SERIAL=%s\n", model);
+                }
+
+                if (id.command_set_1 & (1<<5)) {
+                        printf ("ID_ATA_WRITE_CACHE=1\n");
+                        printf ("ID_ATA_WRITE_CACHE_ENABLED=%d\n", (id.cfs_enable_1 & (1<<5)) ? 1 : 0);
+                }
+                if (id.command_set_1 & (1<<10)) {
+                        printf("ID_ATA_FEATURE_SET_HPA=1\n");
+                        printf("ID_ATA_FEATURE_SET_HPA_ENABLED=%d\n", (id.cfs_enable_1 & (1<<10)) ? 1 : 0);
+
+                        /*
+                         * TODO: use the READ NATIVE MAX ADDRESS command to get the native max address
+                         * so it is easy to check whether the protected area is in use.
+                         */
+                }
+                if (id.command_set_1 & (1<<3)) {
+                        printf("ID_ATA_FEATURE_SET_PM=1\n");
+                        printf("ID_ATA_FEATURE_SET_PM_ENABLED=%d\n", (id.cfs_enable_1 & (1<<3)) ? 1 : 0);
+                }
+                if (id.command_set_1 & (1<<1)) {
+                        printf("ID_ATA_FEATURE_SET_SECURITY=1\n");
+                        printf("ID_ATA_FEATURE_SET_SECURITY_ENABLED=%d\n", (id.cfs_enable_1 & (1<<1)) ? 1 : 0);
+                        printf("ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=%d\n", id.trseuc * 2);
+                        if ((id.cfs_enable_1 & (1<<1))) /* enabled */ {
+                                if (id.dlf & (1<<8))
+                                        printf("ID_ATA_FEATURE_SET_SECURITY_LEVEL=maximum\n");
+                                else
+                                        printf("ID_ATA_FEATURE_SET_SECURITY_LEVEL=high\n");
+                        }
+                        if (id.dlf & (1<<5))
+                                printf("ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=%d\n", id.trsEuc * 2);
+                        if (id.dlf & (1<<4))
+                                printf("ID_ATA_FEATURE_SET_SECURITY_EXPIRE=1\n");
+                        if (id.dlf & (1<<3))
+                                printf("ID_ATA_FEATURE_SET_SECURITY_FROZEN=1\n");
+                        if (id.dlf & (1<<2))
+                                printf("ID_ATA_FEATURE_SET_SECURITY_LOCKED=1\n");
+                }
+                if (id.command_set_1 & (1<<0)) {
+                        printf("ID_ATA_FEATURE_SET_SMART=1\n");
+                        printf("ID_ATA_FEATURE_SET_SMART_ENABLED=%d\n", (id.cfs_enable_1 & (1<<0)) ? 1 : 0);
+                }
+                if (id.command_set_2 & (1<<9)) {
+                        printf("ID_ATA_FEATURE_SET_AAM=1\n");
+                        printf("ID_ATA_FEATURE_SET_AAM_ENABLED=%d\n", (id.cfs_enable_2 & (1<<9)) ? 1 : 0);
+                        printf("ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE=%d\n", id.acoustic >> 8);
+                        printf("ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE=%d\n", id.acoustic & 0xff);
+                }
+                if (id.command_set_2 & (1<<5)) {
+                        printf("ID_ATA_FEATURE_SET_PUIS=1\n");
+                        printf("ID_ATA_FEATURE_SET_PUIS_ENABLED=%d\n", (id.cfs_enable_2 & (1<<5)) ? 1 : 0);
+                }
+                if (id.command_set_2 & (1<<3)) {
+                        printf("ID_ATA_FEATURE_SET_APM=1\n");
+                        printf("ID_ATA_FEATURE_SET_APM_ENABLED=%d\n", (id.cfs_enable_2 & (1<<3)) ? 1 : 0);
+                        if ((id.cfs_enable_2 & (1<<3)))
+                                printf("ID_ATA_FEATURE_SET_APM_CURRENT_VALUE=%d\n", id.CurAPMvalues & 0xff);
+                }
+                if (id.command_set_2 & (1<<0))
+                        printf("ID_ATA_DOWNLOAD_MICROCODE=1\n");
+
+                /*
+                 * Word 76 indicates the capabilities of a SATA device. A PATA device shall set
+                 * word 76 to 0000h or FFFFh. If word 76 is set to 0000h or FFFFh, then
+                 * the device does not claim compliance with the Serial ATA specification and words
+                 * 76 through 79 are not valid and shall be ignored.
+                 */
+                word = *((uint16_t *) identify + 76);
+                if (word != 0x0000 && word != 0xffff) {
+                        printf("ID_ATA_SATA=1\n");
+                        /*
+                         * If bit 2 of word 76 is set to one, then the device supports the Gen2
+                         * signaling rate of 3.0 Gb/s (see SATA 2.6).
+                         *
+                         * If bit 1 of word 76 is set to one, then the device supports the Gen1
+                         * signaling rate of 1.5 Gb/s (see SATA 2.6).
+                         */
+                        if (word & (1<<2))
+                                printf("ID_ATA_SATA_SIGNAL_RATE_GEN2=1\n");
+                        if (word & (1<<1))
+                                printf("ID_ATA_SATA_SIGNAL_RATE_GEN1=1\n");
+                }
+
+                /* Word 217 indicates the nominal media rotation rate of the device */
+                word = *((uint16_t *) identify + 217);
+                if (word != 0x0000) {
+                        if (word == 0x0001) {
+                                printf ("ID_ATA_ROTATION_RATE_RPM=0\n"); /* non-rotating e.g. SSD */
+                        } else if (word >= 0x0401 && word <= 0xfffe) {
+                                printf ("ID_ATA_ROTATION_RATE_RPM=%d\n", word);
+                        }
+                }
+
+                /*
+                 * Words 108-111 contain a mandatory World Wide Name (WWN) in the NAA IEEE Registered identifier
+                 * format. Word 108 bits (15:12) shall contain 5h, indicating that the naming authority is IEEE.
+                 * All other values are reserved.
+                 */
+                word = *((uint16_t *) identify + 108);
+                if ((word & 0xf000) == 0x5000) {
+                        uint64_t wwwn;
+
+                        wwwn   = *((uint16_t *) identify + 108);
+                        wwwn <<= 16;
+                        wwwn  |= *((uint16_t *) identify + 109);
+                        wwwn <<= 16;
+                        wwwn  |= *((uint16_t *) identify + 110);
+                        wwwn <<= 16;
+                        wwwn  |= *((uint16_t *) identify + 111);
+                        printf("ID_WWN=0x%llx\n", (unsigned long long int) wwwn);
+                        /* ATA devices have no vendor extension */
+                        printf("ID_WWN_WITH_EXTENSION=0x%llx\n", (unsigned long long int) wwwn);
+                }
+
+                /* from Linux's include/linux/ata.h */
+                if (identify_words[0] == 0x848a || identify_words[0] == 0x844a) {
+                        printf("ID_ATA_CFA=1\n");
+                } else {
+                        if ((identify_words[83] & 0xc004) == 0x4004) {
+                                printf("ID_ATA_CFA=1\n");
+                        }
+                }
+        } else {
+                if (serial[0] != '\0')
+                        printf("%s_%s\n", model, serial);
+                else
+                        printf("%s\n", model);
+        }
 close:
-       close(fd);
+        close(fd);
 exit:
-       udev_unref(udev);
-       udev_log_close();
-       return rc;
+        udev_unref(udev);
+        udev_log_close();
+        return rc;
 }
index 664a00d..daaebee 100644 (file)
 static bool debug;
 
 static void log_fn(struct udev *udev, int priority,
-                  const char *file, int line, const char *fn,
-                  const char *format, va_list args)
+                   const char *file, int line, const char *fn,
+                   const char *format, va_list args)
 {
-       if (debug) {
-               fprintf(stderr, "%s: ", fn);
-               vfprintf(stderr, format, args);
-       } else {
-               vsyslog(priority, format, args);
-       }
+        if (debug) {
+                fprintf(stderr, "%s: ", fn);
+                vfprintf(stderr, format, args);
+        } else {
+                vsyslog(priority, format, args);
+        }
 }
 
 /* device info */
@@ -110,990 +110,990 @@ static unsigned int cd_media_track_count_data = 0;
 static unsigned int cd_media_track_count_audio = 0;
 static unsigned long long int cd_media_session_last_offset = 0;
 
-#define ERRCODE(s)     ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13]))
-#define SK(errcode)    (((errcode) >> 16) & 0xF)
-#define ASC(errcode)   (((errcode) >> 8) & 0xFF)
-#define ASCQ(errcode)  ((errcode) & 0xFF)
+#define ERRCODE(s)        ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13]))
+#define SK(errcode)        (((errcode) >> 16) & 0xF)
+#define ASC(errcode)        (((errcode) >> 8) & 0xFF)
+#define ASCQ(errcode)        ((errcode) & 0xFF)
 
 static int is_mounted(const char *device)
 {
-       struct stat statbuf;
-       FILE *fp;
-       int maj, min;
-       int mounted = 0;
-
-       if (stat(device, &statbuf) < 0)
-               return -ENODEV;
-
-       fp = fopen("/proc/self/mountinfo", "r");
-       if (fp == NULL)
-               return -ENOSYS;
-       while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
-               if (makedev(maj, min) == statbuf.st_rdev) {
-                       mounted = 1;
-                       break;
-               }
-       }
-       fclose(fp);
-       return mounted;
+        struct stat statbuf;
+        FILE *fp;
+        int maj, min;
+        int mounted = 0;
+
+        if (stat(device, &statbuf) < 0)
+                return -ENODEV;
+
+        fp = fopen("/proc/self/mountinfo", "r");
+        if (fp == NULL)
+                return -ENOSYS;
+        while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
+                if (makedev(maj, min) == statbuf.st_rdev) {
+                        mounted = 1;
+                        break;
+                }
+        }
+        fclose(fp);
+        return mounted;
 }
 
 static void info_scsi_cmd_err(struct udev *udev, char *cmd, int err)
 {
-       if (err == -1) {
-               info(udev, "%s failed\n", cmd);
-               return;
-       }
-       info(udev, "%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
+        if (err == -1) {
+                info(udev, "%s failed\n", cmd);
+                return;
+        }
+        info(udev, "%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
 }
 
 struct scsi_cmd {
-       struct cdrom_generic_command cgc;
-       union {
-               struct request_sense s;
-               unsigned char u[18];
-       } _sense;
-       struct sg_io_hdr sg_io;
+        struct cdrom_generic_command cgc;
+        union {
+                struct request_sense s;
+                unsigned char u[18];
+        } _sense;
+        struct sg_io_hdr sg_io;
 };
 
 static void scsi_cmd_init(struct udev *udev, struct scsi_cmd *cmd)
 {
-       memset(cmd, 0x00, sizeof(struct scsi_cmd));
-       cmd->cgc.quiet = 1;
-       cmd->cgc.sense = &cmd->_sense.s;
-       cmd->sg_io.interface_id = 'S';
-       cmd->sg_io.mx_sb_len = sizeof(cmd->_sense);
-       cmd->sg_io.cmdp = cmd->cgc.cmd;
-       cmd->sg_io.sbp = cmd->_sense.u;
-       cmd->sg_io.flags = SG_FLAG_LUN_INHIBIT | SG_FLAG_DIRECT_IO;
+        memset(cmd, 0x00, sizeof(struct scsi_cmd));
+        cmd->cgc.quiet = 1;
+        cmd->cgc.sense = &cmd->_sense.s;
+        cmd->sg_io.interface_id = 'S';
+        cmd->sg_io.mx_sb_len = sizeof(cmd->_sense);
+        cmd->sg_io.cmdp = cmd->cgc.cmd;
+        cmd->sg_io.sbp = cmd->_sense.u;
+        cmd->sg_io.flags = SG_FLAG_LUN_INHIBIT | SG_FLAG_DIRECT_IO;
 }
 
 static void scsi_cmd_set(struct udev *udev, struct scsi_cmd *cmd, size_t i, unsigned char arg)
 {
-       cmd->sg_io.cmd_len = i + 1;
-       cmd->cgc.cmd[i] = arg;
+        cmd->sg_io.cmd_len = i + 1;
+        cmd->cgc.cmd[i] = arg;
 }
 
 #define CHECK_CONDITION 0x01
 
 static int scsi_cmd_run(struct udev *udev, struct scsi_cmd *cmd, int fd, unsigned char *buf, size_t bufsize)
 {
-       int ret = 0;
-
-       if (bufsize > 0) {
-               cmd->sg_io.dxferp = buf;
-               cmd->sg_io.dxfer_len = bufsize;
-               cmd->sg_io.dxfer_direction = SG_DXFER_FROM_DEV;
-       } else {
-               cmd->sg_io.dxfer_direction = SG_DXFER_NONE;
-       }
-       if (ioctl(fd, SG_IO, &cmd->sg_io))
-               return -1;
-
-       if ((cmd->sg_io.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
-               errno = EIO;
-               ret = -1;
-               if (cmd->sg_io.masked_status & CHECK_CONDITION) {
-                       ret = ERRCODE(cmd->_sense.u);
-                       if (ret == 0)
-                               ret = -1;
-               }
-       }
-       return ret;
+        int ret = 0;
+
+        if (bufsize > 0) {
+                cmd->sg_io.dxferp = buf;
+                cmd->sg_io.dxfer_len = bufsize;
+                cmd->sg_io.dxfer_direction = SG_DXFER_FROM_DEV;
+        } else {
+                cmd->sg_io.dxfer_direction = SG_DXFER_NONE;
+        }
+        if (ioctl(fd, SG_IO, &cmd->sg_io))
+                return -1;
+
+        if ((cmd->sg_io.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
+                errno = EIO;
+                ret = -1;
+                if (cmd->sg_io.masked_status & CHECK_CONDITION) {
+                        ret = ERRCODE(cmd->_sense.u);
+                        if (ret == 0)
+                                ret = -1;
+                }
+        }
+        return ret;
 }
 
 static int media_lock(struct udev *udev, int fd, bool lock)
 {
-       int err;
+        int err;
 
-       /* disable the kernel's lock logic */
-       err = ioctl(fd, CDROM_CLEAR_OPTIONS, CDO_LOCK);
-       if (err < 0)
-               info(udev, "CDROM_CLEAR_OPTIONS, CDO_LOCK failed\n");
+        /* disable the kernel's lock logic */
+        err = ioctl(fd, CDROM_CLEAR_OPTIONS, CDO_LOCK);
+        if (err < 0)
+                info(udev, "CDROM_CLEAR_OPTIONS, CDO_LOCK failed\n");
 
-       err = ioctl(fd, CDROM_LOCKDOOR, lock ? 1 : 0);
-       if (err < 0)
-               info(udev, "CDROM_LOCKDOOR failed\n");
+        err = ioctl(fd, CDROM_LOCKDOOR, lock ? 1 : 0);
+        if (err < 0)
+                info(udev, "CDROM_LOCKDOOR failed\n");
 
-       return err;
+        return err;
 }
 
 static int media_eject(struct udev *udev, int fd)
 {
-       struct scsi_cmd sc;
-       int err;
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x1b);
-       scsi_cmd_set(udev, &sc, 4, 0x02);
-       scsi_cmd_set(udev, &sc, 5, 0);
-       err = scsi_cmd_run(udev, &sc, fd, NULL, 0);
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "START_STOP_UNIT", err);
-               return -1;
-       }
-       return 0;
+        struct scsi_cmd sc;
+        int err;
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x1b);
+        scsi_cmd_set(udev, &sc, 4, 0x02);
+        scsi_cmd_set(udev, &sc, 5, 0);
+        err = scsi_cmd_run(udev, &sc, fd, NULL, 0);
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "START_STOP_UNIT", err);
+                return -1;
+        }
+        return 0;
 }
 
 static int cd_capability_compat(struct udev *udev, int fd)
 {
-       int capability;
-
-       capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
-       if (capability < 0) {
-               info(udev, "CDROM_GET_CAPABILITY failed\n");
-               return -1;
-       }
-
-       if (capability & CDC_CD_R)
-               cd_cd_r = 1;
-       if (capability & CDC_CD_RW)
-               cd_cd_rw = 1;
-       if (capability & CDC_DVD)
-               cd_dvd_rom = 1;
-       if (capability & CDC_DVD_R)
-               cd_dvd_r = 1;
-       if (capability & CDC_DVD_RAM)
-               cd_dvd_ram = 1;
-       if (capability & CDC_MRW)
-               cd_mrw = 1;
-       if (capability & CDC_MRW_W)
-               cd_mrw_w = 1;
-       return 0;
+        int capability;
+
+        capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
+        if (capability < 0) {
+                info(udev, "CDROM_GET_CAPABILITY failed\n");
+                return -1;
+        }
+
+        if (capability & CDC_CD_R)
+                cd_cd_r = 1;
+        if (capability & CDC_CD_RW)
+                cd_cd_rw = 1;
+        if (capability & CDC_DVD)
+                cd_dvd_rom = 1;
+        if (capability & CDC_DVD_R)
+                cd_dvd_r = 1;
+        if (capability & CDC_DVD_RAM)
+                cd_dvd_ram = 1;
+        if (capability & CDC_MRW)
+                cd_mrw = 1;
+        if (capability & CDC_MRW_W)
+                cd_mrw_w = 1;
+        return 0;
 }
 
 static int cd_media_compat(struct udev *udev, int fd)
 {
-       if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
-               info(udev, "CDROM_DRIVE_STATUS != CDS_DISC_OK\n");
-               return -1;
-       }
-       cd_media = 1;
-       return 0;
+        if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
+                info(udev, "CDROM_DRIVE_STATUS != CDS_DISC_OK\n");
+                return -1;
+        }
+        cd_media = 1;
+        return 0;
 }
 
 static int cd_inquiry(struct udev *udev, int fd)
 {
-       struct scsi_cmd sc;
-       unsigned char inq[128];
-       int err;
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x12);
-       scsi_cmd_set(udev, &sc, 4, 36);
-       scsi_cmd_set(udev, &sc, 5, 0);
-       err = scsi_cmd_run(udev, &sc, fd, inq, 36);
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "INQUIRY", err);
-               return -1;
-       }
-
-       if ((inq[0] & 0x1F) != 5) {
-               info(udev, "not an MMC unit\n");
-               return -1;
-       }
-
-       info(udev, "INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
-       return 0;
+        struct scsi_cmd sc;
+        unsigned char inq[128];
+        int err;
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x12);
+        scsi_cmd_set(udev, &sc, 4, 36);
+        scsi_cmd_set(udev, &sc, 5, 0);
+        err = scsi_cmd_run(udev, &sc, fd, inq, 36);
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "INQUIRY", err);
+                return -1;
+        }
+
+        if ((inq[0] & 0x1F) != 5) {
+                info(udev, "not an MMC unit\n");
+                return -1;
+        }
+
+        info(udev, "INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
+        return 0;
 }
 
 static void feature_profile_media(struct udev *udev, int cur_profile)
 {
-       switch (cur_profile) {
-       case 0x03:
-       case 0x04:
-       case 0x05:
-               info(udev, "profile 0x%02x \n", cur_profile);
-               cd_media = 1;
-               cd_media_mo = 1;
-               break;
-       case 0x08:
-               info(udev, "profile 0x%02x media_cd_rom\n", cur_profile);
-               cd_media = 1;
-               cd_media_cd_rom = 1;
-               break;
-       case 0x09:
-               info(udev, "profile 0x%02x media_cd_r\n", cur_profile);
-               cd_media = 1;
-               cd_media_cd_r = 1;
-               break;
-       case 0x0a:
-               info(udev, "profile 0x%02x media_cd_rw\n", cur_profile);
-               cd_media = 1;
-               cd_media_cd_rw = 1;
-               break;
-       case 0x10:
-               info(udev, "profile 0x%02x media_dvd_ro\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_rom = 1;
-               break;
-       case 0x11:
-               info(udev, "profile 0x%02x media_dvd_r\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_r = 1;
-               break;
-       case 0x12:
-               info(udev, "profile 0x%02x media_dvd_ram\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_ram = 1;
-               break;
-       case 0x13:
-               info(udev, "profile 0x%02x media_dvd_rw_ro\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_rw = 1;
-               cd_media_dvd_rw_ro = 1;
-               break;
-       case 0x14:
-               info(udev, "profile 0x%02x media_dvd_rw_seq\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_rw = 1;
-               cd_media_dvd_rw_seq = 1;
-               break;
-       case 0x1B:
-               info(udev, "profile 0x%02x media_dvd_plus_r\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_plus_r = 1;
-               break;
-       case 0x1A:
-               info(udev, "profile 0x%02x media_dvd_plus_rw\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_plus_rw = 1;
-               break;
-       case 0x2A:
-               info(udev, "profile 0x%02x media_dvd_plus_rw_dl\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_plus_rw_dl = 1;
-               break;
-       case 0x2B:
-               info(udev, "profile 0x%02x media_dvd_plus_r_dl\n", cur_profile);
-               cd_media = 1;
-               cd_media_dvd_plus_r_dl = 1;
-               break;
-       case 0x40:
-               info(udev, "profile 0x%02x media_bd\n", cur_profile);
-               cd_media = 1;
-               cd_media_bd = 1;
-               break;
-       case 0x41:
-       case 0x42:
-               info(udev, "profile 0x%02x media_bd_r\n", cur_profile);
-               cd_media = 1;
-               cd_media_bd_r = 1;
-               break;
-       case 0x43:
-               info(udev, "profile 0x%02x media_bd_re\n", cur_profile);
-               cd_media = 1;
-               cd_media_bd_re = 1;
-               break;
-       case 0x50:
-               info(udev, "profile 0x%02x media_hddvd\n", cur_profile);
-               cd_media = 1;
-               cd_media_hddvd = 1;
-               break;
-       case 0x51:
-               info(udev, "profile 0x%02x media_hddvd_r\n", cur_profile);
-               cd_media = 1;
-               cd_media_hddvd_r = 1;
-               break;
-       case 0x52:
-               info(udev, "profile 0x%02x media_hddvd_rw\n", cur_profile);
-               cd_media = 1;
-               cd_media_hddvd_rw = 1;
-               break;
-       default:
-               info(udev, "profile 0x%02x <ignored>\n", cur_profile);
-               break;
-       }
+        switch (cur_profile) {
+        case 0x03:
+        case 0x04:
+        case 0x05:
+                info(udev, "profile 0x%02x \n", cur_profile);
+                cd_media = 1;
+                cd_media_mo = 1;
+                break;
+        case 0x08:
+                info(udev, "profile 0x%02x media_cd_rom\n", cur_profile);
+                cd_media = 1;
+                cd_media_cd_rom = 1;
+                break;
+        case 0x09:
+                info(udev, "profile 0x%02x media_cd_r\n", cur_profile);
+                cd_media = 1;
+                cd_media_cd_r = 1;
+                break;
+        case 0x0a:
+                info(udev, "profile 0x%02x media_cd_rw\n", cur_profile);
+                cd_media = 1;
+                cd_media_cd_rw = 1;
+                break;
+        case 0x10:
+                info(udev, "profile 0x%02x media_dvd_ro\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_rom = 1;
+                break;
+        case 0x11:
+                info(udev, "profile 0x%02x media_dvd_r\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_r = 1;
+                break;
+        case 0x12:
+                info(udev, "profile 0x%02x media_dvd_ram\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_ram = 1;
+                break;
+        case 0x13:
+                info(udev, "profile 0x%02x media_dvd_rw_ro\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_rw = 1;
+                cd_media_dvd_rw_ro = 1;
+                break;
+        case 0x14:
+                info(udev, "profile 0x%02x media_dvd_rw_seq\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_rw = 1;
+                cd_media_dvd_rw_seq = 1;
+                break;
+        case 0x1B:
+                info(udev, "profile 0x%02x media_dvd_plus_r\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_plus_r = 1;
+                break;
+        case 0x1A:
+                info(udev, "profile 0x%02x media_dvd_plus_rw\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_plus_rw = 1;
+                break;
+        case 0x2A:
+                info(udev, "profile 0x%02x media_dvd_plus_rw_dl\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_plus_rw_dl = 1;
+                break;
+        case 0x2B:
+                info(udev, "profile 0x%02x media_dvd_plus_r_dl\n", cur_profile);
+                cd_media = 1;
+                cd_media_dvd_plus_r_dl = 1;
+                break;
+        case 0x40:
+                info(udev, "profile 0x%02x media_bd\n", cur_profile);
+                cd_media = 1;
+                cd_media_bd = 1;
+                break;
+        case 0x41:
+        case 0x42:
+                info(udev, "profile 0x%02x media_bd_r\n", cur_profile);
+                cd_media = 1;
+                cd_media_bd_r = 1;
+                break;
+        case 0x43:
+                info(udev, "profile 0x%02x media_bd_re\n", cur_profile);
+                cd_media = 1;
+                cd_media_bd_re = 1;
+                break;
+        case 0x50:
+                info(udev, "profile 0x%02x media_hddvd\n", cur_profile);
+                cd_media = 1;
+                cd_media_hddvd = 1;
+                break;
+        case 0x51:
+                info(udev, "profile 0x%02x media_hddvd_r\n", cur_profile);
+                cd_media = 1;
+                cd_media_hddvd_r = 1;
+                break;
+        case 0x52:
+                info(udev, "profile 0x%02x media_hddvd_rw\n", cur_profile);
+                cd_media = 1;
+                cd_media_hddvd_rw = 1;
+                break;
+        default:
+                info(udev, "profile 0x%02x <ignored>\n", cur_profile);
+                break;
+        }
 }
 
 static int feature_profiles(struct udev *udev, const unsigned char *profiles, size_t size)
 {
-       unsigned int i;
-
-       for (i = 0; i+4 <= size; i += 4) {
-               int profile;
-
-               profile = profiles[i] << 8 | profiles[i+1];
-               switch (profile) {
-               case 0x03:
-               case 0x04:
-               case 0x05:
-                       info(udev, "profile 0x%02x mo\n", profile);
-                       cd_mo = 1;
-                       break;
-               case 0x08:
-                       info(udev, "profile 0x%02x cd_rom\n", profile);
-                       cd_cd_rom = 1;
-                       break;
-               case 0x09:
-                       info(udev, "profile 0x%02x cd_r\n", profile);
-                       cd_cd_r = 1;
-                       break;
-               case 0x0A:
-                       info(udev, "profile 0x%02x cd_rw\n", profile);
-                       cd_cd_rw = 1;
-                       break;
-               case 0x10:
-                       info(udev, "profile 0x%02x dvd_rom\n", profile);
-                       cd_dvd_rom = 1;
-                       break;
-               case 0x12:
-                       info(udev, "profile 0x%02x dvd_ram\n", profile);
-                       cd_dvd_ram = 1;
-                       break;
-               case 0x13:
-               case 0x14:
-                       info(udev, "profile 0x%02x dvd_rw\n", profile);
-                       cd_dvd_rw = 1;
-                       break;
-               case 0x1B:
-                       info(udev, "profile 0x%02x dvd_plus_r\n", profile);
-                       cd_dvd_plus_r = 1;
-                       break;
-               case 0x1A:
-                       info(udev, "profile 0x%02x dvd_plus_rw\n", profile);
-                       cd_dvd_plus_rw = 1;
-                       break;
-               case 0x2A:
-                       info(udev, "profile 0x%02x dvd_plus_rw_dl\n", profile);
-                       cd_dvd_plus_rw_dl = 1;
-                       break;
-               case 0x2B:
-                       info(udev, "profile 0x%02x dvd_plus_r_dl\n", profile);
-                       cd_dvd_plus_r_dl = 1;
-                       break;
-               case 0x40:
-                       cd_bd = 1;
-                       info(udev, "profile 0x%02x bd\n", profile);
-                       break;
-               case 0x41:
-               case 0x42:
-                       cd_bd_r = 1;
-                       info(udev, "profile 0x%02x bd_r\n", profile);
-                       break;
-               case 0x43:
-                       cd_bd_re = 1;
-                       info(udev, "profile 0x%02x bd_re\n", profile);
-                       break;
-               case 0x50:
-                       cd_hddvd = 1;
-                       info(udev, "profile 0x%02x hddvd\n", profile);
-                       break;
-               case 0x51:
-                       cd_hddvd_r = 1;
-                       info(udev, "profile 0x%02x hddvd_r\n", profile);
-                       break;
-               case 0x52:
-                       cd_hddvd_rw = 1;
-                       info(udev, "profile 0x%02x hddvd_rw\n", profile);
-                       break;
-               default:
-                       info(udev, "profile 0x%02x <ignored>\n", profile);
-                       break;
-               }
-       }
-       return 0;
+        unsigned int i;
+
+        for (i = 0; i+4 <= size; i += 4) {
+                int profile;
+
+                profile = profiles[i] << 8 | profiles[i+1];
+                switch (profile) {
+                case 0x03:
+                case 0x04:
+                case 0x05:
+                        info(udev, "profile 0x%02x mo\n", profile);
+                        cd_mo = 1;
+                        break;
+                case 0x08:
+                        info(udev, "profile 0x%02x cd_rom\n", profile);
+                        cd_cd_rom = 1;
+                        break;
+                case 0x09:
+                        info(udev, "profile 0x%02x cd_r\n", profile);
+                        cd_cd_r = 1;
+                        break;
+                case 0x0A:
+                        info(udev, "profile 0x%02x cd_rw\n", profile);
+                        cd_cd_rw = 1;
+                        break;
+                case 0x10:
+                        info(udev, "profile 0x%02x dvd_rom\n", profile);
+                        cd_dvd_rom = 1;
+                        break;
+                case 0x12:
+                        info(udev, "profile 0x%02x dvd_ram\n", profile);
+                        cd_dvd_ram = 1;
+                        break;
+                case 0x13:
+                case 0x14:
+                        info(udev, "profile 0x%02x dvd_rw\n", profile);
+                        cd_dvd_rw = 1;
+                        break;
+                case 0x1B:
+                        info(udev, "profile 0x%02x dvd_plus_r\n", profile);
+                        cd_dvd_plus_r = 1;
+                        break;
+                case 0x1A:
+                        info(udev, "profile 0x%02x dvd_plus_rw\n", profile);
+                        cd_dvd_plus_rw = 1;
+                        break;
+                case 0x2A:
+                        info(udev, "profile 0x%02x dvd_plus_rw_dl\n", profile);
+                        cd_dvd_plus_rw_dl = 1;
+                        break;
+                case 0x2B:
+                        info(udev, "profile 0x%02x dvd_plus_r_dl\n", profile);
+                        cd_dvd_plus_r_dl = 1;
+                        break;
+                case 0x40:
+                        cd_bd = 1;
+                        info(udev, "profile 0x%02x bd\n", profile);
+                        break;
+                case 0x41:
+                case 0x42:
+                        cd_bd_r = 1;
+                        info(udev, "profile 0x%02x bd_r\n", profile);
+                        break;
+                case 0x43:
+                        cd_bd_re = 1;
+                        info(udev, "profile 0x%02x bd_re\n", profile);
+                        break;
+                case 0x50:
+                        cd_hddvd = 1;
+                        info(udev, "profile 0x%02x hddvd\n", profile);
+                        break;
+                case 0x51:
+                        cd_hddvd_r = 1;
+                        info(udev, "profile 0x%02x hddvd_r\n", profile);
+                        break;
+                case 0x52:
+                        cd_hddvd_rw = 1;
+                        info(udev, "profile 0x%02x hddvd_rw\n", profile);
+                        break;
+                default:
+                        info(udev, "profile 0x%02x <ignored>\n", profile);
+                        break;
+                }
+        }
+        return 0;
 }
 
 /* returns 0 if media was detected */
 static int cd_profiles_old_mmc(struct udev *udev, int fd)
 {
-       struct scsi_cmd sc;
-       int err;
-
-       unsigned char header[32];
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x51);
-       scsi_cmd_set(udev, &sc, 8, sizeof(header));
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
-               if (cd_media == 1) {
-                       info(udev, "no current profile, but disc is present; assuming CD-ROM\n");
-                       cd_media_cd_rom = 1;
-                       return 0;
-               } else {
-                       info(udev, "no current profile, assuming no media\n");
-                       return -1;
-               }
-       };
-
-       cd_media = 1;
-
-       if (header[2] & 16) {
-               cd_media_cd_rw = 1;
-               info(udev, "profile 0x0a media_cd_rw\n");
-       } else if ((header[2] & 3) < 2 && cd_cd_r) {
-               cd_media_cd_r = 1;
-               info(udev, "profile 0x09 media_cd_r\n");
-       } else {
-               cd_media_cd_rom = 1;
-               info(udev, "profile 0x08 media_cd_rom\n");
-       }
-       return 0;
+        struct scsi_cmd sc;
+        int err;
+
+        unsigned char header[32];
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x51);
+        scsi_cmd_set(udev, &sc, 8, sizeof(header));
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
+                if (cd_media == 1) {
+                        info(udev, "no current profile, but disc is present; assuming CD-ROM\n");
+                        cd_media_cd_rom = 1;
+                        return 0;
+                } else {
+                        info(udev, "no current profile, assuming no media\n");
+                        return -1;
+                }
+        };
+
+        cd_media = 1;
+
+        if (header[2] & 16) {
+                cd_media_cd_rw = 1;
+                info(udev, "profile 0x0a media_cd_rw\n");
+        } else if ((header[2] & 3) < 2 && cd_cd_r) {
+                cd_media_cd_r = 1;
+                info(udev, "profile 0x09 media_cd_r\n");
+        } else {
+                cd_media_cd_rom = 1;
+                info(udev, "profile 0x08 media_cd_rom\n");
+        }
+        return 0;
 }
 
 /* returns 0 if media was detected */
 static int cd_profiles(struct udev *udev, int fd)
 {
-       struct scsi_cmd sc;
-       unsigned char features[65530];
-       unsigned int cur_profile = 0;
-       unsigned int len;
-       unsigned int i;
-       int err;
-       int ret;
-
-       ret = -1;
-
-       /* First query the current profile */
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x46);
-       scsi_cmd_set(udev, &sc, 8, 8);
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, features, 8);
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
-               /* handle pre-MMC2 drives which do not support GET CONFIGURATION */
-               if (SK(err) == 0x5 && ASC(err) == 0x20) {
-                       info(udev, "drive is pre-MMC2 and does not support 46h get configuration command\n");
-                       info(udev, "trying to work around the problem\n");
-                       ret = cd_profiles_old_mmc(udev, fd);
-               }
-               goto out;
-       }
-
-       cur_profile = features[6] << 8 | features[7];
-       if (cur_profile > 0) {
-               info(udev, "current profile 0x%02x\n", cur_profile);
-               feature_profile_media (udev, cur_profile);
-               ret = 0; /* we have media */
-       } else {
-               info(udev, "no current profile, assuming no media\n");
-       }
-
-       len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
-       info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len);
-
-       if (len > sizeof(features)) {
-               info(udev, "can not get features in a single query, truncating\n");
-               len = sizeof(features);
-       } else if (len <= 8) {
-               len = sizeof(features);
-       }
-
-       /* Now get the full feature buffer */
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x46);
-       scsi_cmd_set(udev, &sc, 7, ( len >> 8 ) & 0xff);
-       scsi_cmd_set(udev, &sc, 8, len & 0xff);
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, features, len);
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
-               return -1;
-       }
-
-       /* parse the length once more, in case the drive decided to have other features suddenly :) */
-       len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
-       info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len);
-
-       if (len > sizeof(features)) {
-               info(udev, "can not get features in a single query, truncating\n");
-               len = sizeof(features);
-       }
-
-       /* device features */
-       for (i = 8; i+4 < len; i += (4 + features[i+3])) {
-               unsigned int feature;
-
-               feature = features[i] << 8 | features[i+1];
-
-               switch (feature) {
-               case 0x00:
-                       info(udev, "GET CONFIGURATION: feature 'profiles', with %i entries\n", features[i+3] / 4);
-                       feature_profiles(udev, &features[i]+4, features[i+3]);
-                       break;
-               default:
-                       info(udev, "GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes\n", feature, features[i+3]);
-                       break;
-               }
-       }
+        struct scsi_cmd sc;
+        unsigned char features[65530];
+        unsigned int cur_profile = 0;
+        unsigned int len;
+        unsigned int i;
+        int err;
+        int ret;
+
+        ret = -1;
+
+        /* First query the current profile */
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x46);
+        scsi_cmd_set(udev, &sc, 8, 8);
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, features, 8);
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
+                /* handle pre-MMC2 drives which do not support GET CONFIGURATION */
+                if (SK(err) == 0x5 && ASC(err) == 0x20) {
+                        info(udev, "drive is pre-MMC2 and does not support 46h get configuration command\n");
+                        info(udev, "trying to work around the problem\n");
+                        ret = cd_profiles_old_mmc(udev, fd);
+                }
+                goto out;
+        }
+
+        cur_profile = features[6] << 8 | features[7];
+        if (cur_profile > 0) {
+                info(udev, "current profile 0x%02x\n", cur_profile);
+                feature_profile_media (udev, cur_profile);
+                ret = 0; /* we have media */
+        } else {
+                info(udev, "no current profile, assuming no media\n");
+        }
+
+        len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
+        info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len);
+
+        if (len > sizeof(features)) {
+                info(udev, "can not get features in a single query, truncating\n");
+                len = sizeof(features);
+        } else if (len <= 8) {
+                len = sizeof(features);
+        }
+
+        /* Now get the full feature buffer */
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x46);
+        scsi_cmd_set(udev, &sc, 7, ( len >> 8 ) & 0xff);
+        scsi_cmd_set(udev, &sc, 8, len & 0xff);
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, features, len);
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
+                return -1;
+        }
+
+        /* parse the length once more, in case the drive decided to have other features suddenly :) */
+        len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3];
+        info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len);
+
+        if (len > sizeof(features)) {
+                info(udev, "can not get features in a single query, truncating\n");
+                len = sizeof(features);
+        }
+
+        /* device features */
+        for (i = 8; i+4 < len; i += (4 + features[i+3])) {
+                unsigned int feature;
+
+                feature = features[i] << 8 | features[i+1];
+
+                switch (feature) {
+                case 0x00:
+                        info(udev, "GET CONFIGURATION: feature 'profiles', with %i entries\n", features[i+3] / 4);
+                        feature_profiles(udev, &features[i]+4, features[i+3]);
+                        break;
+                default:
+                        info(udev, "GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes\n", feature, features[i+3]);
+                        break;
+                }
+        }
 out:
-       return ret;
+        return ret;
 }
 
 static int cd_media_info(struct udev *udev, int fd)
 {
-       struct scsi_cmd sc;
-       unsigned char header[32];
-       static const char *media_status[] = {
-               "blank",
-               "appendable",
-               "complete",
-               "other"
-       };
-       int err;
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x51);
-       scsi_cmd_set(udev, &sc, 8, sizeof(header) & 0xff);
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
-               return -1;
-       };
-
-       cd_media = 1;
-       info(udev, "disk type %02x\n", header[8]);
-       info(udev, "hardware reported media status: %s\n", media_status[header[2] & 3]);
-
-       /* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
-       if (!cd_media_cd_rom)
-               cd_media_state = media_status[header[2] & 3];
-
-       /* fresh DVD-RW in restricted overwite mode reports itself as
-        * "appendable"; change it to "blank" to make it consistent with what
-        * gets reported after blanking, and what userspace expects  */
-       if (cd_media_dvd_rw_ro && (header[2] & 3) == 1)
-               cd_media_state = media_status[0];
-
-       /* DVD+RW discs (and DVD-RW in restricted mode) once formatted are
-        * always "complete", DVD-RAM are "other" or "complete" if the disc is
-        * write protected; we need to check the contents if it is blank */
-       if ((cd_media_dvd_rw_ro || cd_media_dvd_plus_rw || cd_media_dvd_plus_rw_dl || cd_media_dvd_ram) && (header[2] & 3) > 1) {
-               unsigned char buffer[32 * 2048];
-               unsigned char result, len;
-               int block, offset;
-
-               if (cd_media_dvd_ram) {
-                       /* a write protected dvd-ram may report "complete" status */
-
-                       unsigned char dvdstruct[8];
-                       unsigned char format[12];
-
-                       scsi_cmd_init(udev, &sc);
-                       scsi_cmd_set(udev, &sc, 0, 0xAD);
-                       scsi_cmd_set(udev, &sc, 7, 0xC0);
-                       scsi_cmd_set(udev, &sc, 9, sizeof(dvdstruct));
-                       scsi_cmd_set(udev, &sc, 11, 0);
-                       err = scsi_cmd_run(udev, &sc, fd, dvdstruct, sizeof(dvdstruct));
-                       if ((err != 0)) {
-                               info_scsi_cmd_err(udev, "READ DVD STRUCTURE", err);
-                               return -1;
-                       }
-                       if (dvdstruct[4] & 0x02) {
-                               cd_media_state = media_status[2];
-                               info(udev, "write-protected DVD-RAM media inserted\n");
-                               goto determined;
-                       }
-
-                       /* let's make sure we don't try to read unformatted media */
-                       scsi_cmd_init(udev, &sc);
-                       scsi_cmd_set(udev, &sc, 0, 0x23);
-                       scsi_cmd_set(udev, &sc, 8, sizeof(format));
-                       scsi_cmd_set(udev, &sc, 9, 0);
-                       err = scsi_cmd_run(udev, &sc, fd, format, sizeof(format));
-                       if ((err != 0)) {
-                               info_scsi_cmd_err(udev, "READ DVD FORMAT CAPACITIES", err);
-                               return -1;
-                       }
-
-                       len = format[3];
-                       if (len & 7 || len < 16) {
-                               info(udev, "invalid format capacities length\n");
-                               return -1;
-                       }
-
-                       switch(format[8] & 3) {
-                           case 1:
-                               info(udev, "unformatted DVD-RAM media inserted\n");
-                               /* This means that last format was interrupted
-                                * or failed, blank dvd-ram discs are factory
-                                * formatted. Take no action here as it takes
-                                * quite a while to reformat a dvd-ram and it's
-                                * not automatically started */
-                               goto determined;
-
-                           case 2:
-                               info(udev, "formatted DVD-RAM media inserted\n");
-                               break;
-
-                           case 3:
-                               cd_media = 0; //return no media
-                               info(udev, "format capacities returned no media\n");
-                               return -1;
-                       }
-               }
-
-               /* Take a closer look at formatted media (unformatted DVD+RW
-                * has "blank" status", DVD-RAM was examined earlier) and check
-                * for ISO and UDF PVDs or a fs superblock presence and do it
-                * in one ioctl (we need just sectors 0 and 16) */
-               scsi_cmd_init(udev, &sc);
-               scsi_cmd_set(udev, &sc, 0, 0x28);
-               scsi_cmd_set(udev, &sc, 5, 0);
-               scsi_cmd_set(udev, &sc, 8, 32);
-               scsi_cmd_set(udev, &sc, 9, 0);
-               err = scsi_cmd_run(udev, &sc, fd, buffer, sizeof(buffer));
-               if ((err != 0)) {
-                       cd_media = 0;
-                       info_scsi_cmd_err(udev, "READ FIRST 32 BLOCKS", err);
-                       return -1;
-               }
-
-               /* if any non-zero data is found in sector 16 (iso and udf) or
-                * eventually 0 (fat32 boot sector, ext2 superblock, etc), disc
-                * is assumed non-blank */
-               result = 0;
-
-               for (block = 32768; block >= 0 && !result; block -= 32768) {
-                       offset = block;
-                       while (offset < (block + 2048) && !result) {
-                               result = buffer [offset];
-                               offset++;
-                       }
-               }
-
-               if (!result) {
-                       cd_media_state = media_status[0];
-                       info(udev, "no data in blocks 0 or 16, assuming blank\n");
-               } else {
-                       info(udev, "data in blocks 0 or 16, assuming complete\n");
-               }
-       }
+        struct scsi_cmd sc;
+        unsigned char header[32];
+        static const char *media_status[] = {
+                "blank",
+                "appendable",
+                "complete",
+                "other"
+        };
+        int err;
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x51);
+        scsi_cmd_set(udev, &sc, 8, sizeof(header) & 0xff);
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
+                return -1;
+        };
+
+        cd_media = 1;
+        info(udev, "disk type %02x\n", header[8]);
+        info(udev, "hardware reported media status: %s\n", media_status[header[2] & 3]);
+
+        /* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
+        if (!cd_media_cd_rom)
+                cd_media_state = media_status[header[2] & 3];
+
+        /* fresh DVD-RW in restricted overwite mode reports itself as
+         * "appendable"; change it to "blank" to make it consistent with what
+         * gets reported after blanking, and what userspace expects  */
+        if (cd_media_dvd_rw_ro && (header[2] & 3) == 1)
+                cd_media_state = media_status[0];
+
+        /* DVD+RW discs (and DVD-RW in restricted mode) once formatted are
+         * always "complete", DVD-RAM are "other" or "complete" if the disc is
+         * write protected; we need to check the contents if it is blank */
+        if ((cd_media_dvd_rw_ro || cd_media_dvd_plus_rw || cd_media_dvd_plus_rw_dl || cd_media_dvd_ram) && (header[2] & 3) > 1) {
+                unsigned char buffer[32 * 2048];
+                unsigned char result, len;
+                int block, offset;
+
+                if (cd_media_dvd_ram) {
+                        /* a write protected dvd-ram may report "complete" status */
+
+                        unsigned char dvdstruct[8];
+                        unsigned char format[12];
+
+                        scsi_cmd_init(udev, &sc);
+                        scsi_cmd_set(udev, &sc, 0, 0xAD);
+                        scsi_cmd_set(udev, &sc, 7, 0xC0);
+                        scsi_cmd_set(udev, &sc, 9, sizeof(dvdstruct));
+                        scsi_cmd_set(udev, &sc, 11, 0);
+                        err = scsi_cmd_run(udev, &sc, fd, dvdstruct, sizeof(dvdstruct));
+                        if ((err != 0)) {
+                                info_scsi_cmd_err(udev, "READ DVD STRUCTURE", err);
+                                return -1;
+                        }
+                        if (dvdstruct[4] & 0x02) {
+                                cd_media_state = media_status[2];
+                                info(udev, "write-protected DVD-RAM media inserted\n");
+                                goto determined;
+                        }
+
+                        /* let's make sure we don't try to read unformatted media */
+                        scsi_cmd_init(udev, &sc);
+                        scsi_cmd_set(udev, &sc, 0, 0x23);
+                        scsi_cmd_set(udev, &sc, 8, sizeof(format));
+                        scsi_cmd_set(udev, &sc, 9, 0);
+                        err = scsi_cmd_run(udev, &sc, fd, format, sizeof(format));
+                        if ((err != 0)) {
+                                info_scsi_cmd_err(udev, "READ DVD FORMAT CAPACITIES", err);
+                                return -1;
+                        }
+
+                        len = format[3];
+                        if (len & 7 || len < 16) {
+                                info(udev, "invalid format capacities length\n");
+                                return -1;
+                        }
+
+                        switch(format[8] & 3) {
+                            case 1:
+                                info(udev, "unformatted DVD-RAM media inserted\n");
+                                /* This means that last format was interrupted
+                                 * or failed, blank dvd-ram discs are factory
+                                 * formatted. Take no action here as it takes
+                                 * quite a while to reformat a dvd-ram and it's
+                                 * not automatically started */
+                                goto determined;
+
+                            case 2:
+                                info(udev, "formatted DVD-RAM media inserted\n");
+                                break;
+
+                            case 3:
+                                cd_media = 0; //return no media
+                                info(udev, "format capacities returned no media\n");
+                                return -1;
+                        }
+                }
+
+                /* Take a closer look at formatted media (unformatted DVD+RW
+                 * has "blank" status", DVD-RAM was examined earlier) and check
+                 * for ISO and UDF PVDs or a fs superblock presence and do it
+                 * in one ioctl (we need just sectors 0 and 16) */
+                scsi_cmd_init(udev, &sc);
+                scsi_cmd_set(udev, &sc, 0, 0x28);
+                scsi_cmd_set(udev, &sc, 5, 0);
+                scsi_cmd_set(udev, &sc, 8, 32);
+                scsi_cmd_set(udev, &sc, 9, 0);
+                err = scsi_cmd_run(udev, &sc, fd, buffer, sizeof(buffer));
+                if ((err != 0)) {
+                        cd_media = 0;
+                        info_scsi_cmd_err(udev, "READ FIRST 32 BLOCKS", err);
+                        return -1;
+                }
+
+                /* if any non-zero data is found in sector 16 (iso and udf) or
+                 * eventually 0 (fat32 boot sector, ext2 superblock, etc), disc
+                 * is assumed non-blank */
+                result = 0;
+
+                for (block = 32768; block >= 0 && !result; block -= 32768) {
+                        offset = block;
+                        while (offset < (block + 2048) && !result) {
+                                result = buffer [offset];
+                                offset++;
+                        }
+                }
+
+                if (!result) {
+                        cd_media_state = media_status[0];
+                        info(udev, "no data in blocks 0 or 16, assuming blank\n");
+                } else {
+                        info(udev, "data in blocks 0 or 16, assuming complete\n");
+                }
+        }
 
 determined:
-       /* "other" is e. g. DVD-RAM, can't append sessions there; DVDs in
-        * restricted overwrite mode can never append, only in sequential mode */
-       if ((header[2] & 3) < 2 && !cd_media_dvd_rw_ro)
-               cd_media_session_next = header[10] << 8 | header[5];
-       cd_media_session_count = header[9] << 8 | header[4];
-       cd_media_track_count = header[11] << 8 | header[6];
-
-       return 0;
+        /* "other" is e. g. DVD-RAM, can't append sessions there; DVDs in
+         * restricted overwrite mode can never append, only in sequential mode */
+        if ((header[2] & 3) < 2 && !cd_media_dvd_rw_ro)
+                cd_media_session_next = header[10] << 8 | header[5];
+        cd_media_session_count = header[9] << 8 | header[4];
+        cd_media_track_count = header[11] << 8 | header[6];
+
+        return 0;
 }
 
 static int cd_media_toc(struct udev *udev, int fd)
 {
-       struct scsi_cmd sc;
-       unsigned char header[12];
-       unsigned char toc[65536];
-       unsigned int len, i, num_tracks;
-       unsigned char *p;
-       int err;
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x43);
-       scsi_cmd_set(udev, &sc, 6, 1);
-       scsi_cmd_set(udev, &sc, 8, sizeof(header) & 0xff);
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "READ TOC", err);
-               return -1;
-       }
-
-       len = (header[0] << 8 | header[1]) + 2;
-       info(udev, "READ TOC: len: %d, start track: %d, end track: %d\n", len, header[2], header[3]);
-       if (len > sizeof(toc))
-               return -1;
-       if (len < 2)
-               return -1;
-       /* 2: first track, 3: last track */
-       num_tracks = header[3] - header[2] + 1;
-
-       /* empty media has no tracks */
-       if (len < 8)
-               return 0;
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x43);
-       scsi_cmd_set(udev, &sc, 6, header[2]); /* First Track/Session Number */
-       scsi_cmd_set(udev, &sc, 7, (len >> 8) & 0xff);
-       scsi_cmd_set(udev, &sc, 8, len & 0xff);
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, toc, len);
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "READ TOC (tracks)", err);
-               return -1;
-       }
-
-       /* Take care to not iterate beyond the last valid track as specified in
-        * the TOC, but also avoid going beyond the TOC length, just in case
-        * the last track number is invalidly large */
-       for (p = toc+4, i = 4; i < len-8 && num_tracks > 0; i += 8, p += 8, --num_tracks) {
-               unsigned int block;
-               unsigned int is_data_track;
-
-               is_data_track = (p[1] & 0x04) != 0;
-
-               block = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
-               info(udev, "track=%u info=0x%x(%s) start_block=%u\n",
-                    p[2], p[1] & 0x0f, is_data_track ? "data":"audio", block);
-
-               if (is_data_track)
-                       cd_media_track_count_data++;
-               else
-                       cd_media_track_count_audio++;
-       }
-
-       scsi_cmd_init(udev, &sc);
-       scsi_cmd_set(udev, &sc, 0, 0x43);
-       scsi_cmd_set(udev, &sc, 2, 1); /* Session Info */
-       scsi_cmd_set(udev, &sc, 8, sizeof(header));
-       scsi_cmd_set(udev, &sc, 9, 0);
-       err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
-       if ((err != 0)) {
-               info_scsi_cmd_err(udev, "READ TOC (multi session)", err);
-               return -1;
-       }
-       len = header[4+4] << 24 | header[4+5] << 16 | header[4+6] << 8 | header[4+7];
-       info(udev, "last track %u starts at block %u\n", header[4+2], len);
-       cd_media_session_last_offset = (unsigned long long int)len * 2048;
-       return 0;
+        struct scsi_cmd sc;
+        unsigned char header[12];
+        unsigned char toc[65536];
+        unsigned int len, i, num_tracks;
+        unsigned char *p;
+        int err;
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x43);
+        scsi_cmd_set(udev, &sc, 6, 1);
+        scsi_cmd_set(udev, &sc, 8, sizeof(header) & 0xff);
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "READ TOC", err);
+                return -1;
+        }
+
+        len = (header[0] << 8 | header[1]) + 2;
+        info(udev, "READ TOC: len: %d, start track: %d, end track: %d\n", len, header[2], header[3]);
+        if (len > sizeof(toc))
+                return -1;
+        if (len < 2)
+                return -1;
+        /* 2: first track, 3: last track */
+        num_tracks = header[3] - header[2] + 1;
+
+        /* empty media has no tracks */
+        if (len < 8)
+                return 0;
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x43);
+        scsi_cmd_set(udev, &sc, 6, header[2]); /* First Track/Session Number */
+        scsi_cmd_set(udev, &sc, 7, (len >> 8) & 0xff);
+        scsi_cmd_set(udev, &sc, 8, len & 0xff);
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, toc, len);
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "READ TOC (tracks)", err);
+                return -1;
+        }
+
+        /* Take care to not iterate beyond the last valid track as specified in
+         * the TOC, but also avoid going beyond the TOC length, just in case
+         * the last track number is invalidly large */
+        for (p = toc+4, i = 4; i < len-8 && num_tracks > 0; i += 8, p += 8, --num_tracks) {
+                unsigned int block;
+                unsigned int is_data_track;
+
+                is_data_track = (p[1] & 0x04) != 0;
+
+                block = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
+                info(udev, "track=%u info=0x%x(%s) start_block=%u\n",
+                     p[2], p[1] & 0x0f, is_data_track ? "data":"audio", block);
+
+                if (is_data_track)
+                        cd_media_track_count_data++;
+                else
+                        cd_media_track_count_audio++;
+        }
+
+        scsi_cmd_init(udev, &sc);
+        scsi_cmd_set(udev, &sc, 0, 0x43);
+        scsi_cmd_set(udev, &sc, 2, 1); /* Session Info */
+        scsi_cmd_set(udev, &sc, 8, sizeof(header));
+        scsi_cmd_set(udev, &sc, 9, 0);
+        err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
+        if ((err != 0)) {
+                info_scsi_cmd_err(udev, "READ TOC (multi session)", err);
+                return -1;
+        }
+        len = header[4+4] << 24 | header[4+5] << 16 | header[4+6] << 8 | header[4+7];
+        info(udev, "last track %u starts at block %u\n", header[4+2], len);
+        cd_media_session_last_offset = (unsigned long long int)len * 2048;
+        return 0;
 }
 
 int main(int argc, char *argv[])
 {
-       struct udev *udev;
-       static const struct option options[] = {
-               { "lock-media", no_argument, NULL, 'l' },
-               { "unlock-media", no_argument, NULL, 'u' },
-               { "eject-media", no_argument, NULL, 'e' },
-               { "debug", no_argument, NULL, 'd' },
-               { "help", no_argument, NULL, 'h' },
-               {}
-       };
-       bool eject = false;
-       bool lock = false;
-       bool unlock = false;
-       const char *node = NULL;
-       int fd = -1;
-       int cnt;
-       int rc = 0;
-
-       udev = udev_new();
-       if (udev == NULL)
-               goto exit;
-
-       udev_log_init("cdrom_id");
-       udev_set_log_fn(udev, log_fn);
-
-       while (1) {
-               int option;
-
-               option = getopt_long(argc, argv, "deluh", options, NULL);
-               if (option == -1)
-                       break;
-
-               switch (option) {
-               case 'l':
-                       lock = true;
-                       break;
-               case 'u':
-                       unlock = true;
-                       break;
-               case 'e':
-                       eject = true;
-                       break;
-               case 'd':
-                       debug = true;
-                       if (udev_get_log_priority(udev) < LOG_INFO)
-                               udev_set_log_priority(udev, LOG_INFO);
-                       break;
-               case 'h':
-                       printf("Usage: cdrom_id [options] <device>\n"
-                              "  --lock-media    lock the media (to enable eject request events)\n"
-                              "  --unlock-media  unlock the media\n"
-                              "  --eject-media   eject the media\n"
-                              "  --debug         debug to stderr\n"
-                              "  --help          print this help text\n\n");
-                       goto exit;
-               default:
-                       rc = 1;
-                       goto exit;
-               }
-       }
-
-       node = argv[optind];
-       if (!node) {
-               err(udev, "no device\n");
-               fprintf(stderr, "no device\n");
-               rc = 1;
-               goto exit;
-       }
-
-       srand((unsigned int)getpid());
-       for (cnt = 20; cnt > 0; cnt--) {
-               struct timespec duration;
-
-               fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL));
-               if (fd >= 0 || errno != EBUSY)
-                       break;
-               duration.tv_sec = 0;
-               duration.tv_nsec = (100 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
-               nanosleep(&duration, NULL);
-       }
-       if (fd < 0) {
-               info(udev, "unable to open '%s'\n", node);
-               fprintf(stderr, "unable to open '%s'\n", node);
-               rc = 1;
-               goto exit;
-       }
-       info(udev, "probing: '%s'\n", node);
-
-       /* same data as original cdrom_id */
-       if (cd_capability_compat(udev, fd) < 0) {
-               rc = 1;
-               goto exit;
-       }
-
-       /* check for media - don't bail if there's no media as we still need to
+        struct udev *udev;
+        static const struct option options[] = {
+                { "lock-media", no_argument, NULL, 'l' },
+                { "unlock-media", no_argument, NULL, 'u' },
+                { "eject-media", no_argument, NULL, 'e' },
+                { "debug", no_argument, NULL, 'd' },
+                { "help", no_argument, NULL, 'h' },
+                {}
+        };
+        bool eject = false;
+        bool lock = false;
+        bool unlock = false;
+        const char *node = NULL;
+        int fd = -1;
+        int cnt;
+        int rc = 0;
+
+        udev = udev_new();
+        if (udev == NULL)
+                goto exit;
+
+        udev_log_init("cdrom_id");
+        udev_set_log_fn(udev, log_fn);
+
+        while (1) {
+                int option;
+
+                option = getopt_long(argc, argv, "deluh", options, NULL);
+                if (option == -1)
+                        break;
+
+                switch (option) {
+                case 'l':
+                        lock = true;
+                        break;
+                case 'u':
+                        unlock = true;
+                        break;
+                case 'e':
+                        eject = true;
+                        break;
+                case 'd':
+                        debug = true;
+                        if (udev_get_log_priority(udev) < LOG_INFO)
+                                udev_set_log_priority(udev, LOG_INFO);
+                        break;
+                case 'h':
+                        printf("Usage: cdrom_id [options] <device>\n"
+                               "  --lock-media    lock the media (to enable eject request events)\n"
+                               "  --unlock-media  unlock the media\n"
+                               "  --eject-media   eject the media\n"
+                               "  --debug         debug to stderr\n"
+                               "  --help          print this help text\n\n");
+                        goto exit;
+                default:
+                        rc = 1;
+                        goto exit;
+                }
+        }
+
+        node = argv[optind];
+        if (!node) {
+                err(udev, "no device\n");
+                fprintf(stderr, "no device\n");
+                rc = 1;
+                goto exit;
+        }
+
+        srand((unsigned int)getpid());
+        for (cnt = 20; cnt > 0; cnt--) {
+                struct timespec duration;
+
+                fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL));
+                if (fd >= 0 || errno != EBUSY)
+                        break;
+                duration.tv_sec = 0;
+                duration.tv_nsec = (100 * 1000 * 1000) + (rand() % 100 * 1000 * 1000);
+                nanosleep(&duration, NULL);
+        }
+        if (fd < 0) {
+                info(udev, "unable to open '%s'\n", node);
+                fprintf(stderr, "unable to open '%s'\n", node);
+                rc = 1;
+                goto exit;
+        }
+        info(udev, "probing: '%s'\n", node);
+
+        /* same data as original cdrom_id */
+        if (cd_capability_compat(udev, fd) < 0) {
+                rc = 1;
+                goto exit;
+        }
+
+        /* check for media - don't bail if there's no media as we still need to
          * to read profiles */
-       cd_media_compat(udev, fd);
+        cd_media_compat(udev, fd);
 
-       /* check if drive talks MMC */
-       if (cd_inquiry(udev, fd) < 0)
-               goto work;
+        /* check if drive talks MMC */
+        if (cd_inquiry(udev, fd) < 0)
+                goto work;
 
-       /* read drive and possibly current profile */
-       if (cd_profiles(udev, fd) != 0)
-               goto work;
+        /* read drive and possibly current profile */
+        if (cd_profiles(udev, fd) != 0)
+                goto work;
 
-       /* at this point we are guaranteed to have media in the drive - find out more about it */
+        /* at this point we are guaranteed to have media in the drive - find out more about it */
 
-       /* get session/track info */
-       cd_media_toc(udev, fd);
+        /* get session/track info */
+        cd_media_toc(udev, fd);
 
-       /* get writable media state */
-       cd_media_info(udev, fd);
+        /* get writable media state */
+        cd_media_info(udev, fd);
 
 work:
-       /* lock the media, so we enable eject button events */
-       if (lock && cd_media) {
-               info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (lock)\n");
-               media_lock(udev, fd, true);
-       }
-
-       if (unlock && cd_media) {
-               info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
-               media_lock(udev, fd, false);
-       }
-
-       if (eject) {
-               info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
-               media_lock(udev, fd, false);
-               info(udev, "START_STOP_UNIT (eject)\n");
-               media_eject(udev, fd);
-       }
-
-       printf("ID_CDROM=1\n");
-       if (cd_cd_rom)
-               printf("ID_CDROM_CD=1\n");
-       if (cd_cd_r)
-               printf("ID_CDROM_CD_R=1\n");
-       if (cd_cd_rw)
-               printf("ID_CDROM_CD_RW=1\n");
-       if (cd_dvd_rom)
-               printf("ID_CDROM_DVD=1\n");
-       if (cd_dvd_r)
-               printf("ID_CDROM_DVD_R=1\n");
-       if (cd_dvd_rw)
-               printf("ID_CDROM_DVD_RW=1\n");
-       if (cd_dvd_ram)
-               printf("ID_CDROM_DVD_RAM=1\n");
-       if (cd_dvd_plus_r)
-               printf("ID_CDROM_DVD_PLUS_R=1\n");
-       if (cd_dvd_plus_rw)
-               printf("ID_CDROM_DVD_PLUS_RW=1\n");
-       if (cd_dvd_plus_r_dl)
-               printf("ID_CDROM_DVD_PLUS_R_DL=1\n");
-       if (cd_dvd_plus_rw_dl)
-               printf("ID_CDROM_DVD_PLUS_RW_DL=1\n");
-       if (cd_bd)
-               printf("ID_CDROM_BD=1\n");
-       if (cd_bd_r)
-               printf("ID_CDROM_BD_R=1\n");
-       if (cd_bd_re)
-               printf("ID_CDROM_BD_RE=1\n");
-       if (cd_hddvd)
-               printf("ID_CDROM_HDDVD=1\n");
-       if (cd_hddvd_r)
-               printf("ID_CDROM_HDDVD_R=1\n");
-       if (cd_hddvd_rw)
-               printf("ID_CDROM_HDDVD_RW=1\n");
-       if (cd_mo)
-               printf("ID_CDROM_MO=1\n");
-       if (cd_mrw)
-               printf("ID_CDROM_MRW=1\n");
-       if (cd_mrw_w)
-               printf("ID_CDROM_MRW_W=1\n");
-
-       if (cd_media)
-               printf("ID_CDROM_MEDIA=1\n");
-       if (cd_media_mo)
-               printf("ID_CDROM_MEDIA_MO=1\n");
-       if (cd_media_mrw)
-               printf("ID_CDROM_MEDIA_MRW=1\n");
-       if (cd_media_mrw_w)
-               printf("ID_CDROM_MEDIA_MRW_W=1\n");
-       if (cd_media_cd_rom)
-               printf("ID_CDROM_MEDIA_CD=1\n");
-       if (cd_media_cd_r)
-               printf("ID_CDROM_MEDIA_CD_R=1\n");
-       if (cd_media_cd_rw)
-               printf("ID_CDROM_MEDIA_CD_RW=1\n");
-       if (cd_media_dvd_rom)
-               printf("ID_CDROM_MEDIA_DVD=1\n");
-       if (cd_media_dvd_r)
-               printf("ID_CDROM_MEDIA_DVD_R=1\n");
-       if (cd_media_dvd_ram)
-               printf("ID_CDROM_MEDIA_DVD_RAM=1\n");
-       if (cd_media_dvd_rw)
-               printf("ID_CDROM_MEDIA_DVD_RW=1\n");
-       if (cd_media_dvd_plus_r)
-               printf("ID_CDROM_MEDIA_DVD_PLUS_R=1\n");
-       if (cd_media_dvd_plus_rw)
-               printf("ID_CDROM_MEDIA_DVD_PLUS_RW=1\n");
-       if (cd_media_dvd_plus_rw_dl)
-               printf("ID_CDROM_MEDIA_DVD_PLUS_RW_DL=1\n");
-       if (cd_media_dvd_plus_r_dl)
-               printf("ID_CDROM_MEDIA_DVD_PLUS_R_DL=1\n");
-       if (cd_media_bd)
-               printf("ID_CDROM_MEDIA_BD=1\n");
-       if (cd_media_bd_r)
-               printf("ID_CDROM_MEDIA_BD_R=1\n");
-       if (cd_media_bd_re)
-               printf("ID_CDROM_MEDIA_BD_RE=1\n");
-       if (cd_media_hddvd)
-               printf("ID_CDROM_MEDIA_HDDVD=1\n");
-       if (cd_media_hddvd_r)
-               printf("ID_CDROM_MEDIA_HDDVD_R=1\n");
-       if (cd_media_hddvd_rw)
-               printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
-
-       if (cd_media_state != NULL)
-               printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
-       if (cd_media_session_next > 0)
-               printf("ID_CDROM_MEDIA_SESSION_NEXT=%d\n", cd_media_session_next);
-       if (cd_media_session_count > 0)
-               printf("ID_CDROM_MEDIA_SESSION_COUNT=%d\n", cd_media_session_count);
-       if (cd_media_session_count > 1 && cd_media_session_last_offset > 0)
-               printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset);
-       if (cd_media_track_count > 0)
-               printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count);
-       if (cd_media_track_count_audio > 0)
-               printf("ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=%d\n", cd_media_track_count_audio);
-       if (cd_media_track_count_data > 0)
-               printf("ID_CDROM_MEDIA_TRACK_COUNT_DATA=%d\n", cd_media_track_count_data);
+        /* lock the media, so we enable eject button events */
+        if (lock && cd_media) {
+                info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (lock)\n");
+                media_lock(udev, fd, true);
+        }
+
+        if (unlock && cd_media) {
+                info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
+                media_lock(udev, fd, false);
+        }
+
+        if (eject) {
+                info(udev, "PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)\n");
+                media_lock(udev, fd, false);
+                info(udev, "START_STOP_UNIT (eject)\n");
+                media_eject(udev, fd);
+        }
+
+        printf("ID_CDROM=1\n");
+        if (cd_cd_rom)
+                printf("ID_CDROM_CD=1\n");
+        if (cd_cd_r)
+                printf("ID_CDROM_CD_R=1\n");
+        if (cd_cd_rw)
+                printf("ID_CDROM_CD_RW=1\n");
+        if (cd_dvd_rom)
+                printf("ID_CDROM_DVD=1\n");
+        if (cd_dvd_r)
+                printf("ID_CDROM_DVD_R=1\n");
+        if (cd_dvd_rw)
+                printf("ID_CDROM_DVD_RW=1\n");
+        if (cd_dvd_ram)
+                printf("ID_CDROM_DVD_RAM=1\n");
+        if (cd_dvd_plus_r)
+                printf("ID_CDROM_DVD_PLUS_R=1\n");
+        if (cd_dvd_plus_rw)
+                printf("ID_CDROM_DVD_PLUS_RW=1\n");
+        if (cd_dvd_plus_r_dl)
+                printf("ID_CDROM_DVD_PLUS_R_DL=1\n");
+        if (cd_dvd_plus_rw_dl)
+                printf("ID_CDROM_DVD_PLUS_RW_DL=1\n");
+        if (cd_bd)
+                printf("ID_CDROM_BD=1\n");
+        if (cd_bd_r)
+                printf("ID_CDROM_BD_R=1\n");
+        if (cd_bd_re)
+                printf("ID_CDROM_BD_RE=1\n");
+        if (cd_hddvd)
+                printf("ID_CDROM_HDDVD=1\n");
+        if (cd_hddvd_r)
+                printf("ID_CDROM_HDDVD_R=1\n");
+        if (cd_hddvd_rw)
+                printf("ID_CDROM_HDDVD_RW=1\n");
+        if (cd_mo)
+                printf("ID_CDROM_MO=1\n");
+        if (cd_mrw)
+                printf("ID_CDROM_MRW=1\n");
+        if (cd_mrw_w)
+                printf("ID_CDROM_MRW_W=1\n");
+
+        if (cd_media)
+                printf("ID_CDROM_MEDIA=1\n");
+        if (cd_media_mo)
+                printf("ID_CDROM_MEDIA_MO=1\n");
+        if (cd_media_mrw)
+                printf("ID_CDROM_MEDIA_MRW=1\n");
+        if (cd_media_mrw_w)
+                printf("ID_CDROM_MEDIA_MRW_W=1\n");
+        if (cd_media_cd_rom)
+                printf("ID_CDROM_MEDIA_CD=1\n");
+        if (cd_media_cd_r)
+                printf("ID_CDROM_MEDIA_CD_R=1\n");
+        if (cd_media_cd_rw)
+                printf("ID_CDROM_MEDIA_CD_RW=1\n");
+        if (cd_media_dvd_rom)
+                printf("ID_CDROM_MEDIA_DVD=1\n");
+        if (cd_media_dvd_r)
+                printf("ID_CDROM_MEDIA_DVD_R=1\n");
+        if (cd_media_dvd_ram)
+                printf("ID_CDROM_MEDIA_DVD_RAM=1\n");
+        if (cd_media_dvd_rw)
+                printf("ID_CDROM_MEDIA_DVD_RW=1\n");
+        if (cd_media_dvd_plus_r)
+                printf("ID_CDROM_MEDIA_DVD_PLUS_R=1\n");
+        if (cd_media_dvd_plus_rw)
+                printf("ID_CDROM_MEDIA_DVD_PLUS_RW=1\n");
+        if (cd_media_dvd_plus_rw_dl)
+                printf("ID_CDROM_MEDIA_DVD_PLUS_RW_DL=1\n");
+        if (cd_media_dvd_plus_r_dl)
+                printf("ID_CDROM_MEDIA_DVD_PLUS_R_DL=1\n");
+        if (cd_media_bd)
+                printf("ID_CDROM_MEDIA_BD=1\n");
+        if (cd_media_bd_r)
+                printf("ID_CDROM_MEDIA_BD_R=1\n");
+        if (cd_media_bd_re)
+                printf("ID_CDROM_MEDIA_BD_RE=1\n");
+        if (cd_media_hddvd)
+                printf("ID_CDROM_MEDIA_HDDVD=1\n");
+        if (cd_media_hddvd_r)
+                printf("ID_CDROM_MEDIA_HDDVD_R=1\n");
+        if (cd_media_hddvd_rw)
+                printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
+
+        if (cd_media_state != NULL)
+                printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
+        if (cd_media_session_next > 0)
+                printf("ID_CDROM_MEDIA_SESSION_NEXT=%d\n", cd_media_session_next);
+        if (cd_media_session_count > 0)
+                printf("ID_CDROM_MEDIA_SESSION_COUNT=%d\n", cd_media_session_count);
+        if (cd_media_session_count > 1 && cd_media_session_last_offset > 0)
+                printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset);
+        if (cd_media_track_count > 0)
+                printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count);
+        if (cd_media_track_count_audio > 0)
+                printf("ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=%d\n", cd_media_track_count_audio);
+        if (cd_media_track_count_data > 0)
+                printf("ID_CDROM_MEDIA_TRACK_COUNT_DATA=%d\n", cd_media_track_count_data);
 exit:
-       if (fd >= 0)
-               close(fd);
-       udev_unref(udev);
-       udev_log_close();
-       return rc;
+        if (fd >= 0)
+                close(fd);
+        udev_unref(udev);
+        udev_log_close();
+        return rc;
 }
index f78f3b7..076fe47 100644 (file)
 #include "libudev.h"
 #include "libudev-private.h"
 
-#define BUFSIZE                        16
-#define UDEV_ALARM_TIMEOUT     180
+#define BUFSIZE                        16
+#define UDEV_ALARM_TIMEOUT        180
 
 enum collect_state {
-       STATE_NONE,
-       STATE_OLD,
-       STATE_CONFIRMED,
+        STATE_NONE,
+        STATE_OLD,
+        STATE_CONFIRMED,
 };
 
 struct _mate {
-       struct udev_list_node node;
-       char *name;
-       enum collect_state state;
+        struct udev_list_node node;
+        char *name;
+        enum collect_state state;
 };
 
 static struct udev_list_node bunch;
@@ -57,29 +57,29 @@ static size_t bufsize = BUFSIZE;
 
 static struct _mate *node_to_mate(struct udev_list_node *node)
 {
-       char *mate;
+        char *mate;
 
-       mate = (char *)node;
-       mate -= offsetof(struct _mate, node);
-       return (struct _mate *)mate;
+        mate = (char *)node;
+        mate -= offsetof(struct _mate, node);
+        return (struct _mate *)mate;
 }
 
 static void sig_alrm(int signo)
 {
-       exit(4);
+        exit(4);
 }
 
 static void usage(void)
 {
-       printf("usage: collect [--add|--remove] [--debug] <checkpoint> <id> <idlist>\n"
-              "\n"
-              "  Adds ID <id> to the list governed by <checkpoint>.\n"
-              "  <id> must be part of the list <idlist>.\n"
-              "  If all IDs given by <idlist> are listed (ie collect has been\n"
-              "  invoked for each ID in <idlist>) collect returns 0, the\n"
-              "  number of missing IDs otherwise.\n"
-              "  On error a negative number is returned.\n"
-              "\n");
+        printf("usage: collect [--add|--remove] [--debug] <checkpoint> <id> <idlist>\n"
+               "\n"
+               "  Adds ID <id> to the list governed by <checkpoint>.\n"
+               "  <id> must be part of the list <idlist>.\n"
+               "  If all IDs given by <idlist> are listed (ie collect has been\n"
+               "  invoked for each ID in <idlist>) collect returns 0, the\n"
+               "  number of missing IDs otherwise.\n"
+               "  On error a negative number is returned.\n"
+               "\n");
 }
 
 /*
@@ -89,34 +89,34 @@ static void usage(void)
  */
 static int prepare(char *dir, char *filename)
 {
-       struct stat statbuf;
-       char buf[512];
-       int fd;
-
-       if (stat(dir, &statbuf) < 0)
-               mkdir(dir, 0700);
-
-       sprintf(buf, "%s/%s", dir, filename);
-
-       fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
-       if (fd < 0)
-               fprintf(stderr, "Cannot open %s: %s\n", buf, strerror(errno));
-
-       if (lockf(fd,F_TLOCK,0) < 0) {
-               if (debug)
-                       fprintf(stderr, "Lock taken, wait for %d seconds\n", UDEV_ALARM_TIMEOUT);
-               if (errno == EAGAIN || errno == EACCES) {
-                       alarm(UDEV_ALARM_TIMEOUT);
-                       lockf(fd, F_LOCK, 0);
-                       if (debug)
-                               fprintf(stderr, "Acquired lock on %s\n", buf);
-               } else {
-                       if (debug)
-                               fprintf(stderr, "Could not get lock on %s: %s\n", buf, strerror(errno));
-               }
-       }
-
-       return fd;
+        struct stat statbuf;
+        char buf[512];
+        int fd;
+
+        if (stat(dir, &statbuf) < 0)
+                mkdir(dir, 0700);
+
+        sprintf(buf, "%s/%s", dir, filename);
+
+        fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+        if (fd < 0)
+                fprintf(stderr, "Cannot open %s: %s\n", buf, strerror(errno));
+
+        if (lockf(fd,F_TLOCK,0) < 0) {
+                if (debug)
+                        fprintf(stderr, "Lock taken, wait for %d seconds\n", UDEV_ALARM_TIMEOUT);
+                if (errno == EAGAIN || errno == EACCES) {
+                        alarm(UDEV_ALARM_TIMEOUT);
+                        lockf(fd, F_LOCK, 0);
+                        if (debug)
+                                fprintf(stderr, "Acquired lock on %s\n", buf);
+                } else {
+                        if (debug)
+                                fprintf(stderr, "Could not get lock on %s: %s\n", buf, strerror(errno));
+                }
+        }
+
+        return fd;
 }
 
 /*
@@ -136,58 +136,58 @@ static int prepare(char *dir, char *filename)
  */
 static int checkout(int fd)
 {
-       int len;
-       char *buf, *ptr, *word = NULL;
-       struct _mate *him;
+        int len;
+        char *buf, *ptr, *word = NULL;
+        struct _mate *him;
 
  restart:
-       len = bufsize >> 1;
-       buf = calloc(1,bufsize + 1);
-       if (!buf) {
-               fprintf(stderr, "Out of memory\n");
-               return -1;
-       }
-       memset(buf, ' ', bufsize);
-       ptr = buf + len;
-       while ((read(fd, buf + len, len)) > 0) {
-               while (ptr && *ptr) {
-                       word = ptr;
-                       ptr = strpbrk(word," \n\t\r");
-                       if (!ptr && word < (buf + len)) {
-                               bufsize = bufsize << 1;
-                               if (debug)
-                                       fprintf(stderr, "ID overflow, restarting with size %zi\n", bufsize);
-                               free(buf);
-                               lseek(fd, 0, SEEK_SET);
-                               goto restart;
-                       }
-                       if (ptr) {
-                               *ptr = '\0';
-                               ptr++;
-                               if (!strlen(word))
-                                       continue;
-
-                               if (debug)
-                                       fprintf(stderr, "Found word %s\n", word);
-                               him = malloc(sizeof (struct _mate));
-                               him->name = strdup(word);
-                               him->state = STATE_OLD;
-                               udev_list_node_append(&him->node, &bunch);
-                               word = NULL;
-                       }
-               }
-               memcpy(buf, buf + len, len);
-               memset(buf + len, ' ', len);
-
-               if (!ptr)
-                       ptr = word;
-               if (!ptr)
-                       break;
-               ptr -= len;
-       }
-
-       free(buf);
-       return 0;
+        len = bufsize >> 1;
+        buf = calloc(1,bufsize + 1);
+        if (!buf) {
+                fprintf(stderr, "Out of memory\n");
+                return -1;
+        }
+        memset(buf, ' ', bufsize);
+        ptr = buf + len;
+        while ((read(fd, buf + len, len)) > 0) {
+                while (ptr && *ptr) {
+                        word = ptr;
+                        ptr = strpbrk(word," \n\t\r");
+                        if (!ptr && word < (buf + len)) {
+                                bufsize = bufsize << 1;
+                                if (debug)
+                                        fprintf(stderr, "ID overflow, restarting with size %zi\n", bufsize);
+                                free(buf);
+                                lseek(fd, 0, SEEK_SET);
+                                goto restart;
+                        }
+                        if (ptr) {
+                                *ptr = '\0';
+                                ptr++;
+                                if (!strlen(word))
+                                        continue;
+
+                                if (debug)
+                                        fprintf(stderr, "Found word %s\n", word);
+                                him = malloc(sizeof (struct _mate));
+                                him->name = strdup(word);
+                                him->state = STATE_OLD;
+                                udev_list_node_append(&him->node, &bunch);
+                                word = NULL;
+                        }
+                }
+                memcpy(buf, buf + len, len);
+                memset(buf + len, ' ', len);
+
+                if (!ptr)
+                        ptr = word;
+                if (!ptr)
+                        break;
+                ptr -= len;
+        }
+
+        free(buf);
+        return 0;
 }
 
 /*
@@ -198,22 +198,22 @@ static int checkout(int fd)
  */
 static void invite(char *us)
 {
-       struct udev_list_node *him_node;
-       struct _mate *who = NULL;
+        struct udev_list_node *him_node;
+        struct _mate *who = NULL;
 
-       if (debug)
-               fprintf(stderr, "Adding ID '%s'\n", us);
+        if (debug)
+                fprintf(stderr, "Adding ID '%s'\n", us);
 
-       udev_list_node_foreach(him_node, &bunch) {
-               struct _mate *him = node_to_mate(him_node);
+        udev_list_node_foreach(him_node, &bunch) {
+                struct _mate *him = node_to_mate(him_node);
 
-               if (!strcmp(him->name, us)) {
-                       him->state = STATE_CONFIRMED;
-                       who = him;
-               }
-       }
-       if (debug && !who)
-               fprintf(stderr, "ID '%s' not in database\n", us);
+                if (!strcmp(him->name, us)) {
+                        him->state = STATE_CONFIRMED;
+                        who = him;
+                }
+        }
+        if (debug && !who)
+                fprintf(stderr, "ID '%s' not in database\n", us);
 
 }
 
@@ -226,22 +226,22 @@ static void invite(char *us)
  */
 static void reject(char *us)
 {
-       struct udev_list_node *him_node;
-       struct _mate *who = NULL;
-
-       if (debug)
-               fprintf(stderr, "Removing ID '%s'\n", us);
-
-       udev_list_node_foreach(him_node, &bunch) {
-               struct _mate *him = node_to_mate(him_node);
-
-               if (!strcmp(him->name, us)) {
-                       him->state = STATE_NONE;
-                       who = him;
-               }
-       }
-       if (debug && !who)
-               fprintf(stderr, "ID '%s' not in database\n", us);
+        struct udev_list_node *him_node;
+        struct _mate *who = NULL;
+
+        if (debug)
+                fprintf(stderr, "Removing ID '%s'\n", us);
+
+        udev_list_node_foreach(him_node, &bunch) {
+                struct _mate *him = node_to_mate(him_node);
+
+                if (!strcmp(him->name, us)) {
+                        him->state = STATE_NONE;
+                        who = him;
+                }
+        }
+        if (debug && !who)
+                fprintf(stderr, "ID '%s' not in database\n", us);
 }
 
 /*
@@ -252,18 +252,18 @@ static void reject(char *us)
  */
 static void kickout(void)
 {
-       struct udev_list_node *him_node;
-       struct udev_list_node *tmp;
-
-       udev_list_node_foreach_safe(him_node, tmp, &bunch) {
-               struct _mate *him = node_to_mate(him_node);
-
-               if (him->state == STATE_OLD) {
-                       udev_list_node_remove(&him->node);
-                       free(him->name);
-                       free(him);
-               }
-       }
+        struct udev_list_node *him_node;
+        struct udev_list_node *tmp;
+
+        udev_list_node_foreach_safe(him_node, tmp, &bunch) {
+                struct _mate *him = node_to_mate(him_node);
+
+                if (him->state == STATE_OLD) {
+                        udev_list_node_remove(&him->node);
+                        free(him->name);
+                        free(him);
+                }
+        }
 }
 
 /*
@@ -273,38 +273,38 @@ static void kickout(void)
  */
 static int missing(int fd)
 {
-       char *buf;
-       int ret = 0;
-       struct udev_list_node *him_node;
-
-       buf = malloc(bufsize);
-       if (!buf)
-               return -1;
-
-       udev_list_node_foreach(him_node, &bunch) {
-               struct _mate *him = node_to_mate(him_node);
-
-               if (him->state == STATE_NONE) {
-                       ret++;
-               } else {
-                       while (strlen(him->name)+1 >= bufsize) {
-                               char *tmpbuf;
-
-                               bufsize = bufsize << 1;
-                               tmpbuf = realloc(buf, bufsize);
-                               if (!tmpbuf) {
-                                       free(buf);
-                                       return -1;
-                               }
-                               buf = tmpbuf;
-                       }
-                       snprintf(buf, strlen(him->name)+2, "%s ", him->name);
-                       write(fd, buf, strlen(buf));
-               }
-       }
-
-       free(buf);
-       return ret;
+        char *buf;
+        int ret = 0;
+        struct udev_list_node *him_node;
+
+        buf = malloc(bufsize);
+        if (!buf)
+                return -1;
+
+        udev_list_node_foreach(him_node, &bunch) {
+                struct _mate *him = node_to_mate(him_node);
+
+                if (him->state == STATE_NONE) {
+                        ret++;
+                } else {
+                        while (strlen(him->name)+1 >= bufsize) {
+                                char *tmpbuf;
+
+                                bufsize = bufsize << 1;
+                                tmpbuf = realloc(buf, bufsize);
+                                if (!tmpbuf) {
+                                        free(buf);
+                                        return -1;
+                                }
+                                buf = tmpbuf;
+                        }
+                        snprintf(buf, strlen(him->name)+2, "%s ", him->name);
+                        write(fd, buf, strlen(buf));
+                }
+        }
+
+        free(buf);
+        return ret;
 }
 
 /*
@@ -314,160 +314,160 @@ static int missing(int fd)
  */
 static void everybody(void)
 {
-       struct udev_list_node *him_node;
-       const char *state = "";
-
-       udev_list_node_foreach(him_node, &bunch) {
-               struct _mate *him = node_to_mate(him_node);
-
-               switch (him->state) {
-               case STATE_NONE:
-                       state = "none";
-                       break;
-               case STATE_OLD:
-                       state = "old";
-                       break;
-               case STATE_CONFIRMED:
-                       state = "confirmed";
-                       break;
-               }
-               fprintf(stderr, "ID: %s=%s\n", him->name, state);
-       }
+        struct udev_list_node *him_node;
+        const char *state = "";
+
+        udev_list_node_foreach(him_node, &bunch) {
+                struct _mate *him = node_to_mate(him_node);
+
+                switch (him->state) {
+                case STATE_NONE:
+                        state = "none";
+                        break;
+                case STATE_OLD:
+                        state = "old";
+                        break;
+                case STATE_CONFIRMED:
+                        state = "confirmed";
+                        break;
+                }
+                fprintf(stderr, "ID: %s=%s\n", him->name, state);
+        }
 }
 
 int main(int argc, char **argv)
 {
-       struct udev *udev;
-       static const struct option options[] = {
-               { "add", no_argument, NULL, 'a' },
-               { "remove", no_argument, NULL, 'r' },
-               { "debug", no_argument, NULL, 'd' },
-               { "help", no_argument, NULL, 'h' },
-               {}
-       };
-       int argi;
-       char *checkpoint, *us;
-       int fd;
-       int i;
-       int ret = EXIT_SUCCESS;
-       int prune = 0;
-       char tmpdir[UTIL_PATH_SIZE];
-
-       udev = udev_new();
-       if (udev == NULL) {
-               ret = EXIT_FAILURE;
-               goto exit;
-       }
-
-       while (1) {
-               int option;
-
-               option = getopt_long(argc, argv, "ardh", options, NULL);
-               if (option == -1)
-                       break;
-
-               switch (option) {
-               case 'a':
-                       prune = 0;
-                       break;
-               case 'r':
-                       prune = 1;
-                       break;
-               case 'd':
-                       debug = 1;
-                       break;
-               case 'h':
-                       usage();
-                       goto exit;
-               default:
-                       ret = 1;
-                       goto exit;
-               }
-       }
-
-       argi = optind;
-       if (argi + 2 > argc) {
-               printf("Missing parameter(s)\n");
-               ret = 1;
-               goto exit;
-       }
-       checkpoint = argv[argi++];
-       us = argv[argi++];
-
-       if (signal(SIGALRM, sig_alrm) == SIG_ERR) {
-               fprintf(stderr, "Cannot set SIGALRM: %s\n", strerror(errno));
-               ret = 2;
-               goto exit;
-       }
-
-       udev_list_node_init(&bunch);
-
-       if (debug)
-               fprintf(stderr, "Using checkpoint '%s'\n", checkpoint);
-
-       util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL);
-       fd = prepare(tmpdir, checkpoint);
-       if (fd < 0) {
-               ret = 3;
-               goto out;
-       }
-
-       if (checkout(fd) < 0) {
-               ret = 2;
-               goto out;
-       }
-
-       for (i = argi; i < argc; i++) {
-               struct udev_list_node *him_node;
-               struct _mate *who;
-
-               who = NULL;
-               udev_list_node_foreach(him_node, &bunch) {
-                       struct _mate *him = node_to_mate(him_node);
-
-                       if (!strcmp(him->name, argv[i]))
-                               who = him;
-               }
-               if (!who) {
-                       struct _mate *him;
-
-                       if (debug)
-                               fprintf(stderr, "ID %s: not in database\n", argv[i]);
-                       him = malloc(sizeof (struct _mate));
-                       him->name = malloc(strlen(argv[i]) + 1);
-                       strcpy(him->name, argv[i]);
-                       him->state = STATE_NONE;
-                       udev_list_node_append(&him->node, &bunch);
-               } else {
-                       if (debug)
-                               fprintf(stderr, "ID %s: found in database\n", argv[i]);
-                       who->state = STATE_CONFIRMED;
-               }
-       }
-
-       if (prune)
-               reject(us);
-       else
-               invite(us);
-
-       if (debug) {
-               everybody();
-               fprintf(stderr, "Prune lists\n");
-       }
-       kickout();
-
-       lseek(fd, 0, SEEK_SET);
-       ftruncate(fd, 0);
-       ret = missing(fd);
-
-       lockf(fd, F_ULOCK, 0);
-       close(fd);
+        struct udev *udev;
+        static const struct option options[] = {
+                { "add", no_argument, NULL, 'a' },
+                { "remove", no_argument, NULL, 'r' },
+                { "debug", no_argument, NULL, 'd' },
+                { "help", no_argument, NULL, 'h' },
+                {}
+        };
+        int argi;
+        char *checkpoint, *us;
+        int fd;
+        int i;
+        int ret = EXIT_SUCCESS;
+        int prune = 0;
+        char tmpdir[UTIL_PATH_SIZE];
+
+        udev = udev_new();
+        if (udev == NULL) {
+                ret = EXIT_FAILURE;
+                goto exit;
+        }
+
+        while (1) {
+                int option;
+
+                option = getopt_long(argc, argv, "ardh", options, NULL);
+                if (option == -1)
+                        break;
+
+                switch (option) {
+                case 'a':
+                        prune = 0;
+                        break;
+                case 'r':
+                        prune = 1;
+                        break;
+                case 'd':
+                        debug = 1;
+                        break;
+                case 'h':
+                        usage();
+                        goto exit;
+                default:
+                        ret = 1;
+                        goto exit;
+                }
+        }
+
+        argi = optind;
+        if (argi + 2 > argc) {
+                printf("Missing parameter(s)\n");
+                ret = 1;
+                goto exit;
+        }
+        checkpoint = argv[argi++];
+        us = argv[argi++];
+
+        if (signal(SIGALRM, sig_alrm) == SIG_ERR) {
+                fprintf(stderr, "Cannot set SIGALRM: %s\n", strerror(errno));
+                ret = 2;
+                goto exit;
+        }
+
+        udev_list_node_init(&bunch);
+
+        if (debug)
+                fprintf(stderr, "Using checkpoint '%s'\n", checkpoint);
+
+        util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL);
+        fd = prepare(tmpdir, checkpoint);
+        if (fd < 0) {
+                ret = 3;
+                goto out;
+        }
+
+        if (checkout(fd) < 0) {
+                ret = 2;
+                goto out;
+        }
+
+        for (i = argi; i < argc; i++) {
+                struct udev_list_node *him_node;
+                struct _mate *who;
+
+                who = NULL;
+                udev_list_node_foreach(him_node, &bunch) {
+                        struct _mate *him = node_to_mate(him_node);
+
+                        if (!strcmp(him->name, argv[i]))
+                                who = him;
+                }
+                if (!who) {
+                        struct _mate *him;
+
+                        if (debug)
+                                fprintf(stderr, "ID %s: not in database\n", argv[i]);
+                        him = malloc(sizeof (struct _mate));
+                        him->name = malloc(strlen(argv[i]) + 1);
+                        strcpy(him->name, argv[i]);
+                        him->state = STATE_NONE;
+                        udev_list_node_append(&him->node, &bunch);
+                } else {
+                        if (debug)
+                                fprintf(stderr, "ID %s: found in database\n", argv[i]);
+                        who->state = STATE_CONFIRMED;
+                }
+        }
+
+        if (prune)
+                reject(us);
+        else
+                invite(us);
+
+        if (debug) {
+                everybody();
+                fprintf(stderr, "Prune lists\n");
+        }
+        kickout();
+
+        lseek(fd, 0, SEEK_SET);
+        ftruncate(fd, 0);
+        ret = missing(fd);
+
+        lockf(fd, F_ULOCK, 0);
+        close(fd);
 out:
-       if (debug)
-               everybody();
-       if (ret >= 0)
-               printf("COLLECT_%s=%d\n", checkpoint, ret);
+        if (debug)
+                everybody();
+        if (ret >= 0)
+                printf("COLLECT_%s=%d\n", checkpoint, ret);
 exit:
-       udev_unref(udev);
-       return ret;
+        udev_unref(udev);
+        return ret;
 }
index ac4da07..471ea60 100644 (file)
 #include "libudev-private.h"
 
 static void log_fn(struct udev *udev, int priority,
-                  const char *file, int line, const char *fn,
-                  const char *format, va_list args)
+                   const char *file, int line, const char *fn,
+                   const char *format, va_list args)
 {
-       vsyslog(priority, format, args);
+        vsyslog(priority, format, args);
 }
 
 int main(int argc, char *argv[])
 {
-       struct udev *udev;
-       const char *node = NULL;
-       int i;
-       int export = 0;
-       uint32_t disk_id;
-       uint16_t mbr_valid;
-       struct dirent *dent;
-       int disk_fd;
-       int sysfs_fd;
-       DIR *dir = NULL;
-       int rc = 1;
-       char filename[UTIL_PATH_SIZE];
-       char match[UTIL_PATH_SIZE];
-
-       udev = udev_new();
-       if (udev == NULL)
-               goto exit;
-
-       udev_log_init("edd_id");
-       udev_set_log_fn(udev, log_fn);
-
-       for (i = 1 ; i < argc; i++) {
-               char *arg = argv[i];
-
-               if (strcmp(arg, "--export") == 0) {
-                       export = 1;
-               } else
-                       node = arg;
-       }
-       if (node == NULL) {
-               err(udev, "no node specified\n");
-               fprintf(stderr, "no node specified\n");
-               goto exit;
-       }
-
-       /* check for kernel support */
-       util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/firmware/edd", NULL);
-       dir = opendir(filename);
-       if (dir == NULL) {
-               info(udev, "no kernel EDD support\n");
-               fprintf(stderr, "no kernel EDD support\n");
-               rc = 2;
-               goto exit;
-       }
-
-       disk_fd = open(node, O_RDONLY);
-       if (disk_fd < 0) {
-               info(udev, "unable to open '%s'\n", node);
-               fprintf(stderr, "unable to open '%s'\n", node);
-               rc = 3;
-               goto closedir;
-       }
-
-       /* check for valid MBR signature */
-       if (lseek(disk_fd, 510, SEEK_SET) < 0) {
-               info(udev, "seek to MBR validity failed '%s'\n", node);
-               rc = 4;
-               goto close;
-       }
-       if (read(disk_fd, &mbr_valid, sizeof(mbr_valid)) != sizeof(mbr_valid)) {
-               info(udev, "read MBR validity failed '%s'\n", node);
-               rc = 5;
-               goto close;
-       }
-       if (mbr_valid != 0xAA55) {
-               fprintf(stderr, "no valid MBR signature '%s'\n", node);
-               info(udev, "no valid MBR signature '%s'\n", node);
-               rc=6;
-               goto close;
-       }
-
-       /* read EDD signature */
-       if (lseek(disk_fd, 440, SEEK_SET) < 0) {
-               info(udev, "seek to signature failed '%s'\n", node);
-               rc = 7;
-               goto close;
-       }
-       if (read(disk_fd, &disk_id, sizeof(disk_id)) != sizeof(disk_id)) {
-               info(udev, "read signature failed '%s'\n", node);
-               rc = 8;
-               goto close;
-       }
-       /* all zero is invalid */
-       info(udev, "read id 0x%08x from '%s'\n", disk_id, node);
-       if (disk_id == 0) {
-               fprintf(stderr, "no EDD signature '%s'\n", node);
-               info(udev, "'%s' signature is zero\n", node);
-               rc = 9;
-               goto close;
-       }
-
-       /* lookup signature in sysfs to determine the name */
-       match[0] = '\0';
-       for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-               char sysfs_id_buf[256];
-               uint32_t sysfs_id;
-               ssize_t size;
-
-               if (dent->d_name[0] == '.')
-                       continue;
-
-               util_strscpyl(filename, sizeof(filename), dent->d_name, "/mbr_signature", NULL);
-               sysfs_fd = openat(dirfd(dir), filename, O_RDONLY);
-               if (sysfs_fd < 0) {
-                       info(udev, "unable to open sysfs '%s'\n", filename);
-                       continue;
-               }
-
-               size = read(sysfs_fd, sysfs_id_buf, sizeof(sysfs_id_buf)-1);
-               close(sysfs_fd);
-               if (size <= 0) {
-                       info(udev, "read sysfs '%s' failed\n", filename);
-                       continue;
-               }
-               sysfs_id_buf[size] = '\0';
-               info(udev, "read '%s' from '%s'\n", sysfs_id_buf, filename);
-               sysfs_id = strtoul(sysfs_id_buf, NULL, 16);
-
-               /* look for matching value, that appears only once */
-               if (disk_id == sysfs_id) {
-                       if (match[0] == '\0') {
-                               /* store id */
-                               util_strscpy(match, sizeof(match), dent->d_name);
-                       } else {
-                               /* error, same signature for another device */
-                               info(udev, "'%s' does not have a unique signature\n", node);
-                               fprintf(stderr, "'%s' does not have a unique signature\n", node);
-                               rc = 10;
-                               goto exit;
-                       }
-               }
-       }
-
-       if (match[0] != '\0') {
-               if (export)
-                       printf("ID_EDD=%s\n", match);
-               else
-                       printf("%s\n", match);
-               rc = 0;
-       }
+        struct udev *udev;
+        const char *node = NULL;
+        int i;
+        int export = 0;
+        uint32_t disk_id;
+        uint16_t mbr_valid;
+        struct dirent *dent;
+        int disk_fd;
+        int sysfs_fd;
+        DIR *dir = NULL;
+        int rc = 1;
+        char filename[UTIL_PATH_SIZE];
+        char match[UTIL_PATH_SIZE];
+
+        udev = udev_new();
+        if (udev == NULL)
+                goto exit;
+
+        udev_log_init("edd_id");
+        udev_set_log_fn(udev, log_fn);
+
+        for (i = 1 ; i < argc; i++) {
+                char *arg = argv[i];
+
+                if (strcmp(arg, "--export") == 0) {
+                        export = 1;
+                } else
+                        node = arg;
+        }
+        if (node == NULL) {
+                err(udev, "no node specified\n");
+                fprintf(stderr, "no node specified\n");
+                goto exit;
+        }
+
+        /* check for kernel support */
+        util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/firmware/edd", NULL);
+        dir = opendir(filename);
+        if (dir == NULL) {
+                info(udev, "no kernel EDD support\n");
+                fprintf(stderr, "no kernel EDD support\n");
+                rc = 2;
+                goto exit;
+        }
+
+        disk_fd = open(node, O_RDONLY);
+        if (disk_fd < 0) {
+                info(udev, "unable to open '%s'\n", node);
+                fprintf(stderr, "unable to open '%s'\n", node);
+                rc = 3;
+                goto closedir;
+        }
+
+        /* check for valid MBR signature */
+        if (lseek(disk_fd, 510, SEEK_SET) < 0) {
+                info(udev, "seek to MBR validity failed '%s'\n", node);
+                rc = 4;
+                goto close;
+        }
+        if (read(disk_fd, &mbr_valid, sizeof(mbr_valid)) != sizeof(mbr_valid)) {
+                info(udev, "read MBR validity failed '%s'\n", node);
+                rc = 5;
+                goto close;
+        }
+        if (mbr_valid != 0xAA55) {
+                fprintf(stderr, "no valid MBR signature '%s'\n", node);
+                info(udev, "no valid MBR signature '%s'\n", node);
+                rc=6;
+                goto close;
+        }
+
+        /* read EDD signature */
+        if (lseek(disk_fd, 440, SEEK_SET) < 0) {
+                info(udev, "seek to signature failed '%s'\n", node);
+                rc = 7;
+                goto close;
+        }
+        if (read(disk_fd, &disk_id, sizeof(disk_id)) != sizeof(disk_id)) {
+                info(udev, "read signature failed '%s'\n", node);
+                rc = 8;
+                goto close;
+        }
+        /* all zero is invalid */
+        info(udev, "read id 0x%08x from '%s'\n", disk_id, node);
+        if (disk_id == 0) {
+                fprintf(stderr, "no EDD signature '%s'\n", node);
+                info(udev, "'%s' signature is zero\n", node);
+                rc = 9;
+                goto close;
+        }
+
+        /* lookup signature in sysfs to determine the name */
+        match[0] = '\0';
+        for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+                char sysfs_id_buf[256];
+                uint32_t sysfs_id;
+                ssize_t size;
+
+                if (dent->d_name[0] == '.')
+                        continue;
+
+                util_strscpyl(filename, sizeof(filename), dent->d_name, "/mbr_signature", NULL);
+                sysfs_fd = openat(dirfd(dir), filename, O_RDONLY);
+                if (sysfs_fd < 0) {
+                        info(udev, "unable to open sysfs '%s'\n", filename);
+                        continue;
+                }
+
+                size = read(sysfs_fd, sysfs_id_buf, sizeof(sysfs_id_buf)-1);
+                close(sysfs_fd);
+                if (size <= 0) {
+                        info(udev, "read sysfs '%s' failed\n", filename);
+                        continue;
+                }
+                sysfs_id_buf[size] = '\0';
+                info(udev, "read '%s' from '%s'\n", sysfs_id_buf, filename);
+                sysfs_id = strtoul(sysfs_id_buf, NULL, 16);
+
+                /* look for matching value, that appears only once */
+                if (disk_id == sysfs_id) {
+                        if (match[0] == '\0') {
+                                /* store id */
+                                util_strscpy(match, sizeof(match), dent->d_name);
+                        } else {
+                                /* error, same signature for another device */
+                                info(udev, "'%s' does not have a unique signature\n", node);
+                                fprintf(stderr, "'%s' does not have a unique signature\n", node);
+                                rc = 10;
+                                goto exit;
+                        }
+                }
+        }
+
+        if (match[0] != '\0') {
+                if (export)
+                        printf("ID_EDD=%s\n", match);
+                else
+                        printf("%s\n", match);
+                rc = 0;
+        }
 
 close:
-       close(disk_fd);
+        close(disk_fd);
 closedir:
-       closedir(dir);
+        closedir(dir);
 exit:
-       udev_unref(udev);
-       udev_log_close();
-       return rc;
+        udev_unref(udev);
+        udev_log_close();
+        return rc;
 }
index 47724f8..f71ef0d 100644 (file)
 #include "libudev-private.h"
 
 static char *table[] = {
-       "", "d360", "h1200", "u360", "u720", "h360", "h720",
-       "u1440", "u2880", "CompaQ", "h1440", "u1680", "h410",
-       "u820", "h1476", "u1722", "h420", "u830", "h1494", "u1743",
-       "h880", "u1040", "u1120", "h1600", "u1760", "u1920",
-       "u3200", "u3520", "u3840", "u1840", "u800", "u1600",
-       NULL
+        "", "d360", "h1200", "u360", "u720", "h360", "h720",
+        "u1440", "u2880", "CompaQ", "h1440", "u1680", "h410",
+        "u820", "h1476", "u1722", "h420", "u830", "h1494", "u1743",
+        "h880", "u1040", "u1120", "h1600", "u1760", "u1920",
+        "u3200", "u3520", "u3840", "u1840", "u800", "u1600",
+        NULL
 };
 
 static int t360[] = { 1, 0 };
@@ -48,130 +48,130 @@ static int t3in[] = { 8, 9, 26, 27, 28, 7, 11, 15, 19, 24, 25, 29, 31, 3, 4, 13,
 static int *table_sup[] = { NULL, t360, t1200, t3in+5+8, t3in+5, t3in, t3in };
 
 static void log_fn(struct udev *udev, int priority,
-                  const char *file, int line, const char *fn,
-                  const char *format, va_list args)
+                   const char *file, int line, const char *fn,
+                   const char *format, va_list args)
 {
-       vsyslog(priority, format, args);
+        vsyslog(priority, format, args);
 }
 
 int main(int argc, char **argv)
 {
-       struct udev *udev;
-       char *dev;
-       char *devname;
-       char node[64];
-       int type = 0, i, fdnum, c;
-       int major = 2, minor;
-       uid_t uid = 0;
-       gid_t gid = 0;
-       mode_t mode = 0660;
-       int create_nodes = 0;
-       int print_nodes = 0;
-       int is_err = 0;
-
-       udev = udev_new();
-       if (udev == NULL)
-               goto exit;
-
-       udev_log_init("create_floppy_devices");
-       udev_set_log_fn(udev, log_fn);
-       udev_selinux_init(udev);
-
-       while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) {
-               switch (c) {
-               case 'c':
-                       create_nodes = 1;
-                       break;
-               case 'd':
-                       print_nodes = 1;
-                       break;
-               case 'U':
-                       uid = util_lookup_user(udev, optarg);
-                       break;
-               case 'G':
-                       gid = util_lookup_group(udev, optarg);
-                       break;
-               case 'M':
-                       mode = strtol(optarg, NULL, 0);
-                       mode = mode & 0666;
-                       break;
-               case 'm':
-                       major = strtol(optarg, NULL, 0);
-                       break;
-               case 't':
-                       type = strtol(optarg, NULL, 0);
-                       break;
-               default:
-                       is_err++;
-                       break;
-               }
-       }
-
-       if (is_err || optind >= argc) {
-               printf("Usage:  %s [OPTION] device\n"
-                      "  -c   create\n"
-                      "  -d   debug\n"
-                      "  -m   Major number\n"
-                      "  -t   floppy type number\n"
-                      "  -U   device node user ownership\n"
-                      "  -G   device node group owner\n"
-                      "  -M   device node mode\n"
-                      "\n", argv[0]);
-               return 1;
-       }
-
-       dev = argv[optind];
-       devname = strrchr(dev, '/');
-       if (devname != NULL)
-               devname = &devname[1];
-       else
-               devname = dev;
-       if (strncmp(devname, "fd", 2) != 0) {
-               fprintf(stderr,"Device '%s' is not a floppy device\n", dev);
-               return 1;
-       }
-
-       fdnum = strtol(&devname[2], NULL, 10);
-       if (fdnum < 0 || fdnum > 7) {
-               fprintf(stderr,"Floppy device number %d out of range (0-7)\n", fdnum);
-               return 1;
-       }
-       if (fdnum > 3)
-               fdnum += 124;
-
-       if (major < 1) {
-               fprintf(stderr,"Invalid major number %d\n", major);
-               return 1;
-       }
-
-       if (type < 0 || type >= (int) ARRAY_SIZE(table_sup)) {
-               fprintf(stderr,"Invalid CMOS type %d\n", type);
-               return 1;
-       }
-
-       if (type == 0)
-               return 0;
-
-       i = 0;
-       while (table_sup[type][i]) {
-               sprintf(node, "%s%s", dev, table[table_sup[type][i]]);
-               minor = (table_sup[type][i] << 2) + fdnum;
-               if (print_nodes)
-                       printf("%s b %.4o %d %d\n", node, mode, major, minor);
-               if (create_nodes) {
-                       unlink(node);
-                       udev_selinux_setfscreatecon(udev, node, S_IFBLK | mode);
-                       mknod(node, S_IFBLK | mode, makedev(major,minor));
-                       udev_selinux_resetfscreatecon(udev);
-                       chown(node, uid, gid);
-                       chmod(node, S_IFBLK | mode);
-               }
-               i++;
-       }
-
-       udev_selinux_exit(udev);
-       udev_unref(udev);
-       udev_log_close();
+        struct udev *udev;
+        char *dev;
+        char *devname;
+        char node[64];
+        int type = 0, i, fdnum, c;
+        int major = 2, minor;
+        uid_t uid = 0;
+        gid_t gid = 0;
+        mode_t mode = 0660;
+        int create_nodes = 0;
+        int print_nodes = 0;
+        int is_err = 0;
+
+        udev = udev_new();
+        if (udev == NULL)
+                goto exit;
+
+        udev_log_init("create_floppy_devices");
+        udev_set_log_fn(udev, log_fn);
+        udev_selinux_init(udev);
+
+        while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) {
+                switch (c) {
+                case 'c':
+                        create_nodes = 1;
+                        break;
+                case 'd':
+                        print_nodes = 1;
+                        break;
+                case 'U':
+                        uid = util_lookup_user(udev, optarg);
+                        break;
+                case 'G':
+                        gid = util_lookup_group(udev, optarg);
+                        break;
+                case 'M':
+                        mode = strtol(optarg, NULL, 0);
+                        mode = mode & 0666;
+                        break;
+                case 'm':
+                        major = strtol(optarg, NULL, 0);
+                        break;
+                case 't':
+                        type = strtol(optarg, NULL, 0);
+                        break;
+                default:
+                        is_err++;
+                        break;
+                }
+        }
+
+        if (is_err || optind >= argc) {
+                printf("Usage:  %s [OPTION] device\n"
+                       "  -c   create\n"
+                       "  -d   debug\n"
+                       "  -m   Major number\n"
+                       "  -t   floppy type number\n"
+                       "  -U   device node user ownership\n"
+                       "  -G   device node group owner\n"
+                       "  -M   device node mode\n"
+                       "\n", argv[0]);
+                return 1;
+        }
+
+        dev = argv[optind];
+        devname = strrchr(dev, '/');
+        if (devname != NULL)
+                devname = &devname[1];
+        else
+                devname = dev;
+        if (strncmp(devname, "fd", 2) != 0) {
+                fprintf(stderr,"Device '%s' is not a floppy device\n", dev);
+                return 1;
+        }
+
+        fdnum = strtol(&devname[2], NULL, 10);
+        if (fdnum < 0 || fdnum > 7) {
+                fprintf(stderr,"Floppy device number %d out of range (0-7)\n", fdnum);
+                return 1;
+        }
+        if (fdnum > 3)
+                fdnum += 124;
+
+        if (major < 1) {
+                fprintf(stderr,"Invalid major number %d\n", major);
+                return 1;
+        }
+
+        if (type < 0 || type >= (int) ARRAY_SIZE(table_sup)) {
+                fprintf(stderr,"Invalid CMOS type %d\n", type);
+                return 1;
+        }
+
+        if (type == 0)
+                return 0;
+
+        i = 0;
+        while (table_sup[type][i]) {
+                sprintf(node, "%s%s", dev, table[table_sup[type][i]]);
+                minor = (table_sup[type][i] << 2) + fdnum;
+                if (print_nodes)
+                        printf("%s b %.4o %d %d\n", node, mode, major, minor);
+                if (create_nodes) {
+                        unlink(node);
+                        udev_selinux_setfscreatecon(udev, node, S_IFBLK | mode);
+                        mknod(node, S_IFBLK | mode, makedev(major,minor));
+                        udev_selinux_resetfscreatecon(udev);
+                        chown(node, uid, gid);
+                        chmod(node, S_IFBLK | mode);
+                }
+                i++;
+        }
+
+        udev_selinux_exit(udev);
+        udev_unref(udev);
+        udev_log_close();
 exit:
-       return 0;
+        return 0;
 }
index 47044a8..da97db2 100644 (file)
@@ -1,5 +1,5 @@
-                 GNU LESSER GENERAL PUBLIC LICENSE
-                      Version 2.1, February 1999
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
 
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
      51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
@@ -10,7 +10,7 @@
  as the successor of the GNU Library Public License, version 2, hence
  the version number 2.1.]
 
-                           Preamble
+                            Preamble
 
   The licenses for most software are designed to take away your
 freedom to share and change it.  By contrast, the GNU General Public
@@ -112,7 +112,7 @@ modification follow.  Pay close attention to the difference between a
 former contains code derived from the library, whereas the latter must
 be combined with the library in order to run.
 \f
-                 GNU LESSER GENERAL PUBLIC LICENSE
+                  GNU LESSER GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License Agreement applies to any software library or other
@@ -432,7 +432,7 @@ decision will be guided by the two goals of preserving the free status
 of all derivatives of our free software and of promoting the sharing
 and reuse of software generally.
 
-                           NO WARRANTY
+                            NO WARRANTY
 
   15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
 WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
@@ -455,7 +455,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 DAMAGES.
 
-                    END OF TERMS AND CONDITIONS
+                     END OF TERMS AND CONDITIONS
 \f
            How to Apply These Terms to Your New Libraries
 
index 65e6997..3512197 100644 (file)
@@ -78,14 +78,14 @@ expand_content_files=
 # e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
 # e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
 GTKDOC_CFLAGS = \
-       $(DBUS_GLIB_CFLAGS) \
-       $(GLIB_CFLAGS) \
-       -I$(top_srcdir)/src/extras/gudev \
-       -I$(top_builddir)/src/extras/gudev
+        $(DBUS_GLIB_CFLAGS) \
+        $(GLIB_CFLAGS) \
+        -I$(top_srcdir)/src/extras/gudev \
+        -I$(top_builddir)/src/extras/gudev
 
 GTKDOC_LIBS = \
-       $(GLIB_LIBS) \
-       $(top_builddir)/src/extras/gudev/libgudev-1.0.la
+        $(GLIB_LIBS) \
+        $(top_builddir)/src/extras/gudev/libgudev-1.0.la
 
 # This includes the standard gtk-doc make rules, copied by gtkdocize.
 include $(top_srcdir)/gtk-doc.make
index 65fdfff..f876c3b 100644 (file)
@@ -9,22 +9,22 @@
     <releaseinfo>For GUdev version &version;</releaseinfo>
     <authorgroup>
       <author>
-       <firstname>David</firstname>
-       <surname>Zeuthen</surname>
-       <affiliation>
-         <address>
-           <email>davidz@redhat.com</email>
-         </address>
-       </affiliation>
+        <firstname>David</firstname>
+        <surname>Zeuthen</surname>
+        <affiliation>
+          <address>
+            <email>davidz@redhat.com</email>
+          </address>
+        </affiliation>
       </author>
       <author>
-       <firstname>Bastien</firstname>
-       <surname>Nocera</surname>
-       <affiliation>
-         <address>
-           <email>hadess@hadess.net</email>
-         </address>
-       </affiliation>
+        <firstname>Bastien</firstname>
+        <surname>Nocera</surname>
+        <affiliation>
+          <address>
+            <email>hadess@hadess.net</email>
+          </address>
+        </affiliation>
       </author>
     </authorgroup>
 
 
     <legalnotice>
       <para>
-       Permission is granted to copy, distribute and/or modify this
-       document under the terms of the <citetitle>GNU Free
-       Documentation License</citetitle>, Version 1.1 or any later
-       version published by the Free Software Foundation with no
-       Invariant Sections, no Front-Cover Texts, and no Back-Cover
-       Texts. You may obtain a copy of the <citetitle>GNU Free
-       Documentation License</citetitle> from the Free Software
-       Foundation by visiting <ulink type="http"
-       url="http://www.fsf.org">their Web site</ulink> or by writing
-       to:
+        Permission is granted to copy, distribute and/or modify this
+        document under the terms of the <citetitle>GNU Free
+        Documentation License</citetitle>, Version 1.1 or any later
+        version published by the Free Software Foundation with no
+        Invariant Sections, no Front-Cover Texts, and no Back-Cover
+        Texts. You may obtain a copy of the <citetitle>GNU Free
+        Documentation License</citetitle> from the Free Software
+        Foundation by visiting <ulink type="http"
+        url="http://www.fsf.org">their Web site</ulink> or by writing
+        to:
 
-       <address>
-         The Free Software Foundation, Inc.,
-         <street>59 Temple Place</street> - Suite 330,
-         <city>Boston</city>, <state>MA</state> <postcode>02111-1307</postcode>,
-         <country>USA</country>
-       </address>
+        <address>
+          The Free Software Foundation, Inc.,
+          <street>59 Temple Place</street> - Suite 330,
+          <city>Boston</city>, <state>MA</state> <postcode>02111-1307</postcode>,
+          <country>USA</country>
+        </address>
       </para>
 
       <para>
-       Many of the names used by companies to distinguish their
-       products and services are claimed as trademarks. Where those
-       names appear in any freedesktop.org documentation, and those
-       trademarks are made aware to the members of the
-       freedesktop.org Project, the names have been printed in caps
-       or initial caps.
+        Many of the names used by companies to distinguish their
+        products and services are claimed as trademarks. Where those
+        names appear in any freedesktop.org documentation, and those
+        trademarks are made aware to the members of the
+        freedesktop.org Project, the names have been printed in caps
+        or initial caps.
       </para>
     </legalnotice>
   </bookinfo>
@@ -69,8 +69,8 @@
     <title>API Reference</title>
     <partintro>
       <para>
-       This part presents the class and function reference for the
-       <literal>libgudev</literal> library.
+        This part presents the class and function reference for the
+        <literal>libgudev</literal> library.
       </para>
     </partintro>
     <xi:include href="xml/gudevclient.xml"/>
index a6465ad..2b94102 100644 (file)
@@ -87,8 +87,8 @@ G_DEFINE_TYPE (GUdevClient, g_udev_client, G_TYPE_OBJECT)
 
 static gboolean
 monitor_event (GIOChannel *source,
-              GIOCondition condition,
-              gpointer data)
+               GIOCondition condition,
+               gpointer data)
 {
   GUdevClient *client = (GUdevClient *) data;
   GUdevDevice *device;
index ea77b69..f81b6aa 100755 (executable)
@@ -9,30 +9,30 @@ KEYMAPS_DIR=$SRCDIR/src/extras/keymap/keymaps #extras/keymap/keymaps
 RULES=$SRCDIR/src/extras/keymap/95-keymap.rules
 
 [ -e "$KEYLIST" ] || {
-    echo "need $KEYLIST please build first" >&2
-    exit 1
+        echo "need $KEYLIST please build first" >&2
+        exit 1
 }
 
 missing=$(join -v 2 <(awk '{print tolower(substr($1,5))}' $KEYLIST | sort -u) \
                     <(grep -hv '^#' ${KEYMAPS_DIR}/*| awk '{print $2}' | sort -u))
 [ -z "$missing" ] || {
-    echo "ERROR: unknown key names in extras/keymap/keymaps/*:" >&2
-    echo "$missing" >&2
-    exit 1
+        echo "ERROR: unknown key names in extras/keymap/keymaps/*:" >&2
+        echo "$missing" >&2
+        exit 1
 }
 
 # check that all maps referred to in $RULES exist
 maps=$(sed -rn '/keymap \$name/ { s/^.*\$name ([^"[:space:]]+).*$/\1/; p }' $RULES)
 for m in $maps; do
-    # ignore inline mappings
-    [ "$m" = "${m#0x}" ] || continue
+        # ignore inline mappings
+        [ "$m" = "${m#0x}" ] || continue
 
-    [ -e ${KEYMAPS_DIR}/$m ] || {
-       echo "ERROR: unknown map name in $RULES: $m" >&2
-       exit 1
-    }
-    grep -q "extras/keymap/keymaps/$m\>" $SRCDIR/Makefile.am || {
-       echo "ERROR: map file $m is not added to Makefile.am" >&2
-       exit 1
-    }
+        [ -e ${KEYMAPS_DIR}/$m ] || {
+                echo "ERROR: unknown map name in $RULES: $m" >&2
+                exit 1
+        }
+        grep -q "extras/keymap/keymaps/$m\>" $SRCDIR/Makefile.am || {
+                echo "ERROR: map file $m is not added to Makefile.am" >&2
+                exit 1
+        }
 done
index eba3737..9ce2742 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh -e
 # Find "real" keyboard devices and print their device path.
 # Author: Martin Pitt <martin.pitt@ubuntu.com>
 #
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 # General Public License for more details.
 
-set -e
-
 # returns OK if $1 contains $2
 strstr() {
-    [ "${1#*$2*}" != "$1" ]
+        [ "${1#*$2*}" != "$1" ]
 }
 
 # returns OK if $1 contains $2 at the beginning
 str_starts() {
-    [ "${1#$2*}" != "$1" ]
+        [ "${1#$2*}" != "$1" ]
 }
 
 str_line_starts() {
-    while read a; do str_starts "$a" "$1" && return 0;done
-    return 1;
+        while read a; do str_starts "$a" "$1" && return 0;done
+        return 1;
 }
 
 # print a list of input devices which are keyboard-like
 keyboard_devices() {
-    # standard AT keyboard
-    for dev in `udevadm trigger --dry-run --verbose --property-match=ID_INPUT_KEYBOARD=1`; do
-        walk=`udevadm info --attribute-walk --path=$dev`
-        env=`udevadm info --query=env --path=$dev`
-        # filter out non-event devices, such as the parent input devices which
-        # have no devnode
-        if ! echo "$env" | str_line_starts 'DEVNAME='; then
-            continue
-        fi
-        if strstr "$walk" 'DRIVERS=="atkbd"'; then
-            echo -n 'AT keyboard: '
-        elif echo "$env" | str_line_starts 'ID_USB_DRIVER=usbhid'; then
-            echo -n 'USB keyboard: '
-        else
-            echo -n 'Unknown type: '
-        fi
-        udevadm info --query=name --path=$dev
-    done
+        # standard AT keyboard
+        for dev in `udevadm trigger --dry-run --verbose --property-match=ID_INPUT_KEYBOARD=1`; do
+                walk=`udevadm info --attribute-walk --path=$dev`
+                env=`udevadm info --query=env --path=$dev`
+                # filter out non-event devices, such as the parent input devices which have no devnode
+                if ! echo "$env" | str_line_starts 'DEVNAME='; then
+                        continue
+                fi
+                if strstr "$walk" 'DRIVERS=="atkbd"'; then
+                        echo -n 'AT keyboard: '
+                elif echo "$env" | str_line_starts 'ID_USB_DRIVER=usbhid'; then
+                        echo -n 'USB keyboard: '
+                else
+                        echo -n 'Unknown type: '
+               fi
+                       udevadm info --query=name --path=$dev
+        done
 
-    # modules
-    module=$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*Extra Buttons')
-    module="$module
-$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*extra buttons')"
-    module="$module
-$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='Sony Vaio Keys')"
-    for m in $module; do
-        for evdev in $m/event*/dev; do
-            if [ -e "$evdev" ]; then
-               echo -n 'module: '
-               udevadm info --query=name --path=${evdev%%/dev}
-            fi
-       done
-    done
+        # modules
+        module=$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*Extra Buttons')
+        module="$module
+        $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*extra buttons')"
+        module="$module
+        $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='Sony Vaio Keys')"
+        for m in $module; do
+                for evdev in $m/event*/dev; do
+                        if [ -e "$evdev" ]; then
+                                echo -n 'module: '
+                                udevadm info --query=name --path=${evdev%%/dev}
+                        fi
+                done
+        done
 }
 
 keyboard_devices
index 154be3d..dd040ce 100755 (executable)
@@ -5,18 +5,18 @@
 # $2 file with scancode list (hex or dec)
 
 case "$2" in
-       /*) scf="$2" ;;
-       *)  scf="@pkglibexecdir@/keymaps/force-release/$2" ;;
+        /*) scf="$2" ;;
+        *)  scf="@pkglibexecdir@/keymaps/force-release/$2" ;;
 esac
 
 read attr <"/sys/$1/force_release"
 while read scancode dummy; do
-       case "$scancode" in
-               \#*) ;;
-               *)
-                       scancode=$(($scancode))
-                       attr="$attr${attr:+,}$scancode"
-                       ;;
-       esac
+        case "$scancode" in
+                \#*) ;;
+                *)
+                        scancode=$(($scancode))
+                        attr="$attr${attr:+,}$scancode"
+                        ;;
+        esac
 done <"$scf"
 echo "$attr" >"/sys/$1/force_release"
index 6bcfaef..92ec67b 100644 (file)
@@ -45,403 +45,403 @@ const struct key* lookup_key (const char *str, unsigned int len);
 
 static int evdev_open(const char *dev)
 {
-       int fd;
-       char fn[PATH_MAX];
-
-       if (strncmp(dev, "/dev", 4) != 0) {
-               snprintf(fn, sizeof(fn), "/dev/%s", dev);
-               dev = fn;
-       }
-
-       if ((fd = open(dev, O_RDWR)) < 0) {
-               fprintf(stderr, "error open('%s'): %m\n", dev);
-               return -1;
-       }
-       return fd;
+        int fd;
+        char fn[PATH_MAX];
+
+        if (strncmp(dev, "/dev", 4) != 0) {
+                snprintf(fn, sizeof(fn), "/dev/%s", dev);
+                dev = fn;
+        }
+
+        if ((fd = open(dev, O_RDWR)) < 0) {
+                fprintf(stderr, "error open('%s'): %m\n", dev);
+                return -1;
+        }
+        return fd;
 }
 
 static int evdev_get_keycode(int fd, int scancode, int e)
 {
-       int codes[2];
-
-       codes[0] = scancode;
-       if (ioctl(fd, EVIOCGKEYCODE, codes) < 0) {
-               if (e && errno == EINVAL) {
-                       return -2;
-               } else {
-                       fprintf(stderr, "EVIOCGKEYCODE: %m\n");
-                       return -1;
-               }
-       }
-       return codes[1];
+        int codes[2];
+
+        codes[0] = scancode;
+        if (ioctl(fd, EVIOCGKEYCODE, codes) < 0) {
+                if (e && errno == EINVAL) {
+                        return -2;
+                } else {
+                        fprintf(stderr, "EVIOCGKEYCODE: %m\n");
+                        return -1;
+                }
+        }
+        return codes[1];
 }
 
 static int evdev_set_keycode(int fd, int scancode, int keycode)
 {
-       int codes[2];
+        int codes[2];
 
-       codes[0] = scancode;
-       codes[1] = keycode;
+        codes[0] = scancode;
+        codes[1] = keycode;
 
-       if (ioctl(fd, EVIOCSKEYCODE, codes) < 0) {
-               fprintf(stderr, "EVIOCSKEYCODE: %m\n");
-               return -1;
-       }
-       return 0;
+        if (ioctl(fd, EVIOCSKEYCODE, codes) < 0) {
+                fprintf(stderr, "EVIOCSKEYCODE: %m\n");
+                return -1;
+        }
+        return 0;
 }
 
 static int evdev_driver_version(int fd, char *v, size_t l)
 {
-       int version;
+        int version;
 
-       if (ioctl(fd, EVIOCGVERSION, &version)) {
-               fprintf(stderr, "EVIOCGVERSION: %m\n");
-               return -1;
-       }
+        if (ioctl(fd, EVIOCGVERSION, &version)) {
+                fprintf(stderr, "EVIOCGVERSION: %m\n");
+                return -1;
+        }
 
-       snprintf(v, l, "%i.%i.%i.", version >> 16, (version >> 8) & 0xff, version & 0xff);
-       return 0;
+        snprintf(v, l, "%i.%i.%i.", version >> 16, (version >> 8) & 0xff, version & 0xff);
+        return 0;
 }
 
 static int evdev_device_name(int fd, char *n, size_t l)
 {
-       if (ioctl(fd, EVIOCGNAME(l), n) < 0) {
-               fprintf(stderr, "EVIOCGNAME: %m\n");
-               return -1;
-       }
-       return 0;
+        if (ioctl(fd, EVIOCGNAME(l), n) < 0) {
+                fprintf(stderr, "EVIOCGNAME: %m\n");
+                return -1;
+        }
+        return 0;
 }
 
 /* Return a lower-case string with KEY_ prefix removed */
 static const char* format_keyname(const char* key) {
-       static char result[101];
-       const char* s;
-       int len;
-
-       for (s = key+4, len = 0; *s && len < 100; ++len, ++s)
-               result[len] = tolower(*s);
-       result[len] = '\0';
-       return result;
+        static char result[101];
+        const char* s;
+        int len;
+
+        for (s = key+4, len = 0; *s && len < 100; ++len, ++s)
+                result[len] = tolower(*s);
+        result[len] = '\0';
+        return result;
 }
 
 static int dump_table(int fd) {
-       char version[256], name[256];
-       int scancode, r = -1;
+        char version[256], name[256];
+        int scancode, r = -1;
 
-       if (evdev_driver_version(fd, version, sizeof(version)) < 0)
-               goto fail;
+        if (evdev_driver_version(fd, version, sizeof(version)) < 0)
+                goto fail;
 
-       if (evdev_device_name(fd, name, sizeof(name)) < 0)
-               goto fail;
+        if (evdev_device_name(fd, name, sizeof(name)) < 0)
+                goto fail;
 
-       printf("### evdev %s, driver '%s'\n", version, name);
+        printf("### evdev %s, driver '%s'\n", version, name);
 
-       r = 0;
-       for (scancode = 0; scancode < MAX_SCANCODES; scancode++) {
-               int keycode;
+        r = 0;
+        for (scancode = 0; scancode < MAX_SCANCODES; scancode++) {
+                int keycode;
 
-               if ((keycode = evdev_get_keycode(fd, scancode, 1)) < 0) {
-                       if (keycode == -2)
-                               continue;
-                       r = -1;
-                       break;
-               }
+                if ((keycode = evdev_get_keycode(fd, scancode, 1)) < 0) {
+                        if (keycode == -2)
+                                continue;
+                        r = -1;
+                        break;
+                }
 
-               if (keycode < KEY_MAX && key_names[keycode])
-                       printf("0x%03x %s\n", scancode, format_keyname(key_names[keycode]));
-               else
-                       printf("0x%03x 0x%03x\n", scancode, keycode);
-       }
+                if (keycode < KEY_MAX && key_names[keycode])
+                        printf("0x%03x %s\n", scancode, format_keyname(key_names[keycode]));
+                else
+                        printf("0x%03x 0x%03x\n", scancode, keycode);
+        }
 fail:
-       return r;
+        return r;
 }
 
 static void set_key(int fd, const char* scancode_str, const char* keyname)
 {
-       unsigned scancode;
-       char *endptr;
-       char t[105] = "KEY_UNKNOWN";
-       const struct key *k;
-
-       scancode = (unsigned) strtol(scancode_str, &endptr, 0);
-       if (*endptr != '\0') {
-               fprintf(stderr, "ERROR: Invalid scancode\n");
-               exit(1);
-       }
-
-       snprintf(t, sizeof(t), "KEY_%s", keyname);
-
-       if (!(k = lookup_key(t, strlen(t)))) {
-               fprintf(stderr, "ERROR: Unknown key name '%s'\n", keyname);
-               exit(1);
-       }
-
-       if (evdev_set_keycode(fd, scancode, k->id) < 0)
-               fprintf(stderr, "setting scancode 0x%2X to key code %i failed\n",
-                       scancode, k->id);
-       else
-               printf("setting scancode 0x%2X to key code %i\n",
-                       scancode, k->id);
+        unsigned scancode;
+        char *endptr;
+        char t[105] = "KEY_UNKNOWN";
+        const struct key *k;
+
+        scancode = (unsigned) strtol(scancode_str, &endptr, 0);
+        if (*endptr != '\0') {
+                fprintf(stderr, "ERROR: Invalid scancode\n");
+                exit(1);
+        }
+
+        snprintf(t, sizeof(t), "KEY_%s", keyname);
+
+        if (!(k = lookup_key(t, strlen(t)))) {
+                fprintf(stderr, "ERROR: Unknown key name '%s'\n", keyname);
+                exit(1);
+        }
+
+        if (evdev_set_keycode(fd, scancode, k->id) < 0)
+                fprintf(stderr, "setting scancode 0x%2X to key code %i failed\n",
+                        scancode, k->id);
+        else
+                printf("setting scancode 0x%2X to key code %i\n",
+                        scancode, k->id);
 }
 
 static int merge_table(int fd, FILE *f) {
-       int r = 0;
-       int line = 0;
-
-       while (!feof(f)) {
-               char s[256], *p;
-               int scancode, new_keycode, old_keycode;
-
-               if (!fgets(s, sizeof(s), f))
-                       break;
-
-               line++;
-               p = s+strspn(s, "\t ");
-               if (*p == '#' || *p == '\n')
-                       continue;
-
-               if (sscanf(p, "%i %i", &scancode, &new_keycode) != 2) {
-                       char t[105] = "KEY_UNKNOWN";
-                       const struct key *k;
-
-                       if (sscanf(p, "%i %100s", &scancode, t+4) != 2) {
-                               fprintf(stderr, "WARNING: Parse failure at line %i, ignoring.\n", line);
-                               r = -1;
-                               continue;
-                       }
-
-                       if (!(k = lookup_key(t, strlen(t)))) {
-                               fprintf(stderr, "WARNING: Unknown key '%s' at line %i, ignoring.\n", t, line);
-                               r = -1;
-                               continue;
-                       }
-
-                       new_keycode = k->id;
-               }
-
-
-               if ((old_keycode = evdev_get_keycode(fd, scancode, 0)) < 0) {
-                       r = -1;
-                       goto fail;
-               }
-
-               if (evdev_set_keycode(fd, scancode, new_keycode) < 0) {
-                       r = -1;
-                       goto fail;
-               }
-
-               if (new_keycode != old_keycode)
-                       fprintf(stderr, "Remapped scancode 0x%02x to 0x%02x (prior: 0x%02x)\n",
-                               scancode, new_keycode, old_keycode);
-       }
+        int r = 0;
+        int line = 0;
+
+        while (!feof(f)) {
+                char s[256], *p;
+                int scancode, new_keycode, old_keycode;
+
+                if (!fgets(s, sizeof(s), f))
+                        break;
+
+                line++;
+