~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to grub-core/kern/disk_common.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.  */
 
5
static grub_err_t
 
6
grub_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
 
 
42
static inline grub_disk_addr_t
 
43
transform_sector (grub_disk_t disk, grub_disk_addr_t sector)
 
44
{
 
45
  return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
 
46
}
 
47
 
 
48
static unsigned
 
49
grub_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
}