Util-Linux package development
 help / color / mirror / Atom feed
* Re: `fsck -A` and fs-specific options
From: Theodore Tso @ 2011-07-12 11:02 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux
In-Reply-To: <201107112259.55340.vapier@gentoo.org>


On Jul 11, 2011, at 10:59 PM, Mike Frysinger wrote:
> 
> for example, some journaling file systems allow the journal to be stored 
> separately.  reiserfs has the "jdev=" mount option and the "--journal" fsck 
> option.  ext[34] have the "journal_dev=" mount option and the "-j" fsck 
> option.

At least for ext[34] and external journals, e2fsck can find the external
journal using the blkid library since the UUID of the external journal
is in the superblock.   (In fact that's why the blkid library was originally
written, and why it was originally included as part of e2fsprogs.)

> another example is with loop mounts that take an offset.  fsck cannot operate 
> on the loop source as the start of the file is not the image.  it needs to 
> first setup the loop with the offset, and then do the fsck on the loop point.
> 	/tmp/foo.img /mnt/tmp ext3 loop,offset=10000

How often are people using loopback mounts as a default, standard thing which
need to be mounted and checked as part of the boot sequence?   I'm just
curious what the use case is for this?

I suppose if this was something people really did care about, the /etc/fstab
format could be extended to add a new field at the end for fsck options ---
but it's more complexity, and could break programs try to programmatically
modify /etc/fstab.

-- Ted


^ permalink raw reply

* [git pull] mkfs.bfs fixes
From: Sami Kerola @ 2011-07-12  8:43 UTC (permalink / raw)
  To: util-linux

The following changes since commit bfa8d39b5826b928deb6d84aee3a4a1d6557364c:

  build-sys: fix spaces versus tabs conflict (2011-07-11 15:12:06 +0200)

are available in the git repository at:
  https://github.com/kerolasa/lelux-utiliteetit mkfs.bfs

Sami Kerola (7):
      mkfs.bfs: use libc error facilities
      mkfs.bfs: add long options
      mkfs.bfs: use xstrdup from xalloc.h
      mkfs.bfs: validate numeric user inputs
      mkfs.bfs: include-what-you-use header check
      mkfs.bfs: coding style fix
      docs: add long options to mkfs.bfs.8

 disk-utils/Makefile.am |    2 +-
 disk-utils/mkfs.bfs.8  |   38 +++++---
 disk-utils/mkfs.bfs.c  |  245 ++++++++++++++++++++++++-----------------------
 3 files changed, 148 insertions(+), 137 deletions(-)

diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index 7d018b5..604a65c 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -17,7 +17,7 @@ sbin_PROGRAMS = mkfs mkswap fsck.minix mkfs.minix mkfs.bfs

 fsck_minix_SOURCES = fsck.minix.c minix.h $(top_srcdir)/lib/ismounted.c
 mkfs_minix_SOURCES = mkfs.minix.c minix.h mkfs.h $(utils_common)
$(top_srcdir)/lib/strutils.c
-mkfs_bfs_SOURCES = mkfs.bfs.c $(utils_common)
+mkfs_bfs_SOURCES = mkfs.bfs.c $(utils_common) $(top_srcdir)/lib/strutils.c

 swaplabel_SOURCES = swaplabel.c $(utils_common)
 swaplabel_LDADD = $(uuid_ldadd)
diff --git a/disk-utils/mkfs.bfs.8 b/disk-utils/mkfs.bfs.8
index 741fca9..616c358 100644
--- a/disk-utils/mkfs.bfs.8
+++ b/disk-utils/mkfs.bfs.8
@@ -1,42 +1,48 @@
 .\" Copyright 1999 Andries E. Brouwer (aeb@cwi.nl)
 .\" May be freely distributed.
-.TH MKFS.BFS 8 "12 Sept 1999" "Util-linux 2.9x" "Linux System
Administrator's Manual"
+.TH MKFS.BFS "8" "July 2011" "util-linux" "System Administration Utilities"
 .SH NAME
 mkfs.bfs \- make an SCO bfs filesystem
 .SH SYNOPSIS
 .B mkfs.bfs
-.RB [ \-N
-.IR nr-of-inodes ]
-.RB [ \-V
-.IR volume-name ]
-.RB [ \-F
-.IR fsname ]
-.I device
-.RI [ size-in-blocks ]
+[\fIoptions\fR] \fIdevice \fR[\fIblock-count\fR]
 .SH DESCRIPTION
 .B mkfs.bfs
 creates an SCO bfs file-system on a block device
 (usually a disk partition or a file accessed via the loop device).
-
+.PP
 The
-.I size-in-blocks
+.I block-count
 parameter is the desired size of the file system, in blocks.
 If nothing is specified, the entire partition will be used.
 .SH OPTIONS
 .TP
-.B \-N
+\fB\-N\fR, \fB\-\-inodes\fR=\fINUM\fR
 Specify the desired number of inodes (at most 512).
 If nothing is specified some default number in the range 48-512 is picked
 depending on the size of the partition.
 .TP
-.BI \-V " volume-label"
+\fB\-V\fR, \fB\-\-vname\fR=\fINAME\fR
 Specify the volume label. I have no idea if/where this is used.
 .TP
-.BI \-F " fsname"
+\fB\-F\fR, \fB\-\-fname\fR=\fINAME\fR
 Specify the fsname. I have no idea if/where this is used.
 .TP
-.B \-v
-Be verbose.
+\fB\-v\fR, \fB\-\-verbose\fR
+Explain what is being done.
+.TP
+\fB\-c\fR
+This option is silently ignored.
+.TP
+\fB\-l\fR
+This option is silently ignored.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Output version information and exit.
+\fB\-V\fR works only when specified as an only option.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help and exit.
 .SH "EXIT CODES"
 The exit code returned by
 .B mkfs.bfs
diff --git a/disk-utils/mkfs.bfs.c b/disk-utils/mkfs.bfs.c
index 58f5352..3d87fd0 100644
--- a/disk-utils/mkfs.bfs.c
+++ b/disk-utils/mkfs.bfs.c
@@ -1,21 +1,24 @@
 /*
  *  mkfs.bfs - Create SCO BFS filesystem - aeb, 1999-09-07
  *
- *  Usage: mkfs.bfs [-N nr-of-inodes] [-V volume-name] [-F fsname] device
  */

+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <time.h>
-#include "nls.h"
+#include <unistd.h>
+
 #include "blkdev.h"
+#include "c.h"
+#include "nls.h"
+#include "strutils.h"
+#include "xalloc.h"

 #define BFS_ROOT_INO		2
 #define BFS_NAMELEN		14
@@ -24,72 +27,72 @@

 /* superblock - 512 bytes */
 struct bfssb {
-        unsigned int s_magic;
-        unsigned int s_start;	  /* byte offset of start of data */
-        unsigned int s_end;       /* sizeof(slice)-1 */
-
-        /* for recovery during compaction */
-        int s_from, s_to;         /* src and dest block of current transfer */
-        int s_backup_from, s_backup_to;
-
-        /* labels - may well contain garbage */
-        char s_fsname[6];
-        char s_volume[6];
-        char s_pad[472];
+	unsigned int s_magic;
+	unsigned int s_start;	/* byte offset of start of data */
+	unsigned int s_end;	/* sizeof(slice)-1 */
+
+	/* for recovery during compaction */
+	int s_from, s_to;	/* src and dest block of current transfer */
+	int s_backup_from, s_backup_to;
+
+	/* labels - may well contain garbage */
+	char s_fsname[6];
+	char s_volume[6];
+	char s_pad[472];
 };

 /* inode - 64 bytes */
 struct bfsi {
-        unsigned short i_ino;
-        unsigned char i_pad1[2];
-        unsigned long i_first_block;
-        unsigned long i_last_block;
-        unsigned long i_bytes_to_end;
-        unsigned long i_type;           /* 1: file, 2: the unique dir */
-        unsigned long i_mode;
-        unsigned long i_uid, i_gid;
-        unsigned long i_nlinks;
-        unsigned long i_atime, i_mtime, i_ctime;
-        unsigned char i_pad2[16];
+	unsigned short i_ino;
+	unsigned char i_pad1[2];
+	unsigned long i_first_block;
+	unsigned long i_last_block;
+	unsigned long i_bytes_to_end;
+	unsigned long i_type;	/* 1: file, 2: the unique dir */
+	unsigned long i_mode;
+	unsigned long i_uid, i_gid;
+	unsigned long i_nlinks;
+	unsigned long i_atime, i_mtime, i_ctime;
+	unsigned char i_pad2[16];
 };

 #define BFS_DIR_TYPE	2

 /* directory entry - 16 bytes */
 struct bfsde {
-        unsigned short d_ino;
-        char d_name[BFS_NAMELEN];
+	unsigned short d_ino;
+	char d_name[BFS_NAMELEN];
 };

