From 7926576ec2f3d25aecbc128b851326b6dbf85662 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 3 Mar 2009 16:25:23 +0100 Subject: [PATCH] lib: fix fsprobe wrapper (const char * is nonsense) The fsprobe_ functions return newly allocated strings. Signed-off-by: Karel Zak --- include/fsprobe.h | 13 +++++++------ lib/fsprobe.c | 42 +++++++++++++++++++++--------------------- mount/fstab.c | 4 ++-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/include/fsprobe.h b/include/fsprobe.h index ed2cce14..307eb64a 100644 --- a/include/fsprobe.h +++ b/include/fsprobe.h @@ -9,13 +9,14 @@ extern void fsprobe_exit(void); extern int fsprobe_parse_spec(const char *spec, char **name, char **value); -extern const char *fsprobe_get_devname_by_uuid(const char *uuid); -extern const char *fsprobe_get_devname_by_label(const char *label); -extern const char *fsprobe_get_devname_by_spec(const char *spec); +/* all routines return newly allocated string */ +extern char *fsprobe_get_devname_by_uuid(const char *uuid); +extern char *fsprobe_get_devname_by_label(const char *label); +extern char *fsprobe_get_devname_by_spec(const char *spec); -extern const char *fsprobe_get_label_by_devname(const char *devname); -extern const char *fsprobe_get_uuid_by_devname(const char *devname); -extern const char *fsprobe_get_fstype_by_devname(const char *devname); +extern char *fsprobe_get_label_by_devname(const char *devname); +extern char *fsprobe_get_uuid_by_devname(const char *devname); +extern char *fsprobe_get_fstype_by_devname(const char *devname); extern int fsprobe_known_fstype(const char *fstype); diff --git a/lib/fsprobe.c b/lib/fsprobe.c index 9f5adf8c..2091d116 100644 --- a/lib/fsprobe.c +++ b/lib/fsprobe.c @@ -73,7 +73,7 @@ fsprobe_parse_spec(const char *spec, char **name, char **value) return 0; } -const char * +char * fsprobe_get_devname_by_spec(const char *spec) { char *name, *value; @@ -83,7 +83,7 @@ fsprobe_get_devname_by_spec(const char *spec) if (fsprobe_parse_spec(spec, &name, &value) != 0) return NULL; /* parse error */ if (name) { - const char *nspec = NULL; + char *nspec = NULL; if (!strcmp(name,"LABEL")) nspec = fsprobe_get_devname_by_label(value); @@ -131,7 +131,7 @@ fsprobe_exit(void) /* returns device LABEL, UUID, FSTYPE, ... by low-level * probing interface */ -static const char * +static char * fsprobe_get_value(const char *name, const char *devname) { int fd; @@ -160,31 +160,31 @@ done: return data ? strdup((char *) data) : NULL; } -const char * +char * fsprobe_get_label_by_devname(const char *devname) { return fsprobe_get_value("LABEL", devname); } -const char * +char * fsprobe_get_uuid_by_devname(const char *devname) { return fsprobe_get_value("UUID", devname); } -const char * +char * fsprobe_get_fstype_by_devname(const char *devname) { return fsprobe_get_value("TYPE", devname); } -const char * +char * fsprobe_get_devname_by_uuid(const char *uuid) { return blkid_evaluate_spec("UUID", uuid, &blcache); } -const char * +char * fsprobe_get_devname_by_label(const char *label) { return blkid_evaluate_spec("LABEL", label, &blcache); @@ -205,7 +205,7 @@ fsprobe_exit(void) blkid_put_cache(blcache); } -const char * +char * fsprobe_get_devname_by_uuid(const char *uuid) { if (!blcache) @@ -214,7 +214,7 @@ fsprobe_get_devname_by_uuid(const char *uuid) return blkid_get_devname(blcache, "UUID", uuid); } -const char * +char * fsprobe_get_devname_by_label(const char *label) { if (!blcache) @@ -223,7 +223,7 @@ fsprobe_get_devname_by_label(const char *label) return blkid_get_devname(blcache, "LABEL", label); } -const char * +char * fsprobe_get_fstype_by_devname(const char *devname) { blkid_cache c; @@ -243,7 +243,7 @@ fsprobe_get_fstype_by_devname(const char *devname) return tp; } -const char * +char * fsprobe_get_label_by_devname(const char *devname) { if (!blcache) @@ -252,7 +252,7 @@ fsprobe_get_label_by_devname(const char *devname) return blkid_get_tag_value(blcache, "LABEL", devname); } -const char * +char * fsprobe_get_uuid_by_devname(const char *devname) { if (!blcache) @@ -301,15 +301,15 @@ static char switch(type) { case VOLUME_ID_LABEL: if (volume_id_get_label(id, &val)) - value = xstrdup(val); + value = strdup(val); break; case VOLUME_ID_UUID: if (volume_id_get_uuid(id, &val)) - value = xstrdup(val); + value = strdup(val); break; case VOLUME_ID_TYPE: if (volume_id_get_type(id, &val)) - value = xstrdup(val); + value = strdup(val); break; default: break; @@ -338,25 +338,25 @@ fsprobe_known_fstype(const char *fstype) return 0; } -const char * +char * fsprobe_get_uuid_by_devname(const char *devname) { return probe(devname, VOLUME_ID_UUID); } -const char * +char * fsprobe_get_label_by_devname(const char *devname) { return probe(devname, VOLUME_ID_LABEL); } -const char * +char * fsprobe_get_fstype_by_devname(const char *devname) { return probe(devname, VOLUME_ID_TYPE); } -const char * +char * fsprobe_get_devname_by_uuid(const char *uuid) { char dev[PATH_MAX]; @@ -372,7 +372,7 @@ fsprobe_get_devname_by_uuid(const char *uuid) return canonicalize_path(dev); } -const char * +char * fsprobe_get_devname_by_label(const char *label) { char dev[PATH_MAX]; diff --git a/mount/fstab.c b/mount/fstab.c index c238fa2d..13dda871 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -916,8 +916,8 @@ update_mtab (const char *dir, struct my_mntent *instead) { * number and writes the number back to the file. */ /* dummy */ -const char *fsprobe_get_label_by_devname(const char *spec) { return NULL; } -const char *fsprobe_get_uuid_by_devname(const char *spec) { return NULL; } +char *fsprobe_get_label_by_devname(const char *spec) { return NULL; } +char *fsprobe_get_uuid_by_devname(const char *spec) { return NULL; } int fsprobe_parse_spec(const char *spec, char **name, char **value) { return 0; } struct my_mntent *my_getmntent (mntFILE *mfp) { return NULL; } mntFILE *my_setmntent (const char *file, char *mode) { return NULL; } -- 2.39.5