~ubuntu-branches/ubuntu/hardy/util-linux/hardy-security

« back to all changes in this revision

Viewing changes to disk-utils/mkswap.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2008-04-11 21:03:50 UTC
  • Revision ID: james.westby@ubuntu.com-20080411210350-fwhyu2co2pjccjph
Tags: 2.13.1-5ubuntu1
* New Debian version: remaining ubuntu changes:
  - use libvolume-id instead of libblkid
  - udev hooks

Show diffs side-by-side

added added

removed removed

Lines of Context:
488
488
        return 1;
489
489
}
490
490
 
491
 
static ssize_t
 
491
 
 
492
static int
492
493
write_all(int fd, const void *buf, size_t count) {
493
 
        const unsigned char *b = buf;
494
 
        ssize_t ret = 0;
495
 
        ssize_t tmp;
496
 
        do {
497
 
                tmp = write(fd, b + ret, count - ret);
 
494
        while(count) {
 
495
                ssize_t tmp = write(fd, buf, count);
 
496
 
498
497
                if (tmp > 0) {
499
 
                        ret += tmp, b += tmp, count -= tmp;
500
 
                } else if (tmp == 0) {
501
 
                        break;          /* hit end of file... */
502
 
                } else if (errno != EINTR && errno != EAGAIN) {
 
498
                        count -= tmp;
 
499
                        if (count)
 
500
                                buf += tmp;
 
501
                } else if (errno != EINTR && errno != EAGAIN)
503
502
                        return -1;
504
 
                }
505
 
        } while (ret < count && ret != -1);
506
 
        return ret;
 
503
        }
 
504
        return 0;
507
505
}
508
506
 
509
507
int
748
746
        offset = ((version == 0) ? 0 : 1024);
749
747
        if (lseek(DEV, offset, SEEK_SET) != offset)
750
748
                die(_("unable to rewind swap-device"));
751
 
        i=write_all(DEV,(char*)signature_page+offset, pagesize-offset);
752
 
        if (i < 0)
753
 
                fprintf(stderr, _("error writing swap signature: %s"),
754
 
                        strerror(errno));
755
 
        if (i != pagesize-offset)
756
 
                die(_("unable to write signature page"));
 
749
        if (write_all(DEV, (char *) signature_page + offset,
 
750
                                    pagesize - offset) == -1) {
 
751
                fprintf(stderr, _("%s: %s: unable to write signature page: %s"),
 
752
                        program_name, device_name, strerror(errno));
 
753
                exit(1);
 
754
        }
757
755
 
758
756
        /*
759
757
         * A subsequent swapon() will fail if the signature