Do not follow mounted fs in du mode

This commit is contained in:
Arun Prakash Jana 2017-08-22 21:31:06 +05:30
parent 96e9028226
commit 081cb3a3e8
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 24 additions and 12 deletions

36
nnn.c
View File

@ -1665,9 +1665,10 @@ dentfill(char *path, struct entry **dents,
{ {
static DIR *dirp; static DIR *dirp;
static struct dirent *dp; static struct dirent *dp;
static struct stat sb; static struct stat sb_path, sb;
static int fd, n; static int fd, n;
static char *namep; static char *namep;
static ulong num_saved;
static struct entry *dentp; static struct entry *dentp;
dirp = opendir(path); dirp = opendir(path);
@ -1682,6 +1683,11 @@ dentfill(char *path, struct entry **dents,
num_files = 0; num_files = 0;
dir_blocks = 0; dir_blocks = 0;
update_fs_free(path); update_fs_free(path);
if (fstatat(fd, ".", &sb_path, 0) == -1) {
printwarn();
return 0;
}
} }
while ((dp = readdir(dirp)) != NULL) { while ((dp = readdir(dirp)) != NULL) {
@ -1701,15 +1707,17 @@ dentfill(char *path, struct entry **dents,
continue; continue;
if (S_ISDIR(sb.st_mode)) { if (S_ISDIR(sb.st_mode)) {
ent_blocks = 0; if (sb_path.st_dev == sb.st_dev) {
mkpath(path, namep, g_buf, PATH_MAX); ent_blocks = 0;
mkpath(path, namep, g_buf, PATH_MAX);
if (nftw(g_buf, sum_bsizes, open_max, if (nftw(g_buf, sum_bsizes, open_max,
FTW_MOUNT | FTW_PHYS) == -1) { FTW_MOUNT | FTW_PHYS) == -1) {
printmsg(STR_NFTWFAIL); printmsg(STR_NFTWFAIL);
dir_blocks += sb.st_blocks; dir_blocks += sb.st_blocks;
} else } else
dir_blocks += ent_blocks; dir_blocks += ent_blocks;
}
} else { } else {
if (sb.st_blocks) if (sb.st_blocks)
dir_blocks += sb.st_blocks; dir_blocks += sb.st_blocks;
@ -1748,6 +1756,7 @@ dentfill(char *path, struct entry **dents,
if (cfg.blkorder) { if (cfg.blkorder) {
if (S_ISDIR(sb.st_mode)) { if (S_ISDIR(sb.st_mode)) {
ent_blocks = 0; ent_blocks = 0;
num_saved = num_files + 1;
mkpath(path, namep, g_buf, PATH_MAX); mkpath(path, namep, g_buf, PATH_MAX);
if (nftw(g_buf, sum_bsizes, open_max, if (nftw(g_buf, sum_bsizes, open_max,
@ -1756,13 +1765,16 @@ dentfill(char *path, struct entry **dents,
dentp->blocks = sb.st_blocks; dentp->blocks = sb.st_blocks;
} else } else
dentp->blocks = ent_blocks; dentp->blocks = ent_blocks;
if (sb_path.st_dev == sb.st_dev)
dir_blocks += dentp->blocks;
else
num_files = num_saved;
} else { } else {
dentp->blocks = sb.st_blocks; dentp->blocks = sb.st_blocks;
dir_blocks += dentp->blocks;
++num_files; ++num_files;
} }
if (dentp->blocks)
dir_blocks += dentp->blocks;
} }
++n; ++n;