From: Eric Sandeen <sandeen@redhat.com>
To: linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: [PATCH 1/2] btrfs-progs: replace blkid_probe_get_wholedisk_devno
Date: Thu, 11 Apr 2013 10:39:30 -0500 [thread overview]
Message-ID: <5166D932.5010105@redhat.com> (raw)
blkid_probe_get_wholedisk_devno() isn't available in some older
versions of libblkid. It was used to work around an old
bug in blkid_devno_to_wholedisk(), but that has been fixed since
5cd0823 libblkid: fix blkid_devno_to_wholedisk(), present in
util-linux 2.17 and beyond.
If we happen to be missing that fix, the worst that happens is
that we'd fail to detect that a device is an ssd; the upside is
that this code compiles on older systems.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/mkfs.c b/mkfs.c
index c8cb395..7df78fc 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1215,9 +1215,8 @@ static int check_leaf_or_node_size(u32 size, u32 sectorsize)
static int is_ssd(const char *file)
{
- char *devname;
blkid_probe probe;
- char *dev;
+ char dev[32];
char path[PATH_MAX];
dev_t disk;
int fd;
@@ -1227,24 +1226,16 @@ static int is_ssd(const char *file)
if (!probe)
return 0;
- /*
- * We want to use blkid_devno_to_wholedisk() but it's broken for some
- * reason on F17 at least so we'll do this trickery
- */
- disk = blkid_probe_get_wholedisk_devno(probe);
+ /* Device number of this disk (possibly a partition) */
+ disk = blkid_probe_get_devno(probe);
if (!disk)
return 0;
- devname = blkid_devno_to_devname(disk);
- if (!devname)
- return 0;
-
- dev = strrchr(devname, '/');
- dev++;
+ /* Get whole disk name (not full path) for this devno */
+ blkid_devno_to_wholedisk(disk, dev, sizeof(dev), NULL);
snprintf(path, PATH_MAX, "/sys/block/%s/queue/rotational", dev);
- free(devname);
blkid_free_probe(probe);
fd = open(path, O_RDONLY);
next reply other threads:[~2013-04-11 15:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-11 15:39 Eric Sandeen [this message]
2013-04-11 15:44 ` [PATCH 2/2] btrfs-progs: use clearer var names in is_ssd() Eric Sandeen
2013-04-12 17:17 ` Zach Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5166D932.5010105@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.