X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Futils_devpath.c;h=472569e92df3927555cca843413ad366558bcec9;hb=95daec798be76b89ba7d16d6edcc1c8f8b14486e;hp=f78a36eb156e52830805f3ae091c97132dca4c18;hpb=8866e88ec539a862ae437e71534a89b7741e123f;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/lib/utils_devpath.c b/lib/utils_devpath.c index f78a36e..472569e 100644 --- a/lib/utils_devpath.c +++ b/lib/utils_devpath.c @@ -3,7 +3,7 @@ * * Copyright (C) 2004, Christophe Saout * Copyright (C) 2004-2007, Clemens Fruhwirth - * Copyright (C) 2009-2011, Red Hat, Inc. All rights reserved. + * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -24,11 +24,19 @@ #include #include #include +#include +#include #include #include #include "utils_dm.h" +/* These are DM helpers used only by this file */ +int dm_is_dm_device(int major, int minor); +int dm_is_dm_kernel_name(const char *name); +char *dm_device_path(const char *prefix, int major, int minor); + char *crypt_lookup_dev(const char *dev_id); +int crypt_sysfs_get_rotational(int major, int minor, int *rotational); static char *__lookup_dev(char *path, dev_t dev, int dir_level, const int max_level) { @@ -131,7 +139,7 @@ char *crypt_lookup_dev(const char *dev_id) if (snprintf(path, sizeof(path), "/sys/dev/block/%s", dev_id) < 0) return NULL; - len = readlink(path, link, sizeof(link)); + len = readlink(path, link, sizeof(link) - 1); if (len < 0) { /* Without /sys use old scan */ if (stat("/sys/dev/block", &st) < 0) @@ -146,7 +154,7 @@ char *crypt_lookup_dev(const char *dev_id) devname++; if (dm_is_dm_kernel_name(devname)) - devpath = dm_device_path(major, minor); + devpath = dm_device_path("/dev/mapper/", major, minor); else if (snprintf(path, sizeof(path), "/dev/%s", devname) > 0) devpath = strdup(path); @@ -163,3 +171,26 @@ char *crypt_lookup_dev(const char *dev_id) return devpath; } + +int crypt_sysfs_get_rotational(int major, int minor, int *rotational) +{ + 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) + return 0; + + if ((fd = open(path, O_RDONLY)) < 0) + return 0; + r = read(fd, tmp, sizeof(tmp)); + close(fd); + + if (r <= 0) + return 0; + + if (sscanf(tmp, "%d", rotational) != 1) + return 0; + + return 1; +}