|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* |
| 3 | + * Copyright (c) 2025 Wei Gao <wegao@suse.com> |
| 4 | + */ |
| 5 | + |
| 6 | +#include "tst_test.h" |
| 7 | +#include "tst_safe_stdio.h" |
| 8 | + |
| 9 | +#define INODE_SIZE 128 |
| 10 | +#define BLOCK_SIZE 1024 |
| 11 | +#define MKFS_SIZE_VAL 10240 |
| 12 | + |
| 13 | +#define MOUNT_POINT "mount_test_filesystems" |
| 14 | + |
| 15 | +static int check_inode_size(unsigned int size) |
| 16 | +{ |
| 17 | + char path[PATH_MAX]; |
| 18 | + char line[PATH_MAX]; |
| 19 | + FILE *tune2fs; |
| 20 | + char str_size[NAME_MAX]; |
| 21 | + |
| 22 | + snprintf(str_size, sizeof(str_size), "%u", size); |
| 23 | + snprintf(path, sizeof(path), "tune2fs -l %s 2>&1", tst_device->dev); |
| 24 | + tune2fs = SAFE_POPEN(path, "r"); |
| 25 | + |
| 26 | + while (fgets(line, PATH_MAX, tune2fs) != NULL) { |
| 27 | + if (strstr(line, "Inode size:") && strstr(line, str_size)) |
| 28 | + return 0; |
| 29 | + } |
| 30 | + |
| 31 | + pclose(tune2fs); |
| 32 | + return -1; |
| 33 | +} |
| 34 | + |
| 35 | +static int check_mnt_data(char *opt) |
| 36 | +{ |
| 37 | + FILE *fp; |
| 38 | + char line[PATH_MAX]; |
| 39 | + |
| 40 | + fp = SAFE_FOPEN("/proc/mounts", "r"); |
| 41 | + |
| 42 | + while (fgets(line, PATH_MAX, fp) != NULL) { |
| 43 | + if (strstr(line, tst_device->dev) && strstr(line, opt)) |
| 44 | + return 0; |
| 45 | + } |
| 46 | + SAFE_FCLOSE(fp); |
| 47 | + return -1; |
| 48 | +} |
| 49 | + |
| 50 | +static int check_mkfs_size_opt(unsigned int size) |
| 51 | +{ |
| 52 | + char path[PATH_MAX]; |
| 53 | + char line[PATH_MAX]; |
| 54 | + FILE *dumpe2fs; |
| 55 | + char str_size[NAME_MAX]; |
| 56 | + |
| 57 | + snprintf(str_size, sizeof(str_size), "%u", size); |
| 58 | + snprintf(path, sizeof(path), "dumpe2fs -h %s 2>&1", tst_device->dev); |
| 59 | + dumpe2fs = SAFE_POPEN(path, "r"); |
| 60 | + |
| 61 | + while (fgets(line, PATH_MAX, dumpe2fs) != NULL) { |
| 62 | + if (strstr(line, "Block count:") && strstr(line, str_size)) |
| 63 | + return 0; |
| 64 | + } |
| 65 | + |
| 66 | + pclose(dumpe2fs); |
| 67 | + return -1; |
| 68 | +} |
| 69 | + |
| 70 | +static void do_test(void) |
| 71 | +{ |
| 72 | + long fs_type; |
| 73 | + |
| 74 | + fs_type = tst_fs_type(MOUNT_POINT); |
| 75 | + |
| 76 | + if (fs_type == TST_EXT234_MAGIC) { |
| 77 | + TST_EXP_PASS((check_inode_size(INODE_SIZE))); |
| 78 | + TST_EXP_PASS((check_mkfs_size_opt(MKFS_SIZE_VAL))); |
| 79 | + } |
| 80 | + |
| 81 | + if (fs_type == TST_XFS_MAGIC) |
| 82 | + TST_EXP_PASS((check_mnt_data("usrquota"))); |
| 83 | +} |
| 84 | + |
| 85 | +static struct tst_test test = { |
| 86 | + .test_all = do_test, |
| 87 | + .needs_root = 1, |
| 88 | + .mntpoint = MOUNT_POINT, |
| 89 | + .mount_device = 1, |
| 90 | + .needs_cmds = (struct tst_cmd[]) { |
| 91 | + {.cmd = "tune2fs"}, |
| 92 | + {.cmd = "dumpe2fs"}, |
| 93 | + {} |
| 94 | + }, |
| 95 | + .filesystems = (struct tst_fs []) { |
| 96 | + { |
| 97 | + .type = "ext3", |
| 98 | + .mkfs_opts = (const char *const []){"-I", TST_TO_STR(INODE_SIZE), "-b", TST_TO_STR(BLOCK_SIZE), NULL}, |
| 99 | + .mkfs_size_opt = TST_TO_STR(MKFS_SIZE_VAL), |
| 100 | + }, |
| 101 | + { |
| 102 | + .type = "xfs", |
| 103 | + .mnt_data = "usrquota", |
| 104 | + }, |
| 105 | + {} |
| 106 | + }, |
| 107 | + |
| 108 | +}; |
0 commit comments