summaryrefslogtreecommitdiffstats
path: root/libmount/src/fs.c
diff options
context:
space:
mode:
authorOndrej Oprala2013-06-14 12:41:30 +0200
committerKarel Zak2013-07-03 10:17:37 +0200
commitcb90e24e804e2f95eadf01e96561749092c858c1 (patch)
treeddb6c8181d8aa749db571ca9f6a560f205ce169c /libmount/src/fs.c
parentlibmount: add a generic append_string() function (diff)
downloadkernel-qcow2-util-linux-cb90e24e804e2f95eadf01e96561749092c858c1.tar.gz
kernel-qcow2-util-linux-cb90e24e804e2f95eadf01e96561749092c858c1.tar.xz
kernel-qcow2-util-linux-cb90e24e804e2f95eadf01e96561749092c858c1.zip
libmount: add functions to handle comments in fs tables
Co-Author: Karel Zak <kzak@redhat.com> Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/fs.c')
-rw-r--r--libmount/src/fs.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/libmount/src/fs.c b/libmount/src/fs.c
index 75e3bbb26..bcf250597 100644
--- a/libmount/src/fs.c
+++ b/libmount/src/fs.c
@@ -62,6 +62,7 @@ void mnt_free_fs(struct libmnt_fs *fs)
free(fs->user_optstr);
free(fs->attrs);
free(fs->opt_fields);
+ free(fs->comment);
free(fs);
}
@@ -1281,6 +1282,60 @@ int mnt_fs_get_attribute(struct libmnt_fs *fs, const char *name,
}
/**
+ * mnt_fs_get_comment:
+ * @fs: fstab/mtab/mountinfo entry pointer
+ *
+ * Returns: 0 on success, 1 when not found the @name or negative number in case of error.
+ */
+const char *mnt_fs_get_comment(struct libmnt_fs *fs)
+{
+ assert(fs);
+ if (!fs)
+ return NULL;
+ return fs->comment;
+}
+
+/**
+ * mnt_fs_set_comment:
+ * @fs: fstab entry pointer
+ * @comm: comment string
+ *
+ * Returns: 0 on success or <0 in case of error.
+ */
+int mnt_fs_set_comment(struct libmnt_fs *fs, const char *comm)
+{
+ char *p = NULL;
+
+ assert(fs);
+ if (!fs)
+ return -EINVAL;
+ if (comm) {
+ p = strdup(comm);
+ if (!p)
+ return -ENOMEM;
+ }
+
+ free(fs->comment);
+ fs->comment = p;
+ return 0;
+}
+
+/**
+ * mnt_fs_append_comment:
+ * @fs: fstab entry pointer
+ *
+ * Returns: 0 on success or <0 in case of error.
+ */
+int mnt_fs_append_comment(struct libmnt_fs *fs, const char *comm)
+{
+ assert(fs);
+ if (!fs)
+ return -EINVAL;
+
+ return append_string(&fs->comment, comm);
+}
+
+/**
* mnt_fs_match_target:
* @fs: filesystem
* @target: mountpoint path
@@ -1496,6 +1551,8 @@ int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file)
minor(mnt_fs_get_devno(fs)));
if (mnt_fs_get_tid(fs))
fprintf(file, "tid: %d\n", mnt_fs_get_tid(fs));
+ if (mnt_fs_get_comment(fs))
+ fprintf(file, "comment: '%s'\n", mnt_fs_get_comment(fs));
return 0;
}