"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plain_io.c" between
mtools-4.0.35.tar.bz2 and mtools-4.0.36.tar.bz2

About: Mtools is a collection of utilities to access MS-DOS disks from Unix without mounting them.

plain_io.c  (mtools-4.0.35.tar.bz2):plain_io.c  (mtools-4.0.36.tar.bz2)
skipping to change at line 40 skipping to change at line 40
#include "open_image.h" #include "open_image.h"
#include "devices.h" #include "devices.h"
#include "plain_io.h" #include "plain_io.h"
#include "llong.h" #include "llong.h"
#ifdef HAVE_LINUX_FS_H #ifdef HAVE_LINUX_FS_H
# include <linux/fs.h> # include <linux/fs.h>
#endif #endif
typedef struct SimpleFile_t { typedef struct SimpleFile_t {
Class_t *Class; struct Stream_t head;
int refs;
Stream_t *Next;
Stream_t *Buffer;
struct MT_STAT statbuf; struct MT_STAT statbuf;
int fd; int fd;
mt_off_t lastwhere; mt_off_t lastwhere;
int seekable; int seekable;
int privileged; int privileged;
#ifdef OS_hpux #ifdef OS_hpux
int size_limited; int size_limited;
#endif #endif
} SimpleFile_t; } SimpleFile_t;
#include "lockdev.h" #include "lockdev.h"
typedef ssize_t (*iofn) (int, void *, size_t); typedef ssize_t (*iofn) (int, void *, size_t);
static ssize_t file_io(Stream_t *Stream, char *buf, mt_off_t where, size_t len, static ssize_t file_io(SimpleFile_t *This, char *buf,
mt_off_t where, size_t len,
iofn io) iofn io)
{ {
DeclareThis(SimpleFile_t);
ssize_t ret; ssize_t ret;
if (This->seekable && where != This->lastwhere ){ if (This->seekable && where != This->lastwhere ){
if(mt_lseek( This->fd, where, SEEK_SET) < 0 ){ if(mt_lseek( This->fd, where, SEEK_SET) < 0 ){
perror("seek"); perror("seek");
This->lastwhere = -1; return -1; /* If seek failed, lastwhere did
return -1; not change */
} }
This->lastwhere = where;
} }
#ifdef OS_hpux #ifdef OS_hpux
/* /*
* On HP/UX, we can not write more than MAX_LEN bytes in one go. * On HP/UX, we can not write more than MAX_LEN bytes in one go.
* If more are written, the write fails with EINVAL * If more are written, the write fails with EINVAL
*/ */
#define MAX_SCSI_LEN (127*1024) #define MAX_SCSI_LEN (127*1024)
if(This->size_limited && len > MAX_SCSI_LEN) if(This->size_limited && len > MAX_SCSI_LEN)
len = MAX_SCSI_LEN; len = MAX_SCSI_LEN;
skipping to change at line 95 skipping to change at line 94
errno == EINVAL && /* if we got EINVAL */ errno == EINVAL && /* if we got EINVAL */
len > MAX_SCSI_LEN) { len > MAX_SCSI_LEN) {
This->size_limited = 1; This->size_limited = 1;
len = MAX_SCSI_LEN; len = MAX_SCSI_LEN;
ret = io(This->fd, buf, len); ret = io(This->fd, buf, len);
} }
#endif #endif
if ( ret == -1 ){ if ( ret == -1 ){
perror("plain_io"); perror("plain_io");
This->lastwhere = -1;
return -1; return -1;
} }
This->lastwhere = where + ret; This->lastwhere = where + ret;
return ret; return ret;
} }
static ssize_t file_read(Stream_t *Stream, char *buf, static ssize_t file_read(Stream_t *Stream, char *buf, size_t len)
mt_off_t where, size_t len) {
DeclareThis(SimpleFile_t);
return file_io(This, buf, This->lastwhere, len, read);
}
static ssize_t file_write(Stream_t *Stream, char *buf, size_t len)
{ {
return file_io(Stream, buf, where, len, read); DeclareThis(SimpleFile_t);
return file_io(This, buf, This->lastwhere, len, (iofn) write);
} }
static ssize_t file_write(Stream_t *Stream, char *buf, static ssize_t file_pread(Stream_t *Stream, char *buf,
mt_off_t where, size_t len) mt_off_t where, size_t len)
{ {
return file_io(Stream, buf, where, len, (iofn) write); DeclareThis(SimpleFile_t);
return file_io(This, buf, where, len, read);
}
static ssize_t file_pwrite(Stream_t *Stream, char *buf,
mt_off_t where, size_t len)
{
DeclareThis(SimpleFile_t);
return file_io(This, buf, where, len, (iofn) write);
} }
static int file_flush(Stream_t *Stream UNUSEDP) static int file_flush(Stream_t *Stream UNUSEDP)
{ {
#if 0 #if 0
DeclareThis(SimpleFile_t); DeclareThis(SimpleFile_t);
return fsync(This->fd); return fsync(This->fd);
#endif #endif
return 0; return 0;
skipping to change at line 219 skipping to change at line 231
perror("BLKFLSBUF"); perror("BLKFLSBUF");
return ret; return ret;
#else #else
return 0; return 0;
#endif #endif
} }
static Class_t SimpleFileClass = { static Class_t SimpleFileClass = {
file_read, file_read,
file_write, file_write,
file_pread,
file_pwrite,
file_flush, file_flush,
file_free, file_free,
file_geom, file_geom,
file_data, file_data,
0, /* pre_allocate */ 0, /* pre_allocate */
0, /* dos-convert */ 0, /* dos-convert */
file_discard file_discard
}; };
int LockDevice(int fd, struct device *dev, int LockDevice(int fd, struct device *dev,
skipping to change at line 294 skipping to change at line 308
This = New(SimpleFile_t); This = New(SimpleFile_t);
if (!This){ if (!This){
printOom(); printOom();
return 0; return 0;
} }
memset((void*)This, 0, sizeof(SimpleFile_t)); memset((void*)This, 0, sizeof(SimpleFile_t));
This->seekable = 1; This->seekable = 1;
#ifdef OS_hpux #ifdef OS_hpux
This->size_limited = 0; This->size_limited = 0;
#endif #endif
This->Class = &SimpleFileClass; init_head(&This->head, &SimpleFileClass, NULL);
if (!name || strcmp(name,"-") == 0 ){ if (!name || strcmp(name,"-") == 0 ){
if (mode == O_RDONLY) if (mode == O_RDONLY)
This->fd = 0; This->fd = 0;
else else
This->fd = 1; This->fd = 1;
This->seekable = 0; This->seekable = 0;
This->refs = 1;
This->Next = 0;
This->Buffer = 0;
if (MT_FSTAT(This->fd, &This->statbuf) < 0) { if (MT_FSTAT(This->fd, &This->statbuf) < 0) {
Free(This); Free(This);
if(errmsg) if(errmsg)
#ifdef HAVE_SNPRINTF #ifdef HAVE_SNPRINTF
snprintf(errmsg,199,"Can't stat -: %s", snprintf(errmsg,199,"Can't stat -: %s",
strerror(errno)); strerror(errno));
#else #else
sprintf(errmsg,"Can't stat -: %s", sprintf(errmsg,"Can't stat -: %s",
strerror(errno)); strerror(errno));
#endif #endif
return NULL; return NULL;
} }
return (Stream_t *) This; return &This->head;
} }
if(dev) { if(dev) {
if(!(mode2 & NO_PRIV)) if(!(mode2 & NO_PRIV))
This->privileged = IS_PRIVILEGED(dev); This->privileged = IS_PRIVILEGED(dev);
mode |= dev->mode; mode |= dev->mode;
} }
precmd(dev); precmd(dev);
if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV)) if(IS_PRIVILEGED(dev) && !(mode2 & NO_PRIV))
skipping to change at line 425 skipping to change at line 436
&This->statbuf)){ &This->statbuf)){
if(geomFailure && (errno==EBADF || errno==EPERM)) { if(geomFailure && (errno==EBADF || errno==EPERM)) {
*geomFailure=1; *geomFailure=1;
return NULL; return NULL;
} else if(errmsg) } else if(errmsg)
sprintf(errmsg,"init: set default params"); sprintf(errmsg,"init: set default params");
goto exit_0; goto exit_0;
} }
} }
This->refs = 1;
This->Next = 0;
This->Buffer = 0;
if(maxSize) if(maxSize)
*maxSize = max_off_t_seek; *maxSize = max_off_t_seek;
This->lastwhere = 0; This->lastwhere = 0;
return (Stream_t *) This; return &This->head;
exit_0: exit_0:
close(This->fd); close(This->fd);
exit_1: exit_1:
Free(This); Free(This);
return NULL; return NULL;
} }
int get_fd(Stream_t *Stream) int get_fd(Stream_t *Stream)
{ {
Class_t *clazz; Class_t *clazz;
DeclareThis(SimpleFile_t); DeclareThis(SimpleFile_t);
clazz = This->Class; clazz = This->head.Class;
if(clazz != &SimpleFileClass) if(clazz != &SimpleFileClass)
return -1; return -1;
else else
return This->fd; return This->fd;
} }
 End of changes. 17 change blocks. 
25 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)