Removed the error count from sys_rstat() as this can easily happen with
links and can be regarded as an harmless error (maybe it should directly test for broken links, though). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9523 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a7e04f442b
commit
794822a8b5
@ -414,68 +414,65 @@ mode_bits_to_str(int mode, char *str)
|
|||||||
static void
|
static void
|
||||||
do_dir(int argc, char **argv)
|
do_dir(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int dirfd, err, max_err = 10;
|
int dirfd, err, max_err = 10;
|
||||||
char dirname[128], buff[512], time_buf[64] = { '\0', };
|
char dirname[128], buff[512], time_buf[64] = { '\0', };
|
||||||
size_t len,count = 0;
|
size_t len, count = 0;
|
||||||
struct my_dirent *dent;
|
struct my_dirent *dent;
|
||||||
struct my_stat st;
|
struct my_stat st;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
char mode_str[16];
|
char mode_str[16];
|
||||||
|
|
||||||
dent = (struct my_dirent *)buff;
|
|
||||||
strcpy(dirname, "/myfs/");
|
|
||||||
if (argc > 1)
|
|
||||||
strcat(dirname, &argv[1][0]);
|
|
||||||
|
|
||||||
if ((dirfd = sys_opendir(1, -1, dirname, 0)) < 0) {
|
dent = (struct my_dirent *)buff;
|
||||||
printf("dir: error opening: %s\n", dirname);
|
strcpy(dirname, "/myfs/");
|
||||||
return;
|
if (argc > 1)
|
||||||
}
|
strcat(dirname, &argv[1][0]);
|
||||||
|
|
||||||
printf("Directory listing for: %s\n", dirname);
|
if ((dirfd = sys_opendir(1, -1, dirname, 0)) < 0) {
|
||||||
printf(" inode# mode bits uid gid size "
|
printf("dir: error opening: %s\n", dirname);
|
||||||
"Date Name\n");
|
return;
|
||||||
|
}
|
||||||
while (1) {
|
|
||||||
len = 1;
|
|
||||||
err = sys_readdir(1, dirfd, dent, sizeof(buff), len);
|
|
||||||
if (err < 0) {
|
|
||||||
printf("readdir failed for: %s\n", dent->d_name);
|
|
||||||
if (max_err-- <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
printf("Directory listing for: %s\n", dirname);
|
||||||
|
printf(" inode# mode bits uid gid size "
|
||||||
|
"Date Name\n");
|
||||||
|
|
||||||
err = sys_rstat(1, dirfd, dent->d_name, &st, 1);
|
while (1) {
|
||||||
if (err != 0) {
|
len = 1;
|
||||||
printf("stat failed for: %s (%Ld)\n", dent->d_name, dent->d_ino);
|
err = sys_readdir(1, dirfd, dent, sizeof(buff), len);
|
||||||
if (max_err-- <= 0)
|
if (err < 0) {
|
||||||
break;
|
printf("readdir failed for: %s\n", dent->d_name);
|
||||||
|
if (max_err-- <= 0)
|
||||||
continue;
|
break;
|
||||||
}
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
tm = localtime(&st.st_mtime);
|
if (err == 0)
|
||||||
strftime(time_buf, sizeof(time_buf), "%b %d %I:%M", tm);
|
break;
|
||||||
|
|
||||||
mode_bits_to_str(st.st_mode, mode_str);
|
err = sys_rstat(1, dirfd, dent->d_name, &st, 1);
|
||||||
|
if (err != 0) {
|
||||||
|
// may happen for unresolvable links
|
||||||
|
printf("stat failed for: %s (%Ld)\n", dent->d_name, dent->d_ino);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%12Ld %s %6d %6d %12Ld %s %s\n", st.st_ino, mode_str,
|
tm = localtime(&st.st_mtime);
|
||||||
st.st_uid, st.st_gid, st.st_size, time_buf, dent->d_name);
|
strftime(time_buf, sizeof(time_buf), "%b %d %I:%M", tm);
|
||||||
|
|
||||||
|
mode_bits_to_str(st.st_mode, mode_str);
|
||||||
|
|
||||||
|
printf("%12Ld %s %6d %6d %12Ld %s %s\n", st.st_ino, mode_str,
|
||||||
|
st.st_uid, st.st_gid, st.st_size, time_buf, dent->d_name);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0)
|
||||||
printf("readdir failed on: %s\n", dent->d_name);
|
printf("readdir failed on: %s\n", dent->d_name);
|
||||||
}
|
|
||||||
printf("%ld files in directory!\n",count);
|
|
||||||
|
|
||||||
sys_closedir(1, dirfd);
|
printf("%ld files in directory!\n",count);
|
||||||
|
|
||||||
|
sys_closedir(1, dirfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user