From: okuji Date: Sat, 21 Aug 2004 13:54:22 +0000 (+0000) Subject: 2004-08-21 Yoshinori K. Okuji X-Git-Tag: 1.98~2202 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=97543f08fcbb9cab1d819f1625137d341082e6c2;p=thirdparty%2Fgrub.git 2004-08-21 Yoshinori K. Okuji Each disk device has its own id now. This is useful to make use of multiple disk devices. * include/grub/disk.h (grub_disk_dev_id): New enum. (GRUB_DISK_DEVICE_BIOSDISK_ID): New constant. (GRUB_DISK_DEVICE_OFDISK_ID): Likewise. * disk/i386/pc/biosdisk.c (grub_biosdisk_dev): Specify GRUB_DISK_DEVICE_BIOSDISK_ID as an id. * disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_dev): Specify GRUB_DISK_DEVICE_OFDISK_ID as an id. * util/i386/pc/biosdisk.c (grub_util_biosdisk_dev): Specify GRUB_DISK_DEVICE_BIOSDISK_ID as an id. * include/grub/disk.h (struct grub_disk_dev): Added a new member "id" which is used by the cache manager. * normal/main.c (grub_normal_init_page): Use "GNU GRUB" instead of just "GRUB". --- diff --git a/ChangeLog b/ChangeLog index 1fef9972e..b22d59a4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2004-08-21 Yoshinori K. Okuji + + Each disk device has its own id now. This is useful to make use + of multiple disk devices. + + * include/grub/disk.h (grub_disk_dev_id): New enum. + (GRUB_DISK_DEVICE_BIOSDISK_ID): New constant. + (GRUB_DISK_DEVICE_OFDISK_ID): Likewise. + + * disk/i386/pc/biosdisk.c (grub_biosdisk_dev): Specify + GRUB_DISK_DEVICE_BIOSDISK_ID as an id. + + * disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_dev): Specify + GRUB_DISK_DEVICE_OFDISK_ID as an id. + + * util/i386/pc/biosdisk.c (grub_util_biosdisk_dev): Specify + GRUB_DISK_DEVICE_BIOSDISK_ID as an id. + + * include/grub/disk.h (struct grub_disk_dev): Added a new member + "id" which is used by the cache manager. + + * normal/main.c (grub_normal_init_page): Use "GNU GRUB" instead + of just "GRUB". + 2004-08-18 Marco Gerards * fs/hfs.c: New file. diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index e21d10c87..723c394de 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -319,6 +319,7 @@ grub_biosdisk_write (grub_disk_t disk, unsigned long sector, static struct grub_disk_dev grub_biosdisk_dev = { .name = "biosdisk", + .id = GRUB_DISK_DEVICE_BIOSDISK_ID, .iterate = grub_biosdisk_iterate, .open = grub_biosdisk_open, .close = grub_biosdisk_close, diff --git a/disk/powerpc/ieee1275/ofdisk.c b/disk/powerpc/ieee1275/ofdisk.c index 7c21d6699..b70d89312 100644 --- a/disk/powerpc/ieee1275/ofdisk.c +++ b/disk/powerpc/ieee1275/ofdisk.c @@ -146,6 +146,7 @@ grub_ofdisk_write (grub_disk_t disk __attribute ((unused)), static struct grub_disk_dev grub_ofdisk_dev = { .name = "ofdisk", + .id = GRUB_DISK_DEVICE_OFDISK_ID, .iterate = grub_ofdisk_iterate, .open = grub_ofdisk_open, .close = grub_ofdisk_close, diff --git a/include/grub/disk.h b/include/grub/disk.h index 698273580..8fda5036a 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002, 2003 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,14 @@ #include #include +/* These are used to set a device id. When you add a new disk device, + you must define a new id for it here. */ +enum grub_disk_dev_id + { + GRUB_DISK_DEVICE_BIOSDISK_ID, + GRUB_DISK_DEVICE_OFDISK_ID, + }; + struct grub_disk; /* Disk device. */ @@ -33,6 +41,9 @@ struct grub_disk_dev /* The device name. */ const char *name; + /* The device id used by the cache manager. */ + unsigned long id; + /* Call HOOK with each device name, until HOOK returns non-zero. */ int (*iterate) (int (*hook) (const char *name)); diff --git a/kern/disk.c b/kern/disk.c index 8ac3a9295..c913f2d2a 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +35,8 @@ static unsigned long grub_last_time = 0; /* Disk cache. */ struct grub_disk_cache { - unsigned long id; + unsigned long dev_id; + unsigned long disk_id; unsigned long sector; char *data; int lock; @@ -56,23 +57,27 @@ grub_disk_cache_get_performance (unsigned long *hits, unsigned long *misses) #endif static unsigned -grub_disk_cache_get_index (unsigned long id, unsigned long sector) +grub_disk_cache_get_index (unsigned long dev_id, unsigned long disk_id, + unsigned long sector) { - return ((id * 2606459 + (sector >> GRUB_DISK_CACHE_BITS)) + return ((dev_id * 524287UL + disk_id * 2606459UL + + (sector >> GRUB_DISK_CACHE_BITS)) % GRUB_DISK_CACHE_NUM); } static void -grub_disk_cache_invalidate (unsigned long id, unsigned long sector) +grub_disk_cache_invalidate (unsigned long dev_id, unsigned long disk_id, + unsigned long sector) { unsigned index; struct grub_disk_cache *cache; sector &= ~(GRUB_DISK_CACHE_SIZE - 1); - index = grub_disk_cache_get_index (id, sector); + index = grub_disk_cache_get_index (dev_id, disk_id, sector); cache = grub_disk_cache_table + index; - if (cache->id == id && cache->sector == sector && cache->data) + if (cache->dev_id == dev_id && cache->disk_id == disk_id + && cache->sector == sector && cache->data) { cache->lock = 1; grub_free (cache->data); @@ -99,15 +104,17 @@ grub_disk_cache_invalidate_all (void) } static char * -grub_disk_cache_fetch (unsigned long id, unsigned long sector) +grub_disk_cache_fetch (unsigned long dev_id, unsigned long disk_id, + unsigned long sector) { struct grub_disk_cache *cache; unsigned index; - index = grub_disk_cache_get_index (id, sector); + index = grub_disk_cache_get_index (dev_id, disk_id, sector); cache = grub_disk_cache_table + index; - if (cache->id == id && cache->sector == sector) + if (cache->dev_id == dev_id && cache->disk_id == disk_id + && cache->sector == sector) { cache->lock = 1; #if 0 @@ -124,28 +131,30 @@ grub_disk_cache_fetch (unsigned long id, unsigned long sector) } static void -grub_disk_cache_unlock (unsigned long id, unsigned long sector) +grub_disk_cache_unlock (unsigned long dev_id, unsigned long disk_id, + unsigned long sector) { struct grub_disk_cache *cache; unsigned index; - index = grub_disk_cache_get_index (id, sector); + index = grub_disk_cache_get_index (dev_id, disk_id, sector); cache = grub_disk_cache_table + index; - if (cache->id == id && cache->sector == sector) + if (cache->dev_id == dev_id && cache->disk_id == disk_id + && cache->sector == sector) cache->lock = 0; } static grub_err_t -grub_disk_cache_store (unsigned long id, unsigned long sector, - const char *data) +grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id, + unsigned long sector, const char *data) { unsigned index; struct grub_disk_cache *cache; - grub_disk_cache_invalidate (id, sector); + grub_disk_cache_invalidate (dev_id, disk_id, sector); - index = grub_disk_cache_get_index (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); @@ -154,7 +163,8 @@ grub_disk_cache_store (unsigned long id, unsigned long sector, grub_memcpy (cache->data, data, GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); - cache->id = id; + cache->dev_id = dev_id; + cache->disk_id = disk_id; cache->sector = sector; return GRUB_ERR_NONE; @@ -259,7 +269,8 @@ grub_disk_open (const char *name) closed. */ current_time = grub_get_rtc (); - if (current_time > grub_last_time + GRUB_CACHE_TIMEOUT * GRUB_TICKS_PER_SECOND) + if (current_time > (grub_last_time + + GRUB_CACHE_TIMEOUT * GRUB_TICKS_PER_SECOND)) grub_disk_cache_invalidate_all (); grub_last_time = current_time; @@ -354,12 +365,12 @@ grub_disk_read (grub_disk_t disk, unsigned long sector, len = size; /* Fetch the cache. */ - data = grub_disk_cache_fetch (disk->id, start_sector); + data = grub_disk_cache_fetch (disk->dev->id, disk->id, start_sector); if (data) { /* Just copy it! */ grub_memcpy (buf, data + pos + offset, len); - grub_disk_cache_unlock (disk->id, start_sector); + grub_disk_cache_unlock (disk->dev->id, disk->id, start_sector); } else { @@ -404,7 +415,8 @@ grub_disk_read (grub_disk_t disk, unsigned long sector, /* Copy it and store it in the disk cache. */ grub_memcpy (buf, tmp_buf + pos + offset, len); - grub_disk_cache_store (disk->id, start_sector, tmp_buf); + grub_disk_cache_store (disk->dev->id, disk->id, + start_sector, tmp_buf); } /* Call the read hook, if any. */ @@ -466,7 +478,7 @@ grub_disk_write (grub_disk_t disk, unsigned long sector, grub_memcpy (tmp_buf + offset, buf, len); - grub_disk_cache_invalidate (disk->id, sector); + grub_disk_cache_invalidate (disk->dev->id, disk->id, sector); if ((disk->dev->write) (disk, sector, 1, tmp_buf) != GRUB_ERR_NONE) goto finish; @@ -488,7 +500,7 @@ grub_disk_write (grub_disk_t disk, unsigned long sector, goto finish; while (n--) - grub_disk_cache_invalidate (disk->id, sector++); + grub_disk_cache_invalidate (disk->dev->id, disk->id, sector++); buf += len; size -= len; diff --git a/normal/main.c b/normal/main.c index 4070c5be4..499e6ffb1 100644 --- a/normal/main.c +++ b/normal/main.c @@ -281,7 +281,7 @@ grub_normal_init_page (void) { grub_cls (); grub_printf ("\n\ - GRUB version %s\n\n", + GNU GRUB version %s\n\n", PACKAGE_VERSION); } diff --git a/util/i386/pc/biosdisk.c b/util/i386/pc/biosdisk.c index b9071f1cb..022574227 100644 --- a/util/i386/pc/biosdisk.c +++ b/util/i386/pc/biosdisk.c @@ -477,6 +477,7 @@ grub_util_biosdisk_write (grub_disk_t disk, unsigned long sector, static struct grub_disk_dev grub_util_biosdisk_dev = { .name = "biosdisk", + .id = GRUB_DISK_DEVICE_BIOSDISK_ID, .iterate = grub_util_biosdisk_iterate, .open = grub_util_biosdisk_open, .close = 0,