From 0a174516ff48b33da67fd1a79d78416ce8afe5ad Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Sat, 18 Nov 2006 11:51:07 +0000 Subject: [PATCH] - fixed type conflicts in hdimage lseek() methods. Now using always Bit64s for the lseek() methods and off_t is only used for the lowlevel lseek() function. - fixed indent mode and removed unnecessary spaces --- bochs/iodev/harddrv.cc | 20 ++-- bochs/iodev/harddrv.h | 4 +- bochs/iodev/hdimage.cc | 249 ++++++++++++++++++++--------------------- bochs/iodev/hdimage.h | 88 +++++++-------- 4 files changed, 179 insertions(+), 182 deletions(-) diff --git a/bochs/iodev/harddrv.cc b/bochs/iodev/harddrv.cc index 22b4501c0..2fd4beb98 100644 --- a/bochs/iodev/harddrv.cc +++ b/bochs/iodev/harddrv.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: harddrv.cc,v 1.187 2006-09-20 18:24:17 vruppert Exp $ +// $Id: harddrv.cc,v 1.188 2006-11-18 11:51:07 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -146,7 +146,7 @@ void bx_hard_drive_c::init(void) char ata_name[20]; bx_list_c *base; - BX_DEBUG(("Init $Id: harddrv.cc,v 1.187 2006-09-20 18:24:17 vruppert Exp $")); + BX_DEBUG(("Init $Id: harddrv.cc,v 1.188 2006-11-18 11:51:07 vruppert Exp $")); for (channel=0; channel> 24) & 0xf); @@ -3432,8 +3432,8 @@ void bx_hard_drive_c::set_signature(Bit8u channel, Bit8u id) bx_bool bx_hard_drive_c::ide_read_sector(Bit8u channel, Bit8u *buffer, Bit32u buffer_size) { - off_t logical_sector; - off_t ret; + Bit64s logical_sector; + Bit64s ret; int sector_count = (buffer_size / 512); Bit8u *bufptr = buffer; @@ -3468,8 +3468,8 @@ bx_bool bx_hard_drive_c::ide_read_sector(Bit8u channel, Bit8u *buffer, Bit32u bu bx_bool bx_hard_drive_c::ide_write_sector(Bit8u channel, Bit8u *buffer, Bit32u buffer_size) { - off_t logical_sector; - off_t ret; + Bit64s logical_sector; + Bit64s ret; int sector_count = (buffer_size / 512); Bit8u *bufptr = buffer; diff --git a/bochs/iodev/harddrv.h b/bochs/iodev/harddrv.h index 35003aebc..1033b632e 100644 --- a/bochs/iodev/harddrv.h +++ b/bochs/iodev/harddrv.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: harddrv.h,v 1.45 2006-09-16 14:47:40 vruppert Exp $ +// $Id: harddrv.h,v 1.46 2006-11-18 11:51:07 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -197,7 +197,7 @@ public: private: - BX_HD_SMF bx_bool calculate_logical_address(Bit8u channel, off_t *sector) BX_CPP_AttrRegparmN(2); + BX_HD_SMF bx_bool calculate_logical_address(Bit8u channel, Bit64s *sector) BX_CPP_AttrRegparmN(2); BX_HD_SMF void increment_address(Bit8u channel) BX_CPP_AttrRegparmN(1); BX_HD_SMF void identify_drive(Bit8u channel); BX_HD_SMF void identify_ATAPI_drive(Bit8u channel); diff --git a/bochs/iodev/hdimage.cc b/bochs/iodev/hdimage.cc index 37541b6aa..36a54e9ad 100644 --- a/bochs/iodev/hdimage.cc +++ b/bochs/iodev/hdimage.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: hdimage.cc,v 1.8 2006-06-16 08:56:13 vruppert Exp $ +// $Id: hdimage.cc,v 1.9 2006-11-18 11:51:07 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -87,9 +87,9 @@ void default_image_t::close() } } -off_t default_image_t::lseek(off_t offset, int whence) +Bit64s default_image_t::lseek(Bit64s offset, int whence) { - return ::lseek(fd, offset, whence); + return (Bit64s)::lseek(fd, (off_t)offset, whence); } ssize_t default_image_t::read(void* buf, size_t count) @@ -223,7 +223,7 @@ Bit64s concat_image_t::lseek(Bit64s offset, int whence) } seek_was_last_op = 1; - return ::lseek(fd, (off_t)offset, whence); + return (Bit64s)::lseek(fd, (off_t)offset, whence); } ssize_t concat_image_t::read(void* buf, size_t count) @@ -461,7 +461,7 @@ void sparse_image_t::close() } } -off_t sparse_image_t::lseek (off_t offset, int whence) +Bit64s sparse_image_t::lseek(Bit64s offset, int whence) { //showpagetable(pagetable, header.numpages); @@ -486,10 +486,10 @@ off_t sparse_image_t::lseek (off_t offset, int whence) return 0; } -inline off_t sparse_image_t::get_physical_offset() +inline Bit64s sparse_image_t::get_physical_offset() { - off_t physical_offset = data_start; - physical_offset += ((off_t)position_physical_page << pagesize_shift); + Bit64s physical_offset = data_start; + physical_offset += ((Bit64s)position_physical_page << pagesize_shift); physical_offset += position_page_offset; return physical_offset; @@ -524,11 +524,11 @@ ssize_t sparse_image_t::read_page_fragment(Bit32u read_virtual_page, Bit32u read } else { - off_t physical_offset = get_physical_offset(); + Bit64s physical_offset = get_physical_offset(); if (physical_offset != underlying_current_filepos) { - off_t ret = ::lseek(fd, physical_offset, SEEK_SET); + off_t ret = ::lseek(fd, (off_t)physical_offset, SEEK_SET); // underlying_current_filepos update deferred if (ret == -1) panic(strerror(errno)); @@ -628,7 +628,7 @@ ssize_t sparse_image_t::write (const void* buf, size_t count) // We just add on another page at the end of the file // Reclamation, compaction etc should currently be done off-line - off_t data_size = underlying_filesize - data_start; + Bit64s data_size = underlying_filesize - data_start; BX_ASSERT((data_size % pagesize) == 0); @@ -638,7 +638,7 @@ ssize_t sparse_image_t::write (const void* buf, size_t count) pagetable[position_virtual_page] = htod32(next_data_page); position_physical_page = next_data_page; - off_t page_file_start = data_start + ((off_t)position_physical_page << pagesize_shift); + Bit64s page_file_start = data_start + ((Bit64s)position_physical_page << pagesize_shift); if (parent_image != NULL) { @@ -703,11 +703,11 @@ ssize_t sparse_image_t::write (const void* buf, size_t count) BX_ASSERT(position_physical_page != SPARSE_PAGE_NOT_ALLOCATED); - off_t physical_offset = get_physical_offset(); + Bit64s physical_offset = get_physical_offset(); if (physical_offset != underlying_current_filepos) { - off_t ret = ::lseek(fd, physical_offset, SEEK_SET); + off_t ret = ::lseek(fd, (off_t)physical_offset, SEEK_SET); // underlying_current_filepos update deferred if (ret == -1) panic(strerror(errno)); @@ -828,9 +828,9 @@ void dll_image_t::close () } } -off_t dll_image_t::lseek (off_t offset, int whence) +Bit64s dll_image_t::lseek(Bit64s offset, int whence) { - vblk = offset >> 9; + vblk = (int)(offset >> 9); return 0; } @@ -1109,7 +1109,7 @@ Bit64s redolog_t::lseek(Bit64s offset, int whence) BX_PANIC( ("redolog : lseek HD with whence not SEEK_SET")); return -1; } - if (offset > (off_t)dtoh64(header.specific.disk)) + if (offset > (Bit64s)dtoh64(header.specific.disk)) { BX_PANIC(("redolog : lseek to byte %ld failed", (long)offset)); return -1; @@ -1123,143 +1123,140 @@ Bit64s redolog_t::lseek(Bit64s offset, int whence) return offset; } -ssize_t -redolog_t::read (void* buf, size_t count) +ssize_t redolog_t::read(void* buf, size_t count) { - off_t bloc_offset, bitmap_offset; + Bit64s bloc_offset, bitmap_offset; - if (count != 512) - BX_PANIC( ("redolog : read HD with count not 512")); + if (count != 512) + BX_PANIC( ("redolog : read HD with count not 512")); - BX_DEBUG(("redolog : reading index %d, mapping to %d", extent_index, dtoh32(catalog[extent_index]))); + BX_DEBUG(("redolog : reading index %d, mapping to %d", extent_index, dtoh32(catalog[extent_index]))); - if (dtoh32(catalog[extent_index]) == REDOLOG_PAGE_NOT_ALLOCATED) - { - // page not allocated - return 0; - } + if (dtoh32(catalog[extent_index]) == REDOLOG_PAGE_NOT_ALLOCATED) + { + // page not allocated + return 0; + } - bitmap_offset = (off_t)STANDARD_HEADER_SIZE + (dtoh32(header.specific.catalog) * sizeof(Bit32u)); - bitmap_offset += (off_t)512 * dtoh32(catalog[extent_index]) * (extent_blocs + bitmap_blocs); - bloc_offset = bitmap_offset + ((off_t)512 * (bitmap_blocs + extent_offset)); + bitmap_offset = (Bit64s)STANDARD_HEADER_SIZE + (dtoh32(header.specific.catalog) * sizeof(Bit32u)); + bitmap_offset += (Bit64s)512 * dtoh32(catalog[extent_index]) * (extent_blocs + bitmap_blocs); + bloc_offset = bitmap_offset + ((Bit64s)512 * (bitmap_blocs + extent_offset)); - BX_DEBUG(("redolog : bitmap offset is %x", (Bit32u)bitmap_offset)); - BX_DEBUG(("redolog : bloc offset is %x", (Bit32u)bloc_offset)); + BX_DEBUG(("redolog : bitmap offset is %x", (Bit32u)bitmap_offset)); + BX_DEBUG(("redolog : bloc offset is %x", (Bit32u)bloc_offset)); + // FIXME if same extent_index as before we can skip bitmap read - // FIXME if same extent_index as before we can skip bitmap read + ::lseek(fd, (off_t)bitmap_offset, SEEK_SET); - ::lseek(fd, bitmap_offset, SEEK_SET); + if (::read(fd, bitmap, dtoh32(header.specific.bitmap)) != (ssize_t)dtoh32(header.specific.bitmap)) + { + BX_PANIC(("redolog : failed to read bitmap for extent %d", extent_index)); + return 0; + } - if (::read(fd, bitmap, dtoh32(header.specific.bitmap)) != (ssize_t)dtoh32(header.specific.bitmap)) - { - BX_PANIC(("redolog : failed to read bitmap for extent %d", extent_index)); - return 0; - } + if ( ((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00 ) + { + BX_DEBUG(("read not in redolog")); - if ( ((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00 ) - { - BX_DEBUG(("read not in redolog")); + // bitmap says bloc not in reloglog + return 0; + } - // bitmap says bloc not in reloglog - return 0; - } - - ::lseek(fd, bloc_offset, SEEK_SET); + ::lseek(fd, (off_t)bloc_offset, SEEK_SET); - return (::read(fd, buf, count)); + return (::read(fd, buf, count)); } -ssize_t -redolog_t::write (const void* buf, size_t count) +ssize_t redolog_t::write(const void* buf, size_t count) { - Bit32u i; - off_t bloc_offset, bitmap_offset, catalog_offset; - ssize_t written; - bx_bool update_catalog = 0; + Bit32u i; + Bit64s bloc_offset, bitmap_offset, catalog_offset; + ssize_t written; + bx_bool update_catalog = 0; - if (count != 512) - BX_PANIC( ("redolog : write HD with count not 512")); + if (count != 512) + BX_PANIC( ("redolog : write HD with count not 512")); - BX_DEBUG(("redolog : writing index %d, mapping to %d", extent_index, dtoh32(catalog[extent_index]))); - if (dtoh32(catalog[extent_index]) == REDOLOG_PAGE_NOT_ALLOCATED) - { - if(extent_next >= dtoh32(header.specific.catalog)) - { - BX_PANIC(("redolog : can't allocate new extent... catalog is full")); - return 0; - } + BX_DEBUG(("redolog : writing index %d, mapping to %d", extent_index, dtoh32(catalog[extent_index]))); + if (dtoh32(catalog[extent_index]) == REDOLOG_PAGE_NOT_ALLOCATED) + { + if (extent_next >= dtoh32(header.specific.catalog)) + { + BX_PANIC(("redolog : can't allocate new extent... catalog is full")); + return 0; + } - BX_DEBUG(("redolog : allocating new extent at %d", extent_next)); + BX_DEBUG(("redolog : allocating new extent at %d", extent_next)); - // Extent not allocated, allocate new - catalog[extent_index] = htod32(extent_next); - - extent_next += 1; + // Extent not allocated, allocate new + catalog[extent_index] = htod32(extent_next); - char *zerobuffer = (char*)malloc(512); - memset(zerobuffer, 0, 512); + extent_next += 1; - // Write bitmap - bitmap_offset = (off_t)STANDARD_HEADER_SIZE + (dtoh32(header.specific.catalog) * sizeof(Bit32u)); - bitmap_offset += (off_t)512 * dtoh32(catalog[extent_index]) * (extent_blocs + bitmap_blocs); - ::lseek(fd, bitmap_offset, SEEK_SET); - for(i=0; i> (extent_offset%8)) & 0x01) == 0x00 ) - { - bitmap[extent_offset/8] |= 1 << (extent_offset%8); - ::lseek(fd, bitmap_offset, SEEK_SET); - ::write(fd, bitmap, dtoh32(header.specific.bitmap)); - } + // Write bitmap + // FIXME if same extent_index as before we can skip bitmap read + ::lseek(fd, (off_t)bitmap_offset, SEEK_SET); + if (::read(fd, bitmap, dtoh32(header.specific.bitmap)) != (ssize_t)dtoh32(header.specific.bitmap)) + { + BX_PANIC(("redolog : failed to read bitmap for extent %d", extent_index)); + return 0; + } - // Write catalog - if (update_catalog) - { - // FIXME if mmap - catalog_offset = (off_t)STANDARD_HEADER_SIZE + (extent_index * sizeof(Bit32u)); + // If bloc does not belong to extent yet + if ( ((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00 ) + { + bitmap[extent_offset/8] |= 1 << (extent_offset%8); + ::lseek(fd, (off_t)bitmap_offset, SEEK_SET); + ::write(fd, bitmap, dtoh32(header.specific.bitmap)); + } - BX_DEBUG(("redolog : writing catalog at offset %x", (Bit32u)catalog_offset)); + // Write catalog + if (update_catalog) + { + // FIXME if mmap + catalog_offset = (Bit64s)STANDARD_HEADER_SIZE + (extent_index * sizeof(Bit32u)); - ::lseek(fd, catalog_offset, SEEK_SET); - ::write(fd, &catalog[extent_index], sizeof(Bit32u)); - } + BX_DEBUG(("redolog : writing catalog at offset %x", (Bit32u)catalog_offset)); - return written; + ::lseek(fd, (off_t)catalog_offset, SEEK_SET); + ::write(fd, &catalog[extent_index], sizeof(Bit32u)); + } + + return written; } @@ -1370,7 +1367,7 @@ void undoable_image_t::close () Bit64s undoable_image_t::lseek(Bit64s offset, int whence) { redolog->lseek(offset, whence); - return ro_disk->lseek((off_t)offset, whence); + return ro_disk->lseek(offset, whence); } ssize_t undoable_image_t::read(void* buf, size_t count) @@ -1492,7 +1489,7 @@ ssize_t volatile_image_t::write(const void* buf, size_t count) z_ro_image_t::z_ro_image_t() { - offset = (off_t)0; + offset = (Bit64s)0; } int z_ro_image_t::open (const char* pathname) @@ -1521,7 +1518,7 @@ void z_ro_image_t::close () } } -off_t z_ro_image_t::lseek (off_t _offset, int whence) +Bit64s z_ro_image_t::lseek(Bit64s _offset, int whence) { // Only SEEK_SET supported if (whence != SEEK_SET) @@ -1610,7 +1607,7 @@ void z_undoable_image_t::close () free(redolog_name); } -off_t z_undoable_image_t::lseek (off_t offset, int whence) +Bit64s z_undoable_image_t::lseek(Bit64s offset, int whence) { redolog->lseek(offset, whence); return ro_disk->lseek(offset, whence); @@ -1711,7 +1708,7 @@ void z_volatile_image_t::close () free(redolog_name); } -off_t z_volatile_image_t::lseek (off_t offset, int whence) +Bit64s z_volatile_image_t::lseek(Bit64s offset, int whence) { redolog->lseek(offset, whence); return ro_disk->lseek(offset, whence); diff --git a/bochs/iodev/hdimage.h b/bochs/iodev/hdimage.h index de34872b0..f6214b0e0 100644 --- a/bochs/iodev/hdimage.h +++ b/bochs/iodev/hdimage.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: hdimage.h,v 1.6 2006-06-16 07:29:33 vruppert Exp $ +// $Id: hdimage.h,v 1.7 2006-11-18 11:51:07 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2005 MandrakeSoft S.A. @@ -133,22 +133,22 @@ class device_image_t device_image_t(); // Open a image. Returns non-negative if successful. - virtual int open (const char* pathname) = 0; + virtual int open(const char* pathname) = 0; // Close the image. - virtual void close () = 0; + virtual void close() = 0; // Position ourselves. Return the resulting offset from the // beginning of the file. - virtual off_t lseek (off_t offset, int whence) = 0; + virtual Bit64s lseek(Bit64s offset, int whence) = 0; // Read count bytes to the buffer buf. Return the number of // bytes read (count). - virtual ssize_t read (void* buf, size_t count) = 0; + virtual ssize_t read(void* buf, size_t count) = 0; // Write count bytes from buf. Return the number of bytes // written (count). - virtual ssize_t write (const void* buf, size_t count) = 0; + virtual ssize_t write(const void* buf, size_t count) = 0; unsigned cylinders; unsigned heads; @@ -161,25 +161,25 @@ class default_image_t : public device_image_t { public: // Open a image. Returns non-negative if successful. - int open (const char* pathname); + int open(const char* pathname); // Open an image with specific flags. Returns non-negative if successful. - int open (const char* pathname, int flags); + int open(const char* pathname, int flags); // Close the image. - void close (); + void close(); // Position ourselves. Return the resulting offset from the // beginning of the file. - off_t lseek (off_t offset, int whence); + Bit64s lseek(Bit64s offset, int whence); // Read count bytes to the buffer buf. Return the number of // bytes read (count). - ssize_t read (void* buf, size_t count); + ssize_t read(void* buf, size_t count); // Write count bytes from buf. Return the number of bytes // written (count). - ssize_t write (const void* buf, size_t count); + ssize_t write(const void* buf, size_t count); private: int fd; @@ -246,22 +246,22 @@ class sparse_image_t : public device_image_t sparse_image_t(); // Open a image. Returns non-negative if successful. - int open (const char* pathname); + int open(const char* pathname); // Close the image. - void close (); + void close(); // Position ourselves. Return the resulting offset from the // beginning of the file. - off_t lseek (off_t offset, int whence); + Bit64s lseek(Bit64s offset, int whence); // Read count bytes to the buffer buf. Return the number of // bytes read (count). - ssize_t read (void* buf, size_t count); + ssize_t read(void* buf, size_t count); // Write count bytes from buf. Return the number of bytes // written (count). - ssize_t write (const void* buf, size_t count); + ssize_t write(const void* buf, size_t count); private: int fd; @@ -283,23 +283,23 @@ class sparse_image_t : public device_image_t int pagesize_shift; Bit32u pagesize_mask; - off_t data_start; - off_t underlying_filesize; + Bit64s data_start; + Bit64s underlying_filesize; char * pathname; - off_t position; + Bit64s position; Bit32u position_virtual_page; Bit32u position_physical_page; Bit32u position_page_offset; - off_t underlying_current_filepos; + Bit64s underlying_current_filepos; - off_t total_size; + Bit64s total_size; void panic(const char * message); - off_t get_physical_offset(); + Bit64s get_physical_offset(); void set_virtual_page(Bit32u new_virtual_page); void read_header(); ssize_t read_page_fragment(Bit32u read_virtual_page, Bit32u read_page_offset, size_t read_size, void * buf); @@ -316,22 +316,22 @@ class dll_image_t : public device_image_t { public: // Open a image. Returns non-negative if successful. - int open (const char* pathname); + int open(const char* pathname); // Close the image. - void close (); + void close(); // Position ourselves. Return the resulting offset from the // beginning of the file. - off_t lseek (off_t offset, int whence); + Bit64s lseek(Bit64s offset, int whence); // Read count bytes to the buffer buf. Return the number of // bytes read (count). - ssize_t read (void* buf, size_t count); + ssize_t read(void* buf, size_t count); // Write count bytes from buf. Return the number of bytes // written (count). - ssize_t write (const void* buf, size_t count); + ssize_t write(const void* buf, size_t count); private: int vunit,vblk; @@ -476,25 +476,25 @@ class z_ro_image_t : public device_image_t z_ro_image_t(); // Open a image. Returns non-negative if successful. - int open (const char* pathname); + int open(const char* pathname); // Close the image. - void close (); + void close(); // Position ourselves. Return the resulting offset from the // beginning of the file. - off_t lseek (off_t offset, int whence); + Bit64s lseek(Bit64s offset, int whence); // Read count bytes to the buffer buf. Return the number of // bytes read (count). - ssize_t read (void* buf, size_t count); + ssize_t read(void* buf, size_t count); // Write count bytes from buf. Return the number of bytes // written (count). - ssize_t write (const void* buf, size_t count); + ssize_t write(const void* buf, size_t count); private: - off_t offset; + Bit64s offset; int fd; gzFile gzfile; @@ -508,22 +508,22 @@ class z_undoable_image_t : public device_image_t z_undoable_image_t(Bit64u size, const char* redolog_name); // Open a image. Returns non-negative if successful. - int open (const char* pathname); + int open(const char* pathname); // Close the image. - void close (); + void close(); // Position ourselves. Return the resulting offset from the // beginning of the file. - off_t lseek (off_t offset, int whence); + Bit64s lseek(Bit64s offset, int whence); // Read count bytes to the buffer buf. Return the number of // bytes read (count). - ssize_t read (void* buf, size_t count); + ssize_t read(void* buf, size_t count); // Write count bytes from buf. Return the number of bytes // written (count). - ssize_t write (const void* buf, size_t count); + ssize_t write(const void* buf, size_t count); private: redolog_t *redolog; // Redolog instance @@ -540,22 +540,22 @@ class z_volatile_image_t : public device_image_t z_volatile_image_t(Bit64u size, const char* redolog_name); // Open a image. Returns non-negative if successful. - int open (const char* pathname); + int open(const char* pathname); // Close the image. - void close (); + void close(); // Position ourselves. Return the resulting offset from the // beginning of the file. - off_t lseek (off_t offset, int whence); + Bit64s lseek(Bit64s offset, int whence); // Read count bytes to the buffer buf. Return the number of // bytes read (count). - ssize_t read (void* buf, size_t count); + ssize_t read(void* buf, size_t count); // Write count bytes from buf. Return the number of bytes // written (count). - ssize_t write (const void* buf, size_t count); + ssize_t write(const void* buf, size_t count); private: redolog_t *redolog; // Redolog instance