"Fossies" - the Fresh Open Source Software Archive  

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

partition.c  (mtools-4.0.35.tar.bz2):partition.c  (mtools-4.0.36.tar.bz2)
skipping to change at line 26 skipping to change at line 26
* *
* Buffer read/write module * Buffer read/write module
*/ */
#include "sysincludes.h" #include "sysincludes.h"
#include "msdos.h" #include "msdos.h"
#include "mtools.h" #include "mtools.h"
#include "partition.h" #include "partition.h"
typedef struct Partition_t { typedef struct Partition_t {
struct Class_t *Class; struct Stream_t head;
int refs;
struct Stream_t *Next;
struct Stream_t *Buffer;
mt_off_t offset; /* Offset, in bytes */ mt_off_t offset; /* Offset, in bytes */
mt_off_t size; /* size, in bytes */ mt_off_t size; /* size, in bytes */
uint32_t nbSect; /* size, in sectors */ uint32_t nbSect; /* size, in sectors */
uint8_t pos; uint8_t pos;
uint8_t sectors; uint8_t sectors;
uint8_t heads; uint8_t heads;
uint16_t cyclinders; uint16_t cyclinders;
skipping to change at line 141 skipping to change at line 138
} }
static int limit_size(Partition_t *This, mt_off_t start, size_t *len) static int limit_size(Partition_t *This, mt_off_t start, size_t *len)
{ {
if(start > This->size) if(start > This->size)
return -1; return -1;
limitSizeToOffT(len, This->size - start); limitSizeToOffT(len, This->size - start);
return 0; return 0;
} }
static ssize_t partition_read(Stream_t *Stream, char *buf, static ssize_t partition_pread(Stream_t *Stream, char *buf,
mt_off_t start, size_t len) mt_off_t start, size_t len)
{ {
DeclareThis(Partition_t); DeclareThis(Partition_t);
if(limit_size(This, start, &len) < 0) if(limit_size(This, start, &len) < 0)
return -1; return -1;
return READS(This->Next, buf, start+This->offset, len); return PREADS(This->head.Next, buf, start+This->offset, len);
} }
static ssize_t partition_write(Stream_t *Stream, char *buf, static ssize_t partition_pwrite(Stream_t *Stream, char *buf,
mt_off_t start, size_t len) mt_off_t start, size_t len)
{ {
DeclareThis(Partition_t); DeclareThis(Partition_t);
if(limit_size(This, start, &len) < 0) if(limit_size(This, start, &len) < 0)
return -1; return -1;
return WRITES(This->Next, buf, start+This->offset, len); return PWRITES(This->head.Next, buf, start+This->offset, len);
} }
static int partition_data(Stream_t *Stream, time_t *date, mt_off_t *size, static int partition_data(Stream_t *Stream, time_t *date, mt_off_t *size,
int *type, uint32_t *address) int *type, uint32_t *address)
{ {
DeclareThis(Partition_t); DeclareThis(Partition_t);
if(date || type || address) { if(date || type || address) {
int ret = GET_DATA(This->Next, date, NULL, type, address); int ret = GET_DATA(This->head.Next, date, NULL, type, address);
if(ret < 0) if(ret < 0)
return ret; return ret;
} }
if(size) if(size)
*size = This->size * 512; *size = This->size * 512;
return 0; return 0;
} }
static int partition_geom(Stream_t *Stream, struct device *dev, static int partition_geom(Stream_t *Stream, struct device *dev,
UNUSEDP struct device *orig_dev) UNUSEDP struct device *orig_dev)
{ {
DeclareThis(Partition_t); DeclareThis(Partition_t);
if(!dev->tot_sectors) if(!dev->tot_sectors)
dev->tot_sectors = This->nbSect; dev->tot_sectors = This->nbSect;
return 0; return 0;
} }
static Class_t PartitionClass = { static Class_t PartitionClass = {
partition_read, 0,
partition_write, 0,
partition_pread,
partition_pwrite,
0, /* flush */ 0, /* flush */
0, /* free */ 0, /* free */
partition_geom, /* set_geom */ partition_geom, /* set_geom */
partition_data, /* get_data */ partition_data, /* 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 *OpenPartition(Stream_t *Next, struct device *dev, Stream_t *OpenPartition(Stream_t *Next, struct device *dev,
skipping to change at line 219 skipping to change at line 218
dev->partition); dev->partition);
return NULL; return NULL;
} }
This = New(Partition_t); This = New(Partition_t);
if (!This){ if (!This){
printOom(); printOom();
return 0; return 0;
} }
memset((void*)This, 0, sizeof(Partition_t)); memset((void*)This, 0, sizeof(Partition_t));
This->Class = &PartitionClass; init_head(&This->head, &PartitionClass, Next);
This->refs = 1;
This->Next = Next;
/* read the first sector, or part of it */ /* read the first sector, or part of it */
if (force_read(This->Next, (char*) buf, 0, 512) != 512) if (force_pread(This->head.Next, (char*) buf, 0, 512) != 512)
goto exit_0; goto exit_0;
if( _WORD(buf+510) != 0xaa55) { if( _WORD(buf+510) != 0xaa55) {
/* Not a partition table */ /* Not a partition table */
if(errmsg) if(errmsg)
sprintf(errmsg, sprintf(errmsg,
"Device does not have a BIOS partition table\n"); "Device does not have a BIOS partition table\n");
goto exit_0; goto exit_0;
} }
partition = &partTable[dev->partition]; partition = &partTable[dev->partition];
if(!partition->sys_ind) { if(!partition->sys_ind) {
skipping to change at line 275 skipping to change at line 272
dev->partition); dev->partition);
fprintf(stderr, fprintf(stderr,
"If this is a PCMCIA card, or a disk " "If this is a PCMCIA card, or a disk "
"partitioned on another computer, this " "partitioned on another computer, this "
"message may be in error: add " "message may be in error: add "
"mtools_skip_check=1 to your .mtoolsrc " "mtools_skip_check=1 to your .mtoolsrc "
"file to suppress this warning\n"); "file to suppress this warning\n");
} }
dev->tot_sectors = This->nbSect = PART_SIZE(partition); dev->tot_sectors = This->nbSect = PART_SIZE(partition);
This->size = (mt_off_t) This->nbSect << 9; This->size = (mt_off_t) This->nbSect << 9;
return (Stream_t *) This; return &This->head;
exit_0: exit_0:
Free(This); Free(This);
return NULL; return NULL;
} }
 End of changes. 10 change blocks. 
18 lines changed or deleted 15 lines changed or added

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