chiark / gitweb /
Modify mount_propagation_flags_from_string to return a normal int code
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 3 Dec 2016 18:57:42 +0000 (13:57 -0500)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:35 +0000 (17:58 +0200)
This means that callers can distiguish an error from flags==0,
and don't have to special-case the empty string.

src/basic/mount-util.c
src/basic/mount-util.h

index d757aba..f99a543 100644 (file)
@@ -691,3 +691,35 @@ int umount_verbose(const char *what) {
         return 0;
 }
 #endif // 0
+
+const char *mount_propagation_flags_to_string(unsigned long flags) {
+
+        switch (flags & (MS_SHARED|MS_SLAVE|MS_PRIVATE)) {
+        case 0:
+                return "";
+        case MS_SHARED:
+                return "shared";
+        case MS_SLAVE:
+                return "slave";
+        case MS_PRIVATE:
+                return "private";
+        }
+
+        return NULL;
+}
+
+
+int mount_propagation_flags_from_string(const char *name, unsigned long *ret) {
+
+        if (isempty(name))
+                *ret = 0;
+        else if (streq(name, "shared"))
+                *ret = MS_SHARED;
+        else if (streq(name, "slave"))
+                *ret = MS_SLAVE;
+        else if (streq(name, "private"))
+                *ret = MS_PRIVATE;
+        else
+                return -EINVAL;
+        return 0;
+}
index 57cfc36..deaa779 100644 (file)
@@ -69,4 +69,4 @@ int umount_verbose(const char *where);
 #endif // 0
 
 const char *mount_propagation_flags_to_string(unsigned long flags);
-unsigned long mount_propagation_flags_from_string(const char *name);
+int mount_propagation_flags_from_string(const char *name, unsigned long *ret);