"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "remap.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.

remap.c  (mtools-4.0.35.tar.bz2):remap.c  (mtools-4.0.36.tar.bz2)
skipping to change at line 39 skipping to change at line 39
POS POS
}; };
struct map { struct map {
mt_off_t orig; mt_off_t orig;
mt_off_t remapped; mt_off_t remapped;
enum map_type_t type; enum map_type_t type;
}; };
typedef struct Remap_t { typedef struct Remap_t {
struct Class_t *Class; struct Stream_t head;
int refs;
struct Stream_t *Next;
struct Stream_t *Buffer;
struct map *map; struct map *map;
int mapSize; int mapSize;
mt_off_t net_offset; mt_off_t net_offset;
} Remap_t; } Remap_t;
static enum map_type_t remap(Remap_t *This, mt_off_t *start, size_t *len) { static enum map_type_t remap(Remap_t *This, mt_off_t *start, size_t *len) {
int i; int i;
for(i=0; i < This->mapSize - 1; i++) for(i=0; i < This->mapSize - 1; i++)
if(*start < This->map[i+1].remapped) { if(*start < This->map[i+1].remapped) {
limitSizeToOffT(len, This->map[i+1].remapped - *start); limitSizeToOffT(len, This->map[i+1].remapped - *start);
break; break;
} }
*start = *start - This->map[i].remapped + This->map[i].orig; *start = *start - This->map[i].remapped + This->map[i].orig;
return This->map[i].type; return This->map[i].type;
} }
static ssize_t remap_read(Stream_t *Stream, char *buf, static ssize_t remap_pread(Stream_t *Stream, char *buf,
mt_off_t start, size_t len) mt_off_t start, size_t len)
{ {
DeclareThis(Remap_t); DeclareThis(Remap_t);
if(remap(This, &start, &len)==DATA) if(remap(This, &start, &len)==DATA)
return READS(This->Next, buf, start, len); return PREADS(This->head.Next, buf, start, len);
else { else {
memset(buf, 0, len); memset(buf, 0, len);
return (ssize_t) len; return (ssize_t) len;
} }
} }
static ssize_t remap_write(Stream_t *Stream, char *buf, static ssize_t remap_pwrite(Stream_t *Stream, char *buf,
mt_off_t start, size_t len) mt_off_t start, size_t len)
{ {
DeclareThis(Remap_t); DeclareThis(Remap_t);
if(remap(This, &start, &len)==DATA) if(remap(This, &start, &len)==DATA)
return WRITES(This->Next, buf, start, len); return PWRITES(This->head.Next, buf, start, len);
else { else {
unsigned int i; unsigned int i;
/* When writing to a "zero" sector, make sure that we /* When writing to a "zero" sector, make sure that we
indeed only write zeroes back to there. Helps catch indeed only write zeroes back to there. Helps catch
putting filesystems with parameters unsuitable to putting filesystems with parameters unsuitable to
the particular mapping */ the particular mapping */
for(i=0; i<len; i++) { for(i=0; i<len; i++) {
if(buf[i]) { if(buf[i]) {
fprintf(stderr, "Bad data written to unmapped sec tors\n"); fprintf(stderr, "Bad data written to unmapped sec tors\n");
errno = EFAULT; errno = EFAULT;
skipping to change at line 105 skipping to change at line 102
static int remap_free(Stream_t *Stream) static int remap_free(Stream_t *Stream)
{ {
DeclareThis(Remap_t); DeclareThis(Remap_t);
if(This->map) if(This->map)
free(This->map); free(This->map);
return 0; return 0;
} }
static Class_t RemapClass = { static Class_t RemapClass = {
remap_read, 0,
remap_write, 0,
remap_pread,
remap_pwrite,
0, /* flush */ 0, /* flush */
remap_free, /* free */ remap_free, /* free */
set_geom_pass_through, /* set_geom */ set_geom_pass_through, /* set_geom */
0, /* get_data */ 0, /* get_data */
0, /* pre-allocate */ 0, /* pre-allocate */
get_dosConvert_pass_through, /* dos convert */ get_dosConvert_pass_through, /* dos convert */
0, /* discard */ 0, /* discard */
}; };
static int process_map(Remap_t *This, const char *ptr, static int process_map(Remap_t *This, const char *ptr,
skipping to change at line 191 skipping to change at line 190
Remap_t *This; Remap_t *This;
int nrItems=0; int nrItems=0;
const char *map = dev->data_map; const char *map = dev->data_map;
This = New(Remap_t); This = New(Remap_t);
if (!This){ if (!This){
printOom(); printOom();
return 0; return 0;
} }
memset((void*)This, 0, sizeof(Remap_t)); memset((void*)This, 0, sizeof(Remap_t));
This->Class = &RemapClass; init_head(&This->head, &RemapClass, Next);
This->refs = 1;
This->Next = Next;
/* First count number of items */ /* First count number of items */
nrItems=process_map(This, map, 1, errmsg); nrItems=process_map(This, map, 1, errmsg);
if(nrItems < 0) { if(nrItems < 0) {
free(This); free(This);
return NULL; return NULL;
} }
This->map = calloc((size_t)nrItems, sizeof(struct map)); This->map = calloc((size_t)nrItems, sizeof(struct map));
if(!This->map) { if(!This->map) {
printOom(); printOom();
goto exit_0; goto exit_0;
} }
process_map(This, map, 0, errmsg); process_map(This, map, 0, errmsg);
if(adjust_tot_sectors(dev, This->net_offset, errmsg) < 0) if(adjust_tot_sectors(dev, This->net_offset, errmsg) < 0)
goto exit_1; goto exit_1;
This->mapSize=nrItems; This->mapSize=nrItems;
return (Stream_t *) This; return &This->head;
exit_1: exit_1:
free(This->map); free(This->map);
exit_0: exit_0:
free(This); free(This);
printOom(); printOom();
return NULL; return NULL;
} }
 End of changes. 8 change blocks. 
14 lines changed or deleted 11 lines changed or added

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