mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Use correct data type and names for block count
This commit is contained in:
parent
ad4e35215b
commit
2524dfb08c
66
nnn.c
66
nnn.c
|
@ -124,7 +124,7 @@ typedef struct entry {
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
time_t t;
|
time_t t;
|
||||||
off_t size;
|
off_t size;
|
||||||
off_t bsize;
|
blkcnt_t blocks; /* number of 512B blocks allocated */
|
||||||
} *pEntry;
|
} *pEntry;
|
||||||
|
|
||||||
/* Bookmark */
|
/* Bookmark */
|
||||||
|
@ -139,7 +139,7 @@ typedef struct
|
||||||
uchar filtermode : 1; /* Set to enter filter mode */
|
uchar filtermode : 1; /* Set to enter filter mode */
|
||||||
uchar mtimeorder : 1; /* Set to sort by time modified */
|
uchar mtimeorder : 1; /* Set to sort by time modified */
|
||||||
uchar sizeorder : 1; /* Set to sort by file size */
|
uchar sizeorder : 1; /* Set to sort by file size */
|
||||||
uchar bsizeorder : 1; /* Set to sort by blocks used (disk usage) */
|
uchar blkorder : 1; /* Set to sort by blocks used (disk usage) */
|
||||||
uchar showhidden : 1; /* Set to show hidden files */
|
uchar showhidden : 1; /* Set to show hidden files */
|
||||||
uchar showdetail : 1; /* Clear to show fewer file info */
|
uchar showdetail : 1; /* Clear to show fewer file info */
|
||||||
uchar reserved : 2;
|
uchar reserved : 2;
|
||||||
|
@ -167,8 +167,8 @@ static char *player;
|
||||||
static char *copier;
|
static char *copier;
|
||||||
static char *editor;
|
static char *editor;
|
||||||
static char *desktop_manager;
|
static char *desktop_manager;
|
||||||
static off_t blk_size;
|
static blkcnt_t ent_blocks;
|
||||||
static off_t dir_blocks;
|
static blkcnt_t dir_blocks;
|
||||||
static size_t fs_free;
|
static size_t fs_free;
|
||||||
static uint open_max;
|
static uint open_max;
|
||||||
static bm bookmark[MAX_BM];
|
static bm bookmark[MAX_BM];
|
||||||
|
@ -593,10 +593,10 @@ entrycmp(const void *va, const void *vb)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.bsizeorder) {
|
if (cfg.blkorder) {
|
||||||
if (pb->bsize > pa->bsize)
|
if (pb->blocks > pa->blocks)
|
||||||
return 1;
|
return 1;
|
||||||
else if (pb->bsize < pa->bsize)
|
else if (pb->blocks < pa->blocks)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ fill(struct entry **dents,
|
||||||
_dent.mode = (*dents)[count].mode;
|
_dent.mode = (*dents)[count].mode;
|
||||||
_dent.t = (*dents)[count].t;
|
_dent.t = (*dents)[count].t;
|
||||||
_dent.size = (*dents)[count].size;
|
_dent.size = (*dents)[count].size;
|
||||||
_dent.bsize = (*dents)[count].bsize;
|
_dent.blocks = (*dents)[count].blocks;
|
||||||
|
|
||||||
/* Copy ndents - 1 to count */
|
/* Copy ndents - 1 to count */
|
||||||
xstrlcpy((*dents)[count].name,
|
xstrlcpy((*dents)[count].name,
|
||||||
|
@ -703,7 +703,7 @@ fill(struct entry **dents,
|
||||||
(*dents)[count].mode = (*dents)[ndents].mode;
|
(*dents)[count].mode = (*dents)[ndents].mode;
|
||||||
(*dents)[count].t = (*dents)[ndents].t;
|
(*dents)[count].t = (*dents)[ndents].t;
|
||||||
(*dents)[count].size = (*dents)[ndents].size;
|
(*dents)[count].size = (*dents)[ndents].size;
|
||||||
(*dents)[count].bsize = (*dents)[ndents].bsize;
|
(*dents)[count].blocks = (*dents)[ndents].blocks;
|
||||||
|
|
||||||
/* Copy tmp to ndents - 1 */
|
/* Copy tmp to ndents - 1 */
|
||||||
xstrlcpy((*dents)[ndents].name, _dent.name,
|
xstrlcpy((*dents)[ndents].name, _dent.name,
|
||||||
|
@ -711,7 +711,7 @@ fill(struct entry **dents,
|
||||||
(*dents)[ndents].mode = _dent.mode;
|
(*dents)[ndents].mode = _dent.mode;
|
||||||
(*dents)[ndents].t = _dent.t;
|
(*dents)[ndents].t = _dent.t;
|
||||||
(*dents)[ndents].size = _dent.size;
|
(*dents)[ndents].size = _dent.size;
|
||||||
(*dents)[ndents].bsize = _dent.bsize;
|
(*dents)[ndents].blocks = _dent.blocks;
|
||||||
|
|
||||||
--count;
|
--count;
|
||||||
}
|
}
|
||||||
|
@ -1029,7 +1029,7 @@ printent_long(struct entry *ent, int sel)
|
||||||
if (sel)
|
if (sel)
|
||||||
attron(A_REVERSE);
|
attron(A_REVERSE);
|
||||||
|
|
||||||
if (!cfg.bsizeorder) {
|
if (!cfg.blkorder) {
|
||||||
if (S_ISDIR(ent->mode))
|
if (S_ISDIR(ent->mode))
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s / %s/",
|
snprintf(g_buf, ncols, "%s%-16.16s / %s/",
|
||||||
CURSYM(sel), buf, replace_escape(ent->name));
|
CURSYM(sel), buf, replace_escape(ent->name));
|
||||||
|
@ -1059,7 +1059,7 @@ printent_long(struct entry *ent, int sel)
|
||||||
} else {
|
} else {
|
||||||
if (S_ISDIR(ent->mode))
|
if (S_ISDIR(ent->mode))
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s %8.8s/ %s/",
|
snprintf(g_buf, ncols, "%s%-16.16s %8.8s/ %s/",
|
||||||
CURSYM(sel), buf, coolsize(ent->bsize << 9),
|
CURSYM(sel), buf, coolsize(ent->blocks << 9),
|
||||||
replace_escape(ent->name));
|
replace_escape(ent->name));
|
||||||
else if (S_ISLNK(ent->mode))
|
else if (S_ISLNK(ent->mode))
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s @ %s@",
|
snprintf(g_buf, ncols, "%s%-16.16s @ %s@",
|
||||||
|
@ -1083,11 +1083,11 @@ printent_long(struct entry *ent, int sel)
|
||||||
replace_escape(ent->name));
|
replace_escape(ent->name));
|
||||||
else if (ent->mode & 0100)
|
else if (ent->mode & 0100)
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s %8.8s* %s*",
|
snprintf(g_buf, ncols, "%s%-16.16s %8.8s* %s*",
|
||||||
CURSYM(sel), buf, coolsize(ent->bsize << 9),
|
CURSYM(sel), buf, coolsize(ent->blocks << 9),
|
||||||
replace_escape(ent->name));
|
replace_escape(ent->name));
|
||||||
else
|
else
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s %8.8s %s",
|
snprintf(g_buf, ncols, "%s%-16.16s %8.8s %s",
|
||||||
CURSYM(sel), buf, coolsize(ent->bsize << 9),
|
CURSYM(sel), buf, coolsize(ent->blocks << 9),
|
||||||
replace_escape(ent->name));
|
replace_escape(ent->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1429,7 +1429,7 @@ sum_bsizes(const char *fpath, const struct stat *sb,
|
||||||
int typeflag, struct FTW *ftwbuf)
|
int typeflag, struct FTW *ftwbuf)
|
||||||
{
|
{
|
||||||
if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D))
|
if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D))
|
||||||
blk_size += sb->st_blocks;
|
ent_blocks += sb->st_blocks;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1479,7 +1479,7 @@ dentfill(char *path, struct entry **dents,
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
if (cfg.bsizeorder)
|
if (cfg.blkorder)
|
||||||
dir_blocks = 0;
|
dir_blocks = 0;
|
||||||
|
|
||||||
dirp = opendir(path);
|
dirp = opendir(path);
|
||||||
|
@ -1501,17 +1501,17 @@ dentfill(char *path, struct entry **dents,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter(re, dp->d_name) == 0) {
|
if (filter(re, dp->d_name) == 0) {
|
||||||
if (!cfg.bsizeorder)
|
if (!cfg.blkorder)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
blk_size = 0;
|
ent_blocks = 0;
|
||||||
if (nftw(newpath, sum_bsizes, open_max,
|
if (nftw(newpath, sum_bsizes, open_max,
|
||||||
FTW_MOUNT | FTW_PHYS) == -1) {
|
FTW_MOUNT | FTW_PHYS) == -1) {
|
||||||
printmsg("nftw(3) failed");
|
printmsg("nftw(3) failed");
|
||||||
dir_blocks += sb.st_blocks;
|
dir_blocks += sb.st_blocks;
|
||||||
} else
|
} else
|
||||||
dir_blocks += blk_size;
|
dir_blocks += ent_blocks;
|
||||||
} else if (sb.st_blocks)
|
} else if (sb.st_blocks)
|
||||||
dir_blocks += sb.st_blocks;
|
dir_blocks += sb.st_blocks;
|
||||||
|
|
||||||
|
@ -1531,26 +1531,26 @@ dentfill(char *path, struct entry **dents,
|
||||||
(*dents)[n].t = sb.st_mtime;
|
(*dents)[n].t = sb.st_mtime;
|
||||||
(*dents)[n].size = sb.st_size;
|
(*dents)[n].size = sb.st_size;
|
||||||
|
|
||||||
if (cfg.bsizeorder) {
|
if (cfg.blkorder) {
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
blk_size = 0;
|
ent_blocks = 0;
|
||||||
if (nftw(newpath, sum_bsizes, open_max,
|
if (nftw(newpath, sum_bsizes, open_max,
|
||||||
FTW_MOUNT | FTW_PHYS) == -1) {
|
FTW_MOUNT | FTW_PHYS) == -1) {
|
||||||
printmsg("nftw(3) failed");
|
printmsg("nftw(3) failed");
|
||||||
(*dents)[n].bsize = sb.st_blocks;
|
(*dents)[n].blocks = sb.st_blocks;
|
||||||
} else
|
} else
|
||||||
(*dents)[n].bsize = blk_size;
|
(*dents)[n].blocks = ent_blocks;
|
||||||
} else
|
} else
|
||||||
(*dents)[n].bsize = sb.st_blocks;
|
(*dents)[n].blocks = sb.st_blocks;
|
||||||
|
|
||||||
if ((*dents)[n].bsize)
|
if ((*dents)[n].blocks)
|
||||||
dir_blocks += (*dents)[n].bsize;
|
dir_blocks += (*dents)[n].blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.bsizeorder) {
|
if (cfg.blkorder) {
|
||||||
static struct statvfs svb;
|
static struct statvfs svb;
|
||||||
|
|
||||||
if (statvfs(path, &svb) == -1)
|
if (statvfs(path, &svb) == -1)
|
||||||
|
@ -1691,7 +1691,7 @@ redraw(char *path)
|
||||||
else
|
else
|
||||||
ind[0] = '\0';
|
ind[0] = '\0';
|
||||||
|
|
||||||
if (!cfg.bsizeorder)
|
if (!cfg.blkorder)
|
||||||
sprintf(g_buf, "total %d %s[%s%s]", ndents, sort,
|
sprintf(g_buf, "total %d %s[%s%s]", ndents, sort,
|
||||||
replace_escape(dents[cur].name), ind);
|
replace_escape(dents[cur].name), ind);
|
||||||
else {
|
else {
|
||||||
|
@ -2250,15 +2250,15 @@ nochange:
|
||||||
case SEL_FSIZE:
|
case SEL_FSIZE:
|
||||||
cfg.sizeorder ^= 1;
|
cfg.sizeorder ^= 1;
|
||||||
cfg.mtimeorder = 0;
|
cfg.mtimeorder = 0;
|
||||||
cfg.bsizeorder = 0;
|
cfg.blkorder = 0;
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents > 0)
|
if (ndents > 0)
|
||||||
mkpath(path, dents[cur].name, oldpath,
|
mkpath(path, dents[cur].name, oldpath,
|
||||||
PATH_MAX);
|
PATH_MAX);
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_BSIZE:
|
case SEL_BSIZE:
|
||||||
cfg.bsizeorder ^= 1;
|
cfg.blkorder ^= 1;
|
||||||
if (cfg.bsizeorder) {
|
if (cfg.blkorder) {
|
||||||
cfg.showdetail = 1;
|
cfg.showdetail = 1;
|
||||||
printptr = &printent_long;
|
printptr = &printent_long;
|
||||||
}
|
}
|
||||||
|
@ -2272,7 +2272,7 @@ nochange:
|
||||||
case SEL_MTIME:
|
case SEL_MTIME:
|
||||||
cfg.mtimeorder ^= 1;
|
cfg.mtimeorder ^= 1;
|
||||||
cfg.sizeorder = 0;
|
cfg.sizeorder = 0;
|
||||||
cfg.bsizeorder = 0;
|
cfg.blkorder = 0;
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents > 0)
|
if (ndents > 0)
|
||||||
mkpath(path, dents[cur].name, oldpath,
|
mkpath(path, dents[cur].name, oldpath,
|
||||||
|
@ -2355,7 +2355,7 @@ main(int argc, char *argv[])
|
||||||
while ((opt = getopt(argc, argv, "dlSip:vh")) != -1) {
|
while ((opt = getopt(argc, argv, "dlSip:vh")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'S':
|
case 'S':
|
||||||
cfg.bsizeorder = 1;
|
cfg.blkorder = 1;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
cfg.showdetail = 0;
|
cfg.showdetail = 0;
|
||||||
|
|
Loading…
Reference in a new issue