Move OS-dependent files to grub-core/osdep and document it.
This commit is contained in:
parent
a5b0365ab2
commit
672fa55e81
30 changed files with 39 additions and 30 deletions
346
grub-core/osdep/windows/getroot.c
Normal file
346
grub-core/osdep/windows/getroot.c
Normal file
|
@ -0,0 +1,346 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config-util.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#include <grub/types.h>
|
||||
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/util/lvm.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/emu/misc.h>
|
||||
#include <grub/emu/hostdisk.h>
|
||||
#include <grub/emu/getroot.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/util/windows.h>
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
|
||||
char *
|
||||
grub_util_tchar_to_utf8 (LPCTSTR in)
|
||||
{
|
||||
#if SIZEOF_TCHAR == 1
|
||||
return xstrdup (path);
|
||||
#elif SIZEOF_TCHAR == 2
|
||||
size_t ssz;
|
||||
for (ssz = 0; in[ssz]; ssz++);
|
||||
|
||||
size_t tsz = GRUB_MAX_UTF8_PER_UTF16 * ssz + 1;
|
||||
grub_uint8_t *ret = xmalloc (tsz);
|
||||
*grub_utf16_to_utf8 (ret, in, ssz) = '\0';
|
||||
return (char *) ret;
|
||||
#else
|
||||
#error "Unsupported TCHAR size"
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SIZEOF_TCHAR == 1
|
||||
#define tcsnicmp strncasecmp
|
||||
#define tclen strlen
|
||||
#elif SIZEOF_TCHAR == 2
|
||||
#define tcsnicmp wcsnicmp
|
||||
#define tclen wcslen
|
||||
#endif
|
||||
|
||||
char **
|
||||
grub_guess_root_devices (const char *dir)
|
||||
{
|
||||
char **os_dev = NULL;
|
||||
TCHAR *dirwindows, *mntpointwindows;
|
||||
TCHAR *ptr;
|
||||
TCHAR volumename[100];
|
||||
size_t mntpointwindows_sz;
|
||||
|
||||
dirwindows = grub_util_get_windows_path (dir);
|
||||
if (!dirwindows)
|
||||
return 0;
|
||||
|
||||
mntpointwindows_sz = strlen (dir) * 2 + 1;
|
||||
mntpointwindows = xmalloc ((mntpointwindows_sz + 1) * sizeof (mntpointwindows[0]));
|
||||
|
||||
if (!GetVolumePathName (dirwindows,
|
||||
mntpointwindows,
|
||||
mntpointwindows_sz))
|
||||
{
|
||||
free (dirwindows);
|
||||
free (mntpointwindows);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!mntpointwindows[0])
|
||||
{
|
||||
free (dirwindows);
|
||||
free (mntpointwindows);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (ptr = mntpointwindows; *ptr; ptr++);
|
||||
if (*(ptr - 1) != '\\')
|
||||
{
|
||||
*ptr = '\\';
|
||||
*(ptr + 1) = '\0';
|
||||
}
|
||||
|
||||
if (!GetVolumeNameForVolumeMountPoint (mntpointwindows,
|
||||
volumename,
|
||||
ARRAY_SIZE (volumename)))
|
||||
{
|
||||
free (dirwindows);
|
||||
free (mntpointwindows);
|
||||
return 0;
|
||||
}
|
||||
os_dev = xmalloc (2 * sizeof (os_dev[0]));
|
||||
|
||||
for (ptr = volumename; *ptr; ptr++);
|
||||
while (ptr > volumename && *(ptr - 1) == '\\')
|
||||
*--ptr = '\0';
|
||||
|
||||
os_dev[0] = grub_util_tchar_to_utf8 (volumename);
|
||||
free (dirwindows);
|
||||
free (mntpointwindows);
|
||||
|
||||
if (!os_dev[0])
|
||||
{
|
||||
free (os_dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
os_dev[1] = 0;
|
||||
|
||||
return os_dev;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_util_part_to_disk (const char *os_dev,
|
||||
struct stat *st __attribute__ ((unused)),
|
||||
int *is_part)
|
||||
{
|
||||
HANDLE hd;
|
||||
LPTSTR name = grub_util_get_windows_path (os_dev);
|
||||
VOLUME_DISK_EXTENTS exts;
|
||||
DWORD extsbytes;
|
||||
char *ret;
|
||||
|
||||
if (((name[0] == '/') || (name[0] == '\\')) &&
|
||||
((name[1] == '/') || (name[1] == '\\')) &&
|
||||
((name[2] == '.') || (name[2] == '?')) &&
|
||||
((name[3] == '/') || (name[3] == '\\'))
|
||||
&& (tcsnicmp (name + 4, TEXT("PhysicalDrive"), sizeof ("PhysicalDrive") - 1) == 0
|
||||
|| tcsnicmp (name + 4, TEXT("Harddisk"), sizeof ("Harddisk") - 1) == 0
|
||||
|| ((name[4] == 'A' || name[4] == 'a' || name[4] == 'B' || name[4] == 'b')
|
||||
&& name[5] == ':' && name[6] == '\0')))
|
||||
{
|
||||
grub_util_info ("Matches full disk pattern");
|
||||
ret = grub_util_tchar_to_utf8 (name);
|
||||
free (name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
hd = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
0, OPEN_EXISTING, 0, 0);
|
||||
if (hd == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
grub_util_info ("CreateFile failed");
|
||||
ret = grub_util_tchar_to_utf8 (name);
|
||||
free (name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!DeviceIoControl(hd, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
|
||||
NULL, 0, &exts, sizeof (exts), &extsbytes, NULL))
|
||||
{
|
||||
grub_util_info ("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed");
|
||||
ret = grub_util_tchar_to_utf8 (name);
|
||||
CloseHandle (hd);
|
||||
free (name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CloseHandle (hd);
|
||||
|
||||
*is_part = 1;
|
||||
free (name);
|
||||
return xasprintf ("\\\\?\\PhysicalDrive%lu", (unsigned long) exts.Extents[0].DiskNumber);
|
||||
}
|
||||
|
||||
enum grub_dev_abstraction_types
|
||||
grub_util_get_dev_abstraction_os (const char *os_dev __attribute__((unused)))
|
||||
{
|
||||
return GRUB_DEV_ABSTRACTION_NONE;
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_pull_device_os (const char *os_dev __attribute__ ((unused)),
|
||||
enum grub_dev_abstraction_types ab __attribute__ ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_util_get_grub_dev_os (const char *os_dev __attribute__ ((unused)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
grub_disk_addr_t
|
||||
grub_util_find_partition_start_os (const char *os_dev)
|
||||
{
|
||||
HANDLE hd;
|
||||
LPTSTR name = grub_util_get_windows_path (os_dev);
|
||||
VOLUME_DISK_EXTENTS exts;
|
||||
DWORD extsbytes;
|
||||
char *ret;
|
||||
|
||||
if (((name[0] == '/') || (name[0] == '\\')) &&
|
||||
((name[1] == '/') || (name[1] == '\\')) &&
|
||||
((name[2] == '.') || (name[2] == '?')) &&
|
||||
((name[3] == '/') || (name[3] == '\\'))
|
||||
&& (tcsnicmp (name + 4, TEXT("PhysicalDrive"), sizeof ("PhysicalDrive") - 1) == 0
|
||||
|| tcsnicmp (name + 4, TEXT("Harddisk"), sizeof ("Harddisk") - 1) == 0
|
||||
|| ((name[4] == 'A' || name[4] == 'a' || name[4] == 'B' || name[4] == 'b')
|
||||
&& name[5] == ':' && name[6] == '\0')))
|
||||
{
|
||||
ret = grub_util_tchar_to_utf8 (name);
|
||||
free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
hd = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
0, OPEN_EXISTING, 0, 0);
|
||||
if (hd == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ret = grub_util_tchar_to_utf8 (name);
|
||||
free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!DeviceIoControl(hd, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
|
||||
NULL, 0, &exts, sizeof (exts), &extsbytes, NULL))
|
||||
{
|
||||
ret = grub_util_tchar_to_utf8 (name);
|
||||
CloseHandle (hd);
|
||||
free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CloseHandle (hd);
|
||||
free (name);
|
||||
return exts.Extents[0].StartingOffset.QuadPart / 512;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_make_system_path_relative_to_its_root (const char *path)
|
||||
{
|
||||
TCHAR *dirwindows, *mntpointwindows;
|
||||
TCHAR *ptr;
|
||||
TCHAR volumename[100];
|
||||
size_t mntpointwindows_sz;
|
||||
size_t offset, flen;
|
||||
TCHAR *ret;
|
||||
char *cret;
|
||||
|
||||
dirwindows = grub_util_get_windows_path (path);
|
||||
if (!dirwindows)
|
||||
return xstrdup (path);
|
||||
|
||||
mntpointwindows_sz = strlen (path) * 2 + 1;
|
||||
mntpointwindows = xmalloc ((mntpointwindows_sz + 1) * sizeof (mntpointwindows[0]));
|
||||
|
||||
if (!GetVolumePathName (dirwindows,
|
||||
mntpointwindows,
|
||||
mntpointwindows_sz))
|
||||
{
|
||||
offset = 0;
|
||||
if (dirwindows[0] && dirwindows[1] == ':')
|
||||
offset = 2;
|
||||
}
|
||||
offset = tclen (mntpointwindows);
|
||||
free (mntpointwindows);
|
||||
flen = tclen (dirwindows);
|
||||
if (offset > flen)
|
||||
{
|
||||
offset = 0;
|
||||
if (dirwindows[0] && dirwindows[1] == ':')
|
||||
offset = 2;
|
||||
}
|
||||
ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2));
|
||||
if (dirwindows[offset] != '\\'
|
||||
&& dirwindows[offset] != '/'
|
||||
&& dirwindows[offset])
|
||||
{
|
||||
ret[0] = '\\';
|
||||
memcpy (ret + 1, dirwindows + offset, (flen - offset + 1) * sizeof (ret[0]));
|
||||
}
|
||||
else
|
||||
memcpy (ret, dirwindows + offset, (flen - offset + 1) * sizeof (ret[0]));
|
||||
|
||||
free (dirwindows);
|
||||
|
||||
for (ptr = ret; *ptr; ptr++)
|
||||
if (*ptr == '\\')
|
||||
*ptr = '/';
|
||||
|
||||
cret = grub_util_tchar_to_utf8 (ret);
|
||||
free (ret);
|
||||
|
||||
return cret;
|
||||
}
|
||||
|
||||
int
|
||||
grub_util_biosdisk_is_floppy (grub_disk_t disk)
|
||||
{
|
||||
int ret;
|
||||
const char *dname;
|
||||
LPTSTR name;
|
||||
|
||||
dname = grub_util_biosdisk_get_osdev (disk);
|
||||
|
||||
if (!dname)
|
||||
return 0;
|
||||
|
||||
name = grub_util_get_windows_path (dname);
|
||||
|
||||
ret = (((name[0] == '/') || (name[0] == '\\')) &&
|
||||
((name[1] == '/') || (name[1] == '\\')) &&
|
||||
((name[2] == '.') || (name[2] == '?')) &&
|
||||
((name[3] == '/') || (name[3] == '\\'))
|
||||
&& (name[4] == 'A' || name[4] == 'a' || name[4] == 'B' || name[4] == 'b')
|
||||
&& name[5] == ':' && name[6] == '\0');
|
||||
free (name);
|
||||
|
||||
return ret;
|
||||
}
|
257
grub-core/osdep/windows/hostdisk.c
Normal file
257
grub-core/osdep/windows/hostdisk.c
Normal file
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config-util.h>
|
||||
|
||||
#include <grub/disk.h>
|
||||
#include <grub/partition.h>
|
||||
#include <grub/msdos_partition.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/emu/misc.h>
|
||||
#include <grub/emu/hostdisk.h>
|
||||
#include <grub/emu/getroot.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/list.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <grub/util/windows.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
LPTSTR
|
||||
grub_util_get_windows_path (const char *path)
|
||||
{
|
||||
LPTSTR winpath;
|
||||
winpath = xmalloc (sizeof (winpath[0]) * PATH_MAX);
|
||||
if (cygwin_conv_path ((sizeof (winpath[0]) == 1 ? CCP_POSIX_TO_WIN_A
|
||||
: CCP_POSIX_TO_WIN_W) | CCP_ABSOLUTE, path, winpath,
|
||||
sizeof (winpath[0]) * PATH_MAX))
|
||||
grub_util_error ("%s", _("cygwin_conv_path() failed"));
|
||||
return winpath;
|
||||
}
|
||||
#else
|
||||
LPTSTR
|
||||
grub_util_get_windows_path (const char *path)
|
||||
{
|
||||
char *fpa;
|
||||
const char *fp;
|
||||
LPTSTR ret;
|
||||
|
||||
fp = fpa = xmalloc (PATH_MAX);
|
||||
if (!_fullpath (fpa, path, PATH_MAX))
|
||||
fp = path;
|
||||
#if SIZEOF_TCHAR == 1
|
||||
ret = xstrdup (fp);
|
||||
#elif SIZEOF_TCHAR == 2
|
||||
size_t ssz = strlen (fp);
|
||||
size_t tsz = 2 * (GRUB_MAX_UTF16_PER_UTF8 * ssz + 1);
|
||||
ret = xmalloc (tsz);
|
||||
tsz = grub_utf8_to_utf16 (ret, tsz, (const grub_uint8_t *) fp, ssz, NULL);
|
||||
ret[tsz] = 0;
|
||||
#else
|
||||
#error SIZEOF_TCHAR
|
||||
#error "Unsupported TCHAR size"
|
||||
#endif
|
||||
|
||||
free (fpa);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
grub_uint64_t
|
||||
grub_util_get_fd_size (grub_util_fd_t hd, const char *name_in,
|
||||
unsigned *log_secsize)
|
||||
{
|
||||
grub_int64_t size = -1LL;
|
||||
int log_sector_size = 9;
|
||||
LPTSTR name = grub_util_get_windows_path (name_in);
|
||||
|
||||
if (log_secsize)
|
||||
*log_secsize = log_sector_size;
|
||||
|
||||
if (((name[0] == '/') || (name[0] == '\\')) &&
|
||||
((name[1] == '/') || (name[1] == '\\')) &&
|
||||
((name[2] == '.') || (name[2] == '?')) &&
|
||||
((name[3] == '/') || (name[3] == '\\')))
|
||||
{
|
||||
DWORD nr;
|
||||
DISK_GEOMETRY g;
|
||||
|
||||
if (! DeviceIoControl (hd, IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
||||
0, 0, &g, sizeof (g), &nr, 0))
|
||||
goto fail;
|
||||
|
||||
size = g.Cylinders.QuadPart;
|
||||
size *= g.TracksPerCylinder * g.SectorsPerTrack * g.BytesPerSector;
|
||||
|
||||
for (log_sector_size = 0;
|
||||
(1 << log_sector_size) < g.BytesPerSector;
|
||||
log_sector_size++);
|
||||
}
|
||||
else
|
||||
{
|
||||
ULARGE_INTEGER s;
|
||||
|
||||
s.LowPart = GetFileSize (hd, &s.HighPart);
|
||||
size = s.QuadPart;
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
if (log_secsize)
|
||||
*log_secsize = log_sector_size;
|
||||
|
||||
free (name);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void
|
||||
grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
||||
{
|
||||
LARGE_INTEGER offset;
|
||||
offset.QuadPart = off;
|
||||
|
||||
if (!SetFilePointerEx (fd, offset, NULL, FILE_BEGIN))
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||
name, strerror (errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_util_fd_t
|
||||
grub_util_fd_open (const char *os_dev, int flags)
|
||||
{
|
||||
DWORD flg = 0;
|
||||
LPTSTR dev = grub_util_get_windows_path (os_dev);
|
||||
grub_util_fd_t ret;
|
||||
|
||||
if (flags & O_WRONLY)
|
||||
flg |= GENERIC_WRITE;
|
||||
if (flags & O_RDONLY)
|
||||
flg |= GENERIC_READ;
|
||||
flg = GENERIC_READ;
|
||||
ret = CreateFile (dev, flg, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
0, OPEN_EXISTING, 0, 0);
|
||||
free (dev);
|
||||
grub_util_info ("handle = %p", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
grub_util_fd_read (grub_util_fd_t fd, char *buf, size_t len)
|
||||
{
|
||||
DWORD real_read;
|
||||
if (!ReadFile(fd, buf, len, &real_read, NULL))
|
||||
{
|
||||
grub_util_info ("read err %x", (int) GetLastError ());
|
||||
return -1;
|
||||
}
|
||||
grub_util_info ("successful read");
|
||||
return real_read;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
|
||||
{
|
||||
DWORD real_read;
|
||||
if (!WriteFile(fd, buf, len, &real_read, NULL))
|
||||
{
|
||||
grub_util_info ("write err %x", (int) GetLastError ());
|
||||
return -1;
|
||||
}
|
||||
|
||||
grub_util_info ("successful write");
|
||||
return real_read;
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_fd_sync (grub_util_fd_t fd)
|
||||
{
|
||||
FlushFileBuffers (fd);
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_fd_close (grub_util_fd_t fd)
|
||||
{
|
||||
CloseHandle (fd);
|
||||
}
|
||||
|
||||
const char *
|
||||
grub_util_fd_strerror (void)
|
||||
{
|
||||
DWORD err;
|
||||
static TCHAR tbuf[1024];
|
||||
err = GetLastError ();
|
||||
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, err,
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
tbuf, ARRAY_SIZE (tbuf), NULL);
|
||||
|
||||
#if SIZEOF_TCHAR == 1
|
||||
return (char *) tbuf;
|
||||
#elif SIZEOF_TCHAR == 2
|
||||
static grub_uint8_t buf[ARRAY_SIZE (tbuf) * GRUB_MAX_UTF8_PER_UTF16 + 1];
|
||||
*grub_utf16_to_utf8 (buf, tbuf, ARRAY_SIZE (tbuf)) = '\0';
|
||||
return (char *) buf;
|
||||
#else
|
||||
#error "Unsupported TCHAR size"
|
||||
#endif
|
||||
}
|
||||
|
||||
char *
|
||||
canonicalize_file_name (const char *path)
|
||||
{
|
||||
char *ret;
|
||||
ret = xmalloc (PATH_MAX);
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
if (!_fullpath (ret, path, PATH_MAX))
|
||||
return NULL;
|
||||
#else
|
||||
if (!realpath (path, ret))
|
||||
return NULL;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
55
grub-core/osdep/windows/random.c
Normal file
55
grub-core/osdep/windows/random.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1992-1999,2001,2003,2004,2005,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/auth.h>
|
||||
#include <grub/emu/misc.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
int
|
||||
grub_get_random (void *out, grub_size_t len)
|
||||
{
|
||||
HCRYPTPROV hCryptProv;
|
||||
if (!CryptAcquireContext (&hCryptProv,
|
||||
NULL,
|
||||
MS_DEF_PROV,
|
||||
PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT))
|
||||
return 1;
|
||||
if (!CryptGenRandom (hCryptProv, len, out))
|
||||
{
|
||||
CryptReleaseContext (hCryptProv, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
CryptReleaseContext (hCryptProv, 0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue