From: David van Moolenbroek Date: Sun, 13 Jun 2010 10:40:22 +0000 (+0000) Subject: libdriver: make partition code use a contiguous buffer X-Git-Tag: v3.1.8~451 X-Git-Url: http://zhaoyanbai.com/repos/rndc-confgen.html?a=commitdiff_plain;h=eeab8e0680880835d614b54fccae4b56f2fbcb1b;p=minix.git libdriver: make partition code use a contiguous buffer --- diff --git a/drivers/at_wini/at_wini.h b/drivers/at_wini/at_wini.h index 8654f9781..aefa1826b 100644 --- a/drivers/at_wini/at_wini.h +++ b/drivers/at_wini/at_wini.h @@ -170,8 +170,6 @@ #define ATAPI_IDENTIFY 0xA1 /* identify drive */ #define SCSI_READ10 0x28 /* read from disk */ #define SCSI_SENSE 0x03 /* sense request */ - -#define CD_SECTOR_SIZE 2048 /* sector size of a CD-ROM */ #endif /* ATAPI */ /* Interrupt request lines. */ diff --git a/include/minix/driver.h b/include/minix/driver.h index 0ee53af52..56af37aaa 100644 --- a/include/minix/driver.h +++ b/include/minix/driver.h @@ -83,6 +83,8 @@ _PROTOTYPE( int nop_ioctl, (struct driver *dp, message *m_ptr) ); #define SECTOR_SHIFT 9 /* for division */ #define SECTOR_MASK 511 /* and remainder */ +#define CD_SECTOR_SIZE 2048 /* sector size of a CD-ROM in bytes */ + /* Size of the DMA buffer buffer in bytes. */ #define USE_EXTRA_DMA_BUF 0 /* usually not needed */ #define DMA_BUF_SIZE (DMA_SECTORS * SECTOR_SIZE) diff --git a/lib/libdriver/driver.c b/lib/libdriver/driver.c index 6d1dd84d8..36912faef 100644 --- a/lib/libdriver/driver.c +++ b/lib/libdriver/driver.c @@ -434,9 +434,14 @@ PUBLIC void driver_init_buffer(void) * be used to read partition tables and such. Its absolute address is * 'tmp_phys', the normal address is 'tmp_buf'. */ + vir_bytes size; - if(!(tmp_buf = alloc_contig(2*DMA_BUF_SIZE, AC_ALIGN4K, &tmp_phys))) - panic("can't allocate tmp_buf: %d", DMA_BUF_SIZE); + if (tmp_buf == NULL) { + size = MAX(2*DMA_BUF_SIZE, CD_SECTOR_SIZE); + + if(!(tmp_buf = alloc_contig(size, AC_ALIGN4K, &tmp_phys))) + panic("can't allocate tmp_buf: %lu", size); + } } /*===========================================================================* diff --git a/lib/libdriver/drvlib.c b/lib/libdriver/drvlib.c index fd24a9fe9..3172eea2d 100644 --- a/lib/libdriver/drvlib.c +++ b/lib/libdriver/drvlib.c @@ -17,10 +17,6 @@ FORWARD _PROTOTYPE( int get_part_table, (struct driver *dp, int device, unsigned long offset, struct part_entry *table)); FORWARD _PROTOTYPE( void sort, (struct part_entry *table) ); -#ifndef CD_SECTOR_SIZE -#define CD_SECTOR_SIZE 2048 -#endif - /*============================================================================* * partition * *============================================================================*/ @@ -158,10 +154,11 @@ struct part_entry *table; /* four entries */ */ iovec_t iovec1; u64_t position; - static unsigned char partbuf[CD_SECTOR_SIZE]; + + driver_init_buffer(); position = mul64u(offset, SECTOR_SIZE); - iovec1.iov_addr = (vir_bytes) partbuf; + iovec1.iov_addr = (vir_bytes) tmp_buf; iovec1.iov_size = CD_SECTOR_SIZE; if ((*dp->dr_prepare)(device) != NULL) { (void) (*dp->dr_transfer)(SELF, DEV_GATHER_S, position, &iovec1, 1); @@ -169,11 +166,11 @@ struct part_entry *table; /* four entries */ if (iovec1.iov_size != 0) { return 0; } - if (partbuf[510] != 0x55 || partbuf[511] != 0xAA) { + if (tmp_buf[510] != 0x55 || tmp_buf[511] != 0xAA) { /* Invalid partition table. */ return 0; } - memcpy(table, (partbuf + PART_TABLE_OFF), NR_PARTITIONS * sizeof(table[0])); + memcpy(table, (tmp_buf + PART_TABLE_OFF), NR_PARTITIONS * sizeof(table[0])); return 1; } diff --git a/lib/libsys/alloc_util.c b/lib/libsys/alloc_util.c index df4ffd77b..40e906c12 100644 --- a/lib/libsys/alloc_util.c +++ b/lib/libsys/alloc_util.c @@ -33,7 +33,7 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) if(flags & AC_ALIGN64K) mmapflags |= MAP_ALIGN64K; - /* First try to get memory with mmap. This is gauranteed + /* First try to get memory with mmap. This is guaranteed * to be page-aligned, and we can tell VM it has to be * pre-allocated and contiguous. */