]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/readdir.c
2 * Copyright (c) 2013 Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
27 static struct cmdinfo readdir_cmd
;
29 const char *d_type_str(unsigned int type
)
72 struct dirent
*dirent
)
74 printf("%08llx: d_ino: 0x%08lx", offset
, dirent
->d_ino
);
75 #ifdef _DIRENT_HAVE_D_OFF
76 printf(" d_off: 0x%08lx", dirent
->d_off
);
78 #ifdef _DIRENT_HAVE_D_RECLEN
79 printf(" d_reclen: 0x%x", dirent
->d_reclen
);
81 #ifdef _DIRENT_HAVE_D_TYPE
82 printf(" d_type: %s", d_type_str(dirent
->d_type
));
84 printf(" d_name: %s\n", dirent
->d_name
);
91 unsigned long long length
,
93 unsigned long long *total
)
95 struct dirent
*dirent
;
101 while (*total
< length
) {
102 dirent
= readdir(dir
);
106 *total
+= dirent
->d_reclen
;
110 dump_dirent(offset
, dirent
);
111 offset
= dirent
->d_off
;
124 unsigned long long total
;
126 size_t fsblocksize
, fssectsize
;
127 struct timeval t1
, t2
;
128 char s1
[64], s2
[64], ts
[64];
129 long long offset
= -1;
130 unsigned long long length
= -1; /* max length limit */
135 init_cvtnum(&fsblocksize
, &fssectsize
);
137 while ((c
= getopt(argc
, argv
, "l:o:v")) != EOF
) {
140 length
= cvtnum(fsblocksize
, fssectsize
, optarg
);
143 offset
= cvtnum(fsblocksize
, fssectsize
, optarg
);
149 return command_usage(&readdir_cmd
);
157 dir
= fdopendir(dfd
);
165 offset
= telldir(dir
);
168 gettimeofday(&t1
, NULL
);
169 cnt
= read_directory(dir
, offset
, length
, verbose
, &total
);
170 gettimeofday(&t2
, NULL
);
176 timestr(&t2
, ts
, sizeof(ts
), 0);
178 cvtstr(total
, s1
, sizeof(s1
));
179 cvtstr(tdiv(total
, t2
), s2
, sizeof(s2
));
181 printf(_("read %llu bytes from offset %lld\n"), total
, offset
);
182 printf(_("%s, %d ops, %s (%s/sec and %.4f ops/sec)\n"),
183 s1
, cnt
, ts
, s2
, tdiv(cnt
, t2
));
191 readdir_cmd
.name
= "readdir";
192 readdir_cmd
.cfunc
= readdir_f
;
193 readdir_cmd
.argmax
= 5;
194 readdir_cmd
.flags
= CMD_NOMAP_OK
|CMD_FOREIGN_OK
;
195 readdir_cmd
.args
= _("[-v][-o offset][-l length]");
196 readdir_cmd
.oneline
= _("read directory entries");
198 add_command(&readdir_cmd
);