~ubuntu-branches/ubuntu/raring/dosfstools/raring-proposed

« back to all changes in this revision

Viewing changes to dosfsck/io.c

  • Committer: Bazaar Package Importer
  • Author(s): Roman Hodek
  • Date: 2005-04-03 13:56:55 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050403135655-qvztyae9ns6gj65n
Tags: 2.11-2
* Oops, debian/rules overrides OPTFLAGS and therefore the
  -D_FILE_OFFSET_BITS=64 in the toplevel Makefile had no effect; added
  $(shell getconf LFS_CFLAGS) to OPTFLAGS as suggested by Lars Wirzenius in
  #300126. Sorry, I tested a version compiled by the upstream Makefile...
  Closes: #300126, #301254.
* #302517 was indeed the same as #294177, and fix is the same (use __u8) as
  in 2.11-1. Closes: #302517.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
unsigned device_no;
41
41
 
42
 
/* Use the _llseek system call directly, because there (once?) was a bug in
43
 
 * the glibc implementation of it. */
44
 
#include <linux/unistd.h>
45
 
#if defined(__alpha) || defined (__ia64__)
46
 
/* On alpha, the syscall is simply lseek, because it's a 64 bit system. */
47
 
static loff_t llseek( int fd, loff_t offset, int whence )
48
 
{
49
 
    return lseek(fd, offset, whence);
50
 
}
51
 
#else
52
 
# ifndef __NR__llseek
53
 
# error _llseek system call not present
54
 
# endif
55
 
static _syscall5( int, _llseek, uint, fd, ulong, hi, ulong, lo,
56
 
                  loff_t *, res, uint, wh );
57
 
 
58
 
static loff_t llseek( int fd, loff_t offset, int whence )
59
 
{
60
 
    loff_t actual;
61
 
 
62
 
    if (_llseek(fd, offset>>32, offset&0xffffffff, &actual, whence) != 0)
63
 
        return (loff_t)-1;
64
 
    return actual;
65
 
}
 
42
 
 
43
#ifdef __DJGPP__
 
44
#include "volume.h"     /* DOS lowlevel disk access functions */
 
45
#undef llseek
 
46
static loff_t llseek( int fd, loff_t offset, int whence )
 
47
{
 
48
    if ((whence != SEEK_SET) || (fd == 4711)) return -1; /* only those supported */
 
49
    return VolumeSeek(offset);
 
50
}
 
51
#define open OpenVolume
 
52
#define close CloseVolume
 
53
#define read(a,b,c) ReadVolume(b,c)
 
54
#define write(a,b,c) WriteVolume(b,c)
66
55
#endif
67
56
 
68
 
 
69
57
void fs_open(char *path,int rw)
70
58
{
71
59
    struct stat stbuf;
75
63
    changes = last = NULL;
76
64
    did_change = 0;
77
65
 
 
66
#ifndef _DJGPP_
78
67
    if (fstat(fd,&stbuf) < 0)
79
 
        pdie("fstat",path);
 
68
        pdie("fstat %s",path);
80
69
    device_no = S_ISBLK(stbuf.st_mode) ? (stbuf.st_rdev >> 8) & 0xff : 0;
 
70
#else
 
71
    if (IsWorkingOnImageFile()) {
 
72
        if (fstat(GetVolumeHandle(),&stbuf) < 0)
 
73
            pdie("fstat image %s",path);
 
74
        device_no = 0;
 
75
    }
 
76
    else {
 
77
        /* return 2 for floppy, 1 for ramdisk, 7 for loopback  */
 
78
        /* used by boot.c in Atari mode: floppy always FAT12,  */
 
79
        /* loopback / ramdisk only FAT12 if usual floppy size, */
 
80
        /* harddisk always FAT16 on Atari... */
 
81
        device_no = (GetVolumeHandle() < 2) ? 2 : 1;
 
82
        /* telling "floppy" for A:/B:, "ramdisk" for the rest */
 
83
    }
 
84
#endif
81
85
}
82
86
 
83
87
 
146
150
        changes = changes->next;
147
151
        if (llseek(fd,this->pos,0) != this->pos)
148
152
            fprintf(stderr,"Seek to %lld failed: %s\n  Did not write %d bytes.\n",
149
 
              this->pos,strerror(errno),this->size);
 
153
              (long long)this->pos,strerror(errno),this->size);
150
154
        else if ((size = write(fd,this->data,this->size)) < 0)
151
155
                fprintf(stderr,"Writing %d bytes at %lld failed: %s\n",this->size,
152
 
                  this->pos,strerror(errno));
 
156
                  (long long)this->pos,strerror(errno));
153
157
            else if (size != this->size)
154
158
                    fprintf(stderr,"Wrote %d bytes instead of %d bytes at %lld."
155
 
                      "\n",size,this->size,this->pos);
 
159
                      "\n",size,this->size,(long long)this->pos);
156
160
        free(this->data);
157
161
        free(this);
158
162
    }