summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/libreboot-utils/lib/io.c')
-rw-r--r--util/libreboot-utils/lib/io.c82
1 files changed, 12 insertions, 70 deletions
diff --git a/util/libreboot-utils/lib/io.c b/util/libreboot-utils/lib/io.c
index cc38e5c7..295e15c0 100644
--- a/util/libreboot-utils/lib/io.c
+++ b/util/libreboot-utils/lib/io.c
@@ -413,7 +413,15 @@ gbe_mv(void)
int tmp_gbe_bin_exists;
char *dest_tmp;
- int dest_fd;
+ int dest_fd = -1;
+
+ char *dir = NULL;
+ char *base = NULL;
+ char *dest_name = NULL;
+
+ int dirfd = -1;
+
+ struct stat st_dir;
/* will be set 0 if it doesn't
*/
@@ -424,78 +432,12 @@ gbe_mv(void)
saved_errno = errno;
- rval = rename(f->tname, f->fname);
-
- if (rval > -1) {
-
- /* rename on same filesystem
- */
+ rval = fs_rename_at(f->dirfd, f->tmpbase,
+ f->dirfd, f->base);
+ if (rval > -1)
tmp_gbe_bin_exists = 0;
- if (fsync_dir(f->fname) < 0) {
- f->io_err_gbe_bin = 1;
- rval = -1;
- }
-
- goto ret_gbe_mv;
- }
-
- if (errno != EXDEV)
- goto ret_gbe_mv;
-
- /*
- * OR, cross-filesystem rename:
- */
-
- if ((rval = f->tmp_fd = open(f->tname,
- O_RDONLY | O_BINARY)) == -1)
- goto ret_gbe_mv;
-
- /* create replacement temp in target directory
- */
- if (new_tmpfile(&dest_fd, &f->fname) < 1)
- goto ret_gbe_mv;
- if (dest_tmp == NULL)
- goto ret_gbe_mv;
-
- /* copy data
- */
- rval = rw_file_exact(f->tmp_fd, f->bufcmp,
- f->gbe_file_size, 0, IO_PREAD,
- NO_LOOP_EAGAIN, LOOP_EINTR,
- MAX_ZERO_RW_RETRY, OFF_ERR);
-
- if (rval < 0)
- goto ret_gbe_mv;
-
- rval = rw_file_exact(dest_fd, f->bufcmp,
- f->gbe_file_size, 0, IO_PWRITE,
- NO_LOOP_EAGAIN, LOOP_EINTR,
- MAX_ZERO_RW_RETRY, OFF_ERR);
-
- if (rval < 0)
- goto ret_gbe_mv;
-
- if (fsync_on_eintr(dest_fd) == -1)
- goto ret_gbe_mv;
-
- if (close_on_eintr(dest_fd) == -1) {
- dest_fd = -1;
- goto ret_gbe_mv;
- }
- dest_fd = -1;
-
- if (rename(dest_tmp, f->fname) == -1)
- goto ret_gbe_mv;
-
- if (fsync_dir(f->fname) < 0) {
- f->io_err_gbe_bin = 1;
- goto ret_gbe_mv;
- }
-
- free_if_null(&dest_tmp);
-
ret_gbe_mv:
/* TODO: this whole section is bloat.