swap.c (mtools-4.0.35.tar.bz2) | : | swap.c (mtools-4.0.36.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
* | * | |||
* filter to support byte-swapped filesystems | * filter to support byte-swapped filesystems | |||
*/ | */ | |||
#include "sysincludes.h" | #include "sysincludes.h" | |||
#include "msdos.h" | #include "msdos.h" | |||
#include "mtools.h" | #include "mtools.h" | |||
#include "swap.h" | #include "swap.h" | |||
typedef struct Swap_t { | typedef struct Swap_t { | |||
struct Class_t *Class; | struct Stream_t head; | |||
int refs; | ||||
struct Stream_t *Next; | ||||
struct Stream_t *Buffer; | ||||
} Swap_t; | } Swap_t; | |||
static void swap_buffer(char *buf, size_t len) | static void swap_buffer(char *buf, size_t len) | |||
{ | { | |||
unsigned int i; | unsigned int i; | |||
for (i=0; i<len; i+=2) { | for (i=0; i<len; i+=2) { | |||
char temp = buf[i]; | char temp = buf[i]; | |||
buf[i] = buf[i+1]; | buf[i] = buf[i+1]; | |||
buf[i+1] = temp; | buf[i+1] = temp; | |||
} | } | |||
} | } | |||
static ssize_t swap_read(Stream_t *Stream, char *buf, | static ssize_t swap_pread(Stream_t *Stream, char *buf, | |||
mt_off_t where, size_t len) | mt_off_t where, size_t len) | |||
{ | { | |||
DeclareThis(Swap_t); | DeclareThis(Swap_t); | |||
ssize_t result = READS(This->Next, buf, where, len); | ssize_t result = PREADS(This->head.Next, buf, where, len); | |||
if(result < 0) | if(result < 0) | |||
return result; | return result; | |||
swap_buffer( buf, (size_t) result); | swap_buffer( buf, (size_t) result); | |||
return result; | return result; | |||
} | } | |||
static ssize_t swap_write(Stream_t *Stream, char *buf, | static ssize_t swap_pwrite(Stream_t *Stream, char *buf, | |||
mt_off_t where, size_t len) | mt_off_t where, size_t len) | |||
{ | { | |||
DeclareThis(Swap_t); | DeclareThis(Swap_t); | |||
ssize_t result; | ssize_t result; | |||
char *swapping = malloc( len ); | char *swapping = malloc( len ); | |||
memcpy( swapping, buf, len ); | memcpy( swapping, buf, len ); | |||
swap_buffer( swapping, len ); | swap_buffer( swapping, len ); | |||
result = WRITES(This->Next, swapping, where, len); | result = PWRITES(This->head.Next, swapping, where, len); | |||
free(swapping); | free(swapping); | |||
return result; | return result; | |||
} | } | |||
static Class_t SwapClass = { | static Class_t SwapClass = { | |||
swap_read, | 0, | |||
swap_write, | 0, | |||
swap_pread, | ||||
swap_pwrite, | ||||
0, /* flush */ | 0, /* flush */ | |||
0, /* free */ | 0, /* 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 */ | |||
}; | }; | |||
Stream_t *OpenSwap(Stream_t *Next) { | Stream_t *OpenSwap(Stream_t *Next) { | |||
Swap_t *This; | Swap_t *This; | |||
This = New(Swap_t); | This = New(Swap_t); | |||
if (!This){ | if (!This){ | |||
printOom(); | printOom(); | |||
return 0; | return 0; | |||
} | } | |||
memset((void*)This, 0, sizeof(Swap_t)); | memset((void*)This, 0, sizeof(Swap_t)); | |||
This->Class = &SwapClass; | init_head(&This->head, &SwapClass, Next); | |||
This->refs = 1; | ||||
This->Next = Next; | ||||
return (Stream_t *) This; | return &This->head; | |||
} | } | |||
End of changes. 8 change blocks. | ||||
16 lines changed or deleted | 12 lines changed or added |