Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145163982
D33671.id101056.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D33671.id101056.diff
View Options
diff --git a/usr.sbin/kldxref/kldxref.c b/usr.sbin/kldxref/kldxref.c
--- a/usr.sbin/kldxref/kldxref.c
+++ b/usr.sbin/kldxref/kldxref.c
@@ -49,6 +49,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <fts.h>
#include <stdbool.h>
#include <stdio.h>
@@ -134,7 +135,7 @@
int error;
size_t len;
u_char val;
-
+
if (dflag)
return (0);
val = len = strlen(str);
@@ -657,6 +658,43 @@
return (fdopen(fd, "w+"));
}
+/*
+ * Copy an existing file identified by its path to the path specified. The
+ * destination is first truncated if it already exists. On error, a warning
+ * is written to stderr with the details and the function returns false.
+ */
+static bool
+copyfile(char *src, const char *dst)
+{
+ bool retval = true;
+ int ival, src_fd, dst_fd;
+
+ src_fd = open(src, O_RDONLY);
+ if (src_fd < 0) {
+ warn("can't open %s", src);
+ return (1);
+ }
+ dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC);
+ if (dst_fd < 0) {
+ warn("can't create %s", dst);
+ close(src_fd);
+ return (1);
+ }
+
+ while ((ival = copy_file_range(src_fd, NULL, dst_fd,
+ NULL, SSIZE_MAX, 0)) != 0) {
+ if (ival < 0) {
+ warn("can't copy %s to %s", src, dst);
+ retval = false;
+ break;
+ }
+ }
+
+ close(src_fd);
+ close(dst_fd);
+ return (retval);
+}
+
static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN];
static void
@@ -732,7 +770,16 @@
fclose(fxref);
fxref = NULL;
if (reccnt != 0) {
- rename(tempname, xrefname);
+ if (rename(tempname, xrefname) != 0) {
+ /* handle src/dst being on a different filesystems */
+ if (errno == EXDEV) {
+ /* copyfile reports its own errors */
+ copyfile(tempname, xrefname);
+ } else {
+ warn("can't rename %s to %s", xrefname, tempname);
+ }
+ unlink(tempname);
+ }
} else {
/* didn't find any entry, ignore this file */
unlink(tempname);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Feb 17, 3:35 PM (6 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28818054
Default Alt Text
D33671.id101056.diff (1 KB)
Attached To
Mode
D33671: kldxref: report errors and handle cross-device renames
Attached
Detach File
Event Timeline
Log In to Comment