source: grub-pc/trunk/fuentes/grub-core/kern/disk_common.c @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 1.7 KB
Line 
1/* This function performs three tasks:
2   - Make sectors disk relative from partition relative.
3   - Normalize offset to be less than the sector size.
4   - Verify that the range is inside the partition.  */
5static grub_err_t
6grub_disk_adjust_range (grub_disk_t disk, grub_disk_addr_t *sector,
7                        grub_off_t *offset, grub_size_t size)
8{
9  grub_partition_t part;
10  *sector += *offset >> GRUB_DISK_SECTOR_BITS;
11  *offset &= GRUB_DISK_SECTOR_SIZE - 1;
12
13  for (part = disk->partition; part; part = part->parent)
14    {
15      grub_disk_addr_t start;
16      grub_uint64_t len;
17
18      start = part->start;
19      len = part->len;
20
21      if (*sector >= len
22          || len - *sector < ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
23                              >> GRUB_DISK_SECTOR_BITS))
24        return grub_error (GRUB_ERR_OUT_OF_RANGE,
25                           N_("attempt to read or write outside of partition"));
26
27      *sector += start;
28    }
29
30  if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN
31      && ((disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) <= *sector
32          || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
33          >> GRUB_DISK_SECTOR_BITS) > (disk->total_sectors
34                                       << (disk->log_sector_size
35                                           - GRUB_DISK_SECTOR_BITS)) - *sector))
36    return grub_error (GRUB_ERR_OUT_OF_RANGE,
37                       N_("attempt to read or write outside of disk `%s'"), disk->name);
38
39  return GRUB_ERR_NONE;
40}
41
42static inline grub_disk_addr_t
43transform_sector (grub_disk_t disk, grub_disk_addr_t sector)
44{
45  return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
46}
47
48static unsigned
49grub_disk_cache_get_index (unsigned long dev_id, unsigned long disk_id,
50                           grub_disk_addr_t sector)
51{
52  return ((dev_id * 524287UL + disk_id * 2606459UL
53           + ((unsigned) (sector >> GRUB_DISK_CACHE_BITS)))
54          % GRUB_DISK_CACHE_NUM);
55}
Note: See TracBrowser for help on using the repository browser.