aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/chown.c4
-rw-r--r--coreutils/cp.c34
-rw-r--r--coreutils/df.c88
3 files changed, 46 insertions, 80 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index bcaeea38e..8d6cffa14 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -48,9 +48,9 @@ static int fileAction(const char *fileName)
48 ((chownApp==TRUE)? uid: statBuf.st_uid), 48 ((chownApp==TRUE)? uid: statBuf.st_uid),
49 gid) < 0)) { 49 gid) < 0)) {
50 perror(fileName); 50 perror(fileName);
51 return( TRUE); 51 return( FALSE);
52 } 52 }
53 return( FALSE); 53 return( TRUE);
54} 54}
55 55
56int chown_main(int argc, char **argv) 56int chown_main(int argc, char **argv)
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 4cdfc843b..94b4ab024 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -47,43 +47,9 @@ static int fileAction(const char *fileName)
47 char newdestName[NAME_MAX]; 47 char newdestName[NAME_MAX];
48 strcpy(newdestName, destName); 48 strcpy(newdestName, destName);
49 strcat(newdestName, fileName+(strlen(srcName))); 49 strcat(newdestName, fileName+(strlen(srcName)));
50 fprintf(stderr, "A: copying %s to %s\n", fileName, newdestName);
51 return (copyFile(fileName, newdestName, preserveFlag, followLinks)); 50 return (copyFile(fileName, newdestName, preserveFlag, followLinks));
52} 51}
53 52
54static int dirAction(const char *fileName)
55{
56 char newdestName[NAME_MAX];
57 struct stat statBuf;
58 struct utimbuf times;
59
60 strcpy(newdestName, destName);
61 strcat(newdestName, fileName+(strlen(srcName)));
62 if (stat(newdestName, &statBuf)) {
63 if (mkdir( newdestName, 0777777 ^ umask (0))) {
64 perror(newdestName);
65 return( FALSE);
66 }
67 }
68 else if (!S_ISDIR (statBuf.st_mode)) {
69 fprintf(stderr, "`%s' exists but is not a directory", newdestName);
70 return( FALSE);
71 }
72 if (preserveFlag==TRUE) {
73 /* Try to preserve premissions, but don't whine on failure */
74 if (stat(newdestName, &statBuf)) {
75 perror(newdestName);
76 return( FALSE);
77 }
78 chmod(newdestName, statBuf.st_mode);
79 chown(newdestName, statBuf.st_uid, statBuf.st_gid);
80 times.actime = statBuf.st_atime;
81 times.modtime = statBuf.st_mtime;
82 utime(newdestName, &times);
83 }
84 return TRUE;
85}
86
87extern int cp_main(int argc, char **argv) 53extern int cp_main(int argc, char **argv)
88{ 54{
89 55
diff --git a/coreutils/df.c b/coreutils/df.c
index 8cc93814b..a777d70f4 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -43,6 +43,50 @@ df(char* device, const char * mountPoint)
43 return 0; 43 return 0;
44} 44}
45 45
46/*
47 * Given a block device, find the mount table entry if that block device
48 * is mounted.
49 *
50 * Given any other file (or directory), find the mount table entry for its
51 * filesystem.
52 */
53extern struct mntent *
54findMountPoint(const char* name, const char* table)
55{
56 struct stat s;
57 dev_t mountDevice;
58 FILE * mountTable;
59 struct mntent * mountEntry;
60
61 if ( stat(name, &s) != 0 )
62 return 0;
63
64 if ( (s.st_mode & S_IFMT) == S_IFBLK )
65 mountDevice = s.st_rdev;
66 else
67 mountDevice = s.st_dev;
68
69
70 if ( (mountTable = setmntent(table, "r")) == 0 )
71 return 0;
72
73 while ( (mountEntry = getmntent(mountTable)) != 0 ) {
74 if ( strcmp(name, mountEntry->mnt_dir) == 0
75 || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
76 break;
77 if ( stat(mountEntry->mnt_fsname, &s) == 0
78 && s.st_rdev == mountDevice ) /* Match the device. */
79 break;
80 if ( stat(mountEntry->mnt_dir, &s) == 0
81 && s.st_dev == mountDevice ) /* Match the directory's mount point. */
82 break;
83 }
84 endmntent(mountTable);
85 return mountEntry;
86}
87
88
89
46extern int 90extern int
47df_main(int argc, char * * argv) 91df_main(int argc, char * * argv)
48{ 92{
@@ -90,47 +134,3 @@ df_main(int argc, char * * argv)
90 134
91 135
92 136
93
94/*
95 * Given a block device, find the mount table entry if that block device
96 * is mounted.
97 *
98 * Given any other file (or directory), find the mount table entry for its
99 * filesystem.
100 */
101extern struct mntent *
102findMountPoint(const char* name, const char* table)
103{
104 struct stat s;
105 dev_t mountDevice;
106 FILE * mountTable;
107 struct mntent * mountEntry;
108
109 if ( stat(name, &s) != 0 )
110 return 0;
111
112 if ( (s.st_mode & S_IFMT) == S_IFBLK )
113 mountDevice = s.st_rdev;
114 else
115 mountDevice = s.st_dev;
116
117
118 if ( (mountTable = setmntent(table, "r")) == 0 )
119 return 0;
120
121 while ( (mountEntry = getmntent(mountTable)) != 0 ) {
122 if ( strcmp(name, mountEntry->mnt_dir) == 0
123 || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
124 break;
125 if ( stat(mountEntry->mnt_fsname, &s) == 0
126 && s.st_rdev == mountDevice ) /* Match the device. */
127 break;
128 if ( stat(mountEntry->mnt_dir, &s) == 0
129 && s.st_dev == mountDevice ) /* Match the directory's mount point. */
130 break;
131 }
132 endmntent(mountTable);
133 return mountEntry;
134}
135
136