diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/df.c | 9 | ||||
-rw-r--r-- | coreutils/mv.c | 104 | ||||
-rw-r--r-- | coreutils/touch.c | 87 |
3 files changed, 158 insertions, 42 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index 354b2a7ca..8cc93814b 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <mntent.h> | 3 | #include <mntent.h> |
4 | #include <sys/stat.h> | 4 | #include <sys/stat.h> |
5 | #include <sys/vfs.h> | 5 | #include <sys/vfs.h> |
6 | #include <fstab.h> | ||
6 | 7 | ||
7 | const char df_usage[] = "df [filesystem ...]\n" | 8 | const char df_usage[] = "df [filesystem ...]\n" |
8 | "\n" | 9 | "\n" |
@@ -10,7 +11,7 @@ const char df_usage[] = "df [filesystem ...]\n" | |||
10 | 11 | ||
11 | 12 | ||
12 | static int | 13 | static int |
13 | df(const char * device, const char * mountPoint) | 14 | df(char* device, const char * mountPoint) |
14 | { | 15 | { |
15 | struct statfs s; | 16 | struct statfs s; |
16 | long blocks_used; | 17 | long blocks_used; |
@@ -25,6 +26,8 @@ df(const char * device, const char * mountPoint) | |||
25 | blocks_used = s.f_blocks - s.f_bfree; | 26 | blocks_used = s.f_blocks - s.f_bfree; |
26 | blocks_percent_used = (long) | 27 | blocks_percent_used = (long) |
27 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); | 28 | (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); |
29 | if ( strcmp(device, "/dev/root")==0) | ||
30 | device=(getfsfile ("/"))->fs_spec; | ||
28 | 31 | ||
29 | printf( | 32 | printf( |
30 | "%-20s %9ld %9ld %9ld %3ld%% %s\n", | 33 | "%-20s %9ld %9ld %9ld %3ld%% %s\n", |
@@ -75,7 +78,7 @@ df_main(int argc, char * * argv) | |||
75 | } | 78 | } |
76 | 79 | ||
77 | while ( (mountEntry = getmntent (mountTable))) { | 80 | while ( (mountEntry = getmntent (mountTable))) { |
78 | int status=df(mountEntry->mnt_fsname ,mountEntry->mnt_dir); | 81 | int status=df(mountEntry->mnt_fsname, mountEntry->mnt_dir); |
79 | if (status) | 82 | if (status) |
80 | return status; | 83 | return status; |
81 | } | 84 | } |
@@ -129,3 +132,5 @@ findMountPoint(const char* name, const char* table) | |||
129 | endmntent(mountTable); | 132 | endmntent(mountTable); |
130 | return mountEntry; | 133 | return mountEntry; |
131 | } | 134 | } |
135 | |||
136 | |||
diff --git a/coreutils/mv.c b/coreutils/mv.c index 22c4a1207..610040d92 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c | |||
@@ -1,38 +1,84 @@ | |||
1 | /* | ||
2 | * Mini mv implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
1 | #include "internal.h" | 22 | #include "internal.h" |
2 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <fcntl.h> | ||
27 | #include <utime.h> | ||
3 | #include <errno.h> | 28 | #include <errno.h> |
4 | 29 | ||
5 | const char mv_usage[] = "mv source-file destination-file\n" | 30 | const char mv_usage[] = "source-file [source-file ...] destination-file\n" |
6 | "\t\tmv source-file [source-file ...] destination-directory\n" | 31 | "\n" "\tMove the source files to the destination.\n" "\n"; |
7 | "\n" | 32 | |
8 | "\tMove the source files to the destination.\n" | ||
9 | "\n"; | ||
10 | 33 | ||
11 | extern int | 34 | |
12 | mv_fn(const struct FileInfo * i) | 35 | extern int mv_main (int argc, char **argv) |
13 | { | 36 | { |
14 | struct stat destination_stat; | 37 | const char *srcName; |
15 | char d[1024]; | 38 | const char *destName; |
16 | struct FileInfo n; | 39 | const char *lastArg; |
17 | 40 | BOOL dirFlag; | |
18 | if ( stat(i->destination, &destination_stat) == 0 ) { | 41 | |
19 | if ( i->stat.st_ino == destination_stat.st_ino | 42 | if (argc < 3) { |
20 | && i->stat.st_dev == destination_stat.st_dev ) | 43 | fprintf (stderr, "Usage: %s %s", *argv, mv_usage); |
21 | return 0; /* Move file to itself. */ | 44 | return (FALSE); |
22 | } | 45 | } |
23 | if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) { | 46 | lastArg = argv[argc - 1]; |
24 | n = *i; | 47 | |
25 | n.destination = join_paths(d, i->destination, basename(i->source)); | 48 | dirFlag = isDirectory (lastArg); |
26 | i = &n; | 49 | |
50 | if ((argc > 3) && !dirFlag) { | ||
51 | fprintf (stderr, "%s: not a directory\n", lastArg); | ||
52 | |||
53 | return (FALSE); | ||
54 | } | ||
55 | |||
56 | while (argc-- > 2) { | ||
57 | srcName = *(++argv); | ||
58 | |||
59 | if (access (srcName, 0) < 0) { | ||
60 | perror (srcName); | ||
61 | continue; | ||
27 | } | 62 | } |
28 | if ( rename(i->source, i->destination) == 0 ) | 63 | |
29 | return 0; | 64 | destName = lastArg; |
30 | else if ( errno == EXDEV && is_a_directory(i->source) ) { | 65 | |
31 | fprintf(stderr | 66 | if (dirFlag) |
32 | ,"%s: Can't move directory across filesystems.\n" | 67 | destName = buildName (destName, srcName); |
33 | ,i->source); | 68 | |
34 | return 1; | 69 | if (rename (srcName, destName) >= 0) |
70 | continue; | ||
71 | |||
72 | if (errno != EXDEV) { | ||
73 | perror (destName); | ||
74 | continue; | ||
35 | } | 75 | } |
36 | else | 76 | |
37 | return cp_fn(i); | 77 | if (!copyFile (srcName, destName, TRUE)) |
78 | continue; | ||
79 | |||
80 | if (unlink (srcName) < 0) | ||
81 | perror (srcName); | ||
82 | } | ||
83 | return (TRUE); | ||
38 | } | 84 | } |
diff --git a/coreutils/touch.c b/coreutils/touch.c index ca4b98108..8dac10294 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c | |||
@@ -1,20 +1,85 @@ | |||
1 | /* | ||
2 | * Mini touch implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
1 | #include "internal.h" | 22 | #include "internal.h" |
2 | #include <sys/types.h> | ||
3 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <fcntl.h> | ||
4 | #include <utime.h> | 27 | #include <utime.h> |
28 | #include <errno.h> | ||
29 | |||
5 | 30 | ||
6 | const char touch_usage[] = "touch [-c] file [file ...]\n" | 31 | const char touch_usage[] = "touch [-c] file [file ...]\n\n" |
7 | "\n" | ||
8 | "\tUpdate the last-modified date on the given file[s].\n"; | 32 | "\tUpdate the last-modified date on the given file[s].\n"; |
9 | 33 | ||
10 | extern int | 34 | |
11 | touch_fn(const struct FileInfo * i) | 35 | |
36 | extern int | ||
37 | touch_main(int argc, char **argv) | ||
12 | { | 38 | { |
13 | if ( (utime(i->source, 0) != 0) && (i->create != 1) ) { | 39 | int fd; |
14 | if ( fopen(i->source, "w") == NULL ) { | 40 | int create=TRUE; |
15 | name_and_error(i->source); | 41 | |
16 | return 1; | 42 | if (argc < 2) { |
17 | } | 43 | fprintf(stderr, "Usage: %s %s", *argv, touch_usage); |
44 | exit( FALSE); | ||
45 | } | ||
46 | argc--; | ||
47 | argv++; | ||
48 | |||
49 | /* Parse options */ | ||
50 | while (**argv == '-') { | ||
51 | while (*++(*argv)) switch (**argv) { | ||
52 | case 'c': | ||
53 | create = FALSE; | ||
54 | break; | ||
55 | default: | ||
56 | fprintf(stderr, "Unknown option: %c\n", **argv); | ||
57 | exit( FALSE); | ||
18 | } | 58 | } |
19 | return 0; | 59 | argc--; |
60 | argv++; | ||
61 | } | ||
62 | |||
63 | fd = open (*argv, (create==FALSE)? O_RDWR : O_RDWR | O_CREAT, 0644); | ||
64 | if (fd < 0 ) { | ||
65 | if (create==FALSE && errno == ENOENT) | ||
66 | exit( TRUE); | ||
67 | else { | ||
68 | perror("touch"); | ||
69 | exit( FALSE); | ||
70 | } | ||
71 | } | ||
72 | close( fd); | ||
73 | if (utime (*argv, NULL)) { | ||
74 | perror("touch"); | ||
75 | exit( FALSE); | ||
76 | } | ||
77 | else | ||
78 | exit( TRUE); | ||
20 | } | 79 | } |
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | |||