Define GRUB_UTIL_FD_O_* and always use them with grub_util_fd_open.
This commit is contained in:
parent
84379b61d2
commit
6de292cb9b
8 changed files with 67 additions and 19 deletions
|
@ -1,3 +1,7 @@
|
|||
2013-10-14 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
Define GRUB_UTIL_FD_O_* and always use them with grub_util_fd_open.
|
||||
|
||||
2013-10-14 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* include/grub/osdep/hostfile_windows.h (grub_util_utf8_to_tchar): Add
|
||||
|
|
|
@ -505,7 +505,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)
|
|||
if (dev->cheat)
|
||||
{
|
||||
if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd))
|
||||
dev->cheat_fd = grub_util_fd_open (dev->cheat, O_RDONLY);
|
||||
dev->cheat_fd = grub_util_fd_open (dev->cheat, GRUB_UTIL_FD_O_RDONLY);
|
||||
if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd))
|
||||
return grub_error (GRUB_ERR_IO, N_("cannot open `%s': %s"),
|
||||
dev->cheat, strerror (errno));
|
||||
|
|
|
@ -210,7 +210,7 @@ make_uuid (const struct grub_geli_phdr *header,
|
|||
char *
|
||||
grub_util_get_geli_uuid (const char *dev)
|
||||
{
|
||||
grub_util_fd_t fd = grub_util_fd_open (dev, O_RDONLY);
|
||||
grub_util_fd_t fd = grub_util_fd_open (dev, GRUB_UTIL_FD_O_RDONLY);
|
||||
grub_uint64_t s;
|
||||
unsigned log_secsize;
|
||||
grub_uint8_t hdr[512];
|
||||
|
|
|
@ -151,7 +151,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
{
|
||||
grub_util_fd_t fd;
|
||||
|
||||
fd = grub_util_fd_open (map[drive].device, O_RDONLY);
|
||||
fd = grub_util_fd_open (map[drive].device, GRUB_UTIL_FD_O_RDONLY);
|
||||
|
||||
if (!GRUB_UTIL_FD_IS_VALID(fd))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("cannot open `%s': %s"),
|
||||
|
@ -232,12 +232,7 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
|
|||
|
||||
*max = ~0ULL;
|
||||
|
||||
#ifdef O_SYNC
|
||||
flags |= O_SYNC;
|
||||
#endif
|
||||
#ifdef O_FSYNC
|
||||
flags |= O_FSYNC;
|
||||
#endif
|
||||
flags |= GRUB_UTIL_FD_O_SYNC;
|
||||
|
||||
if (data->dev && strcmp (data->dev, map[disk->id].device) == 0 &&
|
||||
data->access_mode == (flags & O_ACCMODE))
|
||||
|
@ -293,7 +288,7 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
{
|
||||
grub_util_fd_t fd;
|
||||
grub_disk_addr_t max = ~0ULL;
|
||||
fd = grub_util_fd_open_device (disk, sector, O_RDONLY, &max);
|
||||
fd = grub_util_fd_open_device (disk, sector, GRUB_UTIL_FD_O_RDONLY, &max);
|
||||
if (!GRUB_UTIL_FD_IS_VALID (fd))
|
||||
return grub_errno;
|
||||
|
||||
|
@ -328,7 +323,7 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
{
|
||||
grub_util_fd_t fd;
|
||||
grub_disk_addr_t max = ~0ULL;
|
||||
fd = grub_util_fd_open_device (disk, sector, O_WRONLY, &max);
|
||||
fd = grub_util_fd_open_device (disk, sector, GRUB_UTIL_FD_O_WRONLY, &max);
|
||||
if (!GRUB_UTIL_FD_IS_VALID (fd))
|
||||
return grub_errno;
|
||||
|
||||
|
@ -364,7 +359,7 @@ grub_util_biosdisk_flush (struct grub_disk *disk)
|
|||
if (!GRUB_UTIL_FD_IS_VALID (data->fd))
|
||||
{
|
||||
grub_disk_addr_t max;
|
||||
data->fd = grub_util_fd_open_device (disk, 0, O_RDONLY, &max);
|
||||
data->fd = grub_util_fd_open_device (disk, 0, GRUB_UTIL_FD_O_RDONLY, &max);
|
||||
if (!GRUB_UTIL_FD_IS_VALID (data->fd))
|
||||
return grub_errno;
|
||||
}
|
||||
|
@ -408,7 +403,7 @@ grub_util_check_file_presence (const char *p)
|
|||
{
|
||||
#if defined (__MINGW32__) || defined(__CYGWIN__)
|
||||
HANDLE h;
|
||||
h = grub_util_fd_open (p, O_RDONLY);
|
||||
h = grub_util_fd_open (p, GRUB_UTIL_FD_O_RDONLY);
|
||||
if (!GRUB_UTIL_FD_IS_VALID(h))
|
||||
return 0;
|
||||
CloseHandle (h);
|
||||
|
|
|
@ -194,19 +194,23 @@ grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
|||
grub_util_fd_t
|
||||
grub_util_fd_open (const char *os_dev, int flags)
|
||||
{
|
||||
DWORD flg = 0;
|
||||
DWORD flg = 0, crt;
|
||||
LPTSTR dev = grub_util_get_windows_path (os_dev);
|
||||
grub_util_fd_t ret;
|
||||
|
||||
if (flags & O_WRONLY)
|
||||
if (flags & GRUB_UTIL_FD_O_WRONLY)
|
||||
flg |= GENERIC_WRITE;
|
||||
if (flags & O_RDONLY)
|
||||
if (flags & GRUB_UTIL_FD_O_RDONLY)
|
||||
flg |= GENERIC_READ;
|
||||
flg = GENERIC_READ;
|
||||
|
||||
if (flags & GRUB_UTIL_FD_O_CREATTRUNC)
|
||||
crt = CREATE_ALWAYS;
|
||||
else
|
||||
crt = OPEN_EXISTING;
|
||||
|
||||
ret = CreateFile (dev, flg, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
0, OPEN_EXISTING, 0, 0);
|
||||
0, crt, 0, 0);
|
||||
free (dev);
|
||||
grub_util_info ("handle = %p", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,22 @@ struct grub_util_fd
|
|||
};
|
||||
typedef struct grub_util_fd *grub_util_fd_t;
|
||||
|
||||
enum grub_util_fd_open_flags_t
|
||||
{
|
||||
GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
|
||||
GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
|
||||
GRUB_UTIL_FD_O_RDWR = O_RDWR,
|
||||
GRUB_UTIL_FD_O_CREAT = O_CREAT,
|
||||
GRUB_UTIL_FD_O_SYNC = (0
|
||||
#ifdef O_SYNC
|
||||
| O_SYNC
|
||||
#endif
|
||||
#ifdef O_FSYNC
|
||||
| O_FSYNC
|
||||
#endif
|
||||
)
|
||||
};
|
||||
|
||||
#define GRUB_UTIL_FD_INVALID NULL
|
||||
#define GRUB_UTIL_FD_IS_VALID(x) ((x) != GRUB_UTIL_FD_INVALID)
|
||||
#define GRUB_UTIL_FD_STAT_IS_FUNCTIONAL 0
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include <grub/symbol.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if defined (__NetBSD__)
|
||||
/* NetBSD uses /boot for its boot block. */
|
||||
# define DEFAULT_DIRECTORY "/"GRUB_DIR_NAME
|
||||
|
@ -32,6 +36,22 @@
|
|||
# define DEFAULT_DIRECTORY "/"GRUB_BOOT_DIR_NAME"/"GRUB_DIR_NAME
|
||||
#endif
|
||||
|
||||
enum grub_util_fd_open_flags_t
|
||||
{
|
||||
GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
|
||||
GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
|
||||
GRUB_UTIL_FD_O_RDWR = O_RDWR,
|
||||
GRUB_UTIL_FD_O_CREATTRUNC = O_CREAT | O_TRUNC,
|
||||
GRUB_UTIL_FD_O_SYNC = (0
|
||||
#ifdef O_SYNC
|
||||
| O_SYNC
|
||||
#endif
|
||||
#ifdef O_FSYNC
|
||||
| O_FSYNC
|
||||
#endif
|
||||
)
|
||||
};
|
||||
|
||||
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
|
||||
|
||||
typedef int grub_util_fd_t;
|
||||
|
|
|
@ -31,6 +31,15 @@ typedef HANDLE grub_util_fd_t;
|
|||
#define DEFAULT_DIRECTORY "C:\\"GRUB_BOOT_DIR_NAME"\\"GRUB_DIR_NAME
|
||||
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
|
||||
|
||||
enum grub_util_fd_open_flags_t
|
||||
{
|
||||
GRUB_UTIL_FD_O_RDONLY = 1,
|
||||
GRUB_UTIL_FD_O_WRONLY = 2,
|
||||
GRUB_UTIL_FD_O_RDWR = 3,
|
||||
GRUB_UTIL_FD_O_CREATTRUNC = 4,
|
||||
GRUB_UTIL_FD_O_SYNC = 0,
|
||||
};
|
||||
|
||||
LPTSTR
|
||||
grub_util_utf8_to_tchar (const char *in);
|
||||
char *
|
||||
|
|
Loading…
Reference in a new issue