1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2009 FUJITSU LIMITED
4 * Author: Li Zefan <lizf@cn.fujitsu.com>
7 #define _POSIX_C_SOURCE 200809L
14 #include <sys/types.h>
18 /* NCHARS = 10 + 26 + 26 = 62 */
22 #define MAX_LEN2 (62 * 62)
23 #define MAX_LEN3 (62 * 62 * 62)
25 /* valid characters for the directory name */
26 char chars[NCHARS + 1] = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
28 /* to store the generated directory name */
29 char name[NAME_LEN + 1];
34 * init_name - initialize the directory name
36 * Generate a randomized directory name, and then we generate more
37 * directory names based on it.
45 for (i = 0; i < NAME_LEN; i++)
46 name[i] = chars[rand() % 62];
51 if (mkdirat(parent_fd, name, S_IRWXU)) {
58 * create_dirs - create @names directory names
59 * @n: how many names to be created
61 * if n <= 62, we need to modify 1 char of the name
62 * if n <= 62*62, we need to modify 2 chars
63 * if n <= 62*62*62, we need to modify 3 chars
65 void create_dirs(int n)
72 else if (n <= MAX_LEN2)
77 for (i = 0; i < NCHARS; i++) {
86 for (j = 0; j < NCHARS; j++) {
95 for (k = 0; k < NCHARS; k++) {
107 fprintf(stderr, "Usage: create_long_dirs nr_dirs parent_dir\n");
111 * Create long-name directories
112 * @argv[1]: directory number
113 * @argv[2]: parent directory
115 int main(int argc, char *argv[])
122 names = atoi(argv[1]);
123 if (names > MAX_LEN3 || names <= 0) {
128 parent_fd = open(argv[2], O_RDONLY);
129 if (parent_fd == -1) {
130 perror("open parent dir failed");