Create a get_device_size() helper function.

This commit is contained in:
Wayne Davison committed 2020-06-11 16:09:36 -07:00
1 parent b040825b86
commit c117fa4bf9
2 files changed
+16 -13

No files matched your search

+14
View File
@@ -1420,6 +1420,20 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
return file;
}
OFF_T get_device_size(int fd, const char *fname)
{
OFF_T off = lseek(fd, 0, SEEK_END);
if (off == (OFF_T) -1) {
rsyserr(FERROR, errno, "failed to get device size via seek: %s", fname);
return 0;
}
if (lseek(fd, 0, SEEK_SET) != 0)
rsyserr(FERROR, errno, "failed to seek device back to start: %s", fname);
return off;
}
/* Only called for temporary file_struct entries created by make_file(). */
void unmake_file(struct file_struct *file)
{
+2 -13
View File
@@ -804,19 +804,8 @@ int recv_files(int f_in, int f_out, char *local_name)
fd1 = -1;
}
/* On Linux systems (at least), st_size is typically 0 for devices.
* If so, try to determine the actual device size. */
if (fd1 != -1 && IS_DEVICE(st.st_mode) && st.st_size == 0) {
OFF_T off = lseek(fd1, 0, SEEK_END);
if (off == (OFF_T) -1)
rsyserr(FERROR, errno, "failed to seek to end of %s to determine size", fname);
else {
st.st_size = off;
off = lseek(fd1, 0, SEEK_SET);
if (off != 0)
rsyserr(FERROR, errno, "failed to seek back to beginning of %s to read it", fname);
}
}
if (fd1 != -1 && IS_DEVICE(st.st_mode) && st.st_size == 0)
st.st_size = get_device_size(fd1, fname);
/* If we're not preserving permissions, change the file-list's
* mode based on the local permissions and some heuristics. */