-
-static char *progname;
-
-static void
-fatal(char *s, ...) {
-    va_list p;
-
-    va_start(p, s);
-    fflush(stdout);
-    fprintf(stderr, "\n%s: ", progname);
-    vfprintf(stderr, s, p);
-    va_end(p);
-    fprintf(stderr, "\n");
-    exit(1);
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
+{
+	fprintf(out,
+		_("Usage: %s [options] device [block-count]\n"),
+		program_invocation_short_name);
+	fprintf(out, _("\nOptions:\n"
+		       " -N, --inodes=NUM    specify desired number of inodes\n"
+		       " -V, --vname=NAME    specify volume name\n"
+		       " -F, --fname=NAME    specify file system name\n"
+		       " -v, --verbose       explain what is being done\n"
+		       " -c                  this option is silently ignored\n"
+		       " -l                  this option is silently ignored\n"
+		       " -V, --version       output version information and exit\n"
+		       "                     -V as version must be only option\n"
+		       " -h, --help          display this help and exit\n\n"));
+
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }

-static void
-usage(void) {
-	fprintf(stderr, _(
-		"Usage: %s [-v] [-N nr-of-inodes] [-V volume-name]\n"
-		"       [-F fsname] device [block-count]\n"),
-		progname);
-	exit(1);
+static void __attribute__ ((__noreturn__)) print_version(void)
+{
+	printf(_("%s (%s)\n"), program_invocation_short_name, PACKAGE_STRING);
+	exit(EXIT_SUCCESS);
 }

-int
-main(int argc, char *argv[]) {
+int main(int argc, char **argv)
+{
 	char *device, *volume, *fsname;
-	int inodes;
+	long inodes;
 	unsigned long long total_blocks, ino_bytes, ino_blocks, data_blocks;
 	unsigned long long user_specified_total_blocks = 0;
 	int verbose = 0;
@@ -100,106 +103,109 @@ main(int argc, char *argv[]) {
 	struct stat statbuf;
 	time_t now;
 	int c, i, len;
-	char *p;

-	progname = argv[0];
-	if ((p = strrchr(progname, '/')) != NULL)
-		progname = p+1;
+	enum { VERSION_OPTION = CHAR_MAX + 1 };
+	static const struct option longopts[] = {
+		{"inodes", required_argument, NULL, 'N'},
+		{"vname", required_argument, NULL, 'V'},
+		{"fname", required_argument, NULL, 'F'},
+		{"verbose", no_argument, NULL, 'v'},
+		{"version", no_argument, NULL, VERSION_OPTION},
+		{"help", no_argument, NULL, 'h'},
+		{NULL, 0, NULL, 0}
+	};

 	if (argc < 2)
-		usage();
+		usage(stderr);

-	if (argc == 2 &&
-	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
-		printf(_("%s (%s)\n"), progname, PACKAGE_STRING);
-		exit(0);
-	}
+	if (argc == 2 && !strcmp(argv[1], "-V"))
+		print_version();

 	volume = fsname = "      ";	/* is there a default? */
 	inodes = 0;

-	while ((c = getopt(argc, argv, "vF:N:V:cl:")) != -1) {
+	while ((c = getopt_long(argc, argv, "N:V:F:vhcl", longopts, NULL)) != -1) {
 		switch (c) {
 		case 'N':
-			inodes = atol(optarg);
+			inodes = strtol_or_err(optarg, _("invalid number of inodes"));
 			break;

 		case 'V':
 			len = strlen(optarg);
 			if (len <= 0 || len > 6)
-				fatal(_("volume name too long"));
-			volume = strdup(optarg);
+				errx(EXIT_FAILURE, _("volume name too long"));
+			volume = xstrdup(optarg);
 			break;

 		case 'F':
 			len = strlen(optarg);
 			if (len <= 0 || len > 6)
-				fatal(_("fsname name too long"));
-			fsname = strdup(optarg);
+				errx(EXIT_FAILURE, _("fsname name too long"));
+			fsname = xstrdup(optarg);
 			break;

 		case 'v':
 			verbose = 1;
 			break;

-			/* when called via mkfs we may get options c,l,v */
 		case 'c':
 		case 'l':
+			/* when called via mkfs we may get options c,l,v */
 			break;

+		case VERSION_OPTION:
+			print_version();
+		case 'h':
+			usage(stdout);
 		default:
-			usage();
+			usage(stderr);
 		}
 	}

 	if (optind == argc)
-		usage();
+		usage(stderr);

 	device = argv[optind++];

-	if (stat(device, &statbuf) == -1) {
-		perror(device);
-		fatal(_("cannot stat device %s"), device);
-	}
+	if (stat(device, &statbuf) < 0)
+		err(EXIT_FAILURE, _("cannot stat device %s"), device);

 	if (!S_ISBLK(statbuf.st_mode))
-		fatal(_("%s is not a block special device"), device);
+		errx(EXIT_FAILURE, _("%s is not a block special device"), device);

 	fd = open(device, O_RDWR | O_EXCL);
-	if (fd == -1) {
-		perror(device);
-		fatal(_("cannot open %s"), device);
-	}
+	if (fd < 0)
+		err(EXIT_FAILURE, _("cannot open %s"), device);

-	if (optind == argc-1)
-		user_specified_total_blocks = atoll(argv[optind]);
+	if (optind == argc - 1)
+		user_specified_total_blocks =
+			strtoll_or_err(argv[optind], _("invalid block-count"));
 	else if (optind != argc)
-		usage();
+		usage(stderr);

 	if (blkdev_get_sectors(fd, &total_blocks) == -1) {
-		if (!user_specified_total_blocks) {
-			perror("blkdev_get_sectors");
-			fatal(_("cannot get size of %s"), device);
-		}
+		if (!user_specified_total_blocks)
+			err(EXIT_FAILURE, _("cannot get size of %s"), device);
 		total_blocks = user_specified_total_blocks;
 	} else if (user_specified_total_blocks) {
 		if (user_specified_total_blocks > total_blocks)
-			fatal(_("blocks argument too large, max is %llu"),
-			      total_blocks);
+			errx(EXIT_FAILURE,
+			     _("blocks argument too large, max is %llu"),
+			     total_blocks);
 		total_blocks = user_specified_total_blocks;
 	}

 	if (!inodes) {
 		/* pick some reasonable default */
-		inodes = 8*(total_blocks/800);
+		inodes = 8 * (total_blocks / 800);
 		if (inodes < 48)
 			inodes = 48;
-		if (inodes > 512)
+		if (512 < inodes)
 			inodes = 512;
 	} else {
 		/* believe the user */
-		if (inodes > 512)
-			fatal(_("too many inodes - max is 512"));
+		if (512 < inodes)
+			errx(EXIT_FAILURE, _("too many inodes - max is 512"));
 	}

 	ino_bytes = inodes * sizeof(struct bfsi);
@@ -208,8 +214,9 @@ main(int argc, char *argv[]) {

 	/* mimic the behaviour of SCO's mkfs - maybe this limit is needed */
 	if (data_blocks < 32)
-		fatal(_("not enough space, need at least %llu blocks"),
-		      ino_blocks + 33);
+		errx(EXIT_FAILURE,
+		     _("not enough space, need at least %llu blocks"),
+		     ino_blocks + 33);

 	memset(&sb, 0, sizeof(sb));
 	sb.s_magic = BFS_SUPER_MAGIC;
@@ -224,29 +231,29 @@ main(int argc, char *argv[]) {
 		fprintf(stderr, _("Volume: <%-6s>\n"), volume);
 		fprintf(stderr, _("FSname: <%-6s>\n"), fsname);
 		fprintf(stderr, _("BlockSize: %d\n"), BFS_BLOCKSIZE);
-		if (ino_blocks==1)
-			fprintf(stderr, _("Inodes: %d (in 1 block)\n"),
+		if (ino_blocks == 1)
+			fprintf(stderr, _("Inodes: %lu (in 1 block)\n"),
 				inodes);
 		else
-			fprintf(stderr, _("Inodes: %d (in %lld blocks)\n"),
+			fprintf(stderr, _("Inodes: %lu (in %llu blocks)\n"),
 				inodes, ino_blocks);
 		fprintf(stderr, _("Blocks: %lld\n"), total_blocks);
 		fprintf(stderr, _("Inode end: %d, Data end: %d\n"),
-			sb.s_start-1, sb.s_end);
+			sb.s_start - 1, sb.s_end);
 	}

 	if (write(fd, &sb, sizeof(sb)) != sizeof(sb))
-		fatal(_("error writing superblock"));
+		errx(EXIT_FAILURE, _("error writing superblock"));

 	memset(&ri, 0, sizeof(ri));
 	ri.i_ino = BFS_ROOT_INO;
 	ri.i_first_block = 1 + ino_blocks;
 	ri.i_last_block = ri.i_first_block +
-		(inodes * sizeof(de) - 1) / BFS_BLOCKSIZE;
+	    (inodes * sizeof(de) - 1) / BFS_BLOCKSIZE;
 	ri.i_bytes_to_end = ri.i_first_block * BFS_BLOCKSIZE
-		+ 2 * sizeof(struct bfsde) - 1;
+	    + 2 * sizeof(struct bfsde) - 1;
 	ri.i_type = BFS_DIR_TYPE;
-	ri.i_mode = S_IFDIR | 0755; 	/* or just 0755 */
+	ri.i_mode = S_IFDIR | 0755;	/* or just 0755 */
 	ri.i_uid = 0;
 	ri.i_gid = 1;			/* random */
 	ri.i_nlinks = 2;
@@ -256,30 +263,28 @@ main(int argc, char *argv[]) {
 	ri.i_ctime = now;

 	if (write(fd, &ri, sizeof(ri)) != sizeof(ri))
-		fatal(_("error writing root inode"));
+		errx(EXIT_FAILURE, _("error writing root inode"));

 	memset(&ri, 0, sizeof(ri));
-	for (i=1; i<inodes; i++)
+	for (i = 1; i < inodes; i++)
 		if (write(fd, &ri, sizeof(ri)) != sizeof(ri))
-			fatal(_("error writing inode"));
+			errx(EXIT_FAILURE, _("error writing inode"));

-	if (lseek(fd, (1 + ino_blocks)*BFS_BLOCKSIZE, SEEK_SET) == -1)
-		fatal(_("seek error"));
+	if (lseek(fd, (1 + ino_blocks) * BFS_BLOCKSIZE, SEEK_SET) == -1)
+		errx(EXIT_FAILURE, _("seek error"));

 	memset(&de, 0, sizeof(de));
 	de.d_ino = BFS_ROOT_INO;
 	memcpy(de.d_name, ".", 1);
 	if (write(fd, &de, sizeof(de)) != sizeof(de))
-		fatal(_("error writing . entry"));
+		errx(EXIT_FAILURE, _("error writing . entry"));

 	memcpy(de.d_name, "..", 2);
 	if (write(fd, &de, sizeof(de)) != sizeof(de))
-		fatal(_("error writing .. entry"));
+		errx(EXIT_FAILURE, _("error writing .. entry"));

-	if (close(fd) == -1) {
-		perror(device);
-		fatal(_("error closing %s"), device);
-	}
+	if (close(fd) < 0)
+		err(EXIT_FAILURE, _("error closing %s"), device);

-	return 0;
+	return EXIT_SUCCESS;
 }

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

^ permalink raw reply related

* `fsck -A` and fs-specific options
From: Mike Frysinger @ 2011-07-12  2:59 UTC (permalink / raw)
  To: util-linux

[-- Attachment #1: Type: text/plain, Size: 1213 bytes --]

ive got some "interesting" bugs here when using the `fsck -A` helper.  
consider file systems that have unique mount options that sometimes the fsck 
program also needs to know about.  for mounting, this isnt a problem as the 
options are stored in /etc/fstab and `mount` will extract the options field 
and pass it along.  but what about fsck ?

for example, some journaling file systems allow the journal to be stored 
separately.  reiserfs has the "jdev=" mount option and the "--journal" fsck 
option.  ext[34] have the "journal_dev=" mount option and the "-j" fsck 
option.

another example is with loop mounts that take an offset.  fsck cannot operate 
on the loop source as the start of the file is not the image.  it needs to 
first setup the loop with the offset, and then do the fsck on the loop point.
	/tmp/foo.img /mnt/tmp ext3 loop,offset=10000

i could code up some crap in the Gentoo init scripts to take care of this, but 
if we handled it in util-linux, everyone would get this for free.  seems like 
we need to add a per-filesystem-type lists that track the mount option (so we 
can extract it from /etc/fstab) and how to translate it into the related fsck 
option.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* [git pull] fdformat fixes
From: Sami Kerola @ 2011-07-11 17:05 UTC (permalink / raw)
  To: util-linux

The following changes since commit 365acc97654d33a01698ada9bf18fbbdce7d88cc:

  fdisk: use a single variable for the current disklabel (2011-07-11
12:01:42 +0200)

are available in the git repository at:
  https://github.com/kerolasa/lelux-utiliteetit fdformat

Sami Kerola (7):
      fdformat: use libc error printing facilities
      fdformat: use long options
      fdformat: integer comparisons & unused parameter
      fdformat: use xalloc.h
      fdformat: include-what-you-use header check
      fdformat: coding style
      docs: add long options to fdformat.8

 disk-utils/fdformat.8 |   18 ++--
 disk-utils/fdformat.c |  253 ++++++++++++++++++++++++++-----------------------
 2 files changed, 147 insertions(+), 124 deletions(-)

diff --git a/disk-utils/fdformat.8 b/disk-utils/fdformat.8
index 7b6e262..0fa9e8d 100644
--- a/disk-utils/fdformat.8
+++ b/disk-utils/fdformat.8
@@ -1,12 +1,11 @@
 .\" Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
 .\" May be distributed under the GNU General Public License
-.TH FDFORMAT 8 "1 February 1993" "Linux 0.99" "Linux Programmer's Manual"
+.TH FDFORMAT "8" "July 2011" "util-linux" "System Administration Utilities"
 .SH NAME
 fdformat \- Low-level formats a floppy disk
 .SH SYNOPSIS
 .B fdformat
-.RB [ \-n ]
-.I device
+[\fIoptions\fR] \fIdevice\fR
 .SH DESCRIPTION
 .B fdformat
 does a low level format on a floppy disk.
@@ -25,7 +24,7 @@ minor is shown for informational purposes only):
 /dev/fd0h360  (minor = 20)
 /dev/fd0h720  (minor = 24)
 /dev/fd0H1440 (minor = 28)
-
+.PP
 /dev/fd1d360  (minor = 5)
 /dev/fd1h1200 (minor = 9)
 /dev/fd1D360  (minor = 13)
@@ -37,19 +36,24 @@ minor is shown for informational purposes only):
 /dev/fd1H1440 (minor = 29)
 .RE
 .fi
-
+.PP
 The generic floppy devices, /dev/fd0 and /dev/fd1, will fail to work with
 .B fdformat
 when a non-standard format is being used, or if the format has not been
 autodetected earlier.  In this case, use
 .BR setfdprm (8)
 to load the disk parameters.
-
 .SH OPTIONS
 .TP
-.B \-n
+\fB\-n\fR, \fB\-\-no\-verify\fR
 No verify.  This option will disable the verification that is performed
 after the format.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Output version information and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help and exit.
 .SH "SEE ALSO"
 .BR fd (4),
 .BR setfdprm (8),
diff --git a/disk-utils/fdformat.c b/disk-utils/fdformat.c
index 4bbb574..d1d8146 100644
--- a/disk-utils/fdformat.c
+++ b/disk-utils/fdformat.c
@@ -6,147 +6,166 @@
  & - more i18n/nls translatable strings marked
  */

-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
 #include <errno.h>
-#include <unistd.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <linux/fd.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <linux/fd.h>
+#include <sys/stat.h>
+#include <unistd.h>

+#include "c.h"
 #include "nls.h"
+#include "xalloc.h"

 struct floppy_struct param;

 #define SECTOR_SIZE 512
-#define PERROR(msg) { perror(msg); exit(1); }

-static void format_disk(int ctrl, char *name)
+static void format_disk(int ctrl)
 {
-    struct format_descr descr;
-    int track;
-
-    printf(_("Formatting ... "));
-    fflush(stdout);
-    if (ioctl(ctrl,FDFMTBEG,NULL) < 0) PERROR("\nioctl(FDFMTBEG)");
-    for (track = 0; track < param.track; track++) {
-	descr.track = track;
-	descr.head = 0;
-	if (ioctl(ctrl,FDFMTTRK,(long) &descr) < 0)
-	  PERROR("\nioctl(FDFMTTRK)");
-
-	printf("%3d\b\b\b",track);
+	struct format_descr descr;
+	unsigned int track;
+
+	printf(_("Formatting ... "));
 	fflush(stdout);
-	if (param.head == 2) {
-	    descr.head = 1;
-	    if (ioctl(ctrl,FDFMTTRK,(long) &descr) < 0)
-	      PERROR("\nioctl(FDFMTTRK)");
+	if (ioctl(ctrl, FDFMTBEG, NULL) < 0)
+		err(EXIT_FAILURE, "\nioctl(FDFMTBEG)");
+	for (track = 0; track < param.track; track++) {
+		descr.track = track;
+		descr.head = 0;
+		if (ioctl(ctrl, FDFMTTRK, (long)&descr) < 0)
+			err(EXIT_FAILURE, "\nioctl(FDFMTTRK)");
+
+		printf("%3d\b\b\b", track);
+		fflush(stdout);
+		if (param.head == 2) {
+			descr.head = 1;
+			if (ioctl(ctrl, FDFMTTRK, (long)&descr) < 0)
+				err(EXIT_FAILURE, "\nioctl(FDFMTTRK)");
+		}
 	}
-    }
-    if (ioctl(ctrl,FDFMTEND,NULL) < 0) PERROR("\nioctl(FDFMTEND)");
-    printf(_("done\n"));
+	if (ioctl(ctrl, FDFMTEND, NULL) < 0)
+		err(EXIT_FAILURE, "\nioctl(FDFMTEND)");
+	printf(_("done\n"));
 }

-
 static void verify_disk(char *name)
 {
-    unsigned char *data;
-    int fd,cyl_size,cyl,count;
-
-    cyl_size = param.sect*param.head*512;
-    if ((data = (unsigned char *) malloc(cyl_size)) == NULL) PERROR("malloc");
-    printf(_("Verifying ... "));
-    fflush(stdout);
-    if ((fd = open(name,O_RDONLY)) < 0) PERROR(name);
-    for (cyl = 0; cyl < param.track; cyl++) {
-	int read_bytes;
-
-	printf("%3d\b\b\b",cyl);
+	unsigned char *data;
+	unsigned int cyl;
+	int fd, cyl_size, count;
+
+	cyl_size = param.sect * param.head * 512;
+	data = xmalloc(cyl_size);
+	printf(_("Verifying ... "));
 	fflush(stdout);
-	read_bytes = read(fd,data,cyl_size);
-	if(read_bytes != cyl_size) {
-	    if(read_bytes < 0)
-		    perror(_("Read: "));
-	    fprintf(stderr,
-		    _("Problem reading cylinder %d, expected %d, read %d\n"),
-		    cyl, cyl_size, read_bytes);
-	    free(data);
-	    exit(1);
-	}
-	for (count = 0; count < cyl_size; count++)
-	    if (data[count] != FD_FILL_BYTE) {
-		printf(_("bad data in cyl %d\nContinuing ... "),cyl);
+	if ((fd = open(name, O_RDONLY)) < 0)
+		err(EXIT_FAILURE, _("cannot open file %s"), name);
+	for (cyl = 0; cyl < param.track; cyl++) {
+		int read_bytes;
+
+		printf("%3d\b\b\b", cyl);
 		fflush(stdout);
-		break;
-	    }
-    }
-    free(data);
-    printf(_("done\n"));
-    if (close(fd) < 0) PERROR("close");
+		read_bytes = read(fd, data, cyl_size);
+		if (read_bytes != cyl_size) {
+			if (read_bytes < 0)
+				perror(_("Read: "));
+			fprintf(stderr,
+				_("Problem reading cylinder %d,"
+				  " expected %d, read %d\n"),
+				cyl, cyl_size, read_bytes);
+			free(data);
+			exit(EXIT_FAILURE);
+		}
+		for (count = 0; count < cyl_size; count++)
+			if (data[count] != FD_FILL_BYTE) {
+				printf(_("bad data in cyl %d\n"
+					 "Continuing ... "), cyl);
+				fflush(stdout);
+				break;
+			}
+	}
+	free(data);
+	printf(_("done\n"));
+	if (close(fd) < 0)
+		err(EXIT_FAILURE, "close");
 }

-
-static void usage(char *name)
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
-    char *this;
+	fprintf(out, _("Usage: %s [options] device\n"),
+		program_invocation_short_name);

-    if ((this = strrchr(name,'/')) != NULL) name = this+1;
-    fprintf(stderr,_("usage: %s [ -n ] device\n"),name);
-    exit(1);
-}
+	fprintf(out, _("\nOptions:\n"
+		       " -n, --no-verify  disable the verification after the format\n"
+		       " -V, --version    output version information and exit\n"
+		       " -h, --help       display this help and exit\n\n"));

+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}

-int main(int argc,char **argv)
+int main(int argc, char **argv)
 {
-    int ctrl;
-    int verify;
-    struct stat st;
-    char *progname, *p;
-
-    progname = argv[0];
-    if ((p = strrchr(progname, '/')) != NULL)
-	    progname = p+1;
-
-    setlocale(LC_ALL, "");
-    bindtextdomain(PACKAGE, LOCALEDIR);
-    textdomain(PACKAGE);
-
-    if (argc == 2 &&
-	(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
-	    printf(_("%s (%s)\n"), progname, PACKAGE_STRING);
-	    exit(0);
-    }
-
-    verify = 1;
-    if (argc > 1 && argv[1][0] == '-') {
-	if (argv[1][1] != 'n') usage(progname);
-	verify = 0;
-	argc--;
-	argv++;
-    }
-    if (argc != 2) usage(progname);
-    if (stat(argv[1],&st) < 0) PERROR(argv[1]);
-    if (!S_ISBLK(st.st_mode)) {
-	fprintf(stderr,_("%s: not a block device\n"),argv[1]);
-	exit(1);
-	/* do not test major - perhaps this was an USB floppy */
-    }
-    if (access(argv[1],W_OK) < 0) PERROR(argv[1]);
-
-    ctrl = open(argv[1],O_WRONLY);
-    if (ctrl < 0)
-	    PERROR(argv[1]);
-    if (ioctl(ctrl,FDGETPRM,(long) &param) < 0)
-	    PERROR(_("Could not determine current format type"));
-    printf(_("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n"),
-	   (param.head == 2) ? _("Double") : _("Single"),
-	   param.track, param.sect,param.size >> 1);
-    format_disk(ctrl, argv[1]);
-    close(ctrl);
-
-    if (verify)
-	    verify_disk(argv[1]);
-    return 0;
+	int ch;
+	int ctrl;
+	int verify;
+	struct stat st;
+
+	static const struct option longopts[] = {
+		{"no-verify", no_argument, NULL, 'n'},
+		{"version", no_argument, NULL, 'V'},
+		{"help", no_argument, NULL, 'h'},
+		{NULL, 0, NULL, 0}
+	};
+
+	setlocale(LC_ALL, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+
+	while ((ch = getopt_long(argc, argv, "nVh", longopts, NULL)) != -1)
+		switch (ch) {
+		case 'n':
+			verify = 0;
+			break;
+		case 'V':
+			printf(_("%s from %s\n"), program_invocation_short_name,
+			       PACKAGE_STRING);
+			exit(EXIT_SUCCESS);
+		case 'h':
+			usage(stdout);
+		default:
+			usage(stderr);
+		}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc < 1)
+		usage(stderr);
+	if (stat(argv[0], &st) < 0)
+		err(EXIT_FAILURE, _("cannot stat file %s"), argv[0]);
+	if (!S_ISBLK(st.st_mode))
+		/* do not test major - perhaps this was an USB floppy */
+		errx(EXIT_FAILURE, _("%s: not a block device"), argv[0]);
+	if (access(argv[0], W_OK) < 0)
+		err(EXIT_FAILURE, _("cannot access file %s"), argv[0]);
+
+	ctrl = open(argv[0], O_WRONLY);
+	if (ctrl < 0)
+		err(EXIT_FAILURE, _("cannot open file %s"), argv[0]);
+	if (ioctl(ctrl, FDGETPRM, (long)&param) < 0)
+		err(EXIT_FAILURE, _("Could not determine current format type"));
+
+	printf(_("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n"),
+	       (param.head == 2) ? _("Double") : _("Single"),
+	       param.track, param.sect, param.size >> 1);
+	format_disk(ctrl);
+	close(ctrl);
+
+	if (verify)
+		verify_disk(argv[0]);
+	return EXIT_SUCCESS;
 }

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

^ permalink raw reply related

* Re: [PATCH] evstate: new utility for querying evdev key/switch/event state
From: Daniel Drake @ 2011-07-11 16:48 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Karel Zak, util-linux, pgf, Kay Sievers, linux-input
In-Reply-To: <20110711163917.GA1648@core.coreip.homeip.net>

On 11 July 2011 17:39, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> Now I'd say that this utility probably better fit into linuxconsole
> project with the rest of input-related utilities...

http://sourceforge.net/projects/linuxconsole/ ?

This must have been what you were referring to before. Yes, this looks
like a more appropriate home. I'll take it in that direction.

Thanks,
Daniel

^ permalink raw reply

* Re: [PATCH] evstate: new utility for querying evdev key/switch/event state
From: Dmitry Torokhov @ 2011-07-11 16:39 UTC (permalink / raw)
  To: Karel Zak; +Cc: Daniel Drake, util-linux, pgf, Kay Sievers
In-Reply-To: <20110711121836.GJ5214@nb.net.home>

On Mon, Jul 11, 2011 at 02:18:36PM +0200, Karel Zak wrote:
> On Sat, Jul 09, 2011 at 02:20:46PM +0100, Daniel Drake wrote:
> > evstate is a small utility that queries evdev state of a specific
> > key, switch, button, LED or sound event. This is useful in programs
> > such as powerd (http://wiki.laptop.org/go/Powerd) which need to query
> > things like the state of the laptop lid switch from shell code.
> > 
> > Our earlier non-upstream approach to this was to add sysfs nodes that
> > would indicate button state, but Dmitry Torokhov is against seeing those
> > in the upstream kernel as it is duplicating info from the input layer:
> 
> Sounds too crazy...
> 
> The duplication is normal (see for example block devices). There is
> many places where we have the same information accessible by ioctl()
> as well as by sysfs.

Sometimes it makes sense to provide alternative way of accessing data;
however block devices do not export every block as a binary sysfs
attribute, do they? Same goes for input.

> 
> The sysfs is usually the preferred way, because it does not require root
> permissions to read the attributes and you can use standard file/text
> utils rather than any specialized ioctl wrappers.

Yep, that'd be great. "Look, ma, I can see what root is typing..."

> 
> > http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/1089
> 
> Wow, so you have already implemented a patch that exports the state
> in *human readable format* by sysfs. This patch was NACKed.

Yes, on the ground that it is not a good idea to sprinkle
driver-specific sysfs attributes all over the place when there is
already a generic way of accessing this data.

> 
> Now it's expected that everyone in userspace will use ioctl() (with
> root permissions?)

Yep, see above.

> and translate any crazy bit array to something
> human readable. Right? Really?

Right. Really.

Now I'd say that this utility probably better fit into linuxconsole
project with the rest of input-related utilities...

Thanks.

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH] evstate: new utility for querying evdev key/switch/event state
From: Daniel Drake @ 2011-07-11 13:14 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, pgf, dmitry.torokhov, Kay Sievers, linux-input
In-Reply-To: <CAGq3pz4smg1pJisnEpnFKKAcNMFyBjDVSSWrLA79O8JK+=AFQQ@mail.gmail.com>

+CC linux-input

On 11 July 2011 14:12, Daniel Drake <dsd@laptop.org> wrote:
> On 11 July 2011 13:18, Karel Zak <kzak@redhat.com> wrote:>
>>> http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/1089
>>
>> Wow, so you have already implemented a patch that exports the state
>> in *human readable format* by sysfs. This patch was NACKed.
>>
>> Now it's expected that everyone in userspace will use ioctl() (with
>> root permissions?) and translate any crazy bit array to something
>> human readable. Right? Really?
>
> Dmitry, what are your thoughts on this?
>
> To clarify, there are 4 different switches that we need to read the state of.
>
> 1. XO-1.5 lid switch, exposed via ACPI via normal acpi-button driver
> 2. XO-1.5 ebook switch, exposed via drivers/platform/x86/xo15-ebook.c
> 3. XO-1 lid switch, exposed via arch/x86/platform/olpc/olpc-xo1-sci.c
> (linux-next)
> 4. XO-1 ebook switch, exposed via
> arch/x86/platform/olpc/olpc-xo1-sci.c (linux-next)
>
> We'd like to do this from shell code, as root.

add 2 more to that list as well in the near future: we are currently
writing drivers for the lid and ebook switches on the ARM-based
XO-1.75 laptop currently in prototype stages.

Daniel

^ permalink raw reply

* Re: [PATCH] build-sys: fix spaces versus tabs conflict
From: Karel Zak @ 2011-07-11 13:12 UTC (permalink / raw)
  To: Marc-Antoine Perennou; +Cc: util-linux@vger.kernel.org
In-Reply-To: <1310388392.30860.1.camel@Lou.local>

On Mon, Jul 11, 2011 at 02:46:27PM +0200, Marc-Antoine Perennou wrote:
> For some reason, tabs were replaced by spaces in commit
> 73ae0d5be6e070afe83d1a2324ac79941629201e

 Ah... sorry. Fixed. Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH] evstate: new utility for querying evdev key/switch/event state
From: Daniel Drake @ 2011-07-11 13:12 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, pgf, dmitry.torokhov, Kay Sievers
In-Reply-To: <20110711121836.GJ5214@nb.net.home>

On 11 July 2011 13:18, Karel Zak <kzak@redhat.com> wrote:>
>> http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/1089
>
> Wow, so you have already implemented a patch that exports the state
> in *human readable format* by sysfs. This patch was NACKed.
>
> Now it's expected that everyone in userspace will use ioctl() (with
> root permissions?) and translate any crazy bit array to something
> human readable. Right? Really?

Dmitry, what are your thoughts on this?

To clarify, there are 4 different switches that we need to read the state of.

1. XO-1.5 lid switch, exposed via ACPI via normal acpi-button driver
2. XO-1.5 ebook switch, exposed via drivers/platform/x86/xo15-ebook.c
3. XO-1 lid switch, exposed via arch/x86/platform/olpc/olpc-xo1-sci.c
(linux-next)
4. XO-1 ebook switch, exposed via
arch/x86/platform/olpc/olpc-xo1-sci.c (linux-next)

We'd like to do this from shell code, as root.

Daniel

^ permalink raw reply

* [git pull] isosize fixes
From: Sami Kerola @ 2011-07-11 12:54 UTC (permalink / raw)
  To: util-linux

The following changes since commit 37b94458bd0f4a178233ad0366a727bf5bde879f:

  sfdisk: fix coding style. (2011-06-29 12:47:38 +0200)

are available in the git repository at:
  https://github.com/kerolasa/lelux-utiliteetit isosize

Sami Kerola (6):
      isosize: remove global variables
      isosize: use long options
      isosize: check user input to be numeric
      isosize: include-what-you-use header check
      isosize: fix coding style
      docs: isosize.8 add long options

 disk-utils/Makefile.am |    1 +
 disk-utils/isosize.8   |   16 ++--
 disk-utils/isosize.c   |  221 +++++++++++++++++++++++++-----------------------
 3 files changed, 122 insertions(+), 116 deletions(-)

diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index cf4a3e8..6b937bd 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -27,6 +27,7 @@ mkswap_SOURCES = mkswap.c $(utils_common)
$(top_srcdir)/lib/wholedisk.c $(top_sr
 mkswap_LDADD = $(uuid_ldadd)
 mkswap_CFLAGS = $(AM_CFLAGS) $(uuid_cflags)

+isosize_SOURCES = isosize.c $(top_srcdir)/lib/strutils.c
 usrbin_exec_PROGRAMS = isosize
 usrsbin_exec_PROGRAMS =

diff --git a/disk-utils/isosize.8 b/disk-utils/isosize.8
index ea878cf..160f8eb 100644
--- a/disk-utils/isosize.8
+++ b/disk-utils/isosize.8
@@ -1,12 +1,9 @@
-.TH ISOSIZE "8" "December 2000" "sg3_utils-0.91" SG_UTILS
+.TH ISOSIZE "8" "June 2011" "util-linux" "System Administration Utilities"
 .SH NAME
 isosize \- outputs the length of an iso9660 file system
 .SH SYNOPSIS
 .B isosize
-.RB [ \-x ]
-.RB [ \-d
-.IR <num> ]
-.IR <iso9660_image_file> ...
+[\fIoptions\fR] \fIiso9660_image_file\fR
 .SH DESCRIPTION
 .\" Add any additional description here
 .PP
@@ -15,19 +12,20 @@ is contained in given file. That file may be a
normal file or
 a block device (e.g. /dev/hdd or /dev/sr0). In the absence of
 any switches (or errors) it will output the size of the iso9660
 file system in bytes. This can now be a large number (>> 4 GB).
+.SH OPTIONS
 .TP
-.B \-x
+\fB\-x\fR, \fB\-\-sectors\fR
 output in humanly readable form the block count and the block
 size. Output uses the term "sectors" for "blocks".
 .TP
-.BI \-d\  <num>
+\fB\-d\fR, \fB\-\-divisor\fR=\fINUM\fR
 only has affect when
 .B \-x
 is not given. The number output (if no errors)
 is the iso9660 file size in bytes divided by
-.IR <num> .
+.IR NUM .
 So if
-.I <num>
+.I NUM
 is the block size then the output number will be the block count.
 .PP
 The size of the file (or block device) holding a iso9660 file
diff --git a/disk-utils/isosize.c b/disk-utils/isosize.c
index 2bdc74a..7bfa81d 100644
--- a/disk-utils/isosize.c
+++ b/disk-utils/isosize.c
@@ -23,132 +23,128 @@
 #include <getopt.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <string.h>
 #include <errno.h>

 #include "nls.h"
 #include "c.h"
+#include "strutils.h"

 #define ISODCL(from, to) (to - from + 1)

-int xflag;
-
-static int
-isonum_721 (unsigned char * p) {
-        return ((p[0] & 0xff)
-                | ((p[1] & 0xff) << 8));
+static int isonum_721(unsigned char *p)
+{
+	return ((p[0] & 0xff)
+		| ((p[1] & 0xff) << 8));
 }

-static int
-isonum_722 (unsigned char * p) {
-        return ((p[1] & 0xff)
-                | ((p[0] & 0xff) << 8));
+static int isonum_722(unsigned char *p)
+{
+	return ((p[1] & 0xff)
+		| ((p[0] & 0xff) << 8));
 }

-static int
-isonum_723 (unsigned char * p) {
-        int le = isonum_721 (p);
-        int be = isonum_722 (p+2);
-        if (xflag && le != be)
+static int isonum_723(unsigned char *p, int xflag)
+{
+	int le = isonum_721(p);
+	int be = isonum_722(p + 2);
+	if (xflag && le != be)
 		/* translation is useless */
-                fprintf(stderr, "723error: le=%d be=%d\n", le, be);
-        return (le);
+		warnx("723error: le=%d be=%d", le, be);
+	return (le);
 }

-static int
-isonum_731 (unsigned char * p) {
-    return ((p[0] & 0xff)
-            | ((p[1] & 0xff) << 8)
-            | ((p[2] & 0xff) << 16)
-            | ((p[3] & 0xff) << 24));
+static int isonum_731(unsigned char *p)
+{
+	return ((p[0] & 0xff)
+		| ((p[1] & 0xff) << 8)
+		| ((p[2] & 0xff) << 16)
+		| ((p[3] & 0xff) << 24));
 }

-static int
-isonum_732 (unsigned char * p) {
-    return ((p[3] & 0xff)
-            | ((p[2] & 0xff) << 8)
-            | ((p[1] & 0xff) << 16)
-            | ((p[0] & 0xff) << 24));
+static int isonum_732(unsigned char *p)
+{
+	return ((p[3] & 0xff)
+		| ((p[2] & 0xff) << 8)
+		| ((p[1] & 0xff) << 16)
+		| ((p[0] & 0xff) << 24));
 }

-
-static int
-isonum_733 (unsigned char * p) {
-    int le = isonum_731 (p);
-    int be = isonum_732 (p+4);
-    if (xflag && le != be)
-	    /* translation is useless */
-            fprintf(stderr, "733error: le=%d be=%d\n", le, be);
-    return (le);
+static int isonum_733(unsigned char *p, int xflag)
+{
+	int le = isonum_731(p);
+	int be = isonum_732(p + 4);
+	if (xflag && le != be)
+		/* translation is useless */
+		warn("733error: le=%d be=%d", le, be);
+	return (le);
 }

-struct iso_primary_descriptor {
-    unsigned char type                      [ISODCL (  1,   1)]; /* 711 */
-    unsigned char id                        [ISODCL (  2,   6)];
-    unsigned char version                   [ISODCL (  7,   7)]; /* 711 */
-    unsigned char unused1                   [ISODCL (  8,   8)];
-    unsigned char system_id                 [ISODCL (  9,  40)]; /* auchars */
-    unsigned char volume_id                 [ISODCL ( 41,  72)]; /* duchars */
-    unsigned char unused2                   [ISODCL ( 73,  80)];
-    unsigned char volume_space_size         [ISODCL ( 81,  88)]; /* 733 */
-    unsigned char unused3                   [ISODCL ( 89, 120)];
-    unsigned char volume_set_size           [ISODCL (121, 124)]; /* 723 */
-    unsigned char volume_sequence_number    [ISODCL (125, 128)]; /* 723 */
-    unsigned char logical_block_size        [ISODCL (129, 132)]; /* 723 */
-    unsigned char path_table_size           [ISODCL (133, 140)]; /* 733 */
-    unsigned char type_l_path_table         [ISODCL (141, 144)]; /* 731 */
-    unsigned char opt_type_l_path_table     [ISODCL (145, 148)]; /* 731 */
-    unsigned char type_m_path_table         [ISODCL (149, 152)]; /* 732 */
-    unsigned char opt_type_m_path_table     [ISODCL (153, 156)]; /* 732 */
-    unsigned char root_directory_record     [ISODCL (157, 190)]; /* 9.1 */
-    unsigned char volume_set_id             [ISODCL (191, 318)]; /* duchars */
-    unsigned char publisher_id              [ISODCL (319, 446)]; /* achars */
-    unsigned char preparer_id               [ISODCL (447, 574)]; /* achars */
-    unsigned char application_id            [ISODCL (575, 702)]; /* achars */
-    unsigned char copyright_file_id         [ISODCL (703, 739)]; /*
7.5 dchars */
-    unsigned char abstract_file_id          [ISODCL (740, 776)]; /*
7.5 dchars */
-    unsigned char bibliographic_file_id     [ISODCL (777, 813)]; /*
7.5 dchars */
-    unsigned char creation_date             [ISODCL (814, 830)]; /* 8.4.26.1 */
-    unsigned char modification_date         [ISODCL (831, 847)]; /* 8.4.26.1 */
-    unsigned char expiration_date           [ISODCL (848, 864)]; /* 8.4.26.1 */
-    unsigned char effective_date            [ISODCL (865, 881)]; /* 8.4.26.1 */
-    unsigned char file_structure_version    [ISODCL (882, 882)]; /* 711 */
-    unsigned char unused4                   [ISODCL (883, 883)];
-    unsigned char application_data          [ISODCL (884, 1395)];
-    unsigned char unused5                   [ISODCL (1396, 2048)];
+struct iso_primary_descriptor
+{
+	unsigned char type			[ISODCL (   1,	  1)]; /* 711 */
+	unsigned char id			[ISODCL (   2,	  6)];
+	unsigned char version			[ISODCL (   7,	  7)]; /* 711 */
+	unsigned char unused1			[ISODCL (   8,	  8)];
+	unsigned char system_id			[ISODCL (   9,	 40)]; /* auchars */
+	unsigned char volume_id			[ISODCL (  41,	 72)]; /* duchars */
+	unsigned char unused2			[ISODCL (  73,	 80)];
+	unsigned char volume_space_size		[ISODCL (  81,	 88)]; /* 733 */
+	unsigned char unused3			[ISODCL (  89,	120)];
+	unsigned char volume_set_size		[ISODCL ( 121,	124)]; /* 723 */
+	unsigned char volume_sequence_number	[ISODCL ( 125,	128)]; /* 723 */
+	unsigned char logical_block_size	[ISODCL ( 129,	132)]; /* 723 */
+	unsigned char path_table_size		[ISODCL ( 133,	140)]; /* 733 */
+	unsigned char type_l_path_table		[ISODCL ( 141,	144)]; /* 731 */
+	unsigned char opt_type_l_path_table	[ISODCL ( 145,	148)]; /* 731 */
+	unsigned char type_m_path_table		[ISODCL ( 149,	152)]; /* 732 */
+	unsigned char opt_type_m_path_table	[ISODCL ( 153,	156)]; /* 732 */
+	unsigned char root_directory_record	[ISODCL ( 157,	190)]; /* 9.1 */
+	unsigned char volume_set_id		[ISODCL ( 191,	318)]; /* duchars */
+	unsigned char publisher_id		[ISODCL ( 319,	446)]; /* achars */
+	unsigned char preparer_id		[ISODCL ( 447,	574)]; /* achars */
+	unsigned char application_id		[ISODCL ( 575,	702)]; /* achars */
+	unsigned char copyright_file_id		[ISODCL ( 703,	739)]; /* 7.5 dchars */
+	unsigned char abstract_file_id		[ISODCL ( 740,	776)]; /* 7.5 dchars */
+	unsigned char bibliographic_file_id	[ISODCL ( 777,	813)]; /* 7.5 dchars */
+	unsigned char creation_date		[ISODCL ( 814,	830)]; /* 8.4.26.1 */
+	unsigned char modification_date		[ISODCL ( 831,	847)]; /* 8.4.26.1 */
+	unsigned char expiration_date		[ISODCL ( 848,	864)]; /* 8.4.26.1 */
+	unsigned char effective_date		[ISODCL ( 865,	881)]; /* 8.4.26.1 */
+	unsigned char file_structure_version	[ISODCL ( 882,	882)]; /* 711 */
+	unsigned char unused4			[ISODCL ( 883,	883)];
+	unsigned char application_data		[ISODCL ( 884, 1395)];
+	unsigned char unused5			[ISODCL (1396, 2048)];
 };

-int divisor = 0;
-
-static void
-isosize(char *filenamep) {
+static void isosize(char *filenamep, int xflag, long divisor)
+{
 	int fd, nsecs, ssize;
 	struct iso_primary_descriptor ipd;

 	if ((fd = open(filenamep, O_RDONLY)) < 0)
 		err(EXIT_FAILURE, _("failed to open %s"), filenamep);

-	if (lseek(fd, 16 << 11, 0) == (off_t)-1)
+	if (lseek(fd, 16 << 11, 0) == (off_t) - 1)
 		err(EXIT_FAILURE, _("seek error on %s"), filenamep);

 	if (read(fd, &ipd, sizeof(ipd)) < 0)
 		err(EXIT_FAILURE, _("read error on %s"), filenamep);

-	nsecs = isonum_733(ipd.volume_space_size);
-	ssize = isonum_723(ipd.logical_block_size); /* nowadays always 2048 */
+	nsecs = isonum_733(ipd.volume_space_size, xflag);
+	/* isonum_723 returns nowadays always 2048 */
+	ssize = isonum_723(ipd.logical_block_size, xflag);

 	if (xflag) {
-		printf (_("sector count: %d, sector size: %d\n"),
-			nsecs, ssize);
+		printf(_("sector count: %d, sector size: %d\n"), nsecs, ssize);
 	} else {
 		long long product = nsecs;

 		if (divisor == 0)
-			printf ("%lld\n", product * ssize);
+			printf("%lld\n", product * ssize);
 		else if (divisor == ssize)
-			printf ("%d\n", nsecs);
+			printf("%d\n", nsecs);
 		else
-			printf ("%lld\n", (product * ssize) / divisor);
+			printf("%lld\n", (product * ssize) / divisor);
 	}

 	close(fd);
@@ -156,55 +152,66 @@ isosize(char *filenamep) {

 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
-	fprintf(out, _("Usage: %s [-x] [-d <num>] iso9660-image\n"),
+	fprintf(out, _("\nUsage:\n"
+		       " %s [options] iso9660_image_file\n"),
 		program_invocation_short_name);

+	fprintf(out, _("\nOptions:\n"
+		       " -d, --divisor=NUM      devide bytes NUM\n"
+		       " -x, --sectors          show sector count and size\n"
+		       " -V, --version          output version information and exit\n"
+		       " -H, --help             display this help and exit\n\n"));
+
 	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }

-int
-main(int argc, char * argv[]) {
-	int j, ct;
+int main(int argc, char **argv)
+{
+	int j, ct, opt, xflag = 0;
+	long divisor = 0;
+
+	static const struct option longopts[] = {
+		{"divisor", no_argument, 0, 'd'},
+		{"sectors", no_argument, 0, 'x'},
+		{"version", no_argument, 0, 'V'},
+		{"help", no_argument, 0, 'h'},
+		{NULL, 0, 0, 0}
+	};

 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);

-	if (argc >= 2 &&
-	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
-		printf(_("%s (%s)\n"), program_invocation_short_name, PACKAGE_STRING);
-		return EXIT_SUCCESS;
-	}
-
-	for (;;) {
-		int opt;
-
-		opt = getopt(argc, argv, "xd:");
-		if (opt == -1)
-			break;
+	while ((opt = getopt_long(argc, argv, "d:xVh", longopts, NULL)) != -1)
 		switch (opt) {
 		case 'd':
-			divisor = atoi(optarg);
+			divisor =
+			    strtol_or_err(optarg,
+					  _("invalid divisor argument"));
 			break;
 		case 'x':
 			xflag = 1;
 			break;
+		case 'V':
+			printf(_("%s (%s)\n"), program_invocation_short_name,
+			       PACKAGE_STRING);
+			return EXIT_SUCCESS;
+		case 'h':
+			usage(stdout);
 		default:
 			usage(stderr);
 		}
-	}

 	ct = argc - optind;

-	if (ct <= 0) {
+	if (ct <= 0)
 		usage(stderr);
-	}

 	for (j = optind; j < argc; j++) {
 		if (ct > 1)
 			printf("%s: ", argv[j]);
-		isosize(argv[j]);
+		isosize(argv[j], xflag, divisor);
 	}

-	return 0;
+	return EXIT_SUCCESS;
 }

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

^ permalink raw reply related

* [PATCH] build-sys: fix spaces versus tabs conflict
From: Marc-Antoine Perennou @ 2011-07-11 12:46 UTC (permalink / raw)
  To: util-linux@vger.kernel.org

For some reason, tabs were replaced by spaces in commit
73ae0d5be6e070afe83d1a2324ac79941629201e

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
---
 term-utils/Makefile.am |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/term-utils/Makefile.am b/term-utils/Makefile.am
index 5013898..7b545c3 100644
--- a/term-utils/Makefile.am
+++ b/term-utils/Makefile.am
@@ -68,12 +68,12 @@ if USE_TTY_GROUP
 if MAKEINSTALL_DO_CHOWN
 install-exec-hook::
 if BUILD_WALL
-       chgrp tty $(DESTDIR)$(usrbin_execdir)/wall
-       chmod g+s $(DESTDIR)$(usrbin_execdir)/wall
+	chgrp tty $(DESTDIR)$(usrbin_execdir)/wall
+	chmod g+s $(DESTDIR)$(usrbin_execdir)/wall
 endif
 if BUILD_WRITE
-       chgrp tty $(DESTDIR)$(usrbin_execdir)/write
-       chmod g+s $(DESTDIR)$(usrbin_execdir)/write
+	chgrp tty $(DESTDIR)$(usrbin_execdir)/write
+	chmod g+s $(DESTDIR)$(usrbin_execdir)/write
 endif
 endif
 endif
-- 
1.7.6.134.gcf13f6.dirty



^ permalink raw reply related

* Re: [PATCH] evstate: new utility for querying evdev key/switch/event state
From: Karel Zak @ 2011-07-11 12:18 UTC (permalink / raw)
  To: Daniel Drake; +Cc: util-linux, pgf, dmitry.torokhov, Kay Sievers
In-Reply-To: <20110709132046.90A119D401C@zog.reactivated.net>

On Sat, Jul 09, 2011 at 02:20:46PM +0100, Daniel Drake wrote:
> evstate is a small utility that queries evdev state of a specific
> key, switch, button, LED or sound event. This is useful in programs
> such as powerd (http://wiki.laptop.org/go/Powerd) which need to query
> things like the state of the laptop lid switch from shell code.
> 
> Our earlier non-upstream approach to this was to add sysfs nodes that
> would indicate button state, but Dmitry Torokhov is against seeing those
> in the upstream kernel as it is duplicating info from the input layer:

Sounds too crazy...

The duplication is normal (see for example block devices). There is
many places where we have the same information accessible by ioctl()
as well as by sysfs.

The sysfs is usually the preferred way, because it does not require root
permissions to read the attributes and you can use standard file/text
utils rather than any specialized ioctl wrappers.

> http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/1089

Wow, so you have already implemented a patch that exports the state
in *human readable format* by sysfs. This patch was NACKed.

Now it's expected that everyone in userspace will use ioctl() (with
root permissions?) and translate any crazy bit array to something
human readable. Right? Really?

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH] Fix double free in mount.c with SELinux enabled
From: Karel Zak @ 2011-07-11 11:05 UTC (permalink / raw)
  To: Kirill Elagin; +Cc: util-linux
In-Reply-To: <CABVT_gfBiyqfbmDNB9aPiMAWsFLFwn64WhuJi=EA0-oy3cnsTQ@mail.gmail.com>

On Wed, Jul 06, 2011 at 01:50:37AM +0400, Kirill Elagin wrote:
>  mount/mount.c |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)

Applied, thanks!

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH] lscpu: add support for books
From: Karel Zak @ 2011-07-11 10:40 UTC (permalink / raw)
  To: Heiko Carstens; +Cc: util-linux
In-Reply-To: <20110705112909.GA3450@osiris.boeblingen.de.ibm.com>

On Tue, Jul 05, 2011 at 01:29:10PM +0200, Heiko Carstens wrote:
> This patch adds support for books in cpu topology output. 

 Thanks!

> Please note that I assume that other programs that get fed by the
> output of lscpu actually parse the last comment line and react in a
> sane way if new entries appear in the cpu list.

 Never assume anything :-)

> Also the readable output is changed from
> "CPU socket(s):" to "Socket(s) per book:" or simply "Socket(s):" in the
> absence of books.

 You're right, the "Socket(s)" is probably better. Unfortunately it's
 not backwardly compatible (for people who use "lscpu | grep ..."), so
 I'll add a note to the ReleaseNotes...

> @@ -732,7 +750,7 @@ print_parsable(struct lscpu_desc *desc)
>  	"# The following is the parsable format, which can be fed to other\n"
>  	"# programs. Each different item in every column has an unique ID\n"
>  	"# starting from zero.\n"
> -	"# CPU,Core,Socket,Node"));
> +	"# CPU,Core,Socket,Book,Node"));

 It would be better to use

    # CPU,Core,Socket,Node,Book

 to keep it usable for stupid scripts where the header is not parsed.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH] Fix install-exec-hook to check whether wall and write were built
From: Karel Zak @ 2011-07-11 10:04 UTC (permalink / raw)
  To: Kirill Elagin; +Cc: util-linux
In-Reply-To: <CABVT_geJbR477C0OBrT1_Mn+iz0sUEE7mLuG56JytoF15uMHTg@mail.gmail.com>

On Tue, Jul 05, 2011 at 09:13:51PM +0400, Kirill Elagin wrote:
> Signed-off-by: Kirill Elagin <kirelagin@gmail.com>
> ---
>  term-utils/Makefile.am |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)

 Thanks, but it seems already fixed by

 commit 73ae0d5be6e070afe83d1a2324ac79941629201e
 Author: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH] fdisk: use a single variable for the current disklabel
From: Karel Zak @ 2011-07-11 10:02 UTC (permalink / raw)
  To: Francesco Cosoleto; +Cc: util-linux
In-Reply-To: <1309687281-6403-1-git-send-email-cosoleto@gmail.com>

On Sun, Jul 03, 2011 at 12:01:21PM +0200, Francesco Cosoleto wrote:
>  fdisk/fdisk.c         |  142 ++++++++++++++++++++++++-------------------------
>  fdisk/fdisk.h         |   15 ++++--
>  fdisk/fdiskaixlabel.c |    5 +--
>  fdisk/fdiskmaclabel.c |    5 +--
>  fdisk/fdisksgilabel.c |    6 +--
>  fdisk/fdisksunlabel.c |    4 +-
>  6 files changed, 85 insertions(+), 92 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH 0/6] Trivial documentation fixes
From: Karel Zak @ 2011-07-11 10:01 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux, lamont
In-Reply-To: <1309528305-12626-1-git-send-email-petr.uzel@suse.cz>

On Fri, Jul 01, 2011 at 03:51:39PM +0200, Petr Uzel wrote:
> Petr Uzel (6):
>   mount.8: fix reference to sharedsubtree documentation
>   mount.8: remove accidental extra word in ext4 documentation
>   mount.8: fix typo
>   mount.8: fix typo
>   mount: make the error message clear
>   mount.8: fix typos
> 
>  mount/mount.8 |   12 ++++++------
>  mount/mount.c |    2 +-
>  2 files changed, 7 insertions(+), 7 deletions(-)

 All applied, thanks. 

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH] Don't try to chgrp write or wall if they are not built
From: Karel Zak @ 2011-07-11  9:54 UTC (permalink / raw)
  To: Marc-Antoine Perennou; +Cc: util-linux
In-Reply-To: <BANLkTikpHa-0aVp7G7cpRw_ePOQQiuXSEYnrV-AgssjhFEf2zg@mail.gmail.com>

On Thu, Jun 30, 2011 at 02:26:32AM +0200, Marc-Antoine Perennou wrote:
>  term-utils/Makefile.am |   10 ++++++++--
>  1 files changed, 8 insertions(+), 2 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [git pull] blockdev fixes
From: Karel Zak @ 2011-07-11  9:46 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux
In-Reply-To: <BANLkTikQsgSXBs4kybTvF0QvDDvbMub5hg@mail.gmail.com>

On Thu, Jun 30, 2011 at 11:38:31AM +0200, Sami Kerola wrote:
> The following changes since commit 37b94458bd0f4a178233ad0366a727bf5bde879f:
> 
>   sfdisk: fix coding style. (2011-06-29 12:47:38 +0200)
> 
> are available in the git repository at:
>   https://github.com/kerolasa/lelux-utiliteetit blockdev
> 
> Sami Kerola (8):
>       blockdev: set options read only
>       blockdev: remove progname
>       blockdev: add --help option
>       blockdev: use libc error facilities
>       blockdev: use pathnames.h to find partitions
>       blockdev: broken compiler warning circumvention removed
>       blockdev: type mismatch fix
>       blockdev: coding style fix
> 
>  disk-utils/blockdev.c |  158 +++++++++++++++++++++---------------------------
>  1 files changed, 69 insertions(+), 89 deletions(-)

 Merged, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH 3/3] mkfs.minix: document -3 option
