return -1;
}
-void
+int
grub_util_fd_close (grub_util_fd_t fd)
{
switch (fd->type)
{
case GRUB_UTIL_FD_FILE:
- close (fd->fd);
- return;
+ return close (fd->fd);
case GRUB_UTIL_FD_DISK:
CloseDevice ((struct IORequest *) fd->ioreq);
DeleteIORequest((struct IORequest *) fd->ioreq);
DeleteMsgPort (fd->mp);
- return;
+ return 0;
}
+ return 0;
}
static int allow_fd_syncs = 1;
-static void
+static int
grub_util_fd_sync_volume (grub_util_fd_t fd)
{
+ LONG err;
+
fd->ioreq->iotd_Req.io_Command = CMD_UPDATE;
fd->ioreq->iotd_Req.io_Length = 0;
fd->ioreq->iotd_Req.io_Data = 0;
fd->ioreq->iotd_Req.io_Offset = 0;
fd->ioreq->iotd_Req.io_Actual = 0;
- DoIO ((struct IORequest *) fd->ioreq);
+ err = DoIO ((struct IORequest *) fd->ioreq);
+ if (err)
+ {
+ grub_util_info ("I/O failed with error %d, IoErr=%d", (int)err, (int) IoErr ());
+ return -1;
+ }
+ return 0;
}
-void
+int
grub_util_fd_sync (grub_util_fd_t fd)
{
if (allow_fd_syncs)
switch (fd->type)
{
case GRUB_UTIL_FD_FILE:
- fsync (fd->fd);
- return;
+ return fsync (fd->fd);
case GRUB_UTIL_FD_DISK:
- grub_util_fd_sync_volume (fd);
- return;
+ return grub_util_fd_sync_volume (fd);
}
}
+ return 0;
}
-void
+int
grub_util_file_sync (FILE *f)
{
- fflush (f);
+ if (fflush (f) != 0)
+ return -1;
if (!allow_fd_syncs)
- return;
- fsync (fileno (f));
+ return 0;
+ return fsync (fileno (f));
}
void
static int allow_fd_syncs = 1;
-void
+int
grub_util_fd_sync (grub_util_fd_t fd)
{
if (allow_fd_syncs)
- fsync (fd);
+ return fsync (fd);
+ return 0;
}
-void
+int
grub_util_file_sync (FILE *f)
{
- fflush (f);
+ if (fflush (f) != 0)
+ return -1;
if (!allow_fd_syncs)
- return;
- fsync (fileno (f));
+ return 0;
+ return fsync (fileno (f));
}
void
allow_fd_syncs = 0;
}
-void
+int
grub_util_fd_close (grub_util_fd_t fd)
{
- close (fd);
+ return close (fd);
}
char *
static int allow_fd_syncs = 1;
-void
+int
grub_util_fd_sync (grub_util_fd_t fd)
{
if (allow_fd_syncs)
- FlushFileBuffers (fd);
+ {
+ if (!FlushFileBuffers (fd))
+ {
+ grub_util_info ("flush err %x", (int) GetLastError ());
+ return -1;
+ }
+ }
+ return 0;
}
void
allow_fd_syncs = 0;
}
-void
+int
grub_util_fd_close (grub_util_fd_t fd)
{
- CloseHandle (fd);
+ if (!CloseHandle (fd))
+ {
+ grub_util_info ("close err %x", (int) GetLastError ());
+ return -1;
+ }
+ return 0;
}
const char *
return ret;
}
-void
+int
grub_util_file_sync (FILE *f)
{
HANDLE hnd;
- fflush (f);
+ if (fflush (f) != 0)
+ {
+ grub_util_info ("fflush err %x", (int) GetLastError ());
+ return -1;
+ }
if (!allow_fd_syncs)
- return;
+ return 0;
hnd = (HANDLE) _get_osfhandle (fileno (f));
- FlushFileBuffers (hnd);
+ if (!FlushFileBuffers (hnd))
+ {
+ grub_util_info ("flush err %x", (int) GetLastError ());
+ return -1;
+ }
+ return 0;
}
int
EXPORT_FUNC(grub_util_fd_open) (const char *os_dev, int flags);
const char *
EXPORT_FUNC(grub_util_fd_strerror) (void);
-void
+int
grub_util_fd_sync (grub_util_fd_t fd);
void
grub_util_disable_fd_syncs (void);
-void
+int
EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
grub_uint64_t
grub_util_fopen (const char *path, const char *mode);
#endif
-void grub_util_file_sync (FILE *f);
+int grub_util_file_sync (FILE *f);
#endif /* GRUB_EMU_MISC_H */
strerror (errno));
- grub_util_file_sync (fp);
+ if (grub_util_file_sync (fp) < 0)
+ grub_util_error (_("cannot sync `%s': %s"), namenew, strerror (errno));
free (buf);
fclose (fp);
grub_util_error (_("cannot write to `%s': %s"), name,
strerror (errno));
- grub_util_file_sync (fp);
+ if (grub_util_file_sync (fp) < 0)
+ grub_util_error (_("cannot sync `%s': %s"), name, strerror (errno));
fclose (fp);
}
r = grub_util_fd_read (in, grub_install_copy_buffer, GRUB_INSTALL_COPY_BUFFER_SIZE);
if (r <= 0)
break;
- grub_util_fd_write (out, grub_install_copy_buffer, r);
+ r = grub_util_fd_write (out, grub_install_copy_buffer, r);
+ if (r <= 0)
+ break;
}
- grub_util_fd_sync (out);
- grub_util_fd_close (in);
- grub_util_fd_close (out);
+ if (grub_util_fd_sync (out) < 0)
+ r = -1;
+ if (grub_util_fd_close (in) < 0)
+ r = -1;
+ if (grub_util_fd_close (out) < 0)
+ r = -1;
if (r < 0)
grub_util_error (_("cannot copy `%s' to `%s': %s"),
grub_install_make_image_wrap_file (dir, prefix, fp, outname,
memdisk_path, config_path,
mkimage_target, note);
- grub_util_file_sync (fp);
+ if (grub_util_file_sync (fp) < 0)
+ grub_util_error (_("cannot sync `%s': %s"), outname, strerror (errno));
fclose (fp);
}
arguments.image_target, arguments.note,
arguments.comp, arguments.dtb);
- grub_util_file_sync (fp);
- fclose (fp);
+ if (grub_util_file_sync (fp) < 0)
+ grub_util_error (_("cannot sync `%s': %s"), arguments.output ? : "stdout",
+ strerror (errno));
+ if (fclose (fp) == EOF)
+ grub_util_error (_("cannot close `%s': %s"), arguments.output ? : "stdout",
+ strerror (errno));
for (i = 0; i < arguments.nmodules; i++)
free (arguments.modules[i]);
!= GRUB_DISK_SECTOR_SIZE * 2)
grub_util_error (_("cannot write to `%s': %s"),
core_path, strerror (errno));
- grub_util_fd_sync (fp);
- grub_util_fd_close (fp);
+ if (grub_util_fd_sync (fp) < 0)
+ grub_util_error (_("cannot sync `%s': %s"), core_path, strerror (errno));
+ if (grub_util_fd_close (fp) < 0)
+ grub_util_error (_("cannot close `%s': %s"), core_path, strerror (errno));
grub_util_biosdisk_flush (root_dev->disk);
grub_disk_cache_invalidate_all ();