]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: move fstab_node_to_udev_node() to fstab-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 17:43:29 +0000 (18:43 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:55 +0000 (13:25 +0100)
src/basic/device-nodes.h
src/basic/util.c
src/basic/util.h
src/hibernate-resume/hibernate-resume-generator.c
src/shared/fstab-util.c
src/shared/fstab-util.h
src/test/test-util.c

index 04ba4897e5f908617d2062d15c5af9a8cdaa73f3..7db81f3d52e4e1110c5274fec8bdc196c9671ee1 100644 (file)
@@ -21,5 +21,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <sys/types.h>
+
 int encode_devnode_name(const char *str, char *str_enc, size_t len);
 int whitelisted_char_for_devnode(char c, const char *additional);
index 25ba59505df6e5bd3a951d22dbd80c101ede80d5..607d9cd933ad25483542dba1869a40039ac02be2 100644 (file)
@@ -571,26 +571,6 @@ int touch(const char *path) {
         return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, 0);
 }
 
-static char *unquote(const char *s, const char* quotes) {
-        size_t l;
-        assert(s);
-
-        /* This is rather stupid, simply removes the heading and
-         * trailing quotes if there is one. Doesn't care about
-         * escaping or anything.
-         *
-         * DON'T USE THIS FOR NEW CODE ANYMORE!*/
-
-        l = strlen(s);
-        if (l < 2)
-                return strdup(s);
-
-        if (strchr(quotes, s[0]) && s[l-1] == s[0])
-                return strndup(s+1, l-2);
-
-        return strdup(s);
-}
-
 noreturn void freeze(void) {
 
         /* Make sure nobody waits for us on a socket anymore */
@@ -636,43 +616,6 @@ int null_or_empty_fd(int fd) {
         return null_or_empty(&st);
 }
 
-static char *tag_to_udev_node(const char *tagvalue, const char *by) {
-        _cleanup_free_ char *t = NULL, *u = NULL;
-        size_t enc_len;
-
-        u = unquote(tagvalue, QUOTES);
-        if (!u)
-                return NULL;
-
-        enc_len = strlen(u) * 4 + 1;
-        t = new(char, enc_len);
-        if (!t)
-                return NULL;
-
-        if (encode_devnode_name(u, t, enc_len) < 0)
-                return NULL;
-
-        return strjoin("/dev/disk/by-", by, "/", t, NULL);
-}
-
-char *fstab_node_to_udev_node(const char *p) {
-        assert(p);
-
-        if (startswith(p, "LABEL="))
-                return tag_to_udev_node(p+6, "label");
-
-        if (startswith(p, "UUID="))
-                return tag_to_udev_node(p+5, "uuid");
-
-        if (startswith(p, "PARTUUID="))
-                return tag_to_udev_node(p+9, "partuuid");
-
-        if (startswith(p, "PARTLABEL="))
-                return tag_to_udev_node(p+10, "partlabel");
-
-        return strdup(p);
-}
-
 bool dirent_is_file(const struct dirent *de) {
         assert(de);
 
index 9393140c727b9eb5e22bae6aea8161a03f28ba9d..c6c3ba99f245db6d5e99ef6717c2ce04386521b4 100644 (file)
@@ -199,8 +199,6 @@ bool null_or_empty(struct stat *st) _pure_;
 int null_or_empty_path(const char *fn);
 int null_or_empty_fd(int fd);
 
-char *fstab_node_to_udev_node(const char *p);
-
 void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
 
 bool plymouth_running(void);
index dff2ada3842638843413262543c895a3052baa67..da7d33508dc2de9af5dbccf6ad433a181777e039 100644 (file)
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <stdio.h>
 
+#include "fstab-util.h"
 #include "log.h"
 #include "mkdir.h"
 #include "special.h"
index 20fb0f5a065256ba2c2b9ec391da52491f26ab58..77faa7bc3502f21e8b0b5259f606ec39247bb06e 100644 (file)
@@ -19,6 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "device-nodes.h"
 #include "fstab-util.h"
 #include "parse-util.h"
 #include "path-util.h"
@@ -196,3 +197,60 @@ int fstab_find_pri(const char *options, int *ret) {
         *ret = (int) pri;
         return 1;
 }
+
+static char *unquote(const char *s, const char* quotes) {
+        size_t l;
+        assert(s);
+
+        /* This is rather stupid, simply removes the heading and
+         * trailing quotes if there is one. Doesn't care about
+         * escaping or anything.
+         *
+         * DON'T USE THIS FOR NEW CODE ANYMORE!*/
+
+        l = strlen(s);
+        if (l < 2)
+                return strdup(s);
+
+        if (strchr(quotes, s[0]) && s[l-1] == s[0])
+                return strndup(s+1, l-2);
+
+        return strdup(s);
+}
+
+static char *tag_to_udev_node(const char *tagvalue, const char *by) {
+        _cleanup_free_ char *t = NULL, *u = NULL;
+        size_t enc_len;
+
+        u = unquote(tagvalue, QUOTES);
+        if (!u)
+                return NULL;
+
+        enc_len = strlen(u) * 4 + 1;
+        t = new(char, enc_len);
+        if (!t)
+                return NULL;
+
+        if (encode_devnode_name(u, t, enc_len) < 0)
+                return NULL;
+
+        return strjoin("/dev/disk/by-", by, "/", t, NULL);
+}
+
+char *fstab_node_to_udev_node(const char *p) {
+        assert(p);
+
+        if (startswith(p, "LABEL="))
+                return tag_to_udev_node(p+6, "label");
+
+        if (startswith(p, "UUID="))
+                return tag_to_udev_node(p+5, "uuid");
+
+        if (startswith(p, "PARTUUID="))
+                return tag_to_udev_node(p+9, "partuuid");
+
+        if (startswith(p, "PARTLABEL="))
+                return tag_to_udev_node(p+10, "partlabel");
+
+        return strdup(p);
+}
index 872b2363cd500ea36812c5ee6d64886b6910aaff..5ebea4401983ec770e97ce998b847f3778081979 100644 (file)
 
 #include <stdbool.h>
 #include <stddef.h>
+
 #include "macro.h"
 
 bool fstab_is_mount_point(const char *mount);
-int fstab_filter_options(const char *opts, const char *names,
-                         const char **namefound, char **value, char **filtered);
+
+int fstab_filter_options(const char *opts, const char *names, const char **namefound, char **value, char **filtered);
 
 int fstab_extract_values(const char *opts, const char *name, char ***values);
 
@@ -49,3 +50,5 @@ static inline bool fstab_test_yes_no_option(const char *opts, const char *yes_no
 
         return opt == yes_no;
 }
+
+char *fstab_node_to_udev_node(const char *p);
index 848ebe69f462564e41cca332017784663c5cd1cc..8e5860f0e44db647fbe772093204b76310dff1b0 100644 (file)
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
+#include "fstab-util.h"
+#include "hexdecoct.h"
 #include "io-util.h"
 #include "mkdir.h"
-#include "hexdecoct.h"
 #include "parse-util.h"
 #include "process-util.h"
 #include "rm-rf.h"