]>
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
20 #include <xfs/command.h>
21 #include <xfs/input.h>
25 #include <sys/types.h>
28 static struct cmdinfo readdir_cmd
;
30 const char *d_type_str(unsigned int type
)
73 struct dirent
*dirent
)
75 printf("%08llx: d_ino: 0x%08lx", offset
, dirent
->d_ino
);
76 #ifdef _DIRENT_HAVE_D_OFF
77 printf(" d_off: 0x%08lx", dirent
->d_off
);
79 #ifdef _DIRENT_HAVE_D_RECLEN
80 printf(" d_reclen: 0x%x", dirent
->d_reclen
);
82 #ifdef _DIRENT_HAVE_D_TYPE
83 printf(" d_type: %s", d_type_str(dirent
->d_type
));
85 printf(" d_name: %s\n", dirent
->d_name
);
92 unsigned long long length
,
94 unsigned long long *total
)
96 struct dirent
*dirent
;
102 while (*total
< length
) {
103 dirent
= readdir(dir
);
107 *total
+= dirent
->d_reclen
;
111 dump_dirent(offset
, dirent
);
112 offset
= dirent
->d_off
;
125 unsigned long long total
;
127 size_t fsblocksize
, fssectsize
;
128 struct timeval t1
, t2
;
129 char s1
[64], s2
[64], ts
[64];
130 long long offset
= -1;
131 unsigned long long length
= -1; /* max length limit */
136 init_cvtnum(&fsblocksize
, &fssectsize
);
138 while ((c
= getopt(argc
, argv
, "l:o:v")) != EOF
) {
141 length
= cvtnum(fsblocksize
, fssectsize
, optarg
);
144 offset
= cvtnum(fsblocksize
, fssectsize
, optarg
);
150 return command_usage(&readdir_cmd
);
158 dir
= fdopendir(dfd
);
166 offset
= telldir(dir
);
169 gettimeofday(&t1
, NULL
);
170 cnt
= read_directory(dir
, offset
, length
, verbose
, &total
);
171 gettimeofday(&t2
, NULL
);
177 timestr(&t2
, ts
, sizeof(ts
), 0);
179 cvtstr(total
, s1
, sizeof(s1
));
180 cvtstr(tdiv(total
, t2
), s2
, sizeof(s2
));
182 printf(_("read %llu bytes from offset %lld\n"), total
, offset
);
183 printf(_("%s, %d ops, %s (%s/sec and %.4f ops/sec)\n"),
184 s1
, cnt
, ts
, s2
, tdiv(cnt
, t2
));
192 readdir_cmd
.name
= "readdir";
193 readdir_cmd
.cfunc
= readdir_f
;
194 readdir_cmd
.argmax
= 5;
195 readdir_cmd
.flags
= CMD_NOMAP_OK
|CMD_FOREIGN_OK
;
196 readdir_cmd
.args
= _("[-v][-o offset][-l length]");
197 readdir_cmd
.oneline
= _("read directory entries");
199 add_command(&readdir_cmd
);