mnt_fs_get_options
mnt_fs_get_parent_id
mnt_fs_get_passno
+mnt_fs_get_priority
mnt_fs_get_root
+mnt_fs_get_size
mnt_fs_get_source
mnt_fs_get_srcpath
+mnt_fs_get_swaptype
mnt_fs_get_tag
mnt_fs_get_target
+mnt_fs_get_usedsize
mnt_fs_get_userdata
mnt_fs_get_user_options
mnt_fs_get_vfs_options
mnt_table_is_fs_mounted
mnt_table_next_child_fs
mnt_table_next_fs
-mnt_table_parse_file
mnt_table_parse_dir
+mnt_table_parse_file
mnt_table_parse_fstab
mnt_table_parse_mtab
mnt_table_parse_stream
+mnt_table_parse_swaps
mnt_table_remove_fs
mnt_table_set_cache
mnt_table_set_iter
mnt_fstype_is_pseudofs
mnt_get_fstab_path
mnt_get_mtab_path
+mnt_get_swaps_path
mnt_has_regular_mtab
mnt_mangle
mnt_match_fstype
free(fs->tagname);
free(fs->tagval);
free(fs->root);
+ free(fs->swaptype);
free(fs->target);
free(fs->fstype);
free(fs->optstr);
goto err;
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, root)))
goto err;
+ if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, swaptype)))
+ goto err;
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, target)))
goto err;
if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, fstype)))
dest->freq = src->freq;
dest->passno = src->passno;
dest->flags = src->flags;
+ dest->size = src->size;
+ dest->usedsize = src->usedsize;
+ dest->priority = src->priority;
return dest;
err:
return 0;
}
+/**
+ * mnt_fs_get_swaptype:
+ * @fs: /proc/swaps entry
+ *
+ * Returns: swap type or NULL
+ */
+const char *mnt_fs_get_swaptype(struct libmnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->swaptype : NULL;
+}
+
+/**
+ * mnt_fs_get_size:
+ * @fs: /proc/swaps entry
+ *
+ * Returns: size
+ */
+off_t mnt_fs_get_size(struct libmnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->size : 0;
+}
+
+/**
+ * mnt_fs_get_usedsize:
+ * @fs: /proc/swaps entry
+ *
+ * Returns: used size
+ */
+off_t mnt_fs_get_usedsize(struct libmnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->usedsize : 0;
+}
+
+/**
+ * mnt_fs_get_priority:
+ * @fs: /proc/swaps entry
+ *
+ * Returns: priority
+ */
+int mnt_fs_get_priority(struct libmnt_fs *fs)
+{
+ assert(fs);
+ return fs ? fs->priority : 0;
+}
+
+/**
+ * mnt_fs_set_priority:
+ * @fs: /proc/swaps entry
+ *
+ * Returns: 0 or -1 in case of error
+ */
+int mnt_fs_set_priority(struct libmnt_fs *fs, int prio)
+{
+ assert(fs);
+ if (!fs)
+ return -EINVAL;
+ fs->priority = prio;
+ return 0;
+}
+
/**
* mnt_fs_get_bindsrc:
* @fs: /run/mount/utab entry
if (mnt_fs_get_root(fs))
fprintf(file, "root: %s\n", mnt_fs_get_root(fs));
+
+ if (mnt_fs_get_swaptype(fs))
+ fprintf(file, "swaptype: %s\n", mnt_fs_get_swaptype(fs));
+ if (mnt_fs_get_size(fs))
+ fprintf(file, "size: %jd\n", mnt_fs_get_size(fs));
+ if (mnt_fs_get_usedsize(fs))
+ fprintf(file, "usedsize: %jd\n", mnt_fs_get_usedsize(fs));
+ if (mnt_fs_get_priority(fs))
+ fprintf(file, "priority: %d\n", mnt_fs_get_priority(fs));
+
if (mnt_fs_get_bindsrc(fs))
fprintf(file, "bindsrc: %s\n", mnt_fs_get_bindsrc(fs));
if (mnt_fs_get_freq(fs))
extern int mnt_match_fstype(const char *type, const char *pattern);
extern int mnt_match_options(const char *optstr, const char *pattern);
extern const char *mnt_get_fstab_path(void);
+extern const char *mnt_get_swaps_path(void);
extern const char *mnt_get_mtab_path(void);
extern int mnt_has_regular_mtab(const char **mtab, int *writable);
extern int mnt_fs_get_parent_id(struct libmnt_fs *fs);
extern dev_t mnt_fs_get_devno(struct libmnt_fs *fs);
+extern const char *mnt_fs_get_swaptype(struct libmnt_fs *fs);
+extern off_t mnt_fs_get_size(struct libmnt_fs *fs);
+extern off_t mnt_fs_get_usedsize(struct libmnt_fs *fs);
+extern int mnt_fs_get_priority(struct libmnt_fs *fs);
+
extern int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
struct libmnt_cache *cache);
extern int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
extern int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname);
extern int mnt_table_parse_fstab(struct libmnt_table *tb, const char *filename);
+extern int mnt_table_parse_swaps(struct libmnt_table *tb, const char *filename);
extern int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename);
extern int mnt_table_set_parser_errcb(struct libmnt_table *tb,
int (*cb)(struct libmnt_table *tb, const char *filename, int line));
mnt_context_is_loopdel;
mnt_context_is_nocanonicalize;
mnt_context_is_nohelpers;
+ mnt_table_parse_swaps;
+ mnt_get_swaps_path;
+ mnt_fs_get_swaptype;
+ mnt_fs_get_size;
+ mnt_fs_get_usedsize;
+ mnt_fs_get_priority;
} MOUNT_2.21;
char *bindsrc; /* utab, full path from fstab[1] for bind mounts */
- char *source; /* fstab[1], mountinfo[10]:
+ char *source; /* fstab[1], mountinfo[10], swaps[1]:
* source dev, file, dir or TAG */
char *tagname; /* fstab[1]: tag name - "LABEL", "UUID", ..*/
char *tagval; /* tag value */
int freq; /* fstab[5]: dump frequency in days */
int passno; /* fstab[6]: pass number on parallel fsck */
+ /* /proc/swaps */
+ char *swaptype; /* swaps[2]: device type (partition, file, ...) */
+ off_t size; /* swaps[3]: swaparea size */
+ off_t usedsize; /* swaps[4]: used size */
+ int priority; /* swaps[5]: swap priority */
+
int flags; /* MNT_FS_* flags */
void *userdata; /* library independent data */
MNT_FMT_FSTAB, /* /etc/{fs,m}tab */
MNT_FMT_MTAB = MNT_FMT_FSTAB, /* alias */
MNT_FMT_MOUNTINFO, /* /proc/#/mountinfo */
- MNT_FMT_UTAB /* /dev/.mount/utab */
+ MNT_FMT_UTAB, /* /run/mount/utab */
+ MNT_FMT_SWAPS /* /proc/swaps */
};
return -ENOMEM;
}
+/*
+ * Parses one line from /proc/swaps
+ */
+static int mnt_parse_swaps_line(struct libmnt_fs *fs, char *s)
+{
+ uintmax_t fsz, usz;
+ int rc;
+ char *src = NULL;
+
+ rc = sscanf(s, UL_SCNsA" " /* (1) source */
+ UL_SCNsA" " /* (2) type */
+ "%jd" /* (3) size */
+ "%jd" /* (4) used */
+ "%d", /* priority */
+
+ &src,
+ &fs->swaptype,
+ &fsz,
+ &usz,
+ &fs->priority);
+
+ if (rc == 5) {
+ size_t sz;
+
+ fs->size = fsz;
+ fs->usedsize = usz;
+
+ unmangle_string(src);
+
+ /* remove "(deleted)" suffix */
+ sz = strlen(src);
+ if (sz > PATH_DELETED_SUFFIX_SZ) {
+ char *p = src + (sz - PATH_DELETED_SUFFIX_SZ);
+ if (strcmp(p, PATH_DELETED_SUFFIX) == 0)
+ *p = '\0';
+ }
+
+ rc = mnt_fs_set_source(fs, src);
+ if (!rc)
+ mnt_fs_set_fstype(fs, "swap");
+ free(src);
+ } else {
+ DBG(TAB, mnt_debug("tab parse error: [sscanf rc=%d]: '%s'", rc, s));
+ rc = -EINVAL;
+ }
+
+ return rc;
+}
+
+
/*
* Returns {m,fs}tab or mountinfo file format (MNT_FMT_*)
*
{
unsigned int a, b;
+ DBG(TAB, mnt_debug("trying to guess table type"));
+
if (sscanf(line, "%u %u", &a, &b) == 2)
return MNT_FMT_MOUNTINFO;
+ if (strncmp(line, "Filename\t", 9) == 0)
+ return MNT_FMT_SWAPS;
+
return MNT_FMT_FSTAB; /* fstab, mtab or /proc/mounts */
}
assert(fs);
/* read the next non-blank non-comment line */
+next_line:
do {
if (fgets(buf, sizeof(buf), f) == NULL)
return -EINVAL;
s = skip_spaces(buf);
} while (*s == '\0' || *s == '#');
- if (tb->fmt == MNT_FMT_GUESS)
+ if (tb->fmt == MNT_FMT_GUESS) {
tb->fmt = guess_table_format(s);
+ if (tb->fmt == MNT_FMT_SWAPS)
+ goto next_line; /* skip swap header */
+ }
switch (tb->fmt) {
case MNT_FMT_FSTAB:
case MNT_FMT_UTAB:
rc = mnt_parse_utab_line(fs, s);
break;
+ case MNT_FMT_SWAPS:
+ if (strncmp(s, "Filename\t", 9) == 0)
+ goto next_line; /* skip swap header */
+ rc = mnt_parse_swaps_line(fs, s);
+ break;
default:
rc = -1; /* unknown format */
break;
err:
DBG(TAB, mnt_debug_h(tb, "%s:%d: %s parse error", filename, *nlines,
tb->fmt == MNT_FMT_MOUNTINFO ? "mountinfo" :
+ tb->fmt == MNT_FMT_SWAPS ? "swaps" :
tb->fmt == MNT_FMT_FSTAB ? "tab" : "utab"));
/* by default all errors are recoverable, otherwise behavior depends on
return 0;
}
+/**
+ * mnt_table_parse_swaps:
+ * @tb: table
+ * @filename: overwrites default (/proc/swaps or $LIBMOUNT_SWAPS) or NULL
+ *
+ * This function parses /proc/swaps and appends new lines to the @tab.
+ *
+ * See also mnt_table_set_parser_errcb().
+ *
+ * Returns: 0 on success or negative number in case of error.
+ */
+int mnt_table_parse_swaps(struct libmnt_table *tb, const char *filename)
+{
+ assert(tb);
+
+ if (!tb)
+ return -EINVAL;
+ if (!filename) {
+ filename = mnt_get_swaps_path();
+ if (!filename)
+ return -EINVAL;
+ }
+
+ tb->fmt = MNT_FMT_SWAPS;
+
+ return mnt_table_parse_file(tb, filename);
+}
+
/**
* mnt_table_parse_fstab:
* @tb: table
return 0;
}
+/**
+ * mnt_get_swaps_path:
+ *
+ * Returns: path to /proc/swaps or $LIBMOUNT_SWAPS.
+ */
+const char *mnt_get_swaps_path(void)
+{
+ const char *p = safe_getenv("LIBMOUNT_SWAPS");
+ return p ? : _PATH_PROC_SWAPS;
+}
+
/**
* mnt_get_fstab_path:
*