diff --git a/include/libmu/human.h b/include/libmu/human.h index 00bd0ab..1248b42 100644 --- a/include/libmu/human.h +++ b/include/libmu/human.h @@ -1,12 +1,15 @@ #ifndef _HUMAN_H #define _HUMAN_H +#include #include #define MU_HUMAN_BUF_SIZE 16 char *mu_humansize(off_t n, off_t block) { static char buf[MU_HUMAN_BUF_SIZE + 1]; + memset(buf, '\0', sizeof(buf)); + char *postfixes = "BKMGTPE"; double size = n; diff --git a/include/libmu/parse_mode.h b/include/libmu/parse_mode.h index 1c1133e..66877c8 100644 --- a/include/libmu/parse_mode.h +++ b/include/libmu/parse_mode.h @@ -12,7 +12,6 @@ #define WR_PERM (S_IWUSR | S_IWGRP | S_IWOTH) #define EX_PERM (S_IXUSR | S_IXGRP | S_IXOTH) #define RD_PERM (S_IRUSR | S_IRGRP | S_IROTH) -#define S_PERM (S_ISUID | S_ISGID | S_ISVTX) #define FULL_PERM (WR_PERM | EX_PERM | RD_PERM) mode_t mu_parse_mode(const char *s, mode_t cur_mode) { @@ -33,10 +32,6 @@ mode_t mu_parse_mode(const char *s, mode_t cur_mode) { for (size_t i = 0; i < strlen(s); i++) { switch (s[i]) { - case 's': - mode |= S_PERM; - break; - case 'r': mode |= RD_PERM; break; diff --git a/src/coreutils/cp/cp.c b/src/coreutils/cp/cp.c index e41db0a..7e32794 100644 --- a/src/coreutils/cp/cp.c +++ b/src/coreutils/cp/cp.c @@ -187,11 +187,17 @@ int main(int argc, char **argv) { } int ret = 0; + if (!access(argv[argc - 1], F_OK)) + goto IF_EXSIST; + if (argc == 2) ret = cptree(argv[0], argv[argc - 1]); + else { - for (int i = 1; i < argc - 1; i++) { + +IF_EXSIST: + for (int i = 0; i < argc - 1; i++) { char *new_path = mu_make_path(f_flag, argv[argc - 1], basename(argv[i])); if (new_path == NULL) return 1; diff --git a/src/coreutils/df/df.c b/src/coreutils/df/df.c index e9e7c4c..ea7f61b 100644 --- a/src/coreutils/df/df.c +++ b/src/coreutils/df/df.c @@ -13,18 +13,6 @@ char a_flag; char h_flag; off_t block = 1024; -void print_human(const char *src, const off_t total, const off_t used, const off_t avail, const off_t capacity, const char *dst) { - char total_s[MU_HUMAN_BUF_SIZE + 1]; - char used_s[MU_HUMAN_BUF_SIZE + 1]; - char avail_s[MU_HUMAN_BUF_SIZE + 1]; - - snprintf(total_s, sizeof(total_s), "%s", mu_humansize(total * block, block)); - snprintf(used_s, sizeof(used_s), "%s", mu_humansize(used * block, block)); - snprintf(avail_s, sizeof(avail_s), "%s", mu_humansize(avail * block, block)); - - printf("%-20s %5s %5s %5s %7ju%% %s\n", src, total_s, used_s, avail_s, capacity, dst); -} - int main(int argc, char **argv) { int opt; @@ -55,35 +43,45 @@ int main(int argc, char **argv) { return 1; } - printf("[Filesystem] [Size] [Used] [Avail] [Capacity] [Mounted on]\n"); + puts("Filesystem Size Used Available Use% Mounted on"); int ret = 0; struct mntent *me; struct statvfs disk; + while ((me = getmntent(fp)) != NULL) { if (!strcmp(me->mnt_fsname, "none")) continue; - if (!a_flag) - if (!strncmp(me->mnt_fsname, "fs", 2)) - continue; - if (statvfs(me->mnt_dir, &disk) < 0) { ret = 1; continue; } + if (!a_flag) + if (!strcmp(me->mnt_fsname, "/dev/root") || disk.f_blocks == 0) + continue; + off_t bs = disk.f_frsize / block; off_t total = disk.f_blocks * bs; off_t avail = disk.f_bfree * bs; off_t used = total - avail; - off_t capacity = (used * 100) / (avail + used) + 1; + off_t capacity = (used * 100 + 1) / (avail + used + 1); - if (h_flag) - print_human(me->mnt_fsname, total, used, avail, capacity, me->mnt_dir); + if (!h_flag) + printf("%-20s %12ju %12ju %12ju %12ju%% %s\n", me->mnt_fsname, total, used, avail, capacity, me->mnt_dir); - else - printf("%-20s %7ju %7ju %7ju %7ju%% %s\n", me->mnt_fsname, total, used, avail, capacity, me->mnt_dir); + else { + char total_s[MU_HUMAN_BUF_SIZE + 1]; + char used_s[MU_HUMAN_BUF_SIZE + 1]; + char avail_s[MU_HUMAN_BUF_SIZE + 1]; + + snprintf(total_s, sizeof(total_s), "%s", mu_humansize(total * block, block)); + snprintf(used_s, sizeof(used_s), "%s", mu_humansize(used * block, block)); + snprintf(avail_s, sizeof(avail_s), "%s", mu_humansize(avail * block, block)); + + printf("%-20s %10s %9s %9s %3ju%% %s\n", me->mnt_fsname, total_s, used_s, avail_s, capacity, me->mnt_dir); + } } endmntent(fp);