From: Karel Zak @ 2011-07-11  8:51 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1309368497.3162.5.camel@offbook>

On Wed, Jun 29, 2011 at 01:28:17PM -0400, Davidlohr Bueso wrote:
>  disk-utils/mkfs.minix.8 |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH 2/3] mkfs.minix: add minix v3 support
From: Karel Zak @ 2011-07-11  8:51 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1309368495.3162.4.camel@offbook>

On Wed, Jun 29, 2011 at 01:28:15PM -0400, Davidlohr Bueso wrote:
>  disk-utils/Makefile.am  |    2 +-
>  disk-utils/mkfs.minix.c |  142 ++++++++++++++++++++++++++++++++++++-----------
>  2 files changed, 110 insertions(+), 34 deletions(-)

 Applied with some changes, thanks.

> +static int *super_set_state_ptr(void)
> +{
> +	switch (fs_version) {
> +	case 3:
> +		Super3.s_state |= MINIX_VALID_FS;
> +		Super3.s_state &= ~MINIX_ERROR_FS;
> +		break;
> +	default:
> +		Super.s_state |= MINIX_VALID_FS;
> +		Super.s_state &= ~MINIX_ERROR_FS;
> +		break;
> +	}

[...]

> +	int *state = super_set_state_ptr();

 This does not make sense. The function does not return anything and
 the 'int *state' is not used. Fixed (but not tested), see the git
 repository.

 It would be nice to have tests/ts/minix/mkfs-v{2,3} ;-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [PATCH 1/3] minix: add version 3 layout
From: Karel Zak @ 2011-07-11  8:47 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1309368493.3162.3.camel@offbook>

On Wed, Jun 29, 2011 at 01:28:13PM -0400, Davidlohr Bueso wrote:
>  disk-utils/minix.h |   83 +++++++++++++++++++++++++++++++++++++++++++++-------
>  1 files changed, 72 insertions(+), 11 deletions(-)

 Applied, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* Re: [git pull] mkfs fixes
From: Karel Zak @ 2011-07-11  8:25 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux
In-Reply-To: <BANLkTikVaACBzs+Y7kKjn-L=RefF=xehgw@mail.gmail.com>

On Wed, Jun 29, 2011 at 02:03:28PM +0200, Sami Kerola wrote:
> The following changes since commit 37b94458bd0f4a178233ad0366a727bf5bde879f:
> 
>   sfdisk: fix coding style. (2011-06-29 12:47:38 +0200)
> 
> are available in the git repository at:
>   https://github.com/kerolasa/lelux-utiliteetit mkfs

 Merged, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply

* [PATCH] evstate: new utility for querying evdev key/switch/event state
From: Daniel Drake @ 2011-07-09 13:20 UTC (permalink / raw)
  To: util-linux; +Cc: pgf, dmitry.torokhov

evstate is a small utility that queries evdev state of a specific
key, switch, button, LED or sound event. This is useful in programs
such as powerd (http://wiki.laptop.org/go/Powerd) which need to query
things like the state of the laptop lid switch from shell code.

Our earlier non-upstream approach to this was to add sysfs nodes that
would indicate button state, but Dmitry Torokhov is against seeing those
in the upstream kernel as it is duplicating info from the input layer:

http://article.gmane.org/gmane.linux.drivers.platform.x86.devel/1089

	No, instead of adding yet another kernel attribute just use ioctl
	to get current switch state. Or write a general purpose utility to
	query switch/key state - many people have asked for it ;)

Here is that general purpose utility that many people are asking for :)

