2 * Common definitions for Linux and XFS quota tests.
4 * Copyright (c) 2016 Eugene Syromiatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef STRACE_TESTS_QUOTACTL_H
32 #define STRACE_TESTS_QUOTACTL_H
34 # include <inttypes.h>
38 # ifdef HAVE_LINUX_QUOTA_H
39 /* Broken in CentOS 5: has extern spinlock_t dq_data_lock; declaration */
40 # include <linux/quota.h>
42 # include <linux/types.h>
43 /* Broken in some new glibc versions: have Q_GETNEXTQUOTA definition but no
44 * struct nextdqblk defined. Fixed in glibc-2.24-106-g4d72808. */
45 # include <sys/quota.h>
49 # define QCMD_CMD(_val) ((unsigned) (_val) >> SUBCMDSHIFT)
50 # endif /* !QCMD_CMD */
53 # define QCMD_TYPE(_val) ((unsigned) (_val) & SUBCMDMASK)
54 # endif /* !QCMD_TYPE */
60 # define PRINT_FIELD_D(prefix, where, field) \
61 printf("%s%s=%lld", (prefix), #field, \
62 sign_extend_unsigned_to_ll((where)->field))
64 # define PRINT_FIELD_U(prefix, where, field) \
65 printf("%s%s=%llu", (prefix), #field, \
66 zero_extend_signed_to_ull((where)->field))
68 # define PRINT_FIELD_X(prefix, where, field) \
69 printf("%s%s=%#llx", (prefix), #field, \
70 zero_extend_signed_to_ull((where)->field))
72 # define ARG_STR(_arg) (_arg), #_arg
74 typedef void (*print_cb)(long rc, void *addr, void *arg);
76 enum check_quotactl_flag_bits {
84 enum check_quotactl_flags {
86 CQF_ID_SKIP = 1 << CQF_ID_SKIP_BIT,
87 CQF_ID_STR = 1 << CQF_ID_STR_BIT,
88 CQF_ADDR_SKIP = 1 << CQF_ADDR_SKIP_BIT,
89 CQF_ADDR_STR = 1 << CQF_ADDR_STR_BIT,
90 CQF_ADDR_CB = 1 << CQF_ADDR_CB_BIT,
95 check_quota(uint32_t flags, int cmd, const char *cmd_str,
96 const char *special, const char *special_str, ...)
99 const char *addr_str = NULL;
100 const char *id_str = NULL;
102 print_cb addr_cb = NULL;
103 void *addr_cb_arg = NULL;
108 va_start(ap, special_str);
110 if (!(flags & CQF_ID_SKIP)) {
111 id = va_arg(ap, uint32_t);
113 if (flags & CQF_ID_STR)
114 id_str = va_arg(ap, const char *);
117 if (!(flags & CQF_ADDR_SKIP)) {
118 addr = va_arg(ap, void *);
120 if (flags & CQF_ADDR_CB) {
121 addr_cb = va_arg(ap, print_cb);
122 addr_cb_arg = va_arg(ap, void *);
123 } else if (flags & CQF_ADDR_STR) {
124 addr_str = va_arg(ap, const char *);
130 rc = syscall(__NR_quotactl, cmd, special, id, addr);
131 printf("quotactl(%s, %s", cmd_str, special_str);
133 if (!(flags & CQF_ID_SKIP)) {
134 if (flags & CQF_ID_STR) {
135 printf(", %s", id_str);
137 if (id == (uint32_t)-1)
144 if (!(flags & CQF_ADDR_SKIP)) {
145 if (flags & CQF_ADDR_CB) {
147 addr_cb(rc, addr, addr_cb_arg);
148 } else if (flags & CQF_ADDR_STR) {
149 printf(", %s", addr_str);
151 printf(", %p", addr);
155 printf(") = %s\n", sprintrc(rc));
159 static const int bogus_cmd = 0xbadc0ded;
160 static const char * const bogus_special =
161 (const char *) (unsigned long) 0xfffffca7ffffc0deULL;
162 static const int bogus_id = 0xca7faced;
163 static void * const bogus_addr =
164 (void *) (unsigned long) 0xffffda7affffdeadULL;
166 /* It is invalid anyway due to the flash in the end */
167 static const char *bogus_dev = "/dev/bogus/";
168 static const char *bogus_dev_str = "\"/dev/bogus/\"";
170 static const char unterminated_data[] = { '\1', '\2', '\3' };
172 #endif /* !STRACE_TESTS_QUOTACTL_H */