You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
3.0 KiB

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