]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/quota-util.c
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / basic / quota-util.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <sys/quota.h>
4
5 #include "alloc-util.h"
6 #include "blockdev-util.h"
7 #include "quota-util.h"
8 #include "stat-util.h"
9
10 int quotactl_devno(int cmd, dev_t devno, int id, void *addr) {
11 _cleanup_free_ char *devnode = NULL;
12 int r;
13
14 /* Like quotactl() but takes a dev_t instead of a path to a device node, and fixes caddr_t → void*,
15 * like we should, today */
16
17 r = device_path_make_major_minor(S_IFBLK, devno, &devnode);
18 if (r < 0)
19 return r;
20
21 if (quotactl(cmd, devnode, id, addr) < 0)
22 return -errno;
23
24 return 0;
25 }
26
27 int quotactl_path(int cmd, const char *path, int id, void *addr) {
28 dev_t devno;
29 int r;
30
31 /* Like quotactl() but takes a path to some fs object, and changes the backing file system. I.e. the
32 * argument shouldn't be a block device but a regular file system object */
33
34 r = get_block_device(path, &devno);
35 if (r < 0)
36 return r;
37 if (devno == 0) /* Doesn't have a block device */
38 return -ENODEV;
39
40 return quotactl_devno(cmd, devno, id, addr);
41 }