]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/swapon-common.c
su: change error message
[thirdparty/util-linux.git] / sys-utils / swapon-common.c
CommitLineData
0b0c231f
KZ
1
2#include "c.h"
3#include "nls.h"
0b0c231f
KZ
4#include "xalloc.h"
5
18b3e549
KZ
6#include "swapon-common.h"
7
0b0c231f
KZ
8/*
9 * content of /proc/swaps and /etc/fstab
10 */
11static struct libmnt_table *swaps, *fstab;
12
13struct libmnt_cache *mntcache;
14
1cd9d0d7
KZ
15static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)),
16 const char *filename, int line)
17{
18 if (filename)
b779c1ae 19 warnx(_("%s: parse error at line %d -- ignored"), filename, line);
1cd9d0d7
KZ
20 return 1;
21}
22
0b0c231f
KZ
23struct libmnt_table *get_fstab(void)
24{
25 if (!fstab) {
26 fstab = mnt_new_table();
27 if (!fstab)
28 return NULL;
1cd9d0d7 29 mnt_table_set_parser_errcb(fstab, table_parser_errcb);
0b0c231f
KZ
30 mnt_table_set_cache(fstab, mntcache);
31 if (mnt_table_parse_fstab(fstab, NULL) != 0)
32 return NULL;
33 }
34
35 return fstab;
36}
37
38struct libmnt_table *get_swaps(void)
39{
40 if (!swaps) {
41 swaps = mnt_new_table();
42 if (!swaps)
43 return NULL;
44 mnt_table_set_cache(swaps, mntcache);
1cd9d0d7 45 mnt_table_set_parser_errcb(swaps, table_parser_errcb);
0b0c231f
KZ
46 if (mnt_table_parse_swaps(swaps, NULL) != 0)
47 return NULL;
48 }
49
50 return swaps;
51}
52
53void free_tables(void)
54{
50fccba1
KZ
55 mnt_unref_table(swaps);
56 mnt_unref_table(fstab);
0b0c231f
KZ
57}
58
59int match_swap(struct libmnt_fs *fs, void *data __attribute__((unused)))
60{
61 return fs && mnt_fs_is_swaparea(fs);
62}
63
64int is_active_swap(const char *filename)
65{
66 struct libmnt_table *st = get_swaps();
e7b63bea 67 return st && mnt_table_find_source(st, filename, MNT_ITER_BACKWARD);
0b0c231f
KZ
68}
69
70
71int cannot_find(const char *special)
72{
73 warnx(_("cannot find the device for %s"), special);
74 return -1;
75}
76
77/*
78 * Lists with -L and -U option
79 */
80static const char **llist;
81static size_t llct;
82static const char **ulist;
83static size_t ulct;
84
85
86void add_label(const char *label)
87{
fea1cbf7 88 llist = xrealloc(llist, (++llct) * sizeof(char *));
0b0c231f
KZ
89 llist[llct - 1] = label;
90}
91
92const char *get_label(size_t i)
93{
94 return i < llct ? llist[i] : NULL;
95}
96
97size_t numof_labels(void)
98{
99 return llct;
100}
101
102void add_uuid(const char *uuid)
103{
fea1cbf7 104 ulist = xrealloc(ulist, (++ulct) * sizeof(char *));
0b0c231f
KZ
105 ulist[ulct - 1] = uuid;
106}
107
108const char *get_uuid(size_t i)
109{
110 return i < ulct ? ulist[i] : NULL;
111}
112
113size_t numof_uuids(void)
114{
115 return ulct;
116}
117