From: Zhang Xiliang <zhangxiliang@cn.fujitsu.com>
To: linux-ext4@vger.kernel.org
Subject: Problems with the max value for create directory
Date: Tue, 23 Dec 2008 11:02:54 +0800 [thread overview]
Message-ID: <495054DE.9030405@cn.fujitsu.com> (raw)
Hi,
I creat 65537 long directories and failed when the block size is 1024.
# mkfs.ext4dev -b 1024 -I 256 /dev/hda3
# tune2fs -E test_fs -O extents /dev/hda3
# mount -t ext4dev /dev/hda3 /mnt
# ./create_long_dirs 65537 /mnt
The code of create_long_dirs.c:
#define _ATFILE_SOURCE
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
//#define __USE_ATFILE
#include <sys/stat.h>
#define NAME_LEN 255
#define NCHARS 62
#define MAX_LEN1 62
#define MAX_LEN2 (62 * 62)
#define MAX_LEN3 (62 * 62 * 62)
/* valid characters for the directory name */
char chars[NCHARS + 1] =
"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
/* to store the generated directory name */
char name[NAME_LEN + 1];
int names;
int parent_fd;
void init_name(void)
{
int i;
srand(time(NULL));
for (i = 0; i < NAME_LEN; i++)
name[i] = chars[rand() % 62];
}
void create_dir(void)
{
if (mkdirat(parent_fd, name, S_IRWXU)) {
perror("mkdir");
exit(1);
}
}
/*
* create_dirs - create @names directory names
* @n: how many names to be created
*
* if n <= 62, we need to modify 1 char of the name
* if n <= 62*62, we need to modify 2 chars
* if n <= 62*62*62, we need to modify 3 chars
*/
void create_dirs(int n)
{
int i, j, k;
int depth;
if (n <= MAX_LEN1)
depth = 1;
else if (n <= MAX_LEN2)
depth = 2;
else
depth = 3;
for (i = 0; i < NCHARS; i++) {
name[0] = chars[i];
if (depth == 1) {
create_dir();
if (--n == 0)
return;
continue;
}
for (j = 0; j < NCHARS; j++) {
name[1] = chars[j];
if (depth == 2) {
create_dir();
if (--n == 0)
return;
continue;
}
for (k = 0; k < NCHARS; k++) {
name[2] = chars[k];
create_dir();
if (--n == 0)
return;
}
}
}
}
void usage()
{
fprintf(stderr, "Usage: create_long_dirs nr_dirs parent_dir\n");
}
int main(int argc, char *argv[])
{
if (argc != 3) {
usage();
return 1;
}
names = atoi(argv[1]);
if (names > MAX_LEN3 || names <= 0) {
usage();
return 1;
}
parent_fd = open(argv[2], O_RDONLY);
if (parent_fd == -1) {
perror("open parent dir failed");
return 1;
}
init_name();
create_dirs(names);
return 0;
}
--
Regards
Zhang Xiliang
next reply other threads:[~2008-12-23 3:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-23 3:02 Zhang Xiliang [this message]
2008-12-23 4:02 ` Problems with the max value for create directory Toshiyuki Okajima
2008-12-23 7:49 ` Andreas Dilger
2008-12-23 20:12 ` Theodore Tso
2008-12-24 1:18 ` Zhang Xiliang
2008-12-24 23:54 ` Theodore Tso
2008-12-29 13:47 ` Peng tao
2009-01-06 3:16 ` Andreas Dilger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=495054DE.9030405@cn.fujitsu.com \
--to=zhangxiliang@cn.fujitsu.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.