summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Broz <gmazyland@gmail.com>2013-06-29 13:06:04 +0200
committerMilan Broz <gmazyland@gmail.com>2013-06-29 13:06:04 +0200
commitc3c65ee864cf792a870ccbb2df36006471e04eb3 (patch)
treeffff38b67e6ccf0ae84488391d1f8a6155a53506
parentdb0f5f8d22ce2574774c9b37babae29ea35ec787 (diff)
downloadcryptsetup-c3c65ee864cf792a870ccbb2df36006471e04eb3.tar.gz
cryptsetup-c3c65ee864cf792a870ccbb2df36006471e04eb3.tar.bz2
cryptsetup-c3c65ee864cf792a870ccbb2df36006471e04eb3.zip
Use internally common uint64 parsing for sysfs values.
-rw-r--r--lib/utils_devpath.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/utils_devpath.c b/lib/utils_devpath.c
index 6c07b5b..7df2db5 100644
--- a/lib/utils_devpath.c
+++ b/lib/utils_devpath.c
@@ -170,7 +170,7 @@ char *crypt_lookup_dev(const char *dev_id)
return devpath;
}
-static int _sysfs_get_int(int major, int minor, int *value, const char *attr)
+static int _sysfs_get_uint64(int major, int minor, uint64_t *value, const char *attr)
{
char path[PATH_MAX], tmp[64] = {0};
int fd, r;
@@ -187,7 +187,7 @@ static int _sysfs_get_int(int major, int minor, int *value, const char *attr)
if (r <= 0)
return 0;
- if (sscanf(tmp, "%d", value) != 1)
+ if (sscanf(tmp, "%" PRIu64, value) != 1)
return 0;
return 1;
@@ -195,11 +195,18 @@ static int _sysfs_get_int(int major, int minor, int *value, const char *attr)
int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
{
- return _sysfs_get_int(major, minor, rotational, "queue/rotational");
+ uint64_t val;
+
+ if (!_sysfs_get_uint64(major, minor, &val, "queue/rotational"))
+ return 0;
+
+ *rotational = val ? 1 : 0;
+ return 1;
}
int crypt_sysfs_get_partition(const char *dev_path, int *partition)
{
+ uint64_t val;
struct stat st;
if (stat(dev_path, &st) < 0)
@@ -208,6 +215,10 @@ int crypt_sysfs_get_partition(const char *dev_path, int *partition)
if (!S_ISBLK(st.st_mode))
return 0;
- return _sysfs_get_int(major(st.st_rdev), minor(st.st_rdev),
- partition, "partition");
+ if (!_sysfs_get_uint64(major(st.st_rdev), minor(st.st_rdev),
+ &val, "partition"))
+ return 0;
+
+ *partition = val ? 1 : 0;
+ return 1;
}