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

« back to all changes in this revision

Viewing changes to grub-core/osdep/apple/hostdisk.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
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010,2011,2012,2013  Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <config-util.h>
 
20
 
 
21
#include <grub/disk.h>
 
22
#include <grub/partition.h>
 
23
#include <grub/msdos_partition.h>
 
24
#include <grub/types.h>
 
25
#include <grub/err.h>
 
26
#include <grub/emu/misc.h>
 
27
#include <grub/emu/hostdisk.h>
 
28
#include <grub/emu/getroot.h>
 
29
#include <grub/misc.h>
 
30
#include <grub/i18n.h>
 
31
#include <grub/list.h>
 
32
 
 
33
#include <stdio.h>
 
34
#include <stdlib.h>
 
35
#include <string.h>
 
36
#include <ctype.h>
 
37
#include <assert.h>
 
38
#include <unistd.h>
 
39
#include <sys/types.h>
 
40
#include <sys/stat.h>
 
41
#include <fcntl.h>
 
42
#include <errno.h>
 
43
#include <limits.h>
 
44
 
 
45
# include <sys/disk.h>
 
46
 
 
47
grub_int64_t
 
48
grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_secsize)
 
49
{
 
50
  unsigned long long nr;
 
51
  unsigned sector_size, log_sector_size;
 
52
 
 
53
  if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
 
54
    return -1;
 
55
 
 
56
  if (ioctl (fd, DKIOCGETBLOCKSIZE, &sector_size))
 
57
    return -1;
 
58
 
 
59
  if (sector_size & (sector_size - 1) || !sector_size)
 
60
    return -1;
 
61
  for (log_sector_size = 0;
 
62
       (1 << log_sector_size) < sector_size;
 
63
       log_sector_size++);
 
64
 
 
65
  if (log_secsize)
 
66
    *log_secsize = log_sector_size;
 
67
 
 
68
  return nr << log_sector_size;
 
69
}
 
70
 
 
71
grub_util_fd_t
 
72
grub_util_fd_open (const char *os_dev, int flags)
 
73
{
 
74
  grub_util_fd_t ret;
 
75
 
 
76
#ifdef O_LARGEFILE
 
77
  flags |= O_LARGEFILE;
 
78
#endif
 
79
#ifdef O_BINARY
 
80
  flags |= O_BINARY;
 
81
#endif
 
82
 
 
83
  ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
 
84
 
 
85
  /* If we can't have exclusive access, try shared access */
 
86
  if (ret < 0)
 
87
    ret = open (os_dev, flags | O_SHLOCK, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
 
88
 
 
89
  return ret;
 
90
}
 
91
 
 
92
void
 
93
grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 
94
{
 
95
}