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.
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.
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.
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/>.
19
#include <config-util.h>
21
#include <grub/disk.h>
22
#include <grub/partition.h>
23
#include <grub/msdos_partition.h>
24
#include <grub/types.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>
39
#include <sys/types.h>
45
# include <sys/disk.h>
48
grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_secsize)
50
unsigned long long nr;
51
unsigned sector_size, log_sector_size;
53
if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
56
if (ioctl (fd, DKIOCGETBLOCKSIZE, §or_size))
59
if (sector_size & (sector_size - 1) || !sector_size)
61
for (log_sector_size = 0;
62
(1 << log_sector_size) < sector_size;
66
*log_secsize = log_sector_size;
68
return nr << log_sector_size;
72
grub_util_fd_open (const char *os_dev, int flags)
83
ret = open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
85
/* If we can't have exclusive access, try shared access */
87
ret = open (os_dev, flags | O_SHLOCK, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR);
93
grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))