]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add function for getting member drive sector size
authorPawel Baldysiak <pawel.baldysiak@intel.com>
Thu, 17 Nov 2016 13:58:35 +0000 (14:58 +0100)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Thu, 17 Nov 2016 14:24:18 +0000 (09:24 -0500)
This patch introduces the function for getting sector size of
given device (fd).

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
mdadm.h
super1.c
util.c

diff --git a/mdadm.h b/mdadm.h
index 41a4494552fb2a65f5b199a626730389c4156ec1..240ab7f831bc971a15db21de744d48f2678f5936 100755 (executable)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1112,6 +1112,7 @@ static inline struct supertype *guess_super(int fd) {
 }
 extern struct supertype *dup_super(struct supertype *st);
 extern int get_dev_size(int fd, char *dname, unsigned long long *sizep);
+extern int get_dev_sector_size(int fd, char *dname, unsigned int *sectsizep);
 extern int must_be_container(int fd);
 extern int dev_size_from_id(dev_t id, unsigned long long *size);
 void wait_for(char *dev, int fd);
index 1d03a0ac8bdca2f4fec4217f473a2f84de153b90..d3234392d453234b18ecbcb4d92980bb0a758f08 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -213,8 +213,7 @@ struct align_fd {
 static void init_afd(struct align_fd *afd, int fd)
 {
        afd->fd = fd;
-
-       if (ioctl(afd->fd, BLKSSZGET, &afd->blk_sz) != 0)
+       if (!get_dev_sector_size(afd->fd, NULL, (unsigned int *)&afd->blk_sz))
                afd->blk_sz = 512;
 }
 
diff --git a/util.c b/util.c
index 9e4718fd988c8ed7de7ec3745deb480e75042f67..883eaa41e869b49b374079c1a7b2b49270a60b11 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1324,7 +1324,7 @@ int get_dev_size(int fd, char *dname, unsigned long long *sizep)
                        ldsize <<= 9;
                } else {
                        if (dname)
-                               pr_err("Cannot get size of %s: %s\b",
+                               pr_err("Cannot get size of %s: %s\n",
                                        dname, strerror(errno));
                        return 0;
                }
@@ -1333,6 +1333,22 @@ int get_dev_size(int fd, char *dname, unsigned long long *sizep)
        return 1;
 }
 
+/* Return sector size of device in bytes */
+int get_dev_sector_size(int fd, char *dname, unsigned int *sectsizep)
+{
+       unsigned int sectsize;
+
+       if (ioctl(fd, BLKSSZGET, &sectsize) != 0) {
+               if (dname)
+                       pr_err("Cannot get sector size of %s: %s\n",
+                               dname, strerror(errno));
+               return 0;
+       }
+
+       *sectsizep = sectsize;
+       return 1;
+}
+
 /* Return true if this can only be a container, not a member device.
  * i.e. is and md device and size is zero
  */