2004-04-04 Yoshinori K. Okuji <okuji@enbug.org>
All symbols prefixed with PUPA_ and pupa_ are renamed to GRUB_ and grub_, respectively. Because the conversion is trivial and mechanical, I omit the details here. Please refer to the CVS if you need more information.
This commit is contained in:
parent
6a1425510d
commit
4b13b216f4
125 changed files with 6198 additions and 6181 deletions
344
kern/disk.c
344
kern/disk.c
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* GRUB is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -13,27 +13,27 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/machine/partition.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/machine/time.h>
|
||||
#include <pupa/file.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/machine/partition.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/machine/time.h>
|
||||
#include <grub/file.h>
|
||||
|
||||
#define PUPA_CACHE_TIMEOUT 2
|
||||
#define GRUB_CACHE_TIMEOUT 2
|
||||
|
||||
/* The last time the disk was used. */
|
||||
static unsigned long pupa_last_time = 0;
|
||||
static unsigned long grub_last_time = 0;
|
||||
|
||||
|
||||
/* Disk cache. */
|
||||
struct pupa_disk_cache
|
||||
struct grub_disk_cache
|
||||
{
|
||||
unsigned long id;
|
||||
unsigned long sector;
|
||||
|
@ -41,142 +41,142 @@ struct pupa_disk_cache
|
|||
int lock;
|
||||
};
|
||||
|
||||
static struct pupa_disk_cache pupa_disk_cache_table[PUPA_DISK_CACHE_NUM];
|
||||
static struct grub_disk_cache grub_disk_cache_table[GRUB_DISK_CACHE_NUM];
|
||||
|
||||
#if 0
|
||||
static unsigned long pupa_disk_cache_hits;
|
||||
static unsigned long pupa_disk_cache_misses;
|
||||
static unsigned long grub_disk_cache_hits;
|
||||
static unsigned long grub_disk_cache_misses;
|
||||
|
||||
void
|
||||
pupa_disk_cache_get_performance (unsigned long *hits, unsigned long *misses)
|
||||
grub_disk_cache_get_performance (unsigned long *hits, unsigned long *misses)
|
||||
{
|
||||
*hits = pupa_disk_cache_hits;
|
||||
*misses = pupa_disk_cache_misses;
|
||||
*hits = grub_disk_cache_hits;
|
||||
*misses = grub_disk_cache_misses;
|
||||
}
|
||||
#endif
|
||||
|
||||
static unsigned
|
||||
pupa_disk_cache_get_index (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_get_index (unsigned long id, unsigned long sector)
|
||||
{
|
||||
return ((id * 2606459 + (sector >> PUPA_DISK_CACHE_BITS))
|
||||
% PUPA_DISK_CACHE_NUM);
|
||||
return ((id * 2606459 + (sector >> GRUB_DISK_CACHE_BITS))
|
||||
% GRUB_DISK_CACHE_NUM);
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_disk_cache_invalidate (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_invalidate (unsigned long id, unsigned long sector)
|
||||
{
|
||||
unsigned index;
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
|
||||
sector &= ~(PUPA_DISK_CACHE_SIZE - 1);
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
sector &= ~(GRUB_DISK_CACHE_SIZE - 1);
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
if (cache->id == id && cache->sector == sector && cache->data)
|
||||
{
|
||||
cache->lock = 1;
|
||||
pupa_free (cache->data);
|
||||
grub_free (cache->data);
|
||||
cache->data = 0;
|
||||
cache->lock = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pupa_disk_cache_invalidate_all (void)
|
||||
grub_disk_cache_invalidate_all (void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < PUPA_DISK_CACHE_NUM; i++)
|
||||
for (i = 0; i < GRUB_DISK_CACHE_NUM; i++)
|
||||
{
|
||||
struct pupa_disk_cache *cache = pupa_disk_cache_table + i;
|
||||
struct grub_disk_cache *cache = grub_disk_cache_table + i;
|
||||
|
||||
if (cache->data && ! cache->lock)
|
||||
{
|
||||
pupa_free (cache->data);
|
||||
grub_free (cache->data);
|
||||
cache->data = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
pupa_disk_cache_fetch (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_fetch (unsigned long id, unsigned long sector)
|
||||
{
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
unsigned index;
|
||||
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
if (cache->id == id && cache->sector == sector)
|
||||
{
|
||||
cache->lock = 1;
|
||||
#if 0
|
||||
pupa_disk_cache_hits++;
|
||||
grub_disk_cache_hits++;
|
||||
#endif
|
||||
return cache->data;
|
||||
}
|
||||
|
||||
#if 0
|
||||
pupa_disk_cache_misses++;
|
||||
grub_disk_cache_misses++;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_disk_cache_unlock (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_unlock (unsigned long id, unsigned long sector)
|
||||
{
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
unsigned index;
|
||||
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
if (cache->id == id && cache->sector == sector)
|
||||
cache->lock = 0;
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_disk_cache_store (unsigned long id, unsigned long sector,
|
||||
static grub_err_t
|
||||
grub_disk_cache_store (unsigned long id, unsigned long sector,
|
||||
const char *data)
|
||||
{
|
||||
unsigned index;
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
|
||||
pupa_disk_cache_invalidate (id, sector);
|
||||
grub_disk_cache_invalidate (id, sector);
|
||||
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
cache->data = pupa_malloc (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS);
|
||||
cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
if (! cache->data)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
pupa_memcpy (cache->data, data,
|
||||
PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS);
|
||||
grub_memcpy (cache->data, data,
|
||||
GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
cache->id = id;
|
||||
cache->sector = sector;
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static pupa_disk_dev_t pupa_disk_dev_list;
|
||||
static grub_disk_dev_t grub_disk_dev_list;
|
||||
|
||||
void
|
||||
pupa_disk_dev_register (pupa_disk_dev_t dev)
|
||||
grub_disk_dev_register (grub_disk_dev_t dev)
|
||||
{
|
||||
dev->next = pupa_disk_dev_list;
|
||||
pupa_disk_dev_list = dev;
|
||||
dev->next = grub_disk_dev_list;
|
||||
grub_disk_dev_list = dev;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_disk_dev_unregister (pupa_disk_dev_t dev)
|
||||
grub_disk_dev_unregister (grub_disk_dev_t dev)
|
||||
{
|
||||
pupa_disk_dev_t *p, q;
|
||||
grub_disk_dev_t *p, q;
|
||||
|
||||
for (p = &pupa_disk_dev_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
for (p = &grub_disk_dev_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (q == dev)
|
||||
{
|
||||
*p = q->next;
|
||||
|
@ -185,25 +185,25 @@ pupa_disk_dev_unregister (pupa_disk_dev_t dev)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_disk_dev_iterate (int (*hook) (const char *name))
|
||||
grub_disk_dev_iterate (int (*hook) (const char *name))
|
||||
{
|
||||
pupa_disk_dev_t p;
|
||||
grub_disk_dev_t p;
|
||||
|
||||
for (p = pupa_disk_dev_list; p; p = p->next)
|
||||
for (p = grub_disk_dev_list; p; p = p->next)
|
||||
if ((p->iterate) (hook))
|
||||
break;
|
||||
}
|
||||
|
||||
pupa_disk_t
|
||||
pupa_disk_open (const char *name)
|
||||
grub_disk_t
|
||||
grub_disk_open (const char *name)
|
||||
{
|
||||
char *p;
|
||||
pupa_disk_t disk;
|
||||
pupa_disk_dev_t dev;
|
||||
grub_disk_t disk;
|
||||
grub_disk_dev_t dev;
|
||||
char *raw = (char *) name;
|
||||
unsigned long current_time;
|
||||
|
||||
disk = (pupa_disk_t) pupa_malloc (sizeof (*disk));
|
||||
disk = (grub_disk_t) grub_malloc (sizeof (*disk));
|
||||
if (! disk)
|
||||
return 0;
|
||||
|
||||
|
@ -211,67 +211,67 @@ pupa_disk_open (const char *name)
|
|||
disk->read_hook = 0;
|
||||
disk->partition = 0;
|
||||
disk->data = 0;
|
||||
disk->name = pupa_strdup (name);
|
||||
disk->name = grub_strdup (name);
|
||||
if (! disk->name)
|
||||
goto fail;
|
||||
|
||||
p = pupa_strchr (name, ',');
|
||||
p = grub_strchr (name, ',');
|
||||
if (p)
|
||||
{
|
||||
pupa_size_t len = p - name;
|
||||
grub_size_t len = p - name;
|
||||
|
||||
raw = pupa_malloc (len + 1);
|
||||
raw = grub_malloc (len + 1);
|
||||
if (! raw)
|
||||
goto fail;
|
||||
|
||||
pupa_memcpy (raw, name, len);
|
||||
grub_memcpy (raw, name, len);
|
||||
raw[len] = '\0';
|
||||
}
|
||||
|
||||
for (dev = pupa_disk_dev_list; dev; dev = dev->next)
|
||||
for (dev = grub_disk_dev_list; dev; dev = dev->next)
|
||||
{
|
||||
if ((dev->open) (raw, disk) == PUPA_ERR_NONE)
|
||||
if ((dev->open) (raw, disk) == GRUB_ERR_NONE)
|
||||
break;
|
||||
else if (pupa_errno == PUPA_ERR_UNKNOWN_DEVICE)
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
else
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (! dev)
|
||||
{
|
||||
pupa_error (PUPA_ERR_UNKNOWN_DEVICE, "no such disk");
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such disk");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (p && ! disk->has_partitions)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_DEVICE, "no partition on this disk");
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "no partition on this disk");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
disk->dev = dev;
|
||||
|
||||
if (p)
|
||||
disk->partition = pupa_partition_probe (disk, p + 1);
|
||||
disk->partition = grub_partition_probe (disk, p + 1);
|
||||
|
||||
/* The cache will be invalidated about 2 seconds after a device was
|
||||
closed. */
|
||||
current_time = pupa_get_rtc ();
|
||||
current_time = grub_get_rtc ();
|
||||
|
||||
if (current_time > pupa_last_time + PUPA_CACHE_TIMEOUT * PUPA_TICKS_PER_SECOND)
|
||||
pupa_disk_cache_invalidate_all ();
|
||||
if (current_time > grub_last_time + GRUB_CACHE_TIMEOUT * GRUB_TICKS_PER_SECOND)
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
pupa_last_time = current_time;
|
||||
grub_last_time = current_time;
|
||||
|
||||
fail:
|
||||
|
||||
if (raw && raw != name)
|
||||
pupa_free (raw);
|
||||
grub_free (raw);
|
||||
|
||||
if (pupa_errno != PUPA_ERR_NONE)
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
pupa_disk_close (disk);
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -279,64 +279,64 @@ pupa_disk_open (const char *name)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_disk_close (pupa_disk_t disk)
|
||||
grub_disk_close (grub_disk_t disk)
|
||||
{
|
||||
if (disk->dev && disk->dev->close)
|
||||
(disk->dev->close) (disk);
|
||||
|
||||
/* Reset the timer. */
|
||||
pupa_last_time = pupa_get_rtc ();
|
||||
grub_last_time = grub_get_rtc ();
|
||||
|
||||
pupa_free (disk->partition);
|
||||
pupa_free ((void *) disk->name);
|
||||
pupa_free (disk);
|
||||
grub_free (disk->partition);
|
||||
grub_free ((void *) disk->name);
|
||||
grub_free (disk);
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_disk_check_range (pupa_disk_t disk, unsigned long *sector,
|
||||
unsigned long *offset, pupa_ssize_t size)
|
||||
static grub_err_t
|
||||
grub_disk_check_range (grub_disk_t disk, unsigned long *sector,
|
||||
unsigned long *offset, grub_ssize_t size)
|
||||
{
|
||||
*sector += *offset >> PUPA_DISK_SECTOR_BITS;
|
||||
*offset &= PUPA_DISK_SECTOR_SIZE - 1;
|
||||
*sector += *offset >> GRUB_DISK_SECTOR_BITS;
|
||||
*offset &= GRUB_DISK_SECTOR_SIZE - 1;
|
||||
|
||||
if (disk->partition)
|
||||
{
|
||||
unsigned long start, len;
|
||||
|
||||
start = pupa_partition_get_start (disk->partition);
|
||||
len = pupa_partition_get_len (disk->partition);
|
||||
start = grub_partition_get_start (disk->partition);
|
||||
len = grub_partition_get_len (disk->partition);
|
||||
|
||||
if (*sector >= len
|
||||
|| len - *sector < ((*offset + size + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS))
|
||||
return pupa_error (PUPA_ERR_OUT_OF_RANGE, "out of partition");
|
||||
|| len - *sector < ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS))
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of partition");
|
||||
|
||||
*sector += start;
|
||||
}
|
||||
|
||||
if (disk->total_sectors <= *sector
|
||||
|| ((*offset + size + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS) > disk->total_sectors - *sector)
|
||||
return pupa_error (PUPA_ERR_OUT_OF_RANGE, "out of disk");
|
||||
|| ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS) > disk->total_sectors - *sector)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk");
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Read data from the disk. */
|
||||
pupa_err_t
|
||||
pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
||||
grub_err_t
|
||||
grub_disk_read (grub_disk_t disk, unsigned long sector,
|
||||
unsigned long offset, unsigned long size, char *buf)
|
||||
{
|
||||
char *tmp_buf;
|
||||
|
||||
/* First of all, check if the region is within the disk. */
|
||||
if (pupa_disk_check_range (disk, §or, &offset, size) != PUPA_ERR_NONE)
|
||||
return pupa_errno;
|
||||
if (grub_disk_check_range (disk, §or, &offset, size) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
/* Allocate a temporary buffer. */
|
||||
tmp_buf = pupa_malloc (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS);
|
||||
tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
if (! tmp_buf)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
/* Until SIZE is zero... */
|
||||
while (size)
|
||||
|
@ -347,54 +347,54 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
unsigned long pos;
|
||||
|
||||
/* For reading bulk data. */
|
||||
start_sector = sector & ~(PUPA_DISK_CACHE_SIZE - 1);
|
||||
pos = (sector - start_sector) << PUPA_DISK_SECTOR_BITS;
|
||||
len = (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS) - pos - offset;
|
||||
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 - offset;
|
||||
if (len > size)
|
||||
len = size;
|
||||
|
||||
/* Fetch the cache. */
|
||||
data = pupa_disk_cache_fetch (disk->id, start_sector);
|
||||
data = grub_disk_cache_fetch (disk->id, start_sector);
|
||||
if (data)
|
||||
{
|
||||
/* Just copy it! */
|
||||
pupa_memcpy (buf, data + pos + offset, len);
|
||||
pupa_disk_cache_unlock (disk->id, start_sector);
|
||||
grub_memcpy (buf, data + pos + offset, len);
|
||||
grub_disk_cache_unlock (disk->id, start_sector);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise read data from the disk actually. */
|
||||
if ((disk->dev->read) (disk, start_sector,
|
||||
PUPA_DISK_CACHE_SIZE, tmp_buf)
|
||||
!= PUPA_ERR_NONE)
|
||||
GRUB_DISK_CACHE_SIZE, tmp_buf)
|
||||
!= GRUB_ERR_NONE)
|
||||
{
|
||||
/* Uggh... Failed. Instead, just read necessary data. */
|
||||
unsigned num;
|
||||
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
/* If more data is required, no way. */
|
||||
if (pos + size
|
||||
>= (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS))
|
||||
>= (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS))
|
||||
goto finish;
|
||||
|
||||
num = ((size + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS);
|
||||
num = ((size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS);
|
||||
if ((disk->dev->read) (disk, sector, num, tmp_buf))
|
||||
goto finish;
|
||||
|
||||
pupa_memcpy (buf, tmp_buf + offset, size);
|
||||
grub_memcpy (buf, tmp_buf + offset, size);
|
||||
|
||||
/* Call the read hook, if any. */
|
||||
if (disk->read_hook)
|
||||
while (size)
|
||||
{
|
||||
(disk->read_hook) (sector, offset,
|
||||
((size > PUPA_DISK_SECTOR_SIZE)
|
||||
? PUPA_DISK_SECTOR_SIZE
|
||||
((size > GRUB_DISK_SECTOR_SIZE)
|
||||
? GRUB_DISK_SECTOR_SIZE
|
||||
: size));
|
||||
sector++;
|
||||
size -= PUPA_DISK_SECTOR_SIZE - offset;
|
||||
size -= GRUB_DISK_SECTOR_SIZE - offset;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
|
@ -403,8 +403,8 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
}
|
||||
|
||||
/* Copy it and store it in the disk cache. */
|
||||
pupa_memcpy (buf, tmp_buf + pos + offset, len);
|
||||
pupa_disk_cache_store (disk->id, start_sector, tmp_buf);
|
||||
grub_memcpy (buf, tmp_buf + pos + offset, len);
|
||||
grub_disk_cache_store (disk->id, start_sector, tmp_buf);
|
||||
}
|
||||
|
||||
/* Call the read hook, if any. */
|
||||
|
@ -416,20 +416,20 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
while (l)
|
||||
{
|
||||
(disk->read_hook) (s, offset,
|
||||
((l > PUPA_DISK_SECTOR_SIZE)
|
||||
? PUPA_DISK_SECTOR_SIZE
|
||||
((l > GRUB_DISK_SECTOR_SIZE)
|
||||
? GRUB_DISK_SECTOR_SIZE
|
||||
: l));
|
||||
|
||||
if (l < PUPA_DISK_SECTOR_SIZE - offset)
|
||||
if (l < GRUB_DISK_SECTOR_SIZE - offset)
|
||||
break;
|
||||
|
||||
s++;
|
||||
l -= PUPA_DISK_SECTOR_SIZE - offset;
|
||||
l -= GRUB_DISK_SECTOR_SIZE - offset;
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sector = start_sector + PUPA_DISK_CACHE_SIZE;
|
||||
sector = start_sector + GRUB_DISK_CACHE_SIZE;
|
||||
buf += len;
|
||||
size -= len;
|
||||
offset = 0;
|
||||
|
@ -437,38 +437,38 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
|
||||
finish:
|
||||
|
||||
pupa_free (tmp_buf);
|
||||
grub_free (tmp_buf);
|
||||
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_disk_write (pupa_disk_t disk, unsigned long sector,
|
||||
grub_err_t
|
||||
grub_disk_write (grub_disk_t disk, unsigned long sector,
|
||||
unsigned long offset, unsigned long size, const char *buf)
|
||||
{
|
||||
if (pupa_disk_check_range (disk, §or, &offset, size) != PUPA_ERR_NONE)
|
||||
if (grub_disk_check_range (disk, §or, &offset, size) != GRUB_ERR_NONE)
|
||||
return -1;
|
||||
|
||||
while (size)
|
||||
{
|
||||
if (offset != 0 || (size < PUPA_DISK_SECTOR_SIZE && size != 0))
|
||||
if (offset != 0 || (size < GRUB_DISK_SECTOR_SIZE && size != 0))
|
||||
{
|
||||
char tmp_buf[PUPA_DISK_SECTOR_SIZE];
|
||||
char tmp_buf[GRUB_DISK_SECTOR_SIZE];
|
||||
unsigned long len;
|
||||
|
||||
if (pupa_disk_read (disk, sector, 0, PUPA_DISK_SECTOR_SIZE, tmp_buf)
|
||||
!= PUPA_ERR_NONE)
|
||||
if (grub_disk_read (disk, sector, 0, GRUB_DISK_SECTOR_SIZE, tmp_buf)
|
||||
!= GRUB_ERR_NONE)
|
||||
goto finish;
|
||||
|
||||
len = PUPA_DISK_SECTOR_SIZE - offset;
|
||||
len = GRUB_DISK_SECTOR_SIZE - offset;
|
||||
if (len > size)
|
||||
len = size;
|
||||
|
||||
pupa_memcpy (tmp_buf + offset, buf, len);
|
||||
grub_memcpy (tmp_buf + offset, buf, len);
|
||||
|
||||
pupa_disk_cache_invalidate (disk->id, sector);
|
||||
grub_disk_cache_invalidate (disk->id, sector);
|
||||
|
||||
if ((disk->dev->write) (disk, sector, 1, tmp_buf) != PUPA_ERR_NONE)
|
||||
if ((disk->dev->write) (disk, sector, 1, tmp_buf) != GRUB_ERR_NONE)
|
||||
goto finish;
|
||||
|
||||
sector++;
|
||||
|
@ -481,14 +481,14 @@ pupa_disk_write (pupa_disk_t disk, unsigned long sector,
|
|||
unsigned long len;
|
||||
unsigned long n;
|
||||
|
||||
len = size & ~(PUPA_DISK_SECTOR_SIZE - 1);
|
||||
n = size >> PUPA_DISK_SECTOR_BITS;
|
||||
len = size & ~(GRUB_DISK_SECTOR_SIZE - 1);
|
||||
n = size >> GRUB_DISK_SECTOR_BITS;
|
||||
|
||||
if ((disk->dev->write) (disk, sector, n, buf) != PUPA_ERR_NONE)
|
||||
if ((disk->dev->write) (disk, sector, n, buf) != GRUB_ERR_NONE)
|
||||
goto finish;
|
||||
|
||||
while (n--)
|
||||
pupa_disk_cache_invalidate (disk->id, sector++);
|
||||
grub_disk_cache_invalidate (disk->id, sector++);
|
||||
|
||||
buf += len;
|
||||
size -= len;
|
||||
|
@ -497,46 +497,46 @@ pupa_disk_write (pupa_disk_t disk, unsigned long sector,
|
|||
|
||||
finish:
|
||||
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_print_partinfo (pupa_device_t disk, char *partname)
|
||||
grub_err_t
|
||||
grub_print_partinfo (grub_device_t disk, char *partname)
|
||||
{
|
||||
pupa_fs_t fs = 0;
|
||||
pupa_device_t part;
|
||||
grub_fs_t fs = 0;
|
||||
grub_device_t part;
|
||||
char devname[20];
|
||||
|
||||
pupa_sprintf (devname, "%s,%s", disk->disk->name, partname);
|
||||
part = pupa_device_open (devname);
|
||||
grub_sprintf (devname, "%s,%s", disk->disk->name, partname);
|
||||
part = grub_device_open (devname);
|
||||
if (!part)
|
||||
pupa_printf ("\tPartition num:%s, Filesystem cannot be accessed",
|
||||
grub_printf ("\tPartition num:%s, Filesystem cannot be accessed",
|
||||
partname);
|
||||
else
|
||||
{
|
||||
char *label;
|
||||
|
||||
fs = pupa_fs_probe (part);
|
||||
fs = grub_fs_probe (part);
|
||||
/* Ignore all errors. */
|
||||
pupa_errno = 0;
|
||||
grub_errno = 0;
|
||||
|
||||
pupa_printf ("\tPartition num:%s, Filesystem type %s",
|
||||
grub_printf ("\tPartition num:%s, Filesystem type %s",
|
||||
partname, fs ? fs->name : "Unknown");
|
||||
|
||||
if (fs)
|
||||
{
|
||||
(fs->label) (part, &label);
|
||||
if (pupa_errno == PUPA_ERR_NONE)
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
if (label && pupa_strlen (label))
|
||||
pupa_printf (", Label: %s", label);
|
||||
pupa_free (label);
|
||||
if (label && grub_strlen (label))
|
||||
grub_printf (", Label: %s", label);
|
||||
grub_free (label);
|
||||
}
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
pupa_device_close (part);
|
||||
grub_device_close (part);
|
||||
}
|
||||
|
||||
pupa_printf ("\n");
|
||||
return pupa_errno;
|
||||
grub_printf ("\n");
|
||||
return grub_errno;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue