|
|
05ad79 |
diff -up util-linux-2.23.2/disk-utils/blockdev.c.kzak util-linux-2.23.2/disk-utils/blockdev.c
|
|
|
05ad79 |
--- util-linux-2.23.2/disk-utils/blockdev.c.kzak 2015-06-23 11:29:27.818001654 +0200
|
|
|
05ad79 |
+++ util-linux-2.23.2/disk-utils/blockdev.c 2015-06-23 11:29:43.752884860 +0200
|
|
|
05ad79 |
@@ -16,6 +16,7 @@
|
|
|
05ad79 |
#include "blkdev.h"
|
|
|
05ad79 |
#include "pathnames.h"
|
|
|
05ad79 |
#include "closestream.h"
|
|
|
05ad79 |
+#include "sysfs.h"
|
|
|
05ad79 |
|
|
|
05ad79 |
struct bdc {
|
|
|
05ad79 |
long ioc; /* ioctl code */
|
|
|
05ad79 |
@@ -364,7 +365,7 @@ static void do_commands(int fd, char **a
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
if (res == -1) {
|
|
|
05ad79 |
- perror(bdcms[j].iocname);
|
|
|
05ad79 |
+ warn(_("ioctl error on %s"), bdcms[j].iocname);
|
|
|
05ad79 |
if (verbose)
|
|
|
05ad79 |
printf(_("%s failed.\n"), _(bdcms[j].help));
|
|
|
05ad79 |
exit(EXIT_FAILURE);
|
|
|
05ad79 |
@@ -436,7 +437,8 @@ static void report_device(char *device,
|
|
|
05ad79 |
int ro, ssz, bsz;
|
|
|
05ad79 |
long ra;
|
|
|
05ad79 |
unsigned long long bytes;
|
|
|
05ad79 |
- struct hd_geometry g;
|
|
|
05ad79 |
+ uint64_t start = 0;
|
|
|
05ad79 |
+ struct stat st;
|
|
|
05ad79 |
|
|
|
05ad79 |
fd = open(device, O_RDONLY | O_NONBLOCK);
|
|
|
05ad79 |
if (fd < 0) {
|
|
|
05ad79 |
@@ -446,15 +448,27 @@ static void report_device(char *device,
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
ro = ssz = bsz = 0;
|
|
|
05ad79 |
- g.start = ra = 0;
|
|
|
05ad79 |
+ ra = 0;
|
|
|
05ad79 |
+ if (fstat(fd, &st) == 0 && !sysfs_devno_is_wholedisk(st.st_rdev)) {
|
|
|
05ad79 |
+ struct sysfs_cxt cxt;
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ if (sysfs_init(&cxt, st.st_rdev, NULL))
|
|
|
05ad79 |
+ err(EXIT_FAILURE,
|
|
|
05ad79 |
+ _("%s: failed to initialize sysfs handler"),
|
|
|
05ad79 |
+ device);
|
|
|
05ad79 |
+ if (sysfs_read_u64(&cxt, "start", &start))
|
|
|
05ad79 |
+ err(EXIT_FAILURE,
|
|
|
05ad79 |
+ _("%s: failed to read partition start from sysfs"),
|
|
|
05ad79 |
+ device);
|
|
|
05ad79 |
+ sysfs_deinit(&cxt);
|
|
|
05ad79 |
+ }
|
|
|
05ad79 |
if (ioctl(fd, BLKROGET, &ro) == 0 &&
|
|
|
05ad79 |
ioctl(fd, BLKRAGET, &ra) == 0 &&
|
|
|
05ad79 |
ioctl(fd, BLKSSZGET, &ssz) == 0 &&
|
|
|
05ad79 |
ioctl(fd, BLKBSZGET, &bsz) == 0 &&
|
|
|
05ad79 |
- ioctl(fd, HDIO_GETGEO, &g) == 0 &&
|
|
|
05ad79 |
blkdev_get_size(fd, &bytes) == 0) {
|
|
|
05ad79 |
- printf("%s %5ld %5d %5d %10ld %15lld %s\n",
|
|
|
05ad79 |
- ro ? "ro" : "rw", ra, ssz, bsz, g.start, bytes, device);
|
|
|
05ad79 |
+ printf("%s %5ld %5d %5d %10ju %15lld %s\n",
|
|
|
05ad79 |
+ ro ? "ro" : "rw", ra, ssz, bsz, start, bytes, device);
|
|
|
05ad79 |
} else {
|
|
|
05ad79 |
if (!quiet)
|
|
|
05ad79 |
warnx(_("ioctl error on %s"), device);
|
|
|
05ad79 |
diff -up util-linux-2.23.2/include/sysfs.h.kzak util-linux-2.23.2/include/sysfs.h
|
|
|
05ad79 |
--- util-linux-2.23.2/include/sysfs.h.kzak 2015-06-23 11:32:12.709793086 +0200
|
|
|
05ad79 |
+++ util-linux-2.23.2/include/sysfs.h 2015-06-23 11:32:31.909652361 +0200
|
|
|
05ad79 |
@@ -72,6 +72,7 @@ extern int sysfs_is_partition_dirent(DIR
|
|
|
05ad79 |
|
|
|
05ad79 |
extern int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
|
|
|
05ad79 |
size_t len, dev_t *diskdevno);
|
|
|
05ad79 |
+extern int sysfs_devno_is_wholedisk(dev_t devno);
|
|
|
05ad79 |
|
|
|
05ad79 |
extern int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h,
|
|
|
05ad79 |
int *c, int *t, int *l);
|
|
|
05ad79 |
diff -up util-linux-2.23.2/lib/sysfs.c.kzak util-linux-2.23.2/lib/sysfs.c
|
|
|
05ad79 |
--- util-linux-2.23.2/lib/sysfs.c.kzak 2015-06-23 11:31:32.166090250 +0200
|
|
|
05ad79 |
+++ util-linux-2.23.2/lib/sysfs.c 2015-06-23 11:31:59.684888551 +0200
|
|
|
05ad79 |
@@ -638,6 +638,18 @@ err:
|
|
|
05ad79 |
return -1;
|
|
|
05ad79 |
}
|
|
|
05ad79 |
|
|
|
05ad79 |
+/*
|
|
|
05ad79 |
+ * Return 0 or 1, or < 0 in case of error
|
|
|
05ad79 |
+ */
|
|
|
05ad79 |
+int sysfs_devno_is_wholedisk(dev_t devno)
|
|
|
05ad79 |
+{
|
|
|
05ad79 |
+ dev_t disk;
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ if (sysfs_devno_to_wholedisk(devno, NULL, 0, &disk) != 0)
|
|
|
05ad79 |
+ return -1;
|
|
|
05ad79 |
+
|
|
|
05ad79 |
+ return devno == disk;
|
|
|
05ad79 |
+}
|
|
|
05ad79 |
|
|
|
05ad79 |
int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h, int *c, int *t, int *l)
|
|
|
05ad79 |
{
|