Signed-off-by: Daniel Drake <dsd@laptop.org>
---
 configure.ac           |    7 +++
 misc-utils/.gitignore  |    1 +
 misc-utils/Makefile.am |    5 ++
 misc-utils/evstate.1   |   43 +++++++++++++++++
 misc-utils/evstate.c   |  123 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 179 insertions(+), 0 deletions(-)
 create mode 100644 misc-utils/evstate.1
 create mode 100644 misc-utils/evstate.c

diff --git a/configure.ac b/configure.ac
index a02b5e3..a031369 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1027,6 +1027,13 @@ AC_ARG_ENABLE([reset],
 AM_CONDITIONAL(BUILD_RESET, test "x$enable_reset" = xyes)
 
 
+AC_ARG_ENABLE([evstate],
+  AS_HELP_STRING([--enable-evstate], [build evstate]),
+  [], enable_evstate=yes
+)
+AM_CONDITIONAL(BUILD_EVSTATE, test "x$enable_evstate" = xyes)
+
+
 AC_ARG_ENABLE([login-utils],
   AS_HELP_STRING([--enable-login-utils], [build chfn, chsh, login, newgrp, vipw]),
   [], enable_login_utils=no
diff --git a/misc-utils/.gitignore b/misc-utils/.gitignore
index 897e6d1..13f0fdd 100644
--- a/misc-utils/.gitignore
+++ b/misc-utils/.gitignore
@@ -17,3 +17,4 @@ blkid
 wipefs
 findmnt
 lsblk
+evstate
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am
index 0644373..28cb034 100644
--- a/misc-utils/Makefile.am
+++ b/misc-utils/Makefile.am
@@ -115,3 +115,8 @@ if BUILD_RENAME
 usrbin_exec_PROGRAMS += rename
 dist_man_MANS += rename.1
 endif
+
+if BUILD_EVSTATE
+usrbin_exec_PROGRAMS += evstate
+dist_man_MANS += evstate.1
+endif
diff --git a/misc-utils/evstate.1 b/misc-utils/evstate.1
new file mode 100644
index 0000000..664b3b5
--- /dev/null
+++ b/misc-utils/evstate.1
@@ -0,0 +1,43 @@
+.\" -*- nroff -*-
+.TH EVSTATE 1 "Jul 2011" "Version 1.0"
+.SH NAME
+evstate \- query evdev key/LED/switch/sound state
+.SH SYNOPSIS
+.B evstate
+.IR device
+.IR mode
+.IR key
+.SH DESCRIPTION
+.B evstate
+queries the state of a Linux evdev key/button, LED, switch or sound status.
+.PP
+Ordinarily, no textual output is produced.
+.B evstate
+returns exit code 1 if the state bit is set (key pressed, LED on, etc.),
+or exit code 0 if the state bit is unset.
+.PP
+.I device
+is the evdev device node of the input device you wish to query, such
+as /dev/input/event0.
+.PP
+.I mode
+is one of key, led, snd, or sw.
+.PP
+.I key
+is the index of the key/switch/event you wish to query in integer form
+(see <linux/input.h> for values).
+.SH EXAMPLE
+Given /dev/input/event0 as the input device of my laptop dock switch, the
+following command will determine if the laptop is plugged into dock (SW_DOCK).
+.RS
+.PP
+.nf
+evstate /dev/input/event0 sw 5
+.fi
+.SH AUTHOR
+.nf
+Daniel Drake <dsd@laptop.org>
+.fi
+.SH AVAILABILITY
+The evstate command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/evstate.c b/misc-utils/evstate.c
new file mode 100644
index 0000000..b42019e
--- /dev/null
+++ b/misc-utils/evstate.c
@@ -0,0 +1,123 @@
+/*
+ * evstate: query evdev key/led/sw/snd state
+ * Returns exit code 1 if the state bit is set (key pressed, LED on, etc.),
+ * and 0 if the state bit is unset.
+ *
+ * Copyright (C) 2011 One Laptop per Child
+ * Written by Daniel Drake <dsd@laptop.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <linux/input.h>
+
+#include "nls.h"
+
+#define BITS_PER_LONG (sizeof(long) * 8)
+
+static int test_bit(unsigned int nr, void *addr)
+{
+	return ((1UL << (nr % BITS_PER_LONG)) &
+		(((unsigned long *) addr)[nr / BITS_PER_LONG])) != 0;
+}
+
+static void __attribute__((noreturn)) usage(void)
+{
+	fprintf(stderr, _("Usage: %s <device> <mode> <key>\n"),
+			program_invocation_short_name);
+	fprintf(stderr, _("Valid modes: key, led, snd, sw\n"));
+	exit(2);
+}
+
+static const struct mode {
+	const char *name;
+	int max;
+	int rq;
+} requests[] = {
+	{ "key", KEY_MAX, EVIOCGKEY(KEY_MAX) },
+	{ "led", LED_MAX, EVIOCGLED(LED_MAX) },
+	{ "snd", SND_MAX, EVIOCGSND(SND_MAX) },
+	{ "sw",  SW_MAX, EVIOCGSW(SW_MAX) },
+};
+
+static const struct mode *find_mode(const char *name)
+{
+	int i;
+	for (i = 0; i < sizeof(requests) / sizeof(*requests); i++) {
+		const struct mode *mode = &requests[i];
+		if (strcmp(mode->name, name) == 0)
+			return mode;
+	}
+	return NULL;
+}
+
+static int query_state(const char *device, long int keyno,
+		       const struct mode *mode)
+{
+	uint8_t state[(mode->max / 8) + 1];
+	int fd;
+	int r;
+
+	if (keyno < 0 || keyno > mode->max) {
+		fprintf(stderr, _("Unrecognised key %d\n"), keyno);
+		exit(3);
+	}
+
+	fd = open(device, O_RDONLY);
+	if (fd == -1) {
+		perror("open");
+		exit(3);
+	}
+
+	memset(state, 0, sizeof(state));
+	r = ioctl(fd, mode->rq, state);
+	close(fd);
+
+	if (r == -1) {
+		perror("ioctl");
+		exit(3);
+	}
+
+	return test_bit(keyno, state);
+}
+
+int main(int argc, char **argv)
+{
+	const struct mode *mode;
+	long int keyno;
+
+	if (argc != 4)
+		usage();
+
+	mode = find_mode(argv[2]);
+	if (!mode) {
+		fprintf(stderr, _("Unrecognised mode.\n"));
+		usage();
+	}
+
+	keyno = strtol(argv[3], NULL, 10);
+	return query_state(argv[1], keyno, mode);
+}
+
-- 
1.7.5.4


^ permalink raw reply related

* [PATCH] Fix double free in mount.c with SELinux enabled
From: Kirill Elagin @ 2011-07-05 21:50 UTC (permalink / raw)
  To: util-linux

append_context reallocates memory, invalidating extra_opts1. As a
result my_free(extra_opts1) crashes.

Signed-off-by: Kirill Elagin <kirelagin@gmail.com>
Signed-off-by: Nikita Ofitserov <himikof@gmail.com>
---
 mount/mount.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/mount/mount.c b/mount/mount.c
index 00637f5..90d7518 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -1535,7 +1535,7 @@ try_mount_one (const char *spec0, const char
*node0, const char *types0,
   struct stat statbuf;

   /* copies for freeing on exit */
-  const char *opts1, *spec1, *node1, *types1, *extra_opts1;
+  const char *opts1, *spec1, *node1, *types1;

   if (verbose > 2) {
      printf("mount: spec:  \"%s\"\n", spec0);
@@ -1550,8 +1550,7 @@ try_mount_one (const char *spec0, const char
*node0, const char *types0,
   opts = opts1 = xstrdup(opts0);

   parse_opts (opts, &flags, &extra_opts);
-  extra_opts1 = extra_opts;
-  mount_opts = extra_opts;
+  mount_opts = xstrdup(extra_opts);

   /* quietly succeed for fstab entries that don't get mounted automatically */
   if (mount_all && (flags & MS_NOAUTO))
@@ -1592,8 +1591,11 @@ try_mount_one (const char *spec0, const char
*node0, const char *types0,
       /*
        * Linux kernel does not accept any selinux context option on remount
        */
-      if (mount_opts)
+      if (mount_opts) {
+          char *tmp = mount_opts;
           mount_opts = remove_context_options(mount_opts);
+          my_free(tmp);
+      }

   } else if (types && strcmp(types, "tmpfs") == 0 &&
is_selinux_enabled() > 0 &&
       !has_context_option(mount_opts)) {
@@ -1922,9 +1924,8 @@ try_mount_one (const char *spec0, const char
*node0, const char *types0,
   }
 #endif

-  if (extra_opts1 != mount_opts)
-     my_free(mount_opts);
-  my_free(extra_opts1);
+  my_free(mount_opts);
+  my_free(extra_opts);
   my_free(spec1);
   my_free(node1);
   my_free(opts1);
--
1.7.3.4

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox