extern blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
const char *name, io_manager manager);
extern int ext2_file_type(unsigned int mode);
+extern int write_all(int fd, char *buf, size_t count);
/* unix.c */
extern void e2fsck_clear_progbar(e2fsck_t ctx);
if (ctx->progress_fd) {
snprintf(buf, sizeof(buf), "%d %lu %lu %s\n",
pass, cur, max, ctx->device_name);
- write(ctx->progress_fd, buf, strlen(buf));
+ write_all(ctx->progress_fd, buf, strlen(buf));
} else {
percent = calc_percent(&e2fsck_tbl, pass, cur, max);
e2fsck_simple_progress(ctx, ctx->device_name,
#endif /* __linux__ */
return (0);
}
+
+/*
+ * Helper function that does the right thing if write returns a
+ * partial write, or an EGAIN/EINTR error.
+ */
+int write_all(int fd, char *buf, size_t count)
+{
+ ssize_t ret;
+ int c = 0;
+
+ while (count > 0) {
+ ret = write(fd, buf, count);
+ if (ret < 0) {
+ if ((errno == EAGAIN) || (errno == EINTR))
+ continue;
+ return -1;
+ }
+ count -= ret;
+ buf += ret;
+ c += ret;
+ }
+ return c;
+}