]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/swapon-common.c
6 #include "swapon-common.h"
9 * content of /proc/swaps and /etc/fstab
11 static struct libmnt_table
*swaps
, *fstab
;
13 struct libmnt_cache
*mntcache
;
15 static int table_parser_errcb(struct libmnt_table
*tb
__attribute__((__unused__
)),
16 const char *filename
, int line
)
19 warnx(_("%s: parse error at line %d -- ignored"), filename
, line
);
23 struct libmnt_table
*get_fstab(void)
26 fstab
= mnt_new_table();
29 mnt_table_set_parser_errcb(fstab
, table_parser_errcb
);
30 mnt_table_set_cache(fstab
, mntcache
);
31 if (mnt_table_parse_fstab(fstab
, NULL
) != 0)
38 struct libmnt_table
*get_swaps(void)
41 swaps
= mnt_new_table();
44 mnt_table_set_cache(swaps
, mntcache
);
45 mnt_table_set_parser_errcb(swaps
, table_parser_errcb
);
46 if (mnt_table_parse_swaps(swaps
, NULL
) != 0)
53 void free_tables(void)
55 mnt_unref_table(swaps
);
56 mnt_unref_table(fstab
);
59 int match_swap(struct libmnt_fs
*fs
, void *data
__attribute__((unused
)))
61 return fs
&& mnt_fs_is_swaparea(fs
);
64 int is_active_swap(const char *filename
)
66 struct libmnt_table
*st
= get_swaps();
67 return st
&& mnt_table_find_source(st
, filename
, MNT_ITER_BACKWARD
);
71 int cannot_find(const char *special
)
73 warnx(_("cannot find the device for %s"), special
);
78 * Lists with -L and -U option
80 static const char **llist
;
82 static const char **ulist
;
86 void add_label(const char *label
)
88 llist
= xrealloc(llist
, (++llct
) * sizeof(char *));
89 llist
[llct
- 1] = label
;
92 const char *get_label(size_t i
)
94 return i
< llct
? llist
[i
] : NULL
;
97 size_t numof_labels(void)
102 void add_uuid(const char *uuid
)
104 ulist
= xrealloc(ulist
, (++ulct
) * sizeof(char *));
105 ulist
[ulct
- 1] = uuid
;
108 const char *get_uuid(size_t i
)
110 return i
< ulct
? ulist
[i
] : NULL
;
113 size_t numof_uuids(void)