* Patch for different sector sizes
@ 2008-10-07 22:30 Clemens Helfmeier
2008-10-08 16:11 ` Clemens Helfmeier
0 siblings, 1 reply; 2+ messages in thread
From: Clemens Helfmeier @ 2008-10-07 22:30 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 387 bytes --]
Hey Guys,
this seems to be a tough topic ;-)
At Least i have fixed a few lines of code today, it compiles not yet in total,
but i hope the task can be completed in a few more hours of work. I guess a few
things will still be broken after completion, i didn't yet test anything.
Maybe this is even too bad to be done? what do you think?
Path Attached, please comment!
bye,
sumsum
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: variable_sector_size.patch --]
[-- Type: text/x-diff; charset=unknown-8bit, Size: 65527 bytes --]
Index: disk/lvm.c
===================================================================
--- disk/lvm.c (revision 1886)
+++ disk/lvm.c (working copy)
@@ -185,7 +185,7 @@
read from. */
if (pv->disk)
err = grub_disk_read (pv->disk, offset, 0,
- size << GRUB_DISK_SECTOR_BITS, buf);
+ size * pv->disk->sector_size, buf);
else
err = grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"Physical volume %s not found", pv->name);
Index: disk/scsi.c
===================================================================
--- disk/scsi.c (revision 1886)
+++ disk/scsi.c (working copy)
@@ -294,7 +294,7 @@
/* SCSI blocks can be something else than 512, although GRUB
wants 512 byte blocks. */
disk->total_sectors = ((scsi->size * scsi->blocksize)
- << GRUB_DISK_SECTOR_BITS);
+ * disk->sector_size);
grub_dprintf ("scsi", "capacity=%llu, blksize=%d\n",
disk->total_sectors, scsi->blocksize);
@@ -325,7 +325,7 @@
/* SCSI sectors are variable in size. GRUB uses 512 byte
sectors. */
- sector = grub_divmod64 (sector, scsi->blocksize >> GRUB_DISK_SECTOR_BITS,
+ sector = grub_divmod64 (sector, scsi->blocksize / disk->sector_size,
NULL);
/* Depending on the type, select a read function. */
Index: disk/ata.c
===================================================================
--- disk/ata.c (revision 1886)
+++ disk/ata.c (working copy)
@@ -77,6 +77,9 @@
GRUB_ATA_CMD_EXEC_DEV_DIAGNOSTICS = 0x90
};
+// TODO: Put the sector size into grub_ata_device
+#define GRUB_ATA_SECTOR_SIZE 512
+
struct grub_ata_device
{
/* IDE port to use. */
@@ -323,7 +326,7 @@
grub_uint16_t *info16;
int ataerr = 0;
- info = grub_malloc (GRUB_DISK_SECTOR_SIZE);
+ info = grub_malloc (GRUB_ATA_SECTOR_SIZE);
if (! info)
return grub_errno;
@@ -343,7 +346,7 @@
}
grub_ata_wait ();
- if (grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE))
+ if (grub_ata_pio_read (dev, info, GRUB_ATA_SECTOR_SIZE))
ataerr = grub_ata_regget (dev, GRUB_ATA_REG_ERROR);
if (ataerr & 4)
{
Index: disk/i386/pc/biosdisk.c
===================================================================
--- disk/i386/pc/biosdisk.c (revision 1886)
+++ disk/i386/pc/biosdisk.c (working copy)
@@ -196,8 +196,7 @@
struct grub_biosdisk_dap *dap;
dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR
- + (data->sectors
- << GRUB_DISK_SECTOR_BITS));
+ + (data->sectors) * disk->sector_size);
dap->length = sizeof (*dap);
dap->reserved = 0;
dap->blocks = size;
@@ -305,8 +304,8 @@
return grub_errno;
grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR,
- len << GRUB_DISK_SECTOR_BITS);
- buf += len << GRUB_DISK_SECTOR_BITS;
+ len * disk->sector_size);
+ buf += len * disk->sector_size;
sector += len;
size -= len;
}
@@ -329,13 +328,13 @@
len = size;
grub_memcpy ((void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, buf,
- len << GRUB_DISK_SECTOR_BITS);
+ len * disk->sector_size);
if (grub_biosdisk_rw (GRUB_BIOSDISK_WRITE, disk, sector, len,
GRUB_MEMORY_MACHINE_SCRATCH_SEG))
return grub_errno;
- buf += len << GRUB_DISK_SECTOR_BITS;
+ buf += len * disk->sector_size;
sector += len;
size -= len;
}
Index: disk/raid.c
===================================================================
--- disk/raid.c (revision 1886)
+++ disk/raid.c (working copy)
@@ -240,6 +240,9 @@
if (read_size > size)
read_size = size;
+ // sector size for array (must be equal for all drives, not checked)
+ unsigned int sector_size = 0;
+
for (i = 0; i < near; i++)
{
unsigned int k;
@@ -249,13 +252,14 @@
{
if (array->device[k])
{
+ sector_size = array->device[k]->sector_size;
if (grub_errno == GRUB_ERR_READ_ERROR)
grub_errno = GRUB_ERR_NONE;
err = grub_disk_read (array->device[k],
read_sector + j * far_ofs + b,
0,
- read_size << GRUB_DISK_SECTOR_BITS,
+ read_size * sector_size,
buf);
if (! err)
break;
@@ -285,7 +289,7 @@
if (err)
return err;
- buf += read_size << GRUB_DISK_SECTOR_BITS;
+ buf += read_size * sector_size;
size -= read_size;
if (! size)
break;
@@ -366,7 +370,7 @@
err = grub_disk_read (array->device[disknr],
read_sector + b, 0,
- read_size << GRUB_DISK_SECTOR_BITS,
+ read_size * array->device[disknr]->sector_size,
buf);
if ((err) && (err != GRUB_ERR_READ_ERROR))
@@ -405,7 +409,7 @@
break;
}
- buf += read_size << GRUB_DISK_SECTOR_BITS;
+ buf += read_size * array->device[disknr]->sector_size;
size -= read_size;
if (! size)
break;
Index: disk/memdisk.c
===================================================================
--- disk/memdisk.c (revision 1886)
+++ disk/memdisk.c (working copy)
@@ -56,7 +56,7 @@
grub_memdisk_read (grub_disk_t disk __attribute((unused)), grub_disk_addr_t sector,
grub_size_t size, char *buf)
{
- grub_memcpy (buf, memdisk_addr + (sector << GRUB_DISK_SECTOR_BITS), size << GRUB_DISK_SECTOR_BITS);
+ grub_memcpy (buf, memdisk_addr + (sector * disk->sector_size), size * disk->sector_size);
return 0;
}
@@ -64,7 +64,7 @@
grub_memdisk_write (grub_disk_t disk __attribute((unused)), grub_disk_addr_t sector,
grub_size_t size, const char *buf)
{
- grub_memcpy (memdisk_addr + (sector << GRUB_DISK_SECTOR_BITS), buf, size << GRUB_DISK_SECTOR_BITS);
+ grub_memcpy (memdisk_addr + (sector * disk->sector_size), buf, size * disk->sector_size);
return 0;
}
Index: disk/raid5_recover.c
===================================================================
--- disk/raid5_recover.c (revision 1886)
+++ disk/raid5_recover.c (working copy)
@@ -31,7 +31,10 @@
char *buf2;
int i;
- size <<= GRUB_DISK_SECTOR_BITS;
+ if (array->device[0] == 0)
+ return grub_errno;
+
+ size *= array->device[0]->sector_size;
buf2 = grub_malloc (size);
if (!buf2)
return grub_errno;
Index: disk/loopback.c
===================================================================
--- disk/loopback.c (revision 1886)
+++ disk/loopback.c (working copy)
@@ -200,20 +200,20 @@
grub_file_t file = (grub_file_t) disk->data;
grub_off_t pos;
- grub_file_seek (file, sector << GRUB_DISK_SECTOR_BITS);
+ grub_file_seek (file, sector * disk->sector_size);
- grub_file_read (file, buf, size << GRUB_DISK_SECTOR_BITS);
+ grub_file_read (file, buf, size * disk->sector_size);
if (grub_errno)
return grub_errno;
/* In case there is more data read than there is available, in case
of files that are not a multiple of GRUB_DISK_SECTOR_SIZE, fill
the rest with zeros. */
- pos = (sector + size) << GRUB_DISK_SECTOR_BITS;
+ pos = (sector + size) * disk->sector_size;
if (pos > file->size)
{
grub_size_t amount = pos - file->size;
- grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);
+ grub_memset (buf + (size * disk->sector_size) - amount, 0, amount);
}
return 0;
Index: disk/raid6_recover.c
===================================================================
--- disk/raid6_recover.c (revision 1886)
+++ disk/raid6_recover.c (working copy)
@@ -95,7 +95,10 @@
int err[2], nerr;
char *pbuf = 0, *qbuf = 0;
- size <<= GRUB_DISK_SECTOR_BITS;
+ if (array->device[0] == 0)
+ goto quit;
+
+ size *= array->device[0]->sector_size;
pbuf = grub_malloc (size);
if (!pbuf)
goto quit;
Index: kern/fs.c
===================================================================
--- kern/fs.c (revision 1886)
+++ kern/fs.c (working copy)
@@ -198,7 +198,7 @@
goto fail;
}
- file->size += (blocks[i].length << GRUB_DISK_SECTOR_BITS);
+ file->size += (blocks[i].length * disk->sector_size);
p++;
}
@@ -212,6 +212,23 @@
return grub_errno;
}
+static grub_uint32_t
+grub_fs_log2 (grub_uint32_t x)
+{
+ grub_uint32_t i;
+
+ if (x == 0)
+ return -1;
+
+ for (i = 0; (x & 1) == 0; i++)
+ x >>= 1;
+
+ if (x != 1)
+ return -1;
+
+ return i;
+}
+
static grub_ssize_t
grub_fs_blocklist_read (grub_file_t file, char *buf, grub_size_t len)
{
@@ -219,12 +236,17 @@
grub_disk_addr_t sector;
grub_off_t offset;
grub_ssize_t ret = 0;
+ grub_disk_t disk = file->device->disk;
if (len > file->size - file->offset)
len = file->size - file->offset;
- sector = (file->offset >> GRUB_DISK_SECTOR_BITS);
- offset = (file->offset & (GRUB_DISK_SECTOR_SIZE - 1));
+// TODO: find something nice for those 64 bit divisions in here,
+// for now we will use a log2 based shifting approach.
+ grub_uint32_t sector_shift = grub_fs_log2( disk->sector_size );
+
+ sector = (file->offset >> sector_shift);
+ offset = (file->offset & (disk->sector_size - 1));
for (p = file->data; p->length && len > 0; p++)
{
if (sector < p->length)
@@ -232,9 +254,9 @@
grub_size_t size;
size = len;
- if (((size + offset + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS) > p->length - sector)
- size = ((p->length - sector) << GRUB_DISK_SECTOR_BITS) - offset;
+ if (((size + offset + disk->sector_size - 1)
+ >> sector_shift) > p->length - sector)
+ size = ((p->length - sector) * disk->sector_size) - offset;
if (grub_disk_read (file->device->disk, p->offset + sector, offset,
size, buf) != GRUB_ERR_NONE)
@@ -242,8 +264,8 @@
ret += size;
len -= size;
- sector -= ((size + offset) >> GRUB_DISK_SECTOR_BITS);
- offset = ((size + offset) & (GRUB_DISK_SECTOR_SIZE - 1));
+ sector -= ((size + offset) >> sector_shift);
+ offset = ((size + offset) & (disk->sector_size - 1));
}
else
sector -= p->length;
Index: kern/rescue.c
===================================================================
--- kern/rescue.c (revision 1886)
+++ kern/rescue.c (working copy)
@@ -129,8 +129,9 @@
static void
grub_rescue_cmd_cat (int argc, char *argv[])
{
+#define CHUNK_SIZE 512
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char buf[CHUNK_SIZE];
grub_ssize_t size;
if (argc < 1)
Index: kern/disk.c
===================================================================
--- kern/disk.c (revision 1886)
+++ kern/disk.c (working copy)
@@ -148,25 +148,25 @@
}
static grub_err_t
-grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
+grub_disk_cache_store (unsigned long dev_id, grub_disk_t disk,
grub_disk_addr_t sector, const char *data)
{
unsigned index;
struct grub_disk_cache *cache;
- grub_disk_cache_invalidate (dev_id, disk_id, sector);
+ grub_disk_cache_invalidate (dev_id, disk->id, sector);
- index = grub_disk_cache_get_index (dev_id, disk_id, sector);
+ index = grub_disk_cache_get_index (dev_id, disk->id, sector);
cache = grub_disk_cache_table + index;
- cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ cache->data = grub_malloc ( disk->sector_size << GRUB_DISK_CACHE_BITS);
if (! cache->data)
return grub_errno;
grub_memcpy (cache->data, data,
- GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ disk->sector_size << GRUB_DISK_CACHE_BITS);
cache->dev_id = dev_id;
- cache->disk_id = disk_id;
+ cache->disk_id = disk->id;
cache->sector = sector;
return GRUB_ERR_NONE;
@@ -330,8 +330,8 @@
grub_disk_adjust_range (grub_disk_t disk, grub_disk_addr_t *sector,
grub_off_t *offset, grub_size_t size)
{
- *sector += *offset >> GRUB_DISK_SECTOR_BITS;
- *offset &= GRUB_DISK_SECTOR_SIZE - 1;
+ *sector += *offset * disk->sector_size;
+ *offset &= disk->sector_size - 1;
if (disk->partition)
{
@@ -342,16 +342,16 @@
len = grub_partition_get_len (disk->partition);
if (*sector >= len
- || len - *sector < ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS))
+ || len - *sector < ((*offset + size + disk->sector_size - 1)
+ * disk->sector_size))
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of partition");
*sector += start;
}
if (disk->total_sectors <= *sector
- || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS) > disk->total_sectors - *sector)
+ || ((*offset + size + disk->sector_size - 1)
+ * disk->sector_size) > disk->total_sectors - *sector)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk");
return GRUB_ERR_NONE;
@@ -380,7 +380,7 @@
real_offset = offset;
/* Allocate a temporary buffer. */
- tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ tmp_buf = grub_malloc (disk->sector_size << GRUB_DISK_CACHE_BITS);
if (! tmp_buf)
return grub_errno;
@@ -394,8 +394,8 @@
/* For reading bulk data. */
start_sector = sector & ~(GRUB_DISK_CACHE_SIZE - 1);
- pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS;
- len = ((GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS)
+ pos = (sector - start_sector) * disk->sector_size;
+ len = ((disk->sector_size << GRUB_DISK_CACHE_BITS)
- pos - real_offset);
if (len > size)
len = size;
@@ -421,10 +421,10 @@
grub_errno = GRUB_ERR_NONE;
- num = ((size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS);
+ num = ((size + disk->sector_size - 1)
+ / disk->sector_size);
- p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS);
+ p = grub_realloc (tmp_buf, num * disk->sector_size);
if (!p)
goto finish;
@@ -445,11 +445,11 @@
while (size)
{
(disk->read_hook) (sector, real_offset,
- ((size > GRUB_DISK_SECTOR_SIZE)
- ? GRUB_DISK_SECTOR_SIZE
+ ((size > disk->sector_size)
+ ? disk->sector_size
: size));
sector++;
- size -= GRUB_DISK_SECTOR_SIZE - real_offset;
+ size -= disk->sector_size - real_offset;
real_offset = 0;
}
@@ -459,7 +459,7 @@
/* Copy it and store it in the disk cache. */
grub_memcpy (buf, tmp_buf + pos + real_offset, len);
- grub_disk_cache_store (disk->dev->id, disk->id,
+ grub_disk_cache_store (disk->dev->id, disk,
start_sector, tmp_buf);
}
@@ -472,15 +472,15 @@
while (l)
{
(disk->read_hook) (s, real_offset,
- ((l > GRUB_DISK_SECTOR_SIZE)
- ? GRUB_DISK_SECTOR_SIZE
+ ((l > disk->sector_size)
+ ? disk->sector_size
: l));
- if (l < GRUB_DISK_SECTOR_SIZE - real_offset)
+ if (l < disk->sector_size - real_offset)
break;
s++;
- l -= GRUB_DISK_SECTOR_SIZE - real_offset;
+ l -= disk->sector_size - real_offset;
real_offset = 0;
}
}
@@ -513,16 +513,16 @@
while (size)
{
- if (real_offset != 0 || (size < GRUB_DISK_SECTOR_SIZE && size != 0))
+ if (real_offset != 0 || (size < disk->sector_size && size != 0))
{
- char tmp_buf[GRUB_DISK_SECTOR_SIZE];
+ char tmp_buf[disk->sector_size];
grub_size_t len;
- if (grub_disk_read (disk, sector, 0, GRUB_DISK_SECTOR_SIZE, tmp_buf)
+ if (grub_disk_read (disk, sector, 0, disk->sector_size, tmp_buf)
!= GRUB_ERR_NONE)
goto finish;
- len = GRUB_DISK_SECTOR_SIZE - real_offset;
+ len = disk->sector_size - real_offset;
if (len > size)
len = size;
@@ -543,8 +543,8 @@
grub_size_t len;
grub_size_t n;
- len = size & ~(GRUB_DISK_SECTOR_SIZE - 1);
- n = size >> GRUB_DISK_SECTOR_BITS;
+ len = size & ~(disk->sector_size - 1);
+ n = size / disk->sector_size;
if ((disk->dev->write) (disk, sector, n, buf) != GRUB_ERR_NONE)
goto finish;
Index: fs/xfs.c
===================================================================
--- fs/xfs.c (revision 1886)
+++ fs/xfs.c (working copy)
@@ -188,6 +188,23 @@
#define GRUB_XFS_NEXT_DIRENT(pos,len) \
(pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2)
\f
+static int
+xfs_log2 (unsigned x)
+{
+ int i;
+
+ if (x == 0)
+ return -1;
+
+ for (i = 0; (x & 1) == 0; i++)
+ x >>= 1;
+
+ if (x != 1)
+ return -1;
+
+ return i;
+}
+
static inline int
grub_xfs_inode_block (struct grub_xfs_data *data,
grub_uint64_t ino)
@@ -197,7 +214,7 @@
long long block;
block = (inoinag >> 4) + ag * data->agsize;
- block <<= (data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS);
+ block <<= (data->sblock.log2_bsize - data->disk->sector_size);
return block;
}
@@ -267,8 +284,7 @@
if (grub_disk_read (node->data->disk,
grub_be_to_cpu64 (keys[i - 1 + XFS_INODE_EXTENTS])
- << (node->data->sblock.log2_bsize
- - GRUB_DISK_SECTOR_BITS),
+ << (node->data->sblock.log2_bsize) / node->data->disk->sector_size,
0, node->data->sblock.bsize, (char *) leaf))
return 0;
@@ -333,8 +349,7 @@
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_xfs_read_block,
grub_be_to_cpu64 (node->inode.size),
- node->data->sblock.log2_bsize
- - GRUB_DISK_SECTOR_BITS);
+ node->data->sblock.log2_bsize - xfs_log2 (node->data->disk->sector_size));
}
Index: fs/afs.c
===================================================================
--- fs/afs.c (revision 1886)
+++ fs/afs.c (working copy)
@@ -179,6 +179,23 @@
static grub_dl_t my_mod;
#endif
+static int
+afs_log2 (unsigned x)
+{
+ int i;
+
+ if (x == 0)
+ return -1;
+
+ for (i = 0; (x & 1) == 0; i++)
+ x >>= 1;
+
+ if (x != 1)
+ return -1;
+
+ return i;
+}
+
static grub_afs_off_t
grub_afs_run_to_num (struct grub_afs_sblock *sb,
struct grub_afs_blockrun *run)
@@ -193,7 +210,7 @@
{
return grub_disk_read (data->disk,
ino *
- (data->sblock.block_size >> GRUB_DISK_SECTOR_BITS),
+ (data->sblock.block_size / data->disk->sector_size),
0, sizeof (struct grub_afs_inode),
(char *) inode);
}
@@ -228,7 +245,7 @@
int j;
if (grub_disk_read (node->data->disk,
- blk * (sb->block_size >> GRUB_DISK_SECTOR_BITS),
+ blk * (sb->block_size / node->data->disk->sector_size),
0, sizeof (indir),
(char *) indir))
return 0;
@@ -264,14 +281,14 @@
if (grub_disk_read (node->data->disk,
(grub_afs_run_to_num (sb, &ds->double_indirect)
+ idblk) *
- (sb->block_size >> GRUB_DISK_SECTOR_BITS),
+ (sb->block_size / node->data->disk->sector_size),
0, sizeof (indir),
(char *) indir))
return 0;
if (grub_disk_read (node->data->disk,
(grub_afs_run_to_num (sb, &indir[idptr]) + dblk) *
- (sb->block_size >> GRUB_DISK_SECTOR_BITS),
+ (sb->block_size / node->data->disk->sector_size),
0, sizeof (indir),
(char *) indir))
return 0;
@@ -293,7 +310,7 @@
U64 (&node->data->sblock,
node->inode.stream.size),
node->data->sblock.block_shift
- - GRUB_DISK_SECTOR_BITS);
+ - afs_log2 (node->data->disk->sector_size));
}
static int
Index: fs/ntfs.c
===================================================================
--- fs/ntfs.c (revision 1886)
+++ fs/ntfs.c (working copy)
@@ -42,10 +42,10 @@
return grub_error (GRUB_ERR_BAD_FS, "%s label not found", magic);
ss = u16at (buf, 6) - 1;
- if (ss * (int) data->blocksize != len * GRUB_DISK_SECTOR_SIZE)
+ if (ss * (int) data->blocksize != len * data->disk->sector_size)
return grub_error (GRUB_ERR_BAD_FS, "Size not match",
ss * (int) data->blocksize,
- len * GRUB_DISK_SECTOR_SIZE);
+ len * data->disk->sector_size);
pu = buf + u16at (buf, 4);
us = u16at (pu, 0);
buf -= 2;
@@ -178,8 +178,8 @@
{
int n;
- n = ((u32at (pa, 0x30) + GRUB_DISK_SECTOR_SIZE - 1)
- & (~(GRUB_DISK_SECTOR_SIZE - 1)));
+ n = ((u32at (pa, 0x30) + at->mft->data->disk->sector_size - 1)
+ & (~(at->mft->data->disk->sector_size - 1)));
at->attr_cur = at->attr_end;
at->edat_buf = grub_malloc (n);
if (!at->edat_buf)
Index: fs/fat.c
===================================================================
--- fs/fat.c (revision 1886)
+++ fs/fat.c (working copy)
@@ -188,11 +188,12 @@
goto fail;
/* Get the sizes of logical sectors and clusters. */
- data->logical_sector_bits =
- fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector));
- if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS)
- goto fail;
- data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS;
+// data->logical_sector_bits =
+// fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector));
+// if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS)
+// goto fail;
+// data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS;
+ data->logical_sector_bits = fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector / disk->sector_size) );
data->cluster_bits = fat_log2 (bpb.sectors_per_cluster);
if (data->cluster_bits < 0)
@@ -226,10 +227,10 @@
data->root_sector = data->fat_sector + bpb.num_fats * data->sectors_per_fat;
data->num_root_sectors
- = ((((grub_uint32_t) grub_le_to_cpu16 (bpb.num_root_entries)
+ = (((((grub_uint32_t) grub_le_to_cpu16 (bpb.num_root_entries)
* GRUB_FAT_DIR_ENTRY_SIZE
+ grub_le_to_cpu16 (bpb.bytes_per_sector) - 1)
- >> (data->logical_sector_bits + GRUB_DISK_SECTOR_BITS))
+ >> (data->logical_sector_bits)) / disk->sector_size )
<< (data->logical_sector_bits));
data->cluster_sector = data->root_sector + data->num_root_sectors;
@@ -353,7 +354,7 @@
in clusters. */
if (data->file_cluster == ~0U)
{
- size = (data->num_root_sectors << GRUB_DISK_SECTOR_BITS) - offset;
+ size = (data->num_root_sectors * disk->sector_size) - offset;
if (size > len)
size = len;
@@ -366,7 +367,7 @@
/* Calculate the logical cluster number and offset. */
logical_cluster_bits = (data->cluster_bits
+ data->logical_sector_bits
- + GRUB_DISK_SECTOR_BITS);
+ + fat_log2 (disk->sector_size));
logical_cluster = offset >> logical_cluster_bits;
offset &= (1 << logical_cluster_bits) - 1;
Index: fs/iso9660.c
===================================================================
--- fs/iso9660.c (revision 1886)
+++ fs/iso9660.c (working copy)
@@ -550,8 +550,8 @@
{
if (grub_disk_read (dir->data->disk,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
- + offset / GRUB_DISK_SECTOR_SIZE,
- offset % GRUB_DISK_SECTOR_SIZE,
+ + offset / dir->data->disk->sector_size,
+ offset % dir->data->disk->sector_size,
sizeof (dirent), (char *) &dirent))
return 0;
@@ -580,16 +580,16 @@
&& grub_iso9660_susp_iterate (dir->data,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
+ (sua_off
- / GRUB_DISK_SECTOR_SIZE),
- sua_off % GRUB_DISK_SECTOR_SIZE,
+ / dir->data->disk->sector_size),
+ sua_off % dir->data->disk->sector_size,
sua_size, susp_iterate_dir))
return 0;
/* Read the name. */
if (grub_disk_read (dir->data->disk,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
- + nameoffset / GRUB_DISK_SECTOR_SIZE,
- nameoffset % GRUB_DISK_SECTOR_SIZE,
+ + nameoffset / dir->data->disk->sector_size,
+ nameoffset % dir->data->disk->sector_size,
dirent.namelen, (char *) name))
return 0;
@@ -602,8 +602,8 @@
node->size = grub_le_to_cpu32 (dirent.size);
node->blk = grub_le_to_cpu32 (dirent.first_sector);
node->dir_blk = ((dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
- + offset / GRUB_DISK_SECTOR_SIZE);
- node->dir_off = offset % GRUB_DISK_SECTOR_SIZE;
+ + offset / dir->data->disk->sector_size);
+ node->dir_off = offset % dir->data->disk->sector_size;
/* If the filetype was not stored using rockridge, use
whatever is stored in the iso9660 filesystem. */
Index: fs/affs.c
===================================================================
--- fs/affs.c (revision 1886)
+++ fs/affs.c (working copy)
@@ -124,7 +124,7 @@
for (links = grub_divmod64 (fileblock, data->htsize, &mod); links; links--)
{
grub_disk_read (data->disk, block + data->blocksize - 1,
- data->blocksize * (GRUB_DISK_SECTOR_SIZE
+ data->blocksize * (data->disk->sector_size
- GRUB_AFFS_FILE_LOCATION),
sizeof (file), (char *) &file);
if (grub_errno)
@@ -203,7 +203,7 @@
/* No sane person uses more than 8KB for a block. At least I hope
for that person because in that case this won't work. */
- rootblock = grub_malloc (GRUB_DISK_SECTOR_SIZE * 16);
+ rootblock = grub_malloc (disk->sector_size * 16);
if (!rootblock)
goto fail;
@@ -211,7 +211,7 @@
/* Read the rootblock. */
grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0,
- GRUB_DISK_SECTOR_SIZE * 16, (char *) rootblock);
+ disk->sector_size * 16, (char *) rootblock);
if (grub_errno)
goto fail;
@@ -222,10 +222,10 @@
rblock->checksum = 0;
for (blocksize = 0; blocksize < 8; blocksize++)
{
- grub_uint32_t *currblock = rootblock + GRUB_DISK_SECTOR_SIZE * blocksize;
+ grub_uint32_t *currblock = rootblock + disk->sector_size * blocksize;
unsigned int i;
- for (i = 0; i < GRUB_DISK_SECTOR_SIZE / sizeof (*currblock); i++)
+ for (i = 0; i < disk->sector_size / sizeof (*currblock); i++)
checksum += grub_be_to_cpu32 (currblock[i]);
if (checksumr == -checksum)
@@ -350,7 +350,7 @@
while (next)
{
grub_disk_read (data->disk, next + data->blocksize - 1,
- data->blocksize * GRUB_DISK_SECTOR_SIZE
+ data->blocksize * data->disk->sector_size
- GRUB_AFFS_FILE_LOCATION,
sizeof (file), (char *) &file);
if (grub_errno)
@@ -524,7 +524,7 @@
/* The rootblock maps quite well on a file header block, it's
something we can use here. */
grub_disk_read (data->disk, disk->total_sectors >> 1,
- data->blocksize * (GRUB_DISK_SECTOR_SIZE
+ data->blocksize * (data->disk->sector_size
- GRUB_AFFS_FILE_LOCATION),
sizeof (file), (char *) &file);
if (grub_errno)
Index: fs/fshelp.c
===================================================================
--- fs/fshelp.c (revision 1886)
+++ fs/fshelp.c (working copy)
@@ -233,15 +233,15 @@
grub_off_t filesize, int log2blocksize)
{
grub_disk_addr_t i, blockcnt;
- int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS);
+ int blocksize = (1 << log2blocksize) * disk->sector_size;
/* Adjust LEN so it we can't read past the end of the file. */
if (pos + len > filesize)
len = filesize - pos;
- blockcnt = ((len + pos) + blocksize - 1) >> (log2blocksize + GRUB_DISK_SECTOR_BITS);
+ blockcnt = (((len + pos) + blocksize - 1) >> log2blocksize) / disk->sector_size;
- for (i = pos >> (log2blocksize + GRUB_DISK_SECTOR_BITS); i < blockcnt; i++)
+ for (i = (pos >> log2blocksize) / disk->sector_size; i < blockcnt; i++)
{
grub_disk_addr_t blknr;
int blockoff = pos & (blocksize - 1);
@@ -266,7 +266,7 @@
}
/* First block. */
- if (i == (pos >> (log2blocksize + GRUB_DISK_SECTOR_BITS)))
+ if (i == ((pos >> log2blocksize) / disk->sector_size))
{
skipfirst = blockoff;
blockend -= skipfirst;
Index: fs/reiserfs.c
===================================================================
--- fs/reiserfs.c (revision 1886)
+++ fs/reiserfs.c (working copy)
@@ -509,9 +509,9 @@
do
{
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
(((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
block_size, (char *) block_header);
if (grub_errno)
goto fail;
@@ -659,7 +659,7 @@
block_size = grub_le_to_cpu16 (node->data->superblock.block_size);
len = grub_le_to_cpu16 (found.header.item_size);
- block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS);
+ block = found.block_number * (block_size / node->data->disk->sector_size);
offset = grub_le_to_cpu16 (found.header.item_location);
symlink_buffer = grub_malloc (len + 1);
@@ -686,7 +686,7 @@
data = grub_malloc (sizeof (*data));
if (! data)
goto fail;
- grub_disk_read (disk, REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE,
+ grub_disk_read (disk, REISERFS_SUPER_BLOCK_OFFSET / disk->sector_size,
0, sizeof (data->superblock), (char *) &(data->superblock));
if (grub_errno)
goto fail;
@@ -744,9 +744,9 @@
struct grub_reiserfs_item_header *item_headers;
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
(((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
block_size, (char *) block_header);
if (grub_errno)
goto fail;
@@ -838,7 +838,7 @@
{
struct grub_reiserfs_stat_item_v1 entry_v1_stat;
grub_disk_read (data->disk,
- entry_block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ entry_block_number * (block_size / data->disk->sector_size),
grub_le_to_cpu16 (entry_item->header.item_location),
sizeof (entry_v1_stat),
(char *) &entry_v1_stat);
@@ -880,7 +880,7 @@
{
struct grub_reiserfs_stat_item_v2 entry_v2_stat;
grub_disk_read (data->disk,
- entry_block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ entry_block_number * (block_size / data->disk->sector_size),
grub_le_to_cpu16 (entry_item->header.item_location),
sizeof (entry_v2_stat),
(char *) &entry_v2_stat);
@@ -1028,10 +1028,10 @@
{
struct grub_reiserfs_stat_item_v1 entry_v1_stat;
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
entry_location
+ (((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
sizeof (entry_v1_stat), (char *) &entry_v1_stat);
if (grub_errno)
goto fail;
@@ -1041,10 +1041,10 @@
{
struct grub_reiserfs_stat_item_v2 entry_v2_stat;
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
entry_location
+ (((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
sizeof (entry_v2_stat), (char *) &entry_v2_stat);
if (grub_errno)
goto fail;
@@ -1111,7 +1111,7 @@
switch (found.type)
{
case GRUB_REISERFS_DIRECT:
- block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS);
+ block = found.block_number * (block_size / data->disk->sector_size);
grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block);
if (initial_position < current_position + item_size)
{
@@ -1143,7 +1143,7 @@
if (! indirect_block_ptr)
goto fail;
grub_disk_read (found.data->disk,
- found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ found.block_number * (block_size / found.data->disk->sector_size),
grub_le_to_cpu16 (found.header.item_location),
item_size, (char *) indirect_block_ptr);
if (grub_errno)
@@ -1155,7 +1155,7 @@
indirect_block++)
{
block = grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) *
- (block_size >> GRUB_DISK_SECTOR_BITS);
+ (block_size / found.data->disk->sector_size);
grub_dprintf ("reiserfs_blocktype", "I: %u\n", (unsigned) block);
if (current_position + block_size >= initial_position)
{
@@ -1334,7 +1334,7 @@
if (*label)
{
grub_disk_read (device->disk,
- REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE,
+ REISERFS_SUPER_BLOCK_OFFSET / device->disk->sector_size,
REISERFS_LABEL_OFFSET, REISERFS_MAX_LABEL_LENGTH,
*label);
}
Index: fs/jfs.c
===================================================================
--- fs/jfs.c (revision 1886)
+++ fs/jfs.c (working copy)
@@ -277,8 +277,7 @@
if (grub_disk_read (data->disk,
grub_le_to_cpu32 (extents[found].extent.blk2)
- << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS), 0,
+ << (grub_le_to_cpu16 (data->sblock.log2_blksz)) * data->disk->sector_size, 0,
sizeof (tree), (char *) &tree))
return -1;
@@ -309,14 +308,14 @@
/* Read in the IAG. */
if (grub_disk_read (data->disk,
- iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS), 0,
+ iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)) * data->disk->sector_size, 0,
sizeof (struct grub_jfs_iag), (char *) &iag))
return grub_errno;
inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2);
- inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS);
+ inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz));
+ inoblk /= data->disk->sector_size;
+
inoblk += inonum;
if (grub_disk_read (data->disk, inoblk, 0,
@@ -412,7 +411,8 @@
}
blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2);
- blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS);
+ blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz));
+ blk /= data->disk->sector_size;
/* Read in the nodes until we are on the leaf node level. */
do
@@ -430,8 +430,7 @@
de = (struct grub_jfs_internal_dirent *) diro->dirpage->dirent;
index = diro->dirpage->sorted[diro->dirpage->header.sindex * 32];
blk = (grub_le_to_cpu32 (de[index].ex.blk2)
- << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS));
+ << (grub_le_to_cpu16 (data->sblock.log2_blksz)) * data->disk->sector_size);
} while (!(diro->dirpage->header.flags & GRUB_JFS_TREE_LEAF));
diro->leaf = diro->dirpage->dirent;
@@ -485,8 +484,8 @@
return GRUB_ERR_OUT_OF_RANGE;
next = grub_le_to_cpu64 (diro->dirpage->header.nextb);
- next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS);
+ next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz));
+ next /= diro->data->disk->sector_size;
if (grub_disk_read (diro->data->disk, next, 0,
grub_le_to_cpu32 (diro->data->sblock.blksz),
@@ -583,8 +582,7 @@
data->disk->read_hook = read_hook;
grub_disk_read (data->disk,
- blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS),
+ blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz)) * data->disk->sector_size,
skipfirst, blockend, buf);
data->disk->read_hook = 0;
Index: fs/minix.c
===================================================================
--- fs/minix.c (revision 1886)
+++ fs/minix.c (working copy)
@@ -263,8 +263,8 @@
if (data->version == 1)
{
- block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode));
- int offs = (ino % (GRUB_DISK_SECTOR_SIZE
+ block += ino / (data->disk->sector_size / sizeof (struct grub_minix_inode));
+ int offs = (ino % (data->disk->sector_size
/ sizeof (struct grub_minix_inode))
* sizeof (struct grub_minix_inode));
@@ -273,10 +273,10 @@
}
else
{
- block += ino / (GRUB_DISK_SECTOR_SIZE
+ block += ino / (data->disk->sector_size
/ sizeof (struct grub_minix2_inode));
int offs = (ino
- % (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix2_inode))
+ % (data->disk->sector_size / sizeof (struct grub_minix2_inode))
* sizeof (struct grub_minix2_inode));
grub_disk_read (data->disk, block, offs,
Index: fs/hfsplus.c
===================================================================
--- fs/hfsplus.c (revision 1886)
+++ fs/hfsplus.c (working copy)
@@ -225,6 +225,23 @@
#endif
\f
+static int
+hfsplus_log2 (unsigned x)
+{
+ int i;
+
+ if (x == 0)
+ return -1;
+
+ for (i = 0; (x & 1) == 0; i++)
+ x >>= 1;
+
+ if (x != 1)
+ return -1;
+
+ return i;
+}
+
/* Return the offset of the record with the index INDEX, in the node
NODE which is part of the B+ tree BTREE. */
static inline unsigned int
@@ -310,7 +327,7 @@
if (blk != -1)
return (blk
+ (node->data->embedded_offset >> (node->data->log2blksize
- - GRUB_DISK_SECTOR_BITS)));
+ - hfsplus_log2 (node->data->disk->sector_size))));
/* For the extent overflow file, extra extents can't be found in
the extent overflow file. If this happens, you found a
@@ -363,7 +380,7 @@
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_hfsplus_read_block,
node->size,
- node->data->log2blksize - GRUB_DISK_SECTOR_BITS);
+ node->data->log2blksize - hfsplus_log2 (node->data->disk->sector_size));
}
static struct grub_hfsplus_data *
@@ -409,7 +426,7 @@
ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
data->embedded_offset = (ablk_start
+ extent_start
- * (ablk_size >> GRUB_DISK_SECTOR_BITS));
+ * (ablk_size / data->disk->sector_size));
grub_disk_read (disk, data->embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
sizeof (volheader), (char *) &volheader);
Index: fs/cpio.c
===================================================================
--- fs/cpio.c (revision 1886)
+++ fs/cpio.c (working copy)
@@ -145,9 +145,9 @@
return grub_errno;
data->size = grub_strtoul (hd.size, NULL, 8);
- data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE;
- *ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) &
- ~(GRUB_DISK_SECTOR_SIZE - 1));
+ data->dofs = data->hofs + data->disk->sector_size;
+ *ofs = data->dofs + ((data->size + data->disk->sector_size - 1) &
+ ~(data->disk->sector_size - 1));
}
return GRUB_ERR_NONE;
}
Index: include/grub/ntfs.h
===================================================================
--- include/grub/ntfs.h (revision 1886)
+++ include/grub/ntfs.h (working copy)
@@ -67,7 +67,8 @@
#define FLAG_ENCRYPTED 0x4000
#define FLAG_SPARSE 0x8000
-#define BLK_SHR GRUB_DISK_SECTOR_BITS
+// TODO: This is quite bad, was GRUB_DISK_SECTOR_BITS (whch in turn was 9 for 512 Byte/Sector disks)
+#define BLK_SHR 9
#define MAX_MFT (1024 >> BLK_SHR)
#define MAX_IDX (16384 >> BLK_SHR)
Index: include/grub/disk.h
===================================================================
--- include/grub/disk.h (revision 1886)
+++ include/grub/disk.h (working copy)
@@ -94,6 +94,9 @@
/* The underlying disk device. */
grub_disk_dev_t dev;
+ /* The size of each sector. */
+ grub_uint32_t sector_size;
+
/* The total number of sectors. */
grub_uint64_t total_sectors;
@@ -126,8 +129,8 @@
#endif
/* The sector size. */
-#define GRUB_DISK_SECTOR_SIZE 0x200
-#define GRUB_DISK_SECTOR_BITS 9
+#define GRUB_DISK_SECTOR_SIZE (disk->sector_size)
+// #define GRUB_DISK_SECTOR_BITS 9
/* The maximum number of disk caches. */
#define GRUB_DISK_CACHE_NUM 1021
Index: commands/cat.c
===================================================================
--- commands/cat.c (revision 1886)
+++ commands/cat.c (working copy)
@@ -31,8 +31,9 @@
int argc, char **args)
{
+#define GRUB_CMD_CAT_CHUNK_SIZE 512
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char buf[GRUB_CMD_CAT_CHUNK_SIZE];
grub_ssize_t size;
int key = 0;
Index: commands/blocklist.c
===================================================================
--- commands/blocklist.c (revision 1886)
+++ commands/blocklist.c (working copy)
@@ -31,7 +31,7 @@
int argc, char **args)
{
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char *buf;
unsigned long start_sector = 0;
unsigned num_sectors = 0;
int num_entries = 0;
@@ -47,7 +47,7 @@
if (num_sectors > 0)
{
if (start_sector + num_sectors == sector
- && offset == 0 && length == GRUB_DISK_SECTOR_SIZE)
+ && offset == 0 && length == file->device->disk->sector_size)
{
num_sectors++;
return;
@@ -57,7 +57,7 @@
num_sectors = 0;
}
- if (offset == 0 && length == GRUB_DISK_SECTOR_SIZE)
+ if (offset == 0 && length == file->device->disk->sector_size)
{
start_sector = sector;
num_sectors++;
@@ -90,6 +90,8 @@
return grub_error (GRUB_ERR_BAD_DEVICE,
"this command is available only for disk devices.");
+ buf = grub_malloc (file->device->disk->sector_size);
+
if (file->device->disk->partition)
part_start = grub_partition_get_start (file->device->disk->partition);
@@ -103,6 +105,7 @@
grub_file_close (file);
+ grub_free (buf);
return grub_errno;
}
Index: loader/i386/pc/linux.c
===================================================================
--- loader/i386/pc/linux.c (revision 1886)
+++ loader/i386/pc/linux.c (working copy)
@@ -143,8 +143,8 @@
if (! setup_sects)
setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS;
- real_size = setup_sects << GRUB_DISK_SECTOR_BITS;
- prot_size = grub_file_size (file) - real_size - GRUB_DISK_SECTOR_SIZE;
+ real_size = setup_sects * file->device->disk->sector_size;
+ prot_size = grub_file_size (file) - real_size - file->device->disk->sector_size;
grub_linux_tmp_addr = (char *) GRUB_LINUX_BZIMAGE_ADDR + prot_size;
@@ -229,7 +229,7 @@
/* Put the real mode code at the temporary address. */
grub_memmove (grub_linux_tmp_addr, &lh, sizeof (lh));
- len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
+ len = real_size + file->device->disk->sector_size - sizeof (lh);
if (grub_file_read (file, grub_linux_tmp_addr + sizeof (lh), len) != len)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
@@ -240,10 +240,10 @@
|| grub_le_to_cpu16 (lh.version) < 0x0200)
/* Clear the heap space. */
grub_memset (grub_linux_tmp_addr
- + ((setup_sects + 1) << GRUB_DISK_SECTOR_BITS),
+ + ((setup_sects + 1) * file->device->disk->sector_size),
0,
((GRUB_LINUX_MAX_SETUP_SECTS - setup_sects - 1)
- << GRUB_DISK_SECTOR_BITS));
+ * file->device->disk->sector_size));
/* Specify the boot file. */
dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
Index: loader/i386/pc/chainloader.c
===================================================================
--- loader/i386/pc/chainloader.c (revision 1886)
+++ loader/i386/pc/chainloader.c (working copy)
@@ -63,32 +63,9 @@
grub_dl_ref (my_mod);
- file = grub_file_open (filename);
- if (! file)
- goto fail;
- /* Read the first block. */
- if (grub_file_read (file, (char *) 0x7C00, GRUB_DISK_SECTOR_SIZE)
- != GRUB_DISK_SECTOR_SIZE)
- {
- if (grub_errno == GRUB_ERR_NONE)
- grub_error (GRUB_ERR_BAD_OS, "too small");
-
- goto fail;
- }
-
- /* Check the signature. */
- signature = *((grub_uint16_t *) (0x7C00 + GRUB_DISK_SECTOR_SIZE - 2));
- if (signature != grub_le_to_cpu16 (0xaa55)
- && ! (flags & GRUB_CHAINLOADER_FORCE))
- {
- grub_error (GRUB_ERR_BAD_OS, "invalid signature");
- goto fail;
- }
-
- grub_file_close (file);
-
- /* Obtain the partition table from the root device. */
+ /* Obtain the partition table from the root device. we have to open the
+ device in order to get the sector size */
dev = grub_device_open (0);
if (dev)
{
@@ -96,6 +73,35 @@
if (disk)
{
+ file = grub_file_open (filename);
+ if (! file)
+ {
+ goto fail;
+ grub_device_close (dev);
+ }
+
+ /* Read the first block. */
+ if (grub_file_read (file, (char *) 0x7C00, disk->sector_size)
+ != disk->sector_size)
+ {
+ if (grub_errno == GRUB_ERR_NONE)
+ grub_error (GRUB_ERR_BAD_OS, "too small");
+ grub_device_close (dev);
+ goto fail;
+ }
+
+ /* Check the signature. */
+ signature = *((grub_uint16_t *) (0x7C00 + disk->sector_size - 2));
+ if (signature != grub_le_to_cpu16 (0xaa55)
+ && ! (flags & GRUB_CHAINLOADER_FORCE))
+ {
+ grub_error (GRUB_ERR_BAD_OS, "invalid signature");
+ grub_device_close (dev);
+ goto fail;
+ }
+
+ grub_file_close (file);
+
grub_partition_t p = disk->partition;
/* In i386-pc, the id is equal to the BIOS drive number. */
Index: util/grub-probe.c
===================================================================
--- util/grub-probe.c (revision 1886)
+++ util/grub-probe.c (working copy)
@@ -112,18 +112,26 @@
int abstraction_type;
grub_device_t dev = NULL;
grub_fs_t fs;
+
+ grub_util_info ("starting probe...");
if (path == NULL)
{
if (! grub_util_check_block_device (device_name))
+ grub_util_info ("2");
grub_util_error ("%s is not a block device.\n", device_name);
}
- else
+ else {
+ grub_util_info ("3");
device_name = grub_guess_root_device (path);
+ }
+ grub_util_info ("1");
if (! device_name)
grub_util_error ("cannot find a device for %s.\n", path);
+ grub_util_info ("2");
+
if (print == PRINT_DEVICE)
{
printf ("%s\n", device_name);
@@ -165,7 +173,7 @@
grub_util_info ("opening %s", drive_name);
dev = grub_device_open (drive_name);
if (! dev)
- grub_util_error ("%s", grub_errmsg);
+ grub_util_error ("grub_device_open failed: %s", grub_errmsg);
if (print == PRINT_PARTMAP)
{
@@ -358,22 +366,32 @@
}
argument = argv[optind];
+
+ grub_util_info ("arguments parsed.");
/* Initialize the emulated biosdisk driver. */
grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
+
+ grub_util_info ("biosdisk initialized");
/* Initialize all modules. */
grub_init_all ();
+ grub_util_info ("all modules initialized");
+
/* Do it. */
if (argument_is_device)
probe (NULL, argument);
else
probe (argument, NULL);
+
+ grub_util_info ("probe executed");
/* Free resources. */
grub_fini_all ();
grub_util_biosdisk_fini ();
+
+ grub_util_info ("all modules deinitialized");
free (dev_map);
Index: util/i386/pc/grub-mkimage.c
===================================================================
--- util/i386/pc/grub-mkimage.c (revision 1886)
+++ util/i386/pc/grub-mkimage.c (working copy)
@@ -129,7 +129,7 @@
#endif
static void
-generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *memdisk_path)
+generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *memdisk_path, grub_uint32_t target_sector_size)
{
grub_addr_t module_addr = 0;
char *kernel_img, *boot_img, *core_img;
@@ -208,19 +208,19 @@
grub_util_info ("the core size is 0x%x", core_size);
- num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
+ num = ((core_size + target_sector_size - 1) / target_sector_size);
if (num > 0xffff)
grub_util_error ("the core image is too big");
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
- if (boot_size != GRUB_DISK_SECTOR_SIZE)
+ if (boot_size != target_sector_size)
grub_util_error ("diskboot.img is not one sector size");
boot_img = grub_util_read_image (boot_path);
/* i386 is a little endian architecture. */
- *((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
+ *((grub_uint16_t *) (boot_img + target_sector_size
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_cpu_to_le16 (num);
@@ -229,7 +229,7 @@
free (boot_path);
module_addr = (path_list
- ? (GRUB_BOOT_MACHINE_KERNEL_ADDR + GRUB_DISK_SECTOR_SIZE
+ ? (GRUB_BOOT_MACHINE_KERNEL_ADDR + target_sector_size
+ kernel_size)
: 0);
@@ -280,6 +280,7 @@
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
+ {"sector-size", required_argument, 0, 's'},
{0, 0, 0, 0}
};
@@ -301,6 +302,7 @@
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
+ -s, --sector-size=NR set sector size to NR bytes\n\
\n\
Report bugs to <%s>.\n\
", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
@@ -316,6 +318,7 @@
char *prefix = NULL;
char *memdisk = NULL;
FILE *fp = stdout;
+ grub_uint32_t target_sector_size = 0;
progname = "grub-mkimage";
@@ -372,6 +375,10 @@
case 'v':
verbosity++;
break;
+
+ case 's':
+ target_sector_size = atoi (optarg);
+ break;
default:
usage (1);
@@ -386,8 +393,15 @@
grub_util_error ("cannot open %s", output);
}
- generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind, memdisk);
+ if (target_sector_size == 0)
+ {
+ printf ("invalid sector size given!");
+ usage (1);
+ }
+
+ generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind, memdisk, target_sector_size);
+
fclose (fp);
if (dir)
Index: util/i386/pc/grub-setup.c
===================================================================
--- util/i386/pc/grub-setup.c (revision 1886)
+++ util/i386/pc/grub-setup.c (working copy)
@@ -105,9 +105,8 @@
char *tmp_img;
int i;
grub_disk_addr_t first_sector;
- grub_uint16_t current_segment
- = GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
- grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
+ grub_uint16_t current_segment;
+ grub_uint16_t last_length = 0;
grub_file_t file;
FILE *fp;
struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
@@ -160,7 +159,7 @@
grub_util_info ("the first sector is <%llu,%u,%u>",
sector, offset, length);
- if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
+ if (offset != 0 || length != dest_dev->disk->sector_size)
grub_util_error ("The first sector of the core file is not sector-aligned");
first_sector = sector;
@@ -174,7 +173,7 @@
grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x",
sector, offset, length, (unsigned) current_segment);
- if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
+ if (offset != 0 || last_length != dest_dev->disk->sector_size)
grub_util_error ("Non-sector-aligned data is found in the core file");
if (block != first_block
@@ -193,15 +192,25 @@
}
last_length = length;
- current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
+ current_segment += dest_dev->disk->sector_size >> 4;
}
-
+
+ /* Open the destination device and read sector size (automagically done by grub_device_open)*/
+ dest_dev = grub_device_open (dest);
+ if (! dest_dev)
+ grub_util_error ("%s", grub_errmsg);
+
+ /* initialize sector-size dependant variables */
+ last_length = dest_dev->disk->sector_size;
+ current_segment = GRUB_BOOT_MACHINE_KERNEL_SEG + (dest_dev->disk->sector_size >> 4);
+
/* Read the boot image by the OS service. */
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
- if (boot_size != GRUB_DISK_SECTOR_SIZE)
- grub_util_error ("The size of `%s' is not %d",
- boot_path, GRUB_DISK_SECTOR_SIZE);
+ if (boot_size != dest_dev->disk->sector_size)
+ grub_util_error ("The size of `%s' is not %d, you should adapt the image sector size to the\
+ sector size of the target block device.",
+ boot_path, dest_dev->disk->sector_size);
boot_img = grub_util_read_image (boot_path);
free (boot_path);
@@ -215,23 +224,23 @@
core_path = grub_util_get_path (dir, core_file);
core_size = grub_util_get_image_size (core_path);
- core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS);
- if (core_size < GRUB_DISK_SECTOR_SIZE)
+ core_sectors = ((core_size + dest_dev->disk->sector_size - 1)
+ / dest_dev->disk->sector_size);
+ if (core_size < dest_dev->disk->sector_size)
grub_util_error ("The size of `%s' is too small", core_path);
- else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
+ else if (core_size > 0xFFFF * dest_dev->disk->sector_size)
grub_util_error ("The size of `%s' is too large", core_path);
core_img = grub_util_read_image (core_path);
/* Have FIRST_BLOCK to point to the first blocklist. */
first_block = (struct boot_blocklist *) (core_img
- + GRUB_DISK_SECTOR_SIZE
+ + dest_dev->disk->sector_size
- sizeof (*block));
- install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ install_dos_part = (grub_int32_t *) (core_img + dest_dev->disk->sector_size
+ GRUB_KERNEL_MACHINE_INSTALL_DOS_PART);
- install_bsd_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ install_bsd_part = (grub_int32_t *) (core_img + dest_dev->disk->sector_size
+ GRUB_KERNEL_MACHINE_INSTALL_BSD_PART);
/* Open the root device and the destination device. */
@@ -239,17 +248,13 @@
if (! root_dev)
grub_util_error ("%s", grub_errmsg);
- dest_dev = grub_device_open (dest);
- if (! dest_dev)
- grub_util_error ("%s", grub_errmsg);
-
grub_util_info ("setting the root device to `%s'", root);
if (grub_env_set ("root", root) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
/* Read the original sector from the disk. */
- tmp_img = xmalloc (GRUB_DISK_SECTOR_SIZE);
- if (grub_disk_read (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
+ tmp_img = xmalloc (dest_dev->disk->sector_size);
+ if (grub_disk_read (dest_dev->disk, 0, 0, dest_dev->disk->sector_size, tmp_img))
grub_util_error ("%s", grub_errmsg);
/* Copy the possible DOS BPB. */
@@ -327,7 +332,7 @@
first_block->len = grub_cpu_to_le16 (core_sectors - 1);
first_block->segment
= grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG
- + (GRUB_DISK_SECTOR_SIZE >> 4));
+ + (dest_dev->disk->sector_size >> 4));
/* Make sure that the second blocklist is a terminator. */
block = first_block - 1;
@@ -346,7 +351,7 @@
*kernel_sector = grub_cpu_to_le64 (embed_region.start);
/* Write the boot image onto the disk. */
- if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
+ if (grub_disk_write (dest_dev->disk, 0, 0, dest_dev->disk->sector_size,
boot_img))
grub_util_error ("%s", grub_errmsg);
@@ -457,14 +462,14 @@
grub_util_error ("%s", grub_errmsg);
file->read_hook = save_first_sector;
- if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
- != GRUB_DISK_SECTOR_SIZE)
+ if (grub_file_read (file, tmp_img, dest_dev->disk->sector_size)
+ != dest_dev->disk->sector_size)
grub_util_error ("Failed to read the first sector of the core image");
block = first_block;
file->read_hook = save_blocklists;
- if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
- != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
+ if (grub_file_read (file, tmp_img, core_size - dest_dev->disk->sector_size)
+ != (grub_ssize_t) core_size - dest_dev->disk->sector_size)
grub_util_error ("Failed to read the rest sectors of the core image");
grub_file_close (file);
@@ -487,11 +492,11 @@
if (! fp)
grub_util_error ("Cannot open `%s'", core_path);
- grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
+ grub_util_write_image (core_img, dest_dev->disk->sector_size * 2, fp);
fclose (fp);
/* Write the boot image onto the disk. */
- if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, boot_img))
+ if (grub_disk_write (dest_dev->disk, 0, 0, dest_dev->disk->sector_size, boot_img))
grub_util_error ("%s", grub_errmsg);
finish:
Index: util/grub-mkdevicemap.c
===================================================================
--- util/grub-mkdevicemap.c (revision 1886)
+++ util/grub-mkdevicemap.c (working copy)
@@ -70,6 +70,9 @@
# ifndef BLKGETSIZE
# define BLKGETSIZE _IO(0x12,96) /* return device size */
# endif /* ! BLKGETSIZE */
+# ifndef BLKSSZGET
+# define BLKSSZGET _IO(0x12,104)/* get block device sector size */
+#endif
#endif /* __linux__ */
/* Use __FreeBSD_kernel__ instead of __FreeBSD__ for compatibility with
@@ -328,7 +331,7 @@
static int
check_device (const char *device)
{
- char buf[512];
+ char *buf;
FILE *fp;
/* If DEVICE is empty, just return error. */
@@ -393,12 +396,20 @@
#endif /* __FreeBSD_kernel__ || __NetBSD__ || __OpenBSD__ */
/* Attempt to read the first sector. */
- if (fread (buf, 1, 512, fp) != 512)
+ grub_uint32_t size;
+ if (ioctl (fileno (fp), BLKSSZGET, &size))
{
+ grub_util_info ("can not get sector size for %s, assuming 512Bytes (non fatal).", device);
+ size = 512;
+ }
+ buf = grub_malloc( size );
+ if (fread (buf, 1, size, fp) != size)
+ {
+ free (buf);
fclose (fp);
return 0;
}
-
+ free (buf);
fclose (fp);
return 1;
}
Index: util/hostdisk.c
===================================================================
--- util/hostdisk.c (revision 1886)
+++ util/hostdisk.c (working copy)
@@ -64,6 +64,9 @@
# ifndef BLKGETSIZE64
# define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size */
# endif /* ! BLKGETSIZE64 */
+# ifndef BLKSSZGET
+# define BLKSSZGET _IO(0x12,104)/* get block device sector size */
+#endif
# ifndef MAJOR
# ifndef MINORBITS
# define MINORBITS 8
@@ -170,10 +173,14 @@
size = grub_util_get_disk_size (map[drive].device);
- if (size % 512)
+// TODO: find correct sector size for mingw32
+ grub_util_info ("compiled with mingw32, assuming 512 byte sector size!");
+ disk->sector_size = 512;
+
+ if (size % disk->sector_size)
grub_util_error ("unaligned device size");
- disk->total_sectors = size >> 9;
+ disk->total_sectors = size / disk->sector_size;
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
@@ -194,6 +201,13 @@
goto fail;
}
+ if (ioctl (fd, BLKSSZGET, &nr))
+ {
+ close (fd);
+ goto fail;
+ }
+ disk->sector_size = nr;
+
if (ioctl (fd, BLKGETSIZE64, &nr))
{
close (fd);
@@ -201,12 +215,12 @@
}
close (fd);
- disk->total_sectors = nr / 512;
+ disk->total_sectors = nr / disk->sector_size;
- if (nr % 512)
+ if (nr % disk->sector_size)
grub_util_error ("unaligned device size");
- grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
+ grub_util_info ("the size of %s is %llu with sector size %iu", name, disk->total_sectors, disk->sector_size);
return GRUB_ERR_NONE;
}
@@ -215,15 +229,19 @@
/* In GNU/Hurd, stat() will return the right size. */
#elif !defined (__GNU__)
# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal."
+# warning "No routine for getting sector size is implemented, assuming 512 bytes."
+ disk->sector_size = 512;
#endif
- if (stat (map[drive].device, &st) < 0)
- return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
+ {
+ if (stat (map[drive].device, &st) < 0)
+ return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
- disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS;
+ disk->total_sectors = st.st_size / disk->sector_size;
- grub_util_info ("the size of %s is %lu", name, disk->total_sectors);
+ grub_util_info ("the size of %s is %lu with sector size %iu", name, disk->total_sectors, disk->sector_size);
- return GRUB_ERR_NONE;
+ return GRUB_ERR_NONE;
+ }
}
#ifdef __linux__
@@ -346,7 +364,7 @@
_syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo,
loff_t *, res, uint, wh);
- offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS;
+ offset = (loff_t) sector * disk->sector_size;
if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
{
grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id].device);
@@ -356,7 +374,7 @@
}
#else
{
- off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS;
+ off_t offset = (off_t) sector * disk->sector_size;
if (lseek (fd, offset, SEEK_SET) != offset)
{
@@ -422,6 +440,8 @@
return size;
}
+
+/* read size number of SECTORS which each in turn is of disk->sector_size bytes */
static grub_err_t
grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf)
@@ -432,27 +452,29 @@
if (fd < 0)
return grub_errno;
-#ifdef __linux__
- if (sector == 0 && size > 1)
- {
- /* Work around a bug in Linux ez remapping. Linux remaps all
- sectors that are read together with the MBR in one read. It
- should only remap the MBR, so we split the read in two
- parts. -jochen */
- if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE)
- {
- grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device);
- close (fd);
- return grub_errno;
- }
-
- buf += GRUB_DISK_SECTOR_SIZE;
- size--;
- }
-#endif /* __linux__ */
-
- if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS)
- != (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+//#ifdef __linux__
+// if (sector == 0 && size > 1)
+// {
+// /* Work around a bug in Linux ez remapping. Linux remaps all
+// sectors that are read together with the MBR in one read. It
+// should only remap the MBR, so we split the read in two
+// parts. -jochen */
+// if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE)
+// {
+// grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device);
+// close (fd);
+// return grub_errno;
+// }
+//
+// buf += GRUB_DISK_SECTOR_SIZE;
+// size--;
+// }
+//#endif /* __linux__ */
+// since we now read sectors only, we don'Ãt need no sepcial handling for MBRsize!=SectorSize
+// this _must_ be done by the caller now!
+
+ if (nread (fd, buf, size * disk->sector_size)
+ != (ssize_t) (size * disk->sector_size))
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device);
close (fd);
@@ -469,8 +491,8 @@
if (fd < 0)
return grub_errno;
- if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS)
- != (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+ if (nwrite (fd, buf, size * disk->sector_size)
+ != (ssize_t) (size * disk->sector_size))
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device);
close (fd);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Patch for different sector sizes
2008-10-07 22:30 Patch for different sector sizes Clemens Helfmeier
@ 2008-10-08 16:11 ` Clemens Helfmeier
0 siblings, 0 replies; 2+ messages in thread
From: Clemens Helfmeier @ 2008-10-08 16:11 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 1564 bytes --]
Hi everyone,
i have now finished most of the sector size modifications. Still, there are a
few things to be done: e.g. the file system drivers must be checked for correct
handling of places, etc. (ext2 is fixed with this patch, fat works here on a
2048 device without modification, a few others should still be done).
Most likely the ATA and SCSI drivers are also broken. Best would be to have
someone check on that who knows the hardware here.
Unfortunately i could not yet test the bootup procedure since my hardware does
not detect the pendrive which i have here correctly. maybe i will have a
different one with 2048bytes sector size another day. Perhaps there are
volunteers who want to test this patch?
IMPORTANT:
the grub-mkimage tool has got a new option (--sector-size=XX) which must be
given. Since this tool does not actually handle things with hard drives, it can
not detect the correct sector size on it's own. Any suggestions on how to fix
this? (maybe we can make it work with either sector-size or target-device
supplied on command line)
Bye,
Clemens (sum)
On Wed, Oct 08, 2008 at 12:30:57AM +0200, Clemens Helfmeier wrote:
> Hey Guys,
>
> this seems to be a tough topic ;-)
>
> At Least i have fixed a few lines of code today, it compiles not yet in total,
> but i hope the task can be completed in a few more hours of work. I guess a
few
> things will still be broken after completion, i didn't yet test anything.
>
> Maybe this is even too bad to be done? what do you think?
>
> Path Attached, please comment!
>
> bye,
> sumsum
[-- Attachment #2: variable_sector_size.patch --]
[-- Type: text/x-diff, Size: 78887 bytes --]
Index: disk/lvm.c
===================================================================
--- disk/lvm.c (revision 1886)
+++ disk/lvm.c (working copy)
@@ -185,7 +185,7 @@
read from. */
if (pv->disk)
err = grub_disk_read (pv->disk, offset, 0,
- size << GRUB_DISK_SECTOR_BITS, buf);
+ size * pv->disk->sector_size, buf);
else
err = grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"Physical volume %s not found", pv->name);
@@ -221,6 +221,7 @@
struct grub_lvm_vg *vg;
struct grub_lvm_pv *pv;
+
disk = grub_disk_open (name);
if (!disk)
return 0;
Index: disk/scsi.c
===================================================================
--- disk/scsi.c (revision 1886)
+++ disk/scsi.c (working copy)
@@ -294,7 +294,7 @@
/* SCSI blocks can be something else than 512, although GRUB
wants 512 byte blocks. */
disk->total_sectors = ((scsi->size * scsi->blocksize)
- << GRUB_DISK_SECTOR_BITS);
+ * disk->sector_size);
grub_dprintf ("scsi", "capacity=%llu, blksize=%d\n",
disk->total_sectors, scsi->blocksize);
@@ -325,7 +325,7 @@
/* SCSI sectors are variable in size. GRUB uses 512 byte
sectors. */
- sector = grub_divmod64 (sector, scsi->blocksize >> GRUB_DISK_SECTOR_BITS,
+ sector = grub_divmod64 (sector, grub_divmod64(scsi->blocksize, disk->sector_size, NULL),
NULL);
/* Depending on the type, select a read function. */
Index: disk/ata.c
===================================================================
--- disk/ata.c (revision 1886)
+++ disk/ata.c (working copy)
@@ -77,6 +77,9 @@
GRUB_ATA_CMD_EXEC_DEV_DIAGNOSTICS = 0x90
};
+// TODO: Put the sector size into grub_ata_device
+#define GRUB_ATA_SECTOR_SIZE 512
+
struct grub_ata_device
{
/* IDE port to use. */
@@ -323,7 +326,7 @@
grub_uint16_t *info16;
int ataerr = 0;
- info = grub_malloc (GRUB_DISK_SECTOR_SIZE);
+ info = grub_malloc (GRUB_ATA_SECTOR_SIZE);
if (! info)
return grub_errno;
@@ -343,7 +346,7 @@
}
grub_ata_wait ();
- if (grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE))
+ if (grub_ata_pio_read (dev, info, GRUB_ATA_SECTOR_SIZE))
ataerr = grub_ata_regget (dev, GRUB_ATA_REG_ERROR);
if (ataerr & 4)
{
@@ -681,9 +684,9 @@
for (sect = 0; sect < batch; sect++)
{
if (grub_ata_pio_read (dev, buf,
- GRUB_DISK_SECTOR_SIZE))
+ GRUB_ATA_SECTOR_SIZE))
return grub_errno;
- buf += GRUB_DISK_SECTOR_SIZE;
+ buf += GRUB_ATA_SECTOR_SIZE;
}
}
else
@@ -699,9 +702,9 @@
for (sect = 0; sect < batch; sect++)
{
if (grub_ata_pio_write (dev, buf,
- GRUB_DISK_SECTOR_SIZE))
+ GRUB_ATA_SECTOR_SIZE))
return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error");
- buf += GRUB_DISK_SECTOR_SIZE;
+ buf += GRUB_ATA_SECTOR_SIZE;
}
}
sector += batch;
@@ -723,9 +726,9 @@
for (sect = 0; sect < (size % batch); sect++)
{
- if (grub_ata_pio_read (dev, buf, GRUB_DISK_SECTOR_SIZE))
+ if (grub_ata_pio_read (dev, buf, GRUB_ATA_SECTOR_SIZE))
return grub_errno;
- buf += GRUB_DISK_SECTOR_SIZE;
+ buf += GRUB_ATA_SECTOR_SIZE;
}
} else {
/* Write sectors. */
@@ -738,9 +741,9 @@
for (sect = 0; sect < (size % batch); sect++)
{
- if (grub_ata_pio_write (dev, buf, GRUB_DISK_SECTOR_SIZE))
+ if (grub_ata_pio_write (dev, buf, GRUB_ATA_SECTOR_SIZE))
return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error");
- buf += GRUB_DISK_SECTOR_SIZE;
+ buf += GRUB_ATA_SECTOR_SIZE;
}
}
Index: disk/i386/pc/biosdisk.c
===================================================================
--- disk/i386/pc/biosdisk.c (revision 1886)
+++ disk/i386/pc/biosdisk.c (working copy)
@@ -196,8 +196,7 @@
struct grub_biosdisk_dap *dap;
dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR
- + (data->sectors
- << GRUB_DISK_SECTOR_BITS));
+ + (data->sectors) * disk->sector_size);
dap->length = sizeof (*dap);
dap->reserved = 0;
dap->blocks = size;
@@ -305,8 +304,8 @@
return grub_errno;
grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR,
- len << GRUB_DISK_SECTOR_BITS);
- buf += len << GRUB_DISK_SECTOR_BITS;
+ len * disk->sector_size);
+ buf += len * disk->sector_size;
sector += len;
size -= len;
}
@@ -329,13 +328,13 @@
len = size;
grub_memcpy ((void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, buf,
- len << GRUB_DISK_SECTOR_BITS);
+ len * disk->sector_size);
if (grub_biosdisk_rw (GRUB_BIOSDISK_WRITE, disk, sector, len,
GRUB_MEMORY_MACHINE_SCRATCH_SEG))
return grub_errno;
- buf += len << GRUB_DISK_SECTOR_BITS;
+ buf += len * disk->sector_size;
sector += len;
size -= len;
}
Index: disk/raid.c
===================================================================
--- disk/raid.c (revision 1886)
+++ disk/raid.c (working copy)
@@ -240,6 +240,9 @@
if (read_size > size)
read_size = size;
+ // sector size for array (must be equal for all drives, not checked)
+ unsigned int sector_size = 0;
+
for (i = 0; i < near; i++)
{
unsigned int k;
@@ -249,13 +252,14 @@
{
if (array->device[k])
{
+ sector_size = array->device[k]->sector_size;
if (grub_errno == GRUB_ERR_READ_ERROR)
grub_errno = GRUB_ERR_NONE;
err = grub_disk_read (array->device[k],
read_sector + j * far_ofs + b,
0,
- read_size << GRUB_DISK_SECTOR_BITS,
+ read_size * sector_size,
buf);
if (! err)
break;
@@ -285,7 +289,7 @@
if (err)
return err;
- buf += read_size << GRUB_DISK_SECTOR_BITS;
+ buf += read_size * sector_size;
size -= read_size;
if (! size)
break;
@@ -366,7 +370,7 @@
err = grub_disk_read (array->device[disknr],
read_sector + b, 0,
- read_size << GRUB_DISK_SECTOR_BITS,
+ read_size * array->device[disknr]->sector_size,
buf);
if ((err) && (err != GRUB_ERR_READ_ERROR))
@@ -405,7 +409,7 @@
break;
}
- buf += read_size << GRUB_DISK_SECTOR_BITS;
+ buf += read_size * array->device[disknr]->sector_size;
size -= read_size;
if (! size)
break;
Index: disk/raid5_recover.c
===================================================================
--- disk/raid5_recover.c (revision 1886)
+++ disk/raid5_recover.c (working copy)
@@ -31,7 +31,10 @@
char *buf2;
int i;
- size <<= GRUB_DISK_SECTOR_BITS;
+ if (array->device[0] == 0)
+ return grub_errno;
+
+ size *= array->device[0]->sector_size;
buf2 = grub_malloc (size);
if (!buf2)
return grub_errno;
Index: disk/memdisk.c
===================================================================
--- disk/memdisk.c (revision 1886)
+++ disk/memdisk.c (working copy)
@@ -25,6 +25,8 @@
#include <grub/types.h>
#include <grub/machine/kernel.h>
+#define GRUB_MEMDISK_SECTOR_SIZE 512
+
static char *memdisk_addr;
static grub_off_t memdisk_size = 0;
@@ -40,7 +42,9 @@
if (grub_strcmp (name, "memdisk"))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a memdisk");
- disk->total_sectors = memdisk_size / GRUB_DISK_SECTOR_SIZE;
+ // Memdisk may have any number of bytes/sectors, just choose something here.
+ disk->sector_size = GRUB_MEMDISK_SECTOR_SIZE;
+ disk->total_sectors = grub_divmod64(memdisk_size, disk->sector_size, 0);
disk->id = (unsigned long) "mdsk";
disk->has_partitions = 0;
@@ -56,7 +60,7 @@
grub_memdisk_read (grub_disk_t disk __attribute((unused)), grub_disk_addr_t sector,
grub_size_t size, char *buf)
{
- grub_memcpy (buf, memdisk_addr + (sector << GRUB_DISK_SECTOR_BITS), size << GRUB_DISK_SECTOR_BITS);
+ grub_memcpy (buf, memdisk_addr + (sector * disk->sector_size), size * disk->sector_size);
return 0;
}
@@ -64,7 +68,7 @@
grub_memdisk_write (grub_disk_t disk __attribute((unused)), grub_disk_addr_t sector,
grub_size_t size, const char *buf)
{
- grub_memcpy (memdisk_addr + (sector << GRUB_DISK_SECTOR_BITS), buf, size << GRUB_DISK_SECTOR_BITS);
+ grub_memcpy (memdisk_addr + (sector * disk->sector_size), buf, size * disk->sector_size);
return 0;
}
Index: disk/raid6_recover.c
===================================================================
--- disk/raid6_recover.c (revision 1886)
+++ disk/raid6_recover.c (working copy)
@@ -95,7 +95,10 @@
int err[2], nerr;
char *pbuf = 0, *qbuf = 0;
- size <<= GRUB_DISK_SECTOR_BITS;
+ if (array->device[0] == 0)
+ goto quit;
+
+ size *= array->device[0]->sector_size;
pbuf = grub_malloc (size);
if (!pbuf)
goto quit;
Index: disk/loopback.c
===================================================================
--- disk/loopback.c (revision 1886)
+++ disk/loopback.c (working copy)
@@ -25,6 +25,9 @@
#include <grub/disk.h>
#include <grub/mm.h>
+// any value is adequate. this affects the loopback disk
+#define GRUB_LOOPBACK_SECTOR_SIZE 512
+
struct grub_loopback
{
char *devname;
@@ -174,9 +177,11 @@
if (! file)
return grub_errno;
+ /* set size of sectors */
+ disk->sector_size = GRUB_LOOPBACK_SECTOR_SIZE;
/* Use the filesize for the disk size, round up to a complete sector. */
- disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1)
- / GRUB_DISK_SECTOR_SIZE);
+ disk->total_sectors = grub_divmod64((file->size + disk->sector_size - 1),
+ disk->sector_size, NULL);
disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions;
@@ -200,20 +205,20 @@
grub_file_t file = (grub_file_t) disk->data;
grub_off_t pos;
- grub_file_seek (file, sector << GRUB_DISK_SECTOR_BITS);
+ grub_file_seek (file, sector * disk->sector_size);
- grub_file_read (file, buf, size << GRUB_DISK_SECTOR_BITS);
+ grub_file_read (file, buf, size * disk->sector_size);
if (grub_errno)
return grub_errno;
/* In case there is more data read than there is available, in case
of files that are not a multiple of GRUB_DISK_SECTOR_SIZE, fill
the rest with zeros. */
- pos = (sector + size) << GRUB_DISK_SECTOR_BITS;
+ pos = (sector + size) * disk->sector_size;
if (pos > file->size)
{
grub_size_t amount = pos - file->size;
- grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);
+ grub_memset (buf + (size * disk->sector_size) - amount, 0, amount);
}
return 0;
Index: kern/fs.c
===================================================================
--- kern/fs.c (revision 1886)
+++ kern/fs.c (working copy)
@@ -198,7 +198,7 @@
goto fail;
}
- file->size += (blocks[i].length << GRUB_DISK_SECTOR_BITS);
+ file->size += (blocks[i].length * disk->sector_size);
p++;
}
@@ -219,12 +219,12 @@
grub_disk_addr_t sector;
grub_off_t offset;
grub_ssize_t ret = 0;
+ grub_disk_t disk = file->device->disk;
if (len > file->size - file->offset)
len = file->size - file->offset;
- sector = (file->offset >> GRUB_DISK_SECTOR_BITS);
- offset = (file->offset & (GRUB_DISK_SECTOR_SIZE - 1));
+ sector = grub_divmod64(file->offset, disk->sector_size, &offset);
for (p = file->data; p->length && len > 0; p++)
{
if (sector < p->length)
@@ -232,9 +232,9 @@
grub_size_t size;
size = len;
- if (((size + offset + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS) > p->length - sector)
- size = ((p->length - sector) << GRUB_DISK_SECTOR_BITS) - offset;
+ if ((grub_divmod64(size + offset + disk->sector_size - 1,
+ disk->sector_size, NULL) > p->length - sector))
+ size = ((p->length - sector) * disk->sector_size) - offset;
if (grub_disk_read (file->device->disk, p->offset + sector, offset,
size, buf) != GRUB_ERR_NONE)
@@ -242,8 +242,7 @@
ret += size;
len -= size;
- sector -= ((size + offset) >> GRUB_DISK_SECTOR_BITS);
- offset = ((size + offset) & (GRUB_DISK_SECTOR_SIZE - 1));
+ sector -= grub_divmod64((size + offset), disk->sector_size, &offset);
}
else
sector -= p->length;
Index: kern/rescue.c
===================================================================
--- kern/rescue.c (revision 1886)
+++ kern/rescue.c (working copy)
@@ -130,7 +130,7 @@
grub_rescue_cmd_cat (int argc, char *argv[])
{
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char buf[GRUB_RESCUE_BUF_SIZE];
grub_ssize_t size;
if (argc < 1)
Index: kern/disk.c
===================================================================
--- kern/disk.c (revision 1886)
+++ kern/disk.c (working copy)
@@ -148,25 +148,25 @@
}
static grub_err_t
-grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
+grub_disk_cache_store (unsigned long dev_id, grub_disk_t disk,
grub_disk_addr_t sector, const char *data)
{
unsigned index;
struct grub_disk_cache *cache;
- grub_disk_cache_invalidate (dev_id, disk_id, sector);
+ grub_disk_cache_invalidate (dev_id, disk->id, sector);
- index = grub_disk_cache_get_index (dev_id, disk_id, sector);
+ index = grub_disk_cache_get_index (dev_id, disk->id, sector);
cache = grub_disk_cache_table + index;
- cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ cache->data = grub_malloc ( disk->sector_size << GRUB_DISK_CACHE_BITS);
if (! cache->data)
return grub_errno;
grub_memcpy (cache->data, data,
- GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ disk->sector_size << GRUB_DISK_CACHE_BITS);
cache->dev_id = dev_id;
- cache->disk_id = disk_id;
+ cache->disk_id = disk->id;
cache->sector = sector;
return GRUB_ERR_NONE;
@@ -330,9 +330,8 @@
grub_disk_adjust_range (grub_disk_t disk, grub_disk_addr_t *sector,
grub_off_t *offset, grub_size_t size)
{
- *sector += *offset >> GRUB_DISK_SECTOR_BITS;
- *offset &= GRUB_DISK_SECTOR_SIZE - 1;
-
+ *sector += grub_divmod64(*offset, disk->sector_size, offset);
+
if (disk->partition)
{
grub_disk_addr_t start;
@@ -342,16 +341,16 @@
len = grub_partition_get_len (disk->partition);
if (*sector >= len
- || len - *sector < ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS))
+ || len - *sector < (grub_divmod64(*offset + size + disk->sector_size - 1,
+ disk->sector_size, NULL)))
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of partition");
*sector += start;
}
if (disk->total_sectors <= *sector
- || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS) > disk->total_sectors - *sector)
+ || (grub_divmod64(*offset + size + disk->sector_size - 1,
+ disk->sector_size, NULL) > disk->total_sectors - *sector))
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk");
return GRUB_ERR_NONE;
@@ -380,10 +379,11 @@
real_offset = offset;
/* Allocate a temporary buffer. */
- tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+ tmp_buf = grub_malloc (disk->sector_size << GRUB_DISK_CACHE_BITS);
if (! tmp_buf)
return grub_errno;
+
/* Until SIZE is zero... */
while (size)
{
@@ -394,8 +394,8 @@
/* For reading bulk data. */
start_sector = sector & ~(GRUB_DISK_CACHE_SIZE - 1);
- pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS;
- len = ((GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS)
+ pos = (sector - start_sector) * disk->sector_size;
+ len = ((disk->sector_size << GRUB_DISK_CACHE_BITS)
- pos - real_offset);
if (len > size)
len = size;
@@ -404,6 +404,7 @@
data = grub_disk_cache_fetch (disk->dev->id, disk->id, start_sector);
if (data)
{
+// grub_util_info ("disk cache hit, pos=%ul realofs=%ul, len=%ul", pos, real_offset, len);
/* Just copy it! */
grub_memcpy (buf, data + pos + real_offset, len);
grub_disk_cache_unlock (disk->dev->id, disk->id, start_sector);
@@ -421,10 +422,10 @@
grub_errno = GRUB_ERR_NONE;
- num = ((size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS);
+ num = grub_divmod64((size + disk->sector_size - 1),
+ disk->sector_size, NULL);
- p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS);
+ p = grub_realloc (tmp_buf, num * disk->sector_size);
if (!p)
goto finish;
@@ -445,11 +446,11 @@
while (size)
{
(disk->read_hook) (sector, real_offset,
- ((size > GRUB_DISK_SECTOR_SIZE)
- ? GRUB_DISK_SECTOR_SIZE
+ ((size > disk->sector_size)
+ ? disk->sector_size
: size));
sector++;
- size -= GRUB_DISK_SECTOR_SIZE - real_offset;
+ size -= disk->sector_size - real_offset;
real_offset = 0;
}
@@ -457,9 +458,11 @@
goto finish;
}
+// grub_util_info ("disk read ok, pos=%ul realofs=%ul, len=%ul", pos, real_offset, len);
+
/* Copy it and store it in the disk cache. */
grub_memcpy (buf, tmp_buf + pos + real_offset, len);
- grub_disk_cache_store (disk->dev->id, disk->id,
+ grub_disk_cache_store (disk->dev->id, disk,
start_sector, tmp_buf);
}
@@ -472,15 +475,15 @@
while (l)
{
(disk->read_hook) (s, real_offset,
- ((l > GRUB_DISK_SECTOR_SIZE)
- ? GRUB_DISK_SECTOR_SIZE
+ ((l > disk->sector_size)
+ ? disk->sector_size
: l));
- if (l < GRUB_DISK_SECTOR_SIZE - real_offset)
+ if (l < disk->sector_size - real_offset)
break;
s++;
- l -= GRUB_DISK_SECTOR_SIZE - real_offset;
+ l -= disk->sector_size - real_offset;
real_offset = 0;
}
}
@@ -513,16 +516,16 @@
while (size)
{
- if (real_offset != 0 || (size < GRUB_DISK_SECTOR_SIZE && size != 0))
+ if (real_offset != 0 || (size < disk->sector_size && size != 0))
{
- char tmp_buf[GRUB_DISK_SECTOR_SIZE];
+ char tmp_buf[disk->sector_size];
grub_size_t len;
- if (grub_disk_read (disk, sector, 0, GRUB_DISK_SECTOR_SIZE, tmp_buf)
+ if (grub_disk_read (disk, sector, 0, disk->sector_size, tmp_buf)
!= GRUB_ERR_NONE)
goto finish;
- len = GRUB_DISK_SECTOR_SIZE - real_offset;
+ len = disk->sector_size - real_offset;
if (len > size)
len = size;
@@ -543,8 +546,8 @@
grub_size_t len;
grub_size_t n;
- len = size & ~(GRUB_DISK_SECTOR_SIZE - 1);
- n = size >> GRUB_DISK_SECTOR_BITS;
+ len = size & ~(disk->sector_size - 1);
+ n = grub_divmod64 (size, disk->sector_size, NULL);
if ((disk->dev->write) (disk, sector, n, buf) != GRUB_ERR_NONE)
goto finish;
Index: fs/xfs.c
===================================================================
--- fs/xfs.c (revision 1886)
+++ fs/xfs.c (working copy)
@@ -188,6 +188,7 @@
#define GRUB_XFS_NEXT_DIRENT(pos,len) \
(pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2)
\f
+
static inline int
grub_xfs_inode_block (struct grub_xfs_data *data,
grub_uint64_t ino)
@@ -197,7 +198,7 @@
long long block;
block = (inoinag >> 4) + ag * data->agsize;
- block <<= (data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS);
+ block = grub_divmod64((block << data->sblock.log2_bsize), data->disk->sector_size, NULL);
return block;
}
@@ -266,9 +267,8 @@
}
if (grub_disk_read (node->data->disk,
- grub_be_to_cpu64 (keys[i - 1 + XFS_INODE_EXTENTS])
- << (node->data->sblock.log2_bsize
- - GRUB_DISK_SECTOR_BITS),
+ grub_divmod64( grub_be_to_cpu64 (keys[i - 1 + XFS_INODE_EXTENTS])
+ << (node->data->sblock.log2_bsize), node->data->disk->sector_size, NULL),
0, node->data->sblock.bsize, (char *) leaf))
return 0;
@@ -330,11 +330,11 @@
unsigned offset, unsigned length),
int pos, grub_size_t len, char *buf)
{
+// TODO: Check weather the last argument here is correct. maybe it is fixed size and not fixed sector count.
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_xfs_read_block,
grub_be_to_cpu64 (node->inode.size),
- node->data->sblock.log2_bsize
- - GRUB_DISK_SECTOR_BITS);
+ node->data->sblock.log2_bsize - fat_log2 (node->data->disk->sector_size));
}
Index: fs/afs.c
===================================================================
--- fs/afs.c (revision 1886)
+++ fs/afs.c (working copy)
@@ -179,6 +179,7 @@
static grub_dl_t my_mod;
#endif
+
static grub_afs_off_t
grub_afs_run_to_num (struct grub_afs_sblock *sb,
struct grub_afs_blockrun *run)
@@ -193,7 +194,7 @@
{
return grub_disk_read (data->disk,
ino *
- (data->sblock.block_size >> GRUB_DISK_SECTOR_BITS),
+ (data->sblock.block_size / data->disk->sector_size),
0, sizeof (struct grub_afs_inode),
(char *) inode);
}
@@ -228,7 +229,7 @@
int j;
if (grub_disk_read (node->data->disk,
- blk * (sb->block_size >> GRUB_DISK_SECTOR_BITS),
+ blk * (sb->block_size / node->data->disk->sector_size),
0, sizeof (indir),
(char *) indir))
return 0;
@@ -264,14 +265,14 @@
if (grub_disk_read (node->data->disk,
(grub_afs_run_to_num (sb, &ds->double_indirect)
+ idblk) *
- (sb->block_size >> GRUB_DISK_SECTOR_BITS),
+ (sb->block_size / node->data->disk->sector_size),
0, sizeof (indir),
(char *) indir))
return 0;
if (grub_disk_read (node->data->disk,
(grub_afs_run_to_num (sb, &indir[idptr]) + dblk) *
- (sb->block_size >> GRUB_DISK_SECTOR_BITS),
+ (sb->block_size / node->data->disk->sector_size),
0, sizeof (indir),
(char *) indir))
return 0;
@@ -288,12 +289,14 @@
unsigned offset, unsigned length),
int pos, grub_size_t len, char *buf)
{
+// TODO: get some nice way to calculate the log here. check if afs requires this value to
+// be sector oriented and not 512-byte oriented.
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_afs_read_block,
U64 (&node->data->sblock,
node->inode.stream.size),
node->data->sblock.block_shift
- - GRUB_DISK_SECTOR_BITS);
+ - fat_log2 (node->data->disk->sector_size));
}
static int
Index: fs/ntfs.c
===================================================================
--- fs/ntfs.c (revision 1886)
+++ fs/ntfs.c (working copy)
@@ -42,10 +42,10 @@
return grub_error (GRUB_ERR_BAD_FS, "%s label not found", magic);
ss = u16at (buf, 6) - 1;
- if (ss * (int) data->blocksize != len * GRUB_DISK_SECTOR_SIZE)
+ if (ss * (int) data->blocksize != len * data->disk->sector_size)
return grub_error (GRUB_ERR_BAD_FS, "Size not match",
ss * (int) data->blocksize,
- len * GRUB_DISK_SECTOR_SIZE);
+ len * data->disk->sector_size);
pu = buf + u16at (buf, 4);
us = u16at (pu, 0);
buf -= 2;
@@ -178,8 +178,8 @@
{
int n;
- n = ((u32at (pa, 0x30) + GRUB_DISK_SECTOR_SIZE - 1)
- & (~(GRUB_DISK_SECTOR_SIZE - 1)));
+ n = ((u32at (pa, 0x30) + at->mft->data->disk->sector_size - 1)
+ & (~(at->mft->data->disk->sector_size - 1)));
at->attr_cur = at->attr_end;
at->edat_buf = grub_malloc (n);
if (!at->edat_buf)
Index: fs/fat.c
===================================================================
--- fs/fat.c (revision 1886)
+++ fs/fat.c (working copy)
@@ -188,11 +188,7 @@
goto fail;
/* Get the sizes of logical sectors and clusters. */
- data->logical_sector_bits =
- fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector));
- if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS)
- goto fail;
- data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS;
+ data->logical_sector_bits = fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector / disk->sector_size) );
data->cluster_bits = fat_log2 (bpb.sectors_per_cluster);
if (data->cluster_bits < 0)
@@ -226,10 +222,10 @@
data->root_sector = data->fat_sector + bpb.num_fats * data->sectors_per_fat;
data->num_root_sectors
- = ((((grub_uint32_t) grub_le_to_cpu16 (bpb.num_root_entries)
+ = (((((grub_uint32_t) grub_le_to_cpu16 (bpb.num_root_entries)
* GRUB_FAT_DIR_ENTRY_SIZE
+ grub_le_to_cpu16 (bpb.bytes_per_sector) - 1)
- >> (data->logical_sector_bits + GRUB_DISK_SECTOR_BITS))
+ >> (data->logical_sector_bits)) / disk->sector_size )
<< (data->logical_sector_bits));
data->cluster_sector = data->root_sector + data->num_root_sectors;
@@ -353,7 +349,7 @@
in clusters. */
if (data->file_cluster == ~0U)
{
- size = (data->num_root_sectors << GRUB_DISK_SECTOR_BITS) - offset;
+ size = (data->num_root_sectors * disk->sector_size) - offset;
if (size > len)
size = len;
@@ -366,7 +362,7 @@
/* Calculate the logical cluster number and offset. */
logical_cluster_bits = (data->cluster_bits
+ data->logical_sector_bits
- + GRUB_DISK_SECTOR_BITS);
+ + fat_log2 (disk->sector_size));
logical_cluster = offset >> logical_cluster_bits;
offset &= (1 << logical_cluster_bits) - 1;
Index: fs/iso9660.c
===================================================================
--- fs/iso9660.c (revision 1886)
+++ fs/iso9660.c (working copy)
@@ -550,8 +550,8 @@
{
if (grub_disk_read (dir->data->disk,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
- + offset / GRUB_DISK_SECTOR_SIZE,
- offset % GRUB_DISK_SECTOR_SIZE,
+ + offset / dir->data->disk->sector_size,
+ offset % dir->data->disk->sector_size,
sizeof (dirent), (char *) &dirent))
return 0;
@@ -580,16 +580,16 @@
&& grub_iso9660_susp_iterate (dir->data,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
+ (sua_off
- / GRUB_DISK_SECTOR_SIZE),
- sua_off % GRUB_DISK_SECTOR_SIZE,
+ / dir->data->disk->sector_size),
+ sua_off % dir->data->disk->sector_size,
sua_size, susp_iterate_dir))
return 0;
/* Read the name. */
if (grub_disk_read (dir->data->disk,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
- + nameoffset / GRUB_DISK_SECTOR_SIZE,
- nameoffset % GRUB_DISK_SECTOR_SIZE,
+ + nameoffset / dir->data->disk->sector_size,
+ nameoffset % dir->data->disk->sector_size,
dirent.namelen, (char *) name))
return 0;
@@ -602,8 +602,8 @@
node->size = grub_le_to_cpu32 (dirent.size);
node->blk = grub_le_to_cpu32 (dirent.first_sector);
node->dir_blk = ((dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
- + offset / GRUB_DISK_SECTOR_SIZE);
- node->dir_off = offset % GRUB_DISK_SECTOR_SIZE;
+ + offset / dir->data->disk->sector_size);
+ node->dir_off = offset % dir->data->disk->sector_size;
/* If the filetype was not stored using rockridge, use
whatever is stored in the iso9660 filesystem. */
Index: fs/affs.c
===================================================================
--- fs/affs.c (revision 1886)
+++ fs/affs.c (working copy)
@@ -124,7 +124,7 @@
for (links = grub_divmod64 (fileblock, data->htsize, &mod); links; links--)
{
grub_disk_read (data->disk, block + data->blocksize - 1,
- data->blocksize * (GRUB_DISK_SECTOR_SIZE
+ data->blocksize * (data->disk->sector_size
- GRUB_AFFS_FILE_LOCATION),
sizeof (file), (char *) &file);
if (grub_errno)
@@ -203,7 +203,7 @@
/* No sane person uses more than 8KB for a block. At least I hope
for that person because in that case this won't work. */
- rootblock = grub_malloc (GRUB_DISK_SECTOR_SIZE * 16);
+ rootblock = grub_malloc (disk->sector_size * 16);
if (!rootblock)
goto fail;
@@ -211,7 +211,7 @@
/* Read the rootblock. */
grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0,
- GRUB_DISK_SECTOR_SIZE * 16, (char *) rootblock);
+ disk->sector_size * 16, (char *) rootblock);
if (grub_errno)
goto fail;
@@ -222,10 +222,10 @@
rblock->checksum = 0;
for (blocksize = 0; blocksize < 8; blocksize++)
{
- grub_uint32_t *currblock = rootblock + GRUB_DISK_SECTOR_SIZE * blocksize;
+ grub_uint32_t *currblock = rootblock + disk->sector_size * blocksize;
unsigned int i;
- for (i = 0; i < GRUB_DISK_SECTOR_SIZE / sizeof (*currblock); i++)
+ for (i = 0; i < disk->sector_size / sizeof (*currblock); i++)
checksum += grub_be_to_cpu32 (currblock[i]);
if (checksumr == -checksum)
@@ -350,7 +350,7 @@
while (next)
{
grub_disk_read (data->disk, next + data->blocksize - 1,
- data->blocksize * GRUB_DISK_SECTOR_SIZE
+ data->blocksize * data->disk->sector_size
- GRUB_AFFS_FILE_LOCATION,
sizeof (file), (char *) &file);
if (grub_errno)
@@ -524,7 +524,7 @@
/* The rootblock maps quite well on a file header block, it's
something we can use here. */
grub_disk_read (data->disk, disk->total_sectors >> 1,
- data->blocksize * (GRUB_DISK_SECTOR_SIZE
+ data->blocksize * (data->disk->sector_size
- GRUB_AFFS_FILE_LOCATION),
sizeof (file), (char *) &file);
if (grub_errno)
Index: fs/fshelp.c
===================================================================
--- fs/fshelp.c (revision 1886)
+++ fs/fshelp.c (working copy)
@@ -233,15 +233,15 @@
grub_off_t filesize, int log2blocksize)
{
grub_disk_addr_t i, blockcnt;
- int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS);
+ int blocksize = (1 << log2blocksize) * disk->sector_size;
/* Adjust LEN so it we can't read past the end of the file. */
if (pos + len > filesize)
len = filesize - pos;
- blockcnt = ((len + pos) + blocksize - 1) >> (log2blocksize + GRUB_DISK_SECTOR_BITS);
+ blockcnt = grub_divmod64(((len + pos) + blocksize - 1) >> log2blocksize, disk->sector_size, NULL);
- for (i = pos >> (log2blocksize + GRUB_DISK_SECTOR_BITS); i < blockcnt; i++)
+ for (i = grub_divmod64((pos >> log2blocksize), disk->sector_size, NULL); i < blockcnt; i++)
{
grub_disk_addr_t blknr;
int blockoff = pos & (blocksize - 1);
@@ -266,7 +266,7 @@
}
/* First block. */
- if (i == (pos >> (log2blocksize + GRUB_DISK_SECTOR_BITS)))
+ if (i == (grub_divmod64(pos >> log2blocksize, disk->sector_size, NULL)))
{
skipfirst = blockoff;
blockend -= skipfirst;
Index: fs/reiserfs.c
===================================================================
--- fs/reiserfs.c (revision 1886)
+++ fs/reiserfs.c (working copy)
@@ -509,9 +509,9 @@
do
{
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
(((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
block_size, (char *) block_header);
if (grub_errno)
goto fail;
@@ -659,7 +659,7 @@
block_size = grub_le_to_cpu16 (node->data->superblock.block_size);
len = grub_le_to_cpu16 (found.header.item_size);
- block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS);
+ block = found.block_number * (block_size / node->data->disk->sector_size);
offset = grub_le_to_cpu16 (found.header.item_location);
symlink_buffer = grub_malloc (len + 1);
@@ -686,7 +686,7 @@
data = grub_malloc (sizeof (*data));
if (! data)
goto fail;
- grub_disk_read (disk, REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE,
+ grub_disk_read (disk, REISERFS_SUPER_BLOCK_OFFSET / disk->sector_size,
0, sizeof (data->superblock), (char *) &(data->superblock));
if (grub_errno)
goto fail;
@@ -744,9 +744,9 @@
struct grub_reiserfs_item_header *item_headers;
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
(((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
block_size, (char *) block_header);
if (grub_errno)
goto fail;
@@ -838,7 +838,7 @@
{
struct grub_reiserfs_stat_item_v1 entry_v1_stat;
grub_disk_read (data->disk,
- entry_block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ entry_block_number * (block_size / data->disk->sector_size),
grub_le_to_cpu16 (entry_item->header.item_location),
sizeof (entry_v1_stat),
(char *) &entry_v1_stat);
@@ -880,7 +880,7 @@
{
struct grub_reiserfs_stat_item_v2 entry_v2_stat;
grub_disk_read (data->disk,
- entry_block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ entry_block_number * (block_size / data->disk->sector_size),
grub_le_to_cpu16 (entry_item->header.item_location),
sizeof (entry_v2_stat),
(char *) &entry_v2_stat);
@@ -1028,10 +1028,10 @@
{
struct grub_reiserfs_stat_item_v1 entry_v1_stat;
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
entry_location
+ (((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
sizeof (entry_v1_stat), (char *) &entry_v1_stat);
if (grub_errno)
goto fail;
@@ -1041,10 +1041,10 @@
{
struct grub_reiserfs_stat_item_v2 entry_v2_stat;
grub_disk_read (data->disk,
- block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ block_number * (block_size / data->disk->sector_size),
entry_location
+ (((grub_off_t) block_number * block_size)
- & (GRUB_DISK_SECTOR_SIZE - 1)),
+ & (data->disk->sector_size - 1)),
sizeof (entry_v2_stat), (char *) &entry_v2_stat);
if (grub_errno)
goto fail;
@@ -1111,7 +1111,7 @@
switch (found.type)
{
case GRUB_REISERFS_DIRECT:
- block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS);
+ block = found.block_number * (block_size / data->disk->sector_size);
grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block);
if (initial_position < current_position + item_size)
{
@@ -1143,7 +1143,7 @@
if (! indirect_block_ptr)
goto fail;
grub_disk_read (found.data->disk,
- found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
+ found.block_number * (block_size / found.data->disk->sector_size),
grub_le_to_cpu16 (found.header.item_location),
item_size, (char *) indirect_block_ptr);
if (grub_errno)
@@ -1155,7 +1155,7 @@
indirect_block++)
{
block = grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) *
- (block_size >> GRUB_DISK_SECTOR_BITS);
+ (block_size / found.data->disk->sector_size);
grub_dprintf ("reiserfs_blocktype", "I: %u\n", (unsigned) block);
if (current_position + block_size >= initial_position)
{
@@ -1334,7 +1334,7 @@
if (*label)
{
grub_disk_read (device->disk,
- REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE,
+ REISERFS_SUPER_BLOCK_OFFSET / device->disk->sector_size,
REISERFS_LABEL_OFFSET, REISERFS_MAX_LABEL_LENGTH,
*label);
}
Index: fs/jfs.c
===================================================================
--- fs/jfs.c (revision 1886)
+++ fs/jfs.c (working copy)
@@ -276,9 +276,8 @@
} tree;
if (grub_disk_read (data->disk,
- grub_le_to_cpu32 (extents[found].extent.blk2)
- << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS), 0,
+ grub_divmod64(grub_le_to_cpu32 (extents[found].extent.blk2)
+ << (grub_le_to_cpu16 (data->sblock.log2_blksz)), data->disk->sector_size, NULL), 0,
sizeof (tree), (char *) &tree))
return -1;
@@ -309,14 +308,14 @@
/* Read in the IAG. */
if (grub_disk_read (data->disk,
- iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS), 0,
+ grub_divmod64 (iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)), data->disk->sector_size, NULL), 0,
sizeof (struct grub_jfs_iag), (char *) &iag))
return grub_errno;
inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2);
- inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS);
+ inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz));
+ inoblk /= data->disk->sector_size;
+
inoblk += inonum;
if (grub_disk_read (data->disk, inoblk, 0,
@@ -412,7 +411,8 @@
}
blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2);
- blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS);
+ blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz));
+ blk /= data->disk->sector_size;
/* Read in the nodes until we are on the leaf node level. */
do
@@ -430,8 +430,7 @@
de = (struct grub_jfs_internal_dirent *) diro->dirpage->dirent;
index = diro->dirpage->sorted[diro->dirpage->header.sindex * 32];
blk = (grub_le_to_cpu32 (de[index].ex.blk2)
- << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS));
+ << (grub_le_to_cpu16 (data->sblock.log2_blksz)) * data->disk->sector_size);
} while (!(diro->dirpage->header.flags & GRUB_JFS_TREE_LEAF));
diro->leaf = diro->dirpage->dirent;
@@ -485,8 +484,8 @@
return GRUB_ERR_OUT_OF_RANGE;
next = grub_le_to_cpu64 (diro->dirpage->header.nextb);
- next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS);
+ next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz));
+ next /= diro->data->disk->sector_size;
if (grub_disk_read (diro->data->disk, next, 0,
grub_le_to_cpu32 (diro->data->sblock.blksz),
@@ -583,8 +582,7 @@
data->disk->read_hook = read_hook;
grub_disk_read (data->disk,
- blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- - GRUB_DISK_SECTOR_BITS),
+ blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz)) * data->disk->sector_size,
skipfirst, blockend, buf);
data->disk->read_hook = 0;
Index: fs/ext2.c
===================================================================
--- fs/ext2.c (revision 1886)
+++ fs/ext2.c (working copy)
@@ -495,8 +495,8 @@
if (!data)
return 0;
- /* Read the superblock. */
- grub_disk_read (disk, 1 * 2, 0, sizeof (struct grub_ext2_sblock),
+ /* Read the superblock. from address 1024 instead of some sector! */
+ grub_disk_read (disk, 0, 1024, sizeof (struct grub_ext2_sblock),
(char *) &data->sblock);
if (grub_errno)
goto fail;
Index: fs/minix.c
===================================================================
--- fs/minix.c (revision 1886)
+++ fs/minix.c (working copy)
@@ -263,8 +263,8 @@
if (data->version == 1)
{
- block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode));
- int offs = (ino % (GRUB_DISK_SECTOR_SIZE
+ block += ino / (data->disk->sector_size / sizeof (struct grub_minix_inode));
+ int offs = (ino % (data->disk->sector_size
/ sizeof (struct grub_minix_inode))
* sizeof (struct grub_minix_inode));
@@ -273,10 +273,10 @@
}
else
{
- block += ino / (GRUB_DISK_SECTOR_SIZE
+ block += ino / (data->disk->sector_size
/ sizeof (struct grub_minix2_inode));
int offs = (ino
- % (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix2_inode))
+ % (data->disk->sector_size / sizeof (struct grub_minix2_inode))
* sizeof (struct grub_minix2_inode));
grub_disk_read (data->disk, block, offs,
Index: fs/hfsplus.c
===================================================================
--- fs/hfsplus.c (revision 1886)
+++ fs/hfsplus.c (working copy)
@@ -224,7 +224,6 @@
static grub_dl_t my_mod;
#endif
-\f
/* Return the offset of the record with the index INDEX, in the node
NODE which is part of the B+ tree BTREE. */
static inline unsigned int
@@ -309,8 +308,7 @@
if (blk != -1)
return (blk
- + (node->data->embedded_offset >> (node->data->log2blksize
- - GRUB_DISK_SECTOR_BITS)));
+ + (node->data->embedded_offset * node->data->disk->sector_size) >> (node->data->log2blksize));
/* For the extent overflow file, extra extents can't be found in
the extent overflow file. If this happens, you found a
@@ -360,10 +358,11 @@
unsigned offset, unsigned length),
int pos, grub_size_t len, char *buf)
{
+// TODO: Thinks of some nice way for log2 here...
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_hfsplus_read_block,
node->size,
- node->data->log2blksize - GRUB_DISK_SECTOR_BITS);
+ node->data->log2blksize - fat_log2 (node->data->disk->sector_size));
}
static struct grub_hfsplus_data *
@@ -409,7 +408,7 @@
ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
data->embedded_offset = (ablk_start
+ extent_start
- * (ablk_size >> GRUB_DISK_SECTOR_BITS));
+ * (ablk_size / data->disk->sector_size));
grub_disk_read (disk, data->embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
sizeof (volheader), (char *) &volheader);
Index: fs/cpio.c
===================================================================
--- fs/cpio.c (revision 1886)
+++ fs/cpio.c (working copy)
@@ -145,9 +145,9 @@
return grub_errno;
data->size = grub_strtoul (hd.size, NULL, 8);
- data->dofs = data->hofs + GRUB_DISK_SECTOR_SIZE;
- *ofs = data->dofs + ((data->size + GRUB_DISK_SECTOR_SIZE - 1) &
- ~(GRUB_DISK_SECTOR_SIZE - 1));
+ data->dofs = data->hofs + data->disk->sector_size;
+ *ofs = data->dofs + ((data->size + data->disk->sector_size - 1) &
+ ~(data->disk->sector_size - 1));
}
return GRUB_ERR_NONE;
}
Index: include/grub/ntfs.h
===================================================================
--- include/grub/ntfs.h (revision 1886)
+++ include/grub/ntfs.h (working copy)
@@ -67,7 +67,9 @@
#define FLAG_ENCRYPTED 0x4000
#define FLAG_SPARSE 0x8000
-#define BLK_SHR GRUB_DISK_SECTOR_BITS
+// TODO: This is quite bad, was GRUB_DISK_SECTOR_BITS (whch in turn was 9 for 512 Byte/Sector disks)
+// Check if this is ok on devices with different sector sizes
+#define BLK_SHR 9
#define MAX_MFT (1024 >> BLK_SHR)
#define MAX_IDX (16384 >> BLK_SHR)
Index: include/grub/disk.h
===================================================================
--- include/grub/disk.h (revision 1886)
+++ include/grub/disk.h (working copy)
@@ -94,6 +94,9 @@
/* The underlying disk device. */
grub_disk_dev_t dev;
+ /* The size of each sector. */
+ grub_uint32_t sector_size;
+
/* The total number of sectors. */
grub_uint64_t total_sectors;
@@ -125,9 +128,9 @@
typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
#endif
-/* The sector size. */
-#define GRUB_DISK_SECTOR_SIZE 0x200
-#define GRUB_DISK_SECTOR_BITS 9
+/* The sector size is now contained in grub_disk structure */
+//#define GRUB_DISK_SECTOR_SIZE 512
+//#define GRUB_DISK_SECTOR_BITS 9
/* The maximum number of disk caches. */
#define GRUB_DISK_CACHE_NUM 1021
Index: include/grub/lvm.h
===================================================================
--- include/grub/lvm.h (revision 1886)
+++ include/grub/lvm.h (working copy)
@@ -65,7 +65,8 @@
struct grub_lvm_pv *pv;
};
-#define GRUB_LVM_LABEL_SIZE GRUB_DISK_SECTOR_SIZE
+// TODO: Check if LVM_LABEL_SIZE is 1 sector or 512 Bytes and change code accordingly
+#define GRUB_LVM_LABEL_SIZE 512
#define GRUB_LVM_LABEL_SCAN_SECTORS 4L
#define GRUB_LVM_LABEL_ID "LABELONE"
Index: commands/crc.c
===================================================================
--- commands/crc.c (revision 1886)
+++ commands/crc.c (working copy)
@@ -24,6 +24,7 @@
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/lib/crc.h>
+#include <grub/cmd.h>
static grub_err_t
grub_cmd_crc (struct grub_arg_list *state __attribute__ ((unused)),
@@ -31,7 +32,7 @@
{
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char buf[GRUB_CMD_CHUNK_SIZE];
grub_ssize_t size;
grub_uint32_t crc;
Index: commands/cat.c
===================================================================
--- commands/cat.c (revision 1886)
+++ commands/cat.c (working copy)
@@ -31,8 +31,9 @@
int argc, char **args)
{
+#define GRUB_CMD_CAT_CHUNK_SIZE 512
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char buf[GRUB_CMD_CAT_CHUNK_SIZE];
grub_ssize_t size;
int key = 0;
Index: commands/hexdump.c
===================================================================
--- commands/hexdump.c (revision 1886)
+++ commands/hexdump.c (working copy)
@@ -26,6 +26,8 @@
#include <grub/gzio.h>
#include <grub/partition.h>
#include <grub/lib/hexdump.h>
+#include <grub/mm.h>
+#include <grub/cmd.h>
static const struct grub_arg_option options[] = {
{"skip", 's', 0, "skip offset bytes from the beginning of file.", 0,
@@ -37,7 +39,8 @@
static grub_err_t
grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)
{
- char buf[GRUB_DISK_SECTOR_SIZE * 4];
+ // we can not use GRUB_CMD_CHUNK_SIZE here since we want to directly read from the device
+ char *buf;
grub_ssize_t size, length;
grub_addr_t skip;
int namelen;
@@ -63,10 +66,14 @@
return 0;
if (disk->partition)
- skip += grub_partition_get_start (disk->partition) << GRUB_DISK_SECTOR_BITS;
+ skip += grub_partition_get_start (disk->partition) * disk->sector_size;
- sector = (skip >> (GRUB_DISK_SECTOR_BITS + 2)) * 4;
- ofs = skip & (GRUB_DISK_SECTOR_SIZE * 4 - 1);
+ // we are going to read directly from disk, so take a whole sector!
+ // TODO: Why not use grub_disk_read which can handle also smaller and bigger chunks
+ buf = grub_malloc (disk->sector_size);
+
+ sector = (grub_divmod64(skip, disk->sector_size, 0) >> 2) * 4;
+ ofs = skip & (disk->sector_size * 4 - 1);
while (length)
{
grub_size_t len, n;
@@ -75,8 +82,8 @@
if (ofs + len > sizeof (buf))
len = sizeof (buf) - ofs;
- n = ((ofs + len + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS);
+ n = grub_divmod64((ofs + len + disk->sector_size - 1),
+ disk->sector_size, 0);
if (disk->dev->read (disk, sector, n, buf))
break;
@@ -89,6 +96,7 @@
}
grub_disk_close (disk);
+ grub_free (buf);
}
else
{
@@ -99,8 +107,10 @@
return 0;
file->offset = skip;
+ // here the size of the buffer does not matter since we use file access
+ buf = grub_malloc (GRUB_CMD_CHUNK_SIZE);
- while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
+ while ((size = grub_file_read (file, buf, GRUB_CMD_CHUNK_SIZE)) > 0)
{
unsigned long len;
@@ -116,6 +126,7 @@
}
grub_file_close (file);
+ grub_free (buf);
}
return 0;
Index: commands/blocklist.c
===================================================================
--- commands/blocklist.c (revision 1886)
+++ commands/blocklist.c (working copy)
@@ -31,7 +31,7 @@
int argc, char **args)
{
grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
+ char *buf;
unsigned long start_sector = 0;
unsigned num_sectors = 0;
int num_entries = 0;
@@ -47,7 +47,7 @@
if (num_sectors > 0)
{
if (start_sector + num_sectors == sector
- && offset == 0 && length == GRUB_DISK_SECTOR_SIZE)
+ && offset == 0 && length == file->device->disk->sector_size)
{
num_sectors++;
return;
@@ -57,7 +57,7 @@
num_sectors = 0;
}
- if (offset == 0 && length == GRUB_DISK_SECTOR_SIZE)
+ if (offset == 0 && length == file->device->disk->sector_size)
{
start_sector = sector;
num_sectors++;
@@ -90,6 +90,8 @@
return grub_error (GRUB_ERR_BAD_DEVICE,
"this command is available only for disk devices.");
+ buf = grub_malloc (file->device->disk->sector_size);
+
if (file->device->disk->partition)
part_start = grub_partition_get_start (file->device->disk->partition);
@@ -103,6 +105,7 @@
grub_file_close (file);
+ grub_free (buf);
return grub_errno;
}
Index: commands/loadenv.c
===================================================================
--- commands/loadenv.c (revision 1886)
+++ commands/loadenv.c (working copy)
@@ -157,8 +157,8 @@
{
grub_file_t file;
grub_disk_t disk;
- grub_disk_addr_t addr[GRUB_ENVBLK_MAXLEN >> GRUB_DISK_SECTOR_BITS];
- char buf[GRUB_DISK_SECTOR_SIZE];
+ grub_disk_addr_t *addr;
+ char *buf;
grub_disk_addr_t part_start = 0;
int num = 0;
@@ -168,10 +168,10 @@
void NESTED_FUNC_ATTR hook (grub_disk_addr_t sector,
unsigned offset, unsigned length)
{
- if ((offset != 0) || (length != GRUB_DISK_SECTOR_SIZE))
+ if ((offset != 0) || (length != disk->sector_size))
return;
- if (num < (GRUB_ENVBLK_MAXLEN >> GRUB_DISK_SECTOR_BITS))
+ if (num < (GRUB_ENVBLK_MAXLEN / disk->sector_size))
addr[num++] = sector;
}
@@ -184,7 +184,7 @@
file->read_hook = 0;
- if (num != GRUB_ENVBLK_MAXLEN >> GRUB_DISK_SECTOR_BITS)
+ if (num != GRUB_ENVBLK_MAXLEN / disk->sector_size)
{
grub_error (GRUB_ERR_BAD_DEVICE, "invalid blocklist");
goto quit;
@@ -194,14 +194,17 @@
if (disk->partition)
part_start = grub_partition_get_start (disk->partition);
- for (num = 0; num < (GRUB_ENVBLK_MAXLEN >> GRUB_DISK_SECTOR_BITS); num++)
+ buf = grub_malloc (disk->sector_size);
+ addr = grub_malloc (sizeof (*addr) * GRUB_ENVBLK_MAXLEN / disk->sector_size);
+
+ for (num = 0; num < (GRUB_ENVBLK_MAXLEN / disk->sector_size); num++)
{
if (grub_disk_read (disk, addr[num] - part_start, 0,
- GRUB_DISK_SECTOR_SIZE, buf))
+ disk->sector_size, buf))
goto quit;
- if (grub_memcmp (&buffer[num << GRUB_DISK_SECTOR_BITS], buf,
- GRUB_DISK_SECTOR_SIZE))
+ if (grub_memcmp (&buffer[num * disk->sector_size], buf,
+ disk->sector_size))
{
grub_error (GRUB_ERR_BAD_DEVICE, "invalid blocklist");
goto quit;
@@ -226,14 +229,16 @@
args++;
}
- for (num = 0; num < (GRUB_ENVBLK_MAXLEN >> GRUB_DISK_SECTOR_BITS); num++)
+ for (num = 0; num < (GRUB_ENVBLK_MAXLEN / disk->sector_size); num++)
if (grub_disk_write (disk, addr[num] - part_start, 0,
- GRUB_DISK_SECTOR_SIZE,
- &buffer[num << GRUB_DISK_SECTOR_BITS]))
+ disk->sector_size,
+ &buffer[num * disk->sector_size]))
goto quit;
quit:
grub_file_close (file);
+ grub_free (buf);
+ grub_free (addr);
return grub_errno;
}
Index: partmap/apple.c
===================================================================
--- partmap/apple.c (revision 1886)
+++ partmap/apple.c (working copy)
@@ -110,7 +110,7 @@
struct grub_apple_part apart;
struct grub_disk raw;
int partno = 0;
- unsigned pos = GRUB_DISK_SECTOR_SIZE;
+ unsigned pos = disk->sector_size;
/* Enforce raw disk access. */
raw = *disk;
@@ -132,8 +132,8 @@
for (;;)
{
- if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
- pos % GRUB_DISK_SECTOR_SIZE,
+ if (grub_disk_read (&raw, pos / disk->sector_size,
+ pos % disk->sector_size,
sizeof (struct grub_apple_part), (char *) &apart))
return grub_errno;
@@ -161,14 +161,14 @@
return grub_errno;
if (grub_be_to_cpu32 (apart.first_phys_block)
- == GRUB_DISK_SECTOR_SIZE * 2)
+ == disk->sector_size * 2)
return 0;
pos += sizeof (struct grub_apple_part);
partno++;
}
- if (pos != GRUB_DISK_SECTOR_SIZE)
+ if (pos != disk->sector_size)
return 0;
fail:
Index: partmap/acorn.c
===================================================================
--- partmap/acorn.c (revision 1886)
+++ partmap/acorn.c (working copy)
@@ -59,7 +59,7 @@
unsigned int sectors_per_cylinder;
int i;
- err = grub_disk_read (disk, 0xC00 / GRUB_DISK_SECTOR_SIZE, 0,
+ err = grub_disk_read (disk, 0xC00 / disk->sector_size, 0,
sizeof (struct grub_acorn_boot_block),
(char *) &boot);
if (err)
Index: partmap/gpt.c
===================================================================
--- partmap/gpt.c (revision 1886)
+++ partmap/gpt.c (working copy)
@@ -107,7 +107,7 @@
}
last_offset += grub_le_to_cpu32 (gpt.partentry_size);
- if (last_offset == GRUB_DISK_SECTOR_SIZE)
+ if (last_offset == disk->sector_size)
{
last_offset = 0;
entries++;
Index: loader/i386/pc/linux.c
===================================================================
--- loader/i386/pc/linux.c (revision 1886)
+++ loader/i386/pc/linux.c (working copy)
@@ -143,8 +143,8 @@
if (! setup_sects)
setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS;
- real_size = setup_sects << GRUB_DISK_SECTOR_BITS;
- prot_size = grub_file_size (file) - real_size - GRUB_DISK_SECTOR_SIZE;
+ real_size = setup_sects * file->device->disk->sector_size;
+ prot_size = grub_file_size (file) - real_size - file->device->disk->sector_size;
grub_linux_tmp_addr = (char *) GRUB_LINUX_BZIMAGE_ADDR + prot_size;
@@ -229,7 +229,7 @@
/* Put the real mode code at the temporary address. */
grub_memmove (grub_linux_tmp_addr, &lh, sizeof (lh));
- len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
+ len = real_size + file->device->disk->sector_size - sizeof (lh);
if (grub_file_read (file, grub_linux_tmp_addr + sizeof (lh), len) != len)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
@@ -240,10 +240,10 @@
|| grub_le_to_cpu16 (lh.version) < 0x0200)
/* Clear the heap space. */
grub_memset (grub_linux_tmp_addr
- + ((setup_sects + 1) << GRUB_DISK_SECTOR_BITS),
+ + ((setup_sects + 1) * file->device->disk->sector_size),
0,
((GRUB_LINUX_MAX_SETUP_SECTS - setup_sects - 1)
- << GRUB_DISK_SECTOR_BITS));
+ * file->device->disk->sector_size));
/* Specify the boot file. */
dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
Index: loader/i386/pc/chainloader.c
===================================================================
--- loader/i386/pc/chainloader.c (revision 1886)
+++ loader/i386/pc/chainloader.c (working copy)
@@ -63,32 +63,9 @@
grub_dl_ref (my_mod);
- file = grub_file_open (filename);
- if (! file)
- goto fail;
- /* Read the first block. */
- if (grub_file_read (file, (char *) 0x7C00, GRUB_DISK_SECTOR_SIZE)
- != GRUB_DISK_SECTOR_SIZE)
- {
- if (grub_errno == GRUB_ERR_NONE)
- grub_error (GRUB_ERR_BAD_OS, "too small");
-
- goto fail;
- }
-
- /* Check the signature. */
- signature = *((grub_uint16_t *) (0x7C00 + GRUB_DISK_SECTOR_SIZE - 2));
- if (signature != grub_le_to_cpu16 (0xaa55)
- && ! (flags & GRUB_CHAINLOADER_FORCE))
- {
- grub_error (GRUB_ERR_BAD_OS, "invalid signature");
- goto fail;
- }
-
- grub_file_close (file);
-
- /* Obtain the partition table from the root device. */
+ /* Obtain the partition table from the root device. we have to open the
+ device in order to get the sector size */
dev = grub_device_open (0);
if (dev)
{
@@ -96,6 +73,35 @@
if (disk)
{
+ file = grub_file_open (filename);
+ if (! file)
+ {
+ goto fail;
+ grub_device_close (dev);
+ }
+
+ /* Read the first block. */
+ if (grub_file_read (file, (char *) 0x7C00, disk->sector_size)
+ != disk->sector_size)
+ {
+ if (grub_errno == GRUB_ERR_NONE)
+ grub_error (GRUB_ERR_BAD_OS, "too small");
+ grub_device_close (dev);
+ goto fail;
+ }
+
+ /* Check the signature. */
+ signature = *((grub_uint16_t *) (0x7C00 + disk->sector_size - 2));
+ if (signature != grub_le_to_cpu16 (0xaa55)
+ && ! (flags & GRUB_CHAINLOADER_FORCE))
+ {
+ grub_error (GRUB_ERR_BAD_OS, "invalid signature");
+ grub_device_close (dev);
+ goto fail;
+ }
+
+ grub_file_close (file);
+
grub_partition_t p = disk->partition;
/* In i386-pc, the id is equal to the BIOS drive number. */
Index: geninit.sh
===================================================================
--- geninit.sh (revision 1886)
+++ geninit.sh (working copy)
@@ -49,7 +49,7 @@
while read line; do
file=`echo $line | cut -f1 -d:`
if echo $@ | grep $file >/dev/null; then
- echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_\1_init ();/'
+ echo $line | sed -e 's/.*GRUB_MOD_INIT *(\([a-zA-Z0-9_]*\)).*/ grub_\1_init (); grub_util_info ("\1");/'
fi
done < ${lst}
Index: util/grub-probe.c
===================================================================
--- util/grub-probe.c (revision 1886)
+++ util/grub-probe.c (working copy)
@@ -112,18 +112,32 @@
int abstraction_type;
grub_device_t dev = NULL;
grub_fs_t fs;
+
+ grub_util_info ("starting probe...");
+ if (path != NULL) grub_util_info ("path = %s.", path);
+ if (device_name != NULL) grub_util_info ("device_name = %s", device_name);
if (path == NULL)
{
- if (! grub_util_check_block_device (device_name))
+ if (! grub_util_check_block_device (device_name)) {
+ grub_util_info ("2");
grub_util_error ("%s is not a block device.\n", device_name);
+ }
}
- else
+ else {
+ grub_util_info ("3");
device_name = grub_guess_root_device (path);
+ }
+ grub_util_info ("1");
+ if (path != NULL) grub_util_info ("path = %s.", path);
+ if (device_name != NULL) grub_util_info ("device_name = %s", device_name);
+
if (! device_name)
grub_util_error ("cannot find a device for %s.\n", path);
+ grub_util_info ("2");
+
if (print == PRINT_DEVICE)
{
printf ("%s\n", device_name);
@@ -165,7 +179,7 @@
grub_util_info ("opening %s", drive_name);
dev = grub_device_open (drive_name);
if (! dev)
- grub_util_error ("%s", grub_errmsg);
+ grub_util_error ("grub_device_open failed: %s", grub_errmsg);
if (print == PRINT_PARTMAP)
{
@@ -358,22 +372,32 @@
}
argument = argv[optind];
+
+ grub_util_info ("arguments parsed.");
/* Initialize the emulated biosdisk driver. */
grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
+
+ grub_util_info ("biosdisk initialized");
/* Initialize all modules. */
grub_init_all ();
+ grub_util_info ("all modules initialized");
+
/* Do it. */
if (argument_is_device)
probe (NULL, argument);
else
probe (argument, NULL);
+
+ grub_util_info ("probe executed");
/* Free resources. */
grub_fini_all ();
grub_util_biosdisk_fini ();
+
+ grub_util_info ("all modules deinitialized");
free (dev_map);
Index: util/i386/pc/grub-mkimage.c
===================================================================
--- util/i386/pc/grub-mkimage.c (revision 1886)
+++ util/i386/pc/grub-mkimage.c (working copy)
@@ -129,7 +129,7 @@
#endif
static void
-generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *memdisk_path)
+generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *memdisk_path, grub_uint32_t target_sector_size)
{
grub_addr_t module_addr = 0;
char *kernel_img, *boot_img, *core_img;
@@ -208,19 +208,19 @@
grub_util_info ("the core size is 0x%x", core_size);
- num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
+ num = ((core_size + target_sector_size - 1) / target_sector_size);
if (num > 0xffff)
grub_util_error ("the core image is too big");
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
- if (boot_size != GRUB_DISK_SECTOR_SIZE)
+ if (boot_size >= target_sector_size)
grub_util_error ("diskboot.img is not one sector size");
boot_img = grub_util_read_image (boot_path);
/* i386 is a little endian architecture. */
- *((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
+ *((grub_uint16_t *) (boot_img + target_sector_size
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_cpu_to_le16 (num);
@@ -229,7 +229,7 @@
free (boot_path);
module_addr = (path_list
- ? (GRUB_BOOT_MACHINE_KERNEL_ADDR + GRUB_DISK_SECTOR_SIZE
+ ? (GRUB_BOOT_MACHINE_KERNEL_ADDR + target_sector_size
+ kernel_size)
: 0);
@@ -280,6 +280,7 @@
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
+ {"sector-size", required_argument, 0, 's'},
{0, 0, 0, 0}
};
@@ -301,6 +302,7 @@
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
+ -s, --sector-size=NR set sector size to NR bytes\n\
\n\
Report bugs to <%s>.\n\
", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
@@ -316,6 +318,7 @@
char *prefix = NULL;
char *memdisk = NULL;
FILE *fp = stdout;
+ grub_uint32_t target_sector_size = 0;
progname = "grub-mkimage";
@@ -372,6 +375,10 @@
case 'v':
verbosity++;
break;
+
+ case 's':
+ target_sector_size = atoi (optarg);
+ break;
default:
usage (1);
@@ -386,8 +393,15 @@
grub_util_error ("cannot open %s", output);
}
- generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind, memdisk);
+ if (target_sector_size == 0)
+ {
+ printf ("invalid sector size given!");
+ usage (1);
+ }
+
+ generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind, memdisk, target_sector_size);
+
fclose (fp);
if (dir)
Index: util/i386/pc/grub-setup.c
===================================================================
--- util/i386/pc/grub-setup.c (revision 1886)
+++ util/i386/pc/grub-setup.c (working copy)
@@ -105,9 +105,8 @@
char *tmp_img;
int i;
grub_disk_addr_t first_sector;
- grub_uint16_t current_segment
- = GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
- grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
+ grub_uint16_t current_segment;
+ grub_uint16_t last_length = 0;
grub_file_t file;
FILE *fp;
struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
@@ -160,7 +159,7 @@
grub_util_info ("the first sector is <%llu,%u,%u>",
sector, offset, length);
- if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
+ if (offset != 0 || length != dest_dev->disk->sector_size)
grub_util_error ("The first sector of the core file is not sector-aligned");
first_sector = sector;
@@ -174,7 +173,7 @@
grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x",
sector, offset, length, (unsigned) current_segment);
- if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
+ if (offset != 0 || last_length != dest_dev->disk->sector_size)
grub_util_error ("Non-sector-aligned data is found in the core file");
if (block != first_block
@@ -193,15 +192,25 @@
}
last_length = length;
- current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
+ current_segment += dest_dev->disk->sector_size >> 4;
}
-
+
+ /* Open the destination device and read sector size (automagically done by grub_device_open)*/
+ dest_dev = grub_device_open (dest);
+ if (! dest_dev)
+ grub_util_error ("%s", grub_errmsg);
+
+ /* initialize sector-size dependant variables */
+ last_length = dest_dev->disk->sector_size;
+ current_segment = GRUB_BOOT_MACHINE_KERNEL_SEG + (dest_dev->disk->sector_size >> 4);
+
/* Read the boot image by the OS service. */
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
- if (boot_size != GRUB_DISK_SECTOR_SIZE)
- grub_util_error ("The size of `%s' is not %d",
- boot_path, GRUB_DISK_SECTOR_SIZE);
+ if (boot_size != dest_dev->disk->sector_size)
+ grub_util_error ("The size of `%s' is not %d, you should adapt the image sector size to the" \
+ "sector size of the target block device.",
+ boot_path, dest_dev->disk->sector_size);
boot_img = grub_util_read_image (boot_path);
free (boot_path);
@@ -215,23 +224,23 @@
core_path = grub_util_get_path (dir, core_file);
core_size = grub_util_get_image_size (core_path);
- core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
- >> GRUB_DISK_SECTOR_BITS);
- if (core_size < GRUB_DISK_SECTOR_SIZE)
+ core_sectors = ((core_size + dest_dev->disk->sector_size - 1)
+ / dest_dev->disk->sector_size);
+ if (core_size < dest_dev->disk->sector_size)
grub_util_error ("The size of `%s' is too small", core_path);
- else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
+ else if (core_size > 0xFFFF * dest_dev->disk->sector_size)
grub_util_error ("The size of `%s' is too large", core_path);
core_img = grub_util_read_image (core_path);
/* Have FIRST_BLOCK to point to the first blocklist. */
first_block = (struct boot_blocklist *) (core_img
- + GRUB_DISK_SECTOR_SIZE
+ + dest_dev->disk->sector_size
- sizeof (*block));
- install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ install_dos_part = (grub_int32_t *) (core_img + dest_dev->disk->sector_size
+ GRUB_KERNEL_MACHINE_INSTALL_DOS_PART);
- install_bsd_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ install_bsd_part = (grub_int32_t *) (core_img + dest_dev->disk->sector_size
+ GRUB_KERNEL_MACHINE_INSTALL_BSD_PART);
/* Open the root device and the destination device. */
@@ -239,17 +248,13 @@
if (! root_dev)
grub_util_error ("%s", grub_errmsg);
- dest_dev = grub_device_open (dest);
- if (! dest_dev)
- grub_util_error ("%s", grub_errmsg);
-
grub_util_info ("setting the root device to `%s'", root);
if (grub_env_set ("root", root) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
/* Read the original sector from the disk. */
- tmp_img = xmalloc (GRUB_DISK_SECTOR_SIZE);
- if (grub_disk_read (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
+ tmp_img = xmalloc (dest_dev->disk->sector_size);
+ if (grub_disk_read (dest_dev->disk, 0, 0, dest_dev->disk->sector_size, tmp_img))
grub_util_error ("%s", grub_errmsg);
/* Copy the possible DOS BPB. */
@@ -327,7 +332,7 @@
first_block->len = grub_cpu_to_le16 (core_sectors - 1);
first_block->segment
= grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG
- + (GRUB_DISK_SECTOR_SIZE >> 4));
+ + (dest_dev->disk->sector_size >> 4));
/* Make sure that the second blocklist is a terminator. */
block = first_block - 1;
@@ -346,7 +351,7 @@
*kernel_sector = grub_cpu_to_le64 (embed_region.start);
/* Write the boot image onto the disk. */
- if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
+ if (grub_disk_write (dest_dev->disk, 0, 0, dest_dev->disk->sector_size,
boot_img))
grub_util_error ("%s", grub_errmsg);
@@ -457,14 +462,14 @@
grub_util_error ("%s", grub_errmsg);
file->read_hook = save_first_sector;
- if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
- != GRUB_DISK_SECTOR_SIZE)
+ if (grub_file_read (file, tmp_img, dest_dev->disk->sector_size)
+ != dest_dev->disk->sector_size)
grub_util_error ("Failed to read the first sector of the core image");
block = first_block;
file->read_hook = save_blocklists;
- if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
- != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
+ if (grub_file_read (file, tmp_img, core_size - dest_dev->disk->sector_size)
+ != (grub_ssize_t) core_size - dest_dev->disk->sector_size)
grub_util_error ("Failed to read the rest sectors of the core image");
grub_file_close (file);
@@ -487,11 +492,11 @@
if (! fp)
grub_util_error ("Cannot open `%s'", core_path);
- grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
+ grub_util_write_image (core_img, dest_dev->disk->sector_size * 2, fp);
fclose (fp);
/* Write the boot image onto the disk. */
- if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, boot_img))
+ if (grub_disk_write (dest_dev->disk, 0, 0, dest_dev->disk->sector_size, boot_img))
grub_util_error ("%s", grub_errmsg);
finish:
Index: util/grub-mkdevicemap.c
===================================================================
--- util/grub-mkdevicemap.c (revision 1886)
+++ util/grub-mkdevicemap.c (working copy)
@@ -70,6 +70,9 @@
# ifndef BLKGETSIZE
# define BLKGETSIZE _IO(0x12,96) /* return device size */
# endif /* ! BLKGETSIZE */
+# ifndef BLKSSZGET
+# define BLKSSZGET _IO(0x12,104)/* get block device sector size */
+#endif
#endif /* __linux__ */
/* Use __FreeBSD_kernel__ instead of __FreeBSD__ for compatibility with
@@ -328,7 +331,7 @@
static int
check_device (const char *device)
{
- char buf[512];
+ char *buf;
FILE *fp;
/* If DEVICE is empty, just return error. */
@@ -393,12 +396,20 @@
#endif /* __FreeBSD_kernel__ || __NetBSD__ || __OpenBSD__ */
/* Attempt to read the first sector. */
- if (fread (buf, 1, 512, fp) != 512)
+ grub_uint32_t size;
+ if (ioctl (fileno (fp), BLKSSZGET, &size))
{
+ grub_util_info ("can not get sector size for %s, assuming 512Bytes (non fatal).", device);
+ size = 512;
+ }
+ buf = grub_malloc( size );
+ if (fread (buf, 1, size, fp) != size)
+ {
+ free (buf);
fclose (fp);
return 0;
}
-
+ free (buf);
fclose (fp);
return 1;
}
Index: util/hostdisk.c
===================================================================
--- util/hostdisk.c (revision 1886)
+++ util/hostdisk.c (working copy)
@@ -64,6 +64,9 @@
# ifndef BLKGETSIZE64
# define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size */
# endif /* ! BLKGETSIZE64 */
+# ifndef BLKSSZGET
+# define BLKSSZGET _IO(0x12,104)/* get block device sector size */
+#endif
# ifndef MAJOR
# ifndef MINORBITS
# define MINORBITS 8
@@ -170,10 +173,14 @@
size = grub_util_get_disk_size (map[drive].device);
- if (size % 512)
+// TODO: find correct sector size for mingw32
+ grub_util_info ("compiled with mingw32, assuming 512 byte sector size!");
+ disk->sector_size = 512;
+
+ if (size % disk->sector_size)
grub_util_error ("unaligned device size");
- disk->total_sectors = size >> 9;
+ disk->total_sectors = grub_divmod64 (size, disk->sector_size, NULL);
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
@@ -194,6 +201,13 @@
goto fail;
}
+ if (ioctl (fd, BLKSSZGET, &nr))
+ {
+ close (fd);
+ goto fail;
+ }
+ disk->sector_size = nr;
+
if (ioctl (fd, BLKGETSIZE64, &nr))
{
close (fd);
@@ -201,12 +215,12 @@
}
close (fd);
- disk->total_sectors = nr / 512;
+ disk->total_sectors = grub_divmod64 (nr, disk->sector_size, NULL);
- if (nr % 512)
+ if (nr % disk->sector_size)
grub_util_error ("unaligned device size");
- grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
+ grub_util_info ("the size of %s is %llu with sector size %iu", name, disk->total_sectors, disk->sector_size);
return GRUB_ERR_NONE;
}
@@ -215,15 +229,19 @@
/* In GNU/Hurd, stat() will return the right size. */
#elif !defined (__GNU__)
# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal."
+# warning "No routine for getting sector size is implemented, assuming 512 bytes."
+ disk->sector_size = 512;
#endif
- if (stat (map[drive].device, &st) < 0)
- return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
+ {
+ if (stat (map[drive].device, &st) < 0)
+ return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
- disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS;
+ disk->total_sectors = grub_divmod64 (st.st_size, disk->sector_size, NULL);
- grub_util_info ("the size of %s is %lu", name, disk->total_sectors);
+ grub_util_info ("the size of %s is %lu with sector size %iu", name, disk->total_sectors, disk->sector_size);
- return GRUB_ERR_NONE;
+ return GRUB_ERR_NONE;
+ }
}
#ifdef __linux__
@@ -346,7 +364,7 @@
_syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo,
loff_t *, res, uint, wh);
- offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS;
+ offset = (loff_t) sector * disk->sector_size;
if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
{
grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id].device);
@@ -356,7 +374,7 @@
}
#else
{
- off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS;
+ off_t offset = (off_t) sector * disk->sector_size;
if (lseek (fd, offset, SEEK_SET) != offset)
{
@@ -422,6 +440,8 @@
return size;
}
+
+/* read size number of SECTORS which each in turn is of disk->sector_size bytes */
static grub_err_t
grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf)
@@ -439,20 +459,20 @@
sectors that are read together with the MBR in one read. It
should only remap the MBR, so we split the read in two
parts. -jochen */
- if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE)
+ if (nread (fd, buf, disk->sector_size) != disk->sector_size)
{
grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device);
close (fd);
return grub_errno;
}
- buf += GRUB_DISK_SECTOR_SIZE;
+ buf += disk->sector_size;
size--;
}
#endif /* __linux__ */
-
- if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS)
- != (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+
+ if (nread (fd, buf, size * disk->sector_size)
+ != (ssize_t) (size * disk->sector_size))
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device);
close (fd);
@@ -469,8 +489,8 @@
if (fd < 0)
return grub_errno;
- if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS)
- != (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
+ if (nwrite (fd, buf, size * disk->sector_size)
+ != (ssize_t) (size * disk->sector_size))
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device);
close (fd);
@@ -615,7 +635,7 @@
if (bsd_part >= 0)
sprintf (p + strlen (p), ",%c", bsd_part + 'a');
-
+
return p;
}
@@ -788,8 +808,11 @@
return 0;
}
- if (! S_ISBLK (st.st_mode))
+ if (! S_ISBLK (st.st_mode))
+ {
+ grub_util_info ("not a block device: %s.", drive);
return make_device_name (drive, -1, -1);
+ }
#if defined(__linux__) || defined(__CYGWIN__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
@@ -853,7 +876,7 @@
}
name = make_device_name (drive, -1, -1);
-
+
if (MAJOR (st.st_rdev) == FLOPPY_MAJOR)
return name;
@@ -884,9 +907,13 @@
grub_util_info ("opening the device %s", name);
disk = grub_disk_open (name);
free (name);
-
+
if (! disk)
return 0;
+
+ // hdg.start is start in 512 byte sectors size regardless of the actual
+ // sector size of the drive! FIXME
+ hdg.start = hdg.start * 512 / disk->sector_size;
grub_partition_iterate (disk, find_partition);
if (grub_errno != GRUB_ERR_NONE)
@@ -902,7 +929,7 @@
"cannot find the partition of `%s'", os_dev);
return 0;
}
-
+
return make_device_name (drive, dos_part, bsd_part);
}
@@ -929,7 +956,7 @@
bsd_part = *q - 'a';
}
}
-
+
return make_device_name (drive, dos_part, bsd_part);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-10-08 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-07 22:30 Patch for different sector sizes Clemens Helfmeier
2008-10-08 16:11 ` Clemens Helfmeier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.