X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Futils_devpath.c;h=7df2db54e3a0b2bc46b92e1b5cd1348210b3e395;hb=c3c65ee864cf792a870ccbb2df36006471e04eb3;hp=7e872ad6693bf5ce40d296fe88c3d526815688b1;hpb=fe4175b551f9f5df2ba53adaec9dc67e3a8da23e;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/lib/utils_devpath.c b/lib/utils_devpath.c index 7e872ad..7df2db5 100644 --- a/lib/utils_devpath.c +++ b/lib/utils_devpath.c @@ -4,7 +4,7 @@ * Copyright (C) 2004, Christophe Saout * Copyright (C) 2004-2007, Clemens Fruhwirth * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved. - * Copyright (C) 2009-2012, Milan Broz + * Copyright (C) 2009-2013, Milan Broz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include "utils_dm.h" @@ -169,13 +170,13 @@ char *crypt_lookup_dev(const char *dev_id) return devpath; } -int crypt_sysfs_get_rotational(int major, int minor, int *rotational) +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; - if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/queue/rotational", - major, minor) < 0) + if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/%s", + major, minor, attr) < 0) return 0; if ((fd = open(path, O_RDONLY)) < 0) @@ -186,8 +187,38 @@ int crypt_sysfs_get_rotational(int major, int minor, int *rotational) if (r <= 0) return 0; - if (sscanf(tmp, "%d", rotational) != 1) + if (sscanf(tmp, "%" PRIu64, value) != 1) + return 0; + + return 1; +} + +int crypt_sysfs_get_rotational(int major, int minor, int *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) + return 0; + + if (!S_ISBLK(st.st_mode)) + return 0; + + if (!_sysfs_get_uint64(major(st.st_rdev), minor(st.st_rdev), + &val, "partition")) return 0; + *partition = val ? 1 : 0; return 1; }