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