2002-12-27 08:53:07 +00:00
|
|
|
/* fat.c - FAT filesystem */
|
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2009-02-14 14:38:50 +00:00
|
|
|
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
|
2002-12-27 08:53:07 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2002-12-27 08:53:07 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2002-12-27 08:53:07 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2002-12-27 08:53:07 +00:00
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2002-12-27 08:53:07 +00:00
|
|
|
*/
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/fs.h>
|
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/types.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/err.h>
|
|
|
|
#include <grub/dl.h>
|
2009-11-09 17:43:53 +00:00
|
|
|
#include <grub/charset.h>
|
2011-04-05 12:40:15 +00:00
|
|
|
#include <grub/fat.h>
|
2004-04-04 13:46:03 +00:00
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
2011-10-19 18:19:25 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
GRUB_FAT_ATTR_READ_ONLY = 0x01,
|
|
|
|
GRUB_FAT_ATTR_HIDDEN = 0x02,
|
|
|
|
GRUB_FAT_ATTR_SYSTEM = 0x04,
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2011-10-19 18:19:25 +00:00
|
|
|
GRUB_FAT_ATTR_VOLUME_ID = 0x08,
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2011-10-19 18:19:25 +00:00
|
|
|
GRUB_FAT_ATTR_DIRECTORY = 0x10,
|
|
|
|
GRUB_FAT_ATTR_ARCHIVE = 0x20,
|
2008-07-27 14:46:45 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2011-10-19 18:19:25 +00:00
|
|
|
GRUB_FAT_ATTR_LONG_NAME = (GRUB_FAT_ATTR_READ_ONLY
|
|
|
|
| GRUB_FAT_ATTR_HIDDEN
|
|
|
|
| GRUB_FAT_ATTR_SYSTEM
|
|
|
|
| GRUB_FAT_ATTR_VOLUME_ID),
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2011-10-19 18:19:25 +00:00
|
|
|
GRUB_FAT_ATTR_VALID = (GRUB_FAT_ATTR_READ_ONLY
|
|
|
|
| GRUB_FAT_ATTR_HIDDEN
|
|
|
|
| GRUB_FAT_ATTR_SYSTEM
|
|
|
|
| GRUB_FAT_ATTR_DIRECTORY
|
|
|
|
| GRUB_FAT_ATTR_ARCHIVE
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2011-10-19 18:19:25 +00:00
|
|
|
| GRUB_FAT_ATTR_VOLUME_ID
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2011-10-19 18:19:25 +00:00
|
|
|
)
|
|
|
|
};
|
2004-04-04 13:46:03 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
2011-10-19 18:19:25 +00:00
|
|
|
struct grub_exfat_bpb
|
2011-04-11 16:13:00 +00:00
|
|
|
{
|
|
|
|
grub_uint8_t jmp_boot[3];
|
|
|
|
grub_uint8_t oem_name[8];
|
|
|
|
grub_uint8_t mbz[53];
|
|
|
|
grub_uint64_t num_hidden_sectors;
|
|
|
|
grub_uint64_t num_total_sectors;
|
|
|
|
grub_uint32_t num_reserved_sectors;
|
|
|
|
grub_uint32_t sectors_per_fat;
|
|
|
|
grub_uint32_t cluster_offset;
|
|
|
|
grub_uint32_t cluster_count;
|
|
|
|
grub_uint32_t root_cluster;
|
|
|
|
grub_uint32_t num_serial;
|
|
|
|
grub_uint16_t fs_revision;
|
|
|
|
grub_uint16_t volume_flags;
|
|
|
|
grub_uint8_t bytes_per_sector_shift;
|
|
|
|
grub_uint8_t sectors_per_cluster_shift;
|
|
|
|
grub_uint8_t num_fats;
|
|
|
|
grub_uint8_t num_ph_drive;
|
|
|
|
grub_uint8_t reserved[8];
|
|
|
|
} __attribute__ ((packed));
|
2011-10-19 18:19:25 +00:00
|
|
|
typedef struct grub_exfat_bpb grub_current_fat_bpb_t;
|
2011-04-11 16:13:00 +00:00
|
|
|
#else
|
2011-10-19 18:19:25 +00:00
|
|
|
typedef struct grub_fat_bpb grub_current_fat_bpb_t;
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
struct grub_fat_dir_entry
|
|
|
|
{
|
|
|
|
grub_uint8_t entry_type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
grub_uint8_t placeholder[31];
|
|
|
|
struct {
|
|
|
|
grub_uint8_t secondary_count;
|
|
|
|
grub_uint16_t checksum;
|
|
|
|
grub_uint16_t attr;
|
|
|
|
grub_uint16_t reserved1;
|
|
|
|
grub_uint32_t c_time;
|
|
|
|
grub_uint32_t m_time;
|
|
|
|
grub_uint32_t a_time;
|
|
|
|
grub_uint8_t c_time_tenth;
|
|
|
|
grub_uint8_t m_time_tenth;
|
|
|
|
grub_uint8_t a_time_tenth;
|
|
|
|
grub_uint8_t reserved2[9];
|
|
|
|
} __attribute__ ((packed)) file;
|
|
|
|
struct {
|
|
|
|
grub_uint8_t flags;
|
|
|
|
grub_uint8_t reserved1;
|
|
|
|
grub_uint8_t name_length;
|
|
|
|
grub_uint16_t name_hash;
|
|
|
|
grub_uint16_t reserved2;
|
|
|
|
grub_uint64_t valid_size;
|
|
|
|
grub_uint32_t reserved3;
|
|
|
|
grub_uint32_t first_cluster;
|
|
|
|
grub_uint64_t file_size;
|
|
|
|
} __attribute__ ((packed)) stream_extension;
|
|
|
|
struct {
|
|
|
|
grub_uint8_t flags;
|
|
|
|
grub_uint16_t str[15];
|
|
|
|
} __attribute__ ((packed)) file_name;
|
|
|
|
struct {
|
|
|
|
grub_uint8_t character_count;
|
|
|
|
grub_uint16_t str[11];
|
|
|
|
grub_uint8_t reserved[8];
|
|
|
|
} __attribute__ ((packed)) volume_label;
|
|
|
|
} __attribute__ ((packed)) type_specific;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct grub_fat_dir_node
|
|
|
|
{
|
|
|
|
grub_uint32_t attr;
|
|
|
|
grub_uint32_t first_cluster;
|
|
|
|
grub_uint64_t file_size;
|
|
|
|
grub_uint64_t valid_size;
|
|
|
|
int have_stream;
|
|
|
|
int is_label;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct grub_fat_dir_node grub_fat_dir_node_t;
|
|
|
|
|
|
|
|
#else
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_dir_entry
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint8_t name[11];
|
|
|
|
grub_uint8_t attr;
|
|
|
|
grub_uint8_t nt_reserved;
|
|
|
|
grub_uint8_t c_time_tenth;
|
|
|
|
grub_uint16_t c_time;
|
|
|
|
grub_uint16_t c_date;
|
|
|
|
grub_uint16_t a_date;
|
|
|
|
grub_uint16_t first_cluster_high;
|
|
|
|
grub_uint16_t w_time;
|
|
|
|
grub_uint16_t w_date;
|
|
|
|
grub_uint16_t first_cluster_low;
|
|
|
|
grub_uint32_t file_size;
|
2002-12-27 08:53:07 +00:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_long_name_entry
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint8_t id;
|
|
|
|
grub_uint16_t name1[5];
|
|
|
|
grub_uint8_t attr;
|
|
|
|
grub_uint8_t reserved;
|
|
|
|
grub_uint8_t checksum;
|
|
|
|
grub_uint16_t name2[6];
|
|
|
|
grub_uint16_t first_cluster;
|
|
|
|
grub_uint16_t name3[2];
|
2002-12-27 08:53:07 +00:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
typedef struct grub_fat_dir_entry grub_fat_dir_node_t;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_data
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
int logical_sector_bits;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t num_sectors;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint16_t fat_sector;
|
|
|
|
grub_uint32_t sectors_per_fat;
|
2002-12-27 08:53:07 +00:00
|
|
|
int fat_size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t root_cluster;
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t root_sector;
|
|
|
|
grub_uint32_t num_root_sectors;
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
int cluster_bits;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t cluster_eof_mark;
|
|
|
|
grub_uint32_t cluster_sector;
|
|
|
|
grub_uint32_t num_clusters;
|
|
|
|
|
|
|
|
grub_uint8_t attr;
|
|
|
|
grub_ssize_t file_size;
|
|
|
|
grub_uint32_t file_cluster;
|
|
|
|
grub_uint32_t cur_cluster_num;
|
|
|
|
grub_uint32_t cur_cluster;
|
2008-06-01 13:30:00 +00:00
|
|
|
|
2008-07-01 23:18:25 +00:00
|
|
|
grub_uint32_t uuid;
|
2002-12-27 08:53:07 +00:00
|
|
|
};
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_dl_t my_mod;
|
2003-01-06 00:01:35 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2002-12-27 08:53:07 +00:00
|
|
|
static int
|
2004-03-14 17:48:25 +00:00
|
|
|
fat_log2 (unsigned x)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
if (x == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; (x & 1) == 0; i++)
|
|
|
|
x >>= 1;
|
|
|
|
|
|
|
|
if (x != 1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static struct grub_fat_data *
|
|
|
|
grub_fat_mount (grub_disk_t disk)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2011-10-19 18:19:25 +00:00
|
|
|
grub_current_fat_bpb_t bpb;
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_data *data = 0;
|
|
|
|
grub_uint32_t first_fat, magic;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
if (! disk)
|
|
|
|
goto fail;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
data = (struct grub_fat_data *) grub_malloc (sizeof (*data));
|
2002-12-27 08:53:07 +00:00
|
|
|
if (! data)
|
|
|
|
goto fail;
|
2003-01-02 23:46:21 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
/* Read the BPB. */
|
2009-05-13 18:58:38 +00:00
|
|
|
if (grub_disk_read (disk, 0, 0, sizeof (bpb), &bpb))
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
if (grub_memcmp ((const char *) bpb.oem_name, "EXFAT ",
|
|
|
|
sizeof (bpb.oem_name)) != 0)
|
|
|
|
goto fail;
|
|
|
|
#else
|
2009-02-10 09:50:08 +00:00
|
|
|
if (grub_strncmp((const char *) bpb.version_specific.fat12_or_fat16.fstype, "FAT12", 5)
|
|
|
|
&& grub_strncmp((const char *) bpb.version_specific.fat12_or_fat16.fstype, "FAT16", 5)
|
|
|
|
&& grub_strncmp((const char *) bpb.version_specific.fat32.fstype, "FAT32", 5))
|
2009-02-09 14:17:19 +00:00
|
|
|
goto fail;
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
/* Get the sizes of logical sectors and clusters. */
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->logical_sector_bits = bpb.bytes_per_sector_shift;
|
|
|
|
#else
|
2004-03-14 17:48:25 +00:00
|
|
|
data->logical_sector_bits =
|
2004-04-04 13:46:03 +00:00
|
|
|
fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector));
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
|
|
|
if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS
|
|
|
|
|| data->logical_sector_bits >= 16)
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
2004-04-04 13:46:03 +00:00
|
|
|
data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->cluster_bits = bpb.sectors_per_cluster_shift;
|
|
|
|
#else
|
2004-03-14 17:48:25 +00:00
|
|
|
data->cluster_bits = fat_log2 (bpb.sectors_per_cluster);
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
|
|
|
if (data->cluster_bits < 0 || data->cluster_bits > 25)
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
|
|
|
data->cluster_bits += data->logical_sector_bits;
|
|
|
|
|
|
|
|
/* Get information about FATs. */
|
2004-04-04 13:46:03 +00:00
|
|
|
data->fat_sector = (grub_le_to_cpu16 (bpb.num_reserved_sectors)
|
2002-12-27 08:53:07 +00:00
|
|
|
<< data->logical_sector_bits);
|
|
|
|
if (data->fat_sector == 0)
|
|
|
|
goto fail;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->sectors_per_fat = (grub_le_to_cpu32 (bpb.sectors_per_fat)
|
|
|
|
<< data->logical_sector_bits);
|
|
|
|
#else
|
2002-12-27 08:53:07 +00:00
|
|
|
data->sectors_per_fat = ((bpb.sectors_per_fat_16
|
2004-04-04 13:46:03 +00:00
|
|
|
? grub_le_to_cpu16 (bpb.sectors_per_fat_16)
|
2008-06-01 13:30:00 +00:00
|
|
|
: grub_le_to_cpu32 (bpb.version_specific.fat32.sectors_per_fat_32))
|
2002-12-27 08:53:07 +00:00
|
|
|
<< data->logical_sector_bits);
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
if (data->sectors_per_fat == 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Get the number of sectors in this volume. */
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->num_sectors = ((grub_le_to_cpu64 (bpb.num_total_sectors))
|
|
|
|
<< data->logical_sector_bits);
|
|
|
|
#else
|
2002-12-27 08:53:07 +00:00
|
|
|
data->num_sectors = ((bpb.num_total_sectors_16
|
2004-04-04 13:46:03 +00:00
|
|
|
? grub_le_to_cpu16 (bpb.num_total_sectors_16)
|
|
|
|
: grub_le_to_cpu32 (bpb.num_total_sectors_32))
|
2002-12-27 08:53:07 +00:00
|
|
|
<< data->logical_sector_bits);
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
if (data->num_sectors == 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Get information about the root directory. */
|
|
|
|
if (bpb.num_fats == 0)
|
|
|
|
goto fail;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2002-12-27 08:53:07 +00:00
|
|
|
data->root_sector = data->fat_sector + bpb.num_fats * data->sectors_per_fat;
|
|
|
|
data->num_root_sectors
|
2004-04-04 13:46:03 +00:00
|
|
|
= ((((grub_uint32_t) grub_le_to_cpu16 (bpb.num_root_entries)
|
2011-10-19 18:19:25 +00:00
|
|
|
* sizeof (struct grub_fat_dir_entry)
|
2004-04-04 13:46:03 +00:00
|
|
|
+ grub_le_to_cpu16 (bpb.bytes_per_sector) - 1)
|
|
|
|
>> (data->logical_sector_bits + GRUB_DISK_SECTOR_BITS))
|
2002-12-27 08:53:07 +00:00
|
|
|
<< (data->logical_sector_bits));
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->cluster_sector = (grub_le_to_cpu32 (bpb.cluster_offset)
|
|
|
|
<< data->logical_sector_bits);
|
|
|
|
data->num_clusters = (grub_le_to_cpu32 (bpb.cluster_count)
|
|
|
|
<< data->logical_sector_bits);
|
|
|
|
#else
|
2002-12-27 08:53:07 +00:00
|
|
|
data->cluster_sector = data->root_sector + data->num_root_sectors;
|
|
|
|
data->num_clusters = (((data->num_sectors - data->cluster_sector)
|
|
|
|
>> (data->cluster_bits + data->logical_sector_bits))
|
|
|
|
+ 2);
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
if (data->num_clusters <= 2)
|
|
|
|
goto fail;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
{
|
|
|
|
/* exFAT. */
|
|
|
|
grub_uint16_t flags = grub_le_to_cpu16 (bpb.volume_flags);
|
|
|
|
|
|
|
|
data->root_cluster = grub_le_to_cpu32 (bpb.root_cluster);
|
|
|
|
data->fat_size = 32;
|
|
|
|
data->cluster_eof_mark = 0xffffffff;
|
|
|
|
|
|
|
|
if ((flags & 0x1) && bpb.num_fats > 1)
|
|
|
|
data->fat_sector += data->sectors_per_fat;
|
|
|
|
}
|
|
|
|
#else
|
2002-12-27 08:53:07 +00:00
|
|
|
if (! bpb.sectors_per_fat_16)
|
|
|
|
{
|
|
|
|
/* FAT32. */
|
2008-06-01 13:30:00 +00:00
|
|
|
grub_uint16_t flags = grub_le_to_cpu16 (bpb.version_specific.fat32.extended_flags);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2008-06-01 13:30:00 +00:00
|
|
|
data->root_cluster = grub_le_to_cpu32 (bpb.version_specific.fat32.root_cluster);
|
2002-12-27 08:53:07 +00:00
|
|
|
data->fat_size = 32;
|
|
|
|
data->cluster_eof_mark = 0x0ffffff8;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
if (flags & 0x80)
|
|
|
|
{
|
|
|
|
/* Get an active FAT. */
|
|
|
|
unsigned active_fat = flags & 0xf;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
if (active_fat > bpb.num_fats)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
data->fat_sector += active_fat * data->sectors_per_fat;
|
|
|
|
}
|
|
|
|
|
2008-06-01 13:30:00 +00:00
|
|
|
if (bpb.num_root_entries != 0 || bpb.version_specific.fat32.fs_version != 0)
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FAT12 or FAT16. */
|
2007-05-17 15:43:32 +00:00
|
|
|
data->root_cluster = ~0U;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
if (data->num_clusters <= 4085 + 2)
|
|
|
|
{
|
|
|
|
/* FAT12. */
|
|
|
|
data->fat_size = 12;
|
|
|
|
data->cluster_eof_mark = 0x0ff8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FAT16. */
|
|
|
|
data->fat_size = 16;
|
|
|
|
data->cluster_eof_mark = 0xfff8;
|
|
|
|
}
|
|
|
|
}
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
/* More sanity checks. */
|
|
|
|
if (data->num_sectors <= data->fat_sector)
|
|
|
|
goto fail;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
if (grub_disk_read (disk,
|
2002-12-27 08:53:07 +00:00
|
|
|
data->fat_sector,
|
|
|
|
0,
|
|
|
|
sizeof (first_fat),
|
2009-05-13 18:58:38 +00:00
|
|
|
&first_fat))
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
first_fat = grub_le_to_cpu32 (first_fat);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
if (data->fat_size == 32)
|
|
|
|
{
|
|
|
|
first_fat &= 0x0fffffff;
|
|
|
|
magic = 0x0fffff00;
|
|
|
|
}
|
|
|
|
else if (data->fat_size == 16)
|
|
|
|
{
|
|
|
|
first_fat &= 0x0000ffff;
|
|
|
|
magic = 0xff00;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first_fat &= 0x00000fff;
|
|
|
|
magic = 0x0f00;
|
|
|
|
}
|
2008-06-01 13:30:00 +00:00
|
|
|
|
|
|
|
/* Serial number. */
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->uuid = grub_le_to_cpu32 (bpb.num_serial);
|
|
|
|
#else
|
2008-06-01 13:30:00 +00:00
|
|
|
if (bpb.sectors_per_fat_16)
|
2008-07-01 23:18:25 +00:00
|
|
|
data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat12_or_fat16.num_serial);
|
2008-06-01 13:30:00 +00:00
|
|
|
else
|
2008-07-01 23:18:25 +00:00
|
|
|
data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat32.num_serial);
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2005-03-18 18:16:26 +00:00
|
|
|
/* Ignore the 3rd bit, because some BIOSes assigns 0xF0 to the media
|
|
|
|
descriptor, even if it is a so-called superfloppy (e.g. an USB key).
|
|
|
|
The check may be too strict for this kind of stupid BIOSes, as
|
|
|
|
they overwrite the media descriptor. */
|
|
|
|
if ((first_fat | 0x8) != (magic | bpb.media | 0x8))
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
2011-10-19 18:19:25 +00:00
|
|
|
#else
|
|
|
|
(void) magic;
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
/* Start from the root directory. */
|
|
|
|
data->file_cluster = data->root_cluster;
|
2007-05-17 15:43:32 +00:00
|
|
|
data->cur_cluster_num = ~0U;
|
2004-04-04 13:46:03 +00:00
|
|
|
data->attr = GRUB_FAT_ATTR_DIRECTORY;
|
2002-12-27 08:53:07 +00:00
|
|
|
return data;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (data);
|
2009-12-25 00:04:51 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FS, "not a FAT filesystem");
|
2002-12-27 08:53:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_ssize_t
|
|
|
|
grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data,
|
2007-08-02 18:40:37 +00:00
|
|
|
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
|
2002-12-27 08:53:07 +00:00
|
|
|
unsigned offset, unsigned length),
|
2006-06-04 Yoshinori K. Okuji <okuji@enbug.org>
Clean up the code to support 64-bit addressing in disks and
files. This change is not enough for filesystems yet.
* util/i386/pc/grub-setup.c (struct boot_blocklist): Change the
type of "start" to grub_uint64_t.
(setup): Change the types of KERNEL_SECTOR and FIRST_SECTOR to
grub_disk_addr_t * and grub_disk_addr_t. Fix the format string in
save_first_sector and save_blocklists. Use grub_le_to_cpu64 to
convert addresses.
* util/i386/pc/biosdisk.c (open_device): Change the type of SECTOR
to grub_disk_addr_t.
* partmap/gpt.c (gpt_partition_map_iterate): Fix the format
string.
* partmap/pc.c (pc_partition_map_iterate): Likewise.
* partmap/amiga.c (amiga_partition_map_iterate): Cast RDSK.MAGIC
to char *.
* normal/script.c (grub_script_parse): Remove unused MEMFREE.
* normal/parser.y (YYLTYPE_IS_TRIVIAL): New macro.
* normal/lexer.c (grub_script_yyerror): Specify unused to LEX.
* loader/i386/pc/multiboot.c (grub_multiboot_load_elf64): Cast -1
to grub_off_t, to detect an error from grub_file_seek.
(grub_multiboot_load_elf32): Likewise.
* kern/misc.c (grub_strtoul): Use grub_strtoull. Return the
maximum unsigned long value when an overflow is detected.
(grub_strtoull): New function.
(grub_divmod64): Likewise.
(grub_lltoa): use grub_divmod64.
* kern/fs.c (struct grub_fs_block): Change the type of "offset" to
grub_disk_addr_t.
(grub_fs_blocklist_open): Increase P if P is not NULL to advance
the pointer to next character. Use grub_strtoull instead of
grub_strtoul.
(grub_fs_blocklist_read): Change the types of SECTOR, OFFSET and
SIZE to grub_disk_addr_t, grub_off_t and grub_size_t,
respectively.
* kern/file.c (grub_file_read): Prevent an oveflow of LEN, as the
return value is signed.
(grub_file_seek): Change the type of OLD to grub_off_t. Do not
test if OFFSET is less than zero, as OFFSET is unsigned now.
* kern/disk.c (struct grub_disk_cache): Change the type of
"sector" to grub_disk_addr_t.
(grub_disk_cache_get_index): Change the type of SECTOR to
grub_disk_addr_t. Calculate the hash with SECTOR casted to
unsigned after shifting.
(grub_disk_cache_invalidate): Change the type of SECTOR to
grub_disk_addr_t.
(grub_disk_cache_unlock): Likewise.
(grub_disk_cache_store): Likewise.
(grub_disk_check_range): Change the types of SECTOR, OFFSET, SIZE,
START and LEN to grub_disk_addr_t *, grub_off_t *, grub_size_t,
grub_disk_addr_t and grub_uint64_t, respectively.
(grub_disk_read): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of START_SECTOR, LEN and
POS to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
(grub_disk_write): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of LEN and N to
grub_size_t.
* io/gzio.c (struct grub_gzio): Change the types of "data_offset"
and "saved_offset" to grub_off_t.
(test_header): Cast BUF to char *.
(get_byte): Cast GZIO->DATA_OFFSET to grub_off_t. Cast GZIO->INBUF
to char *.
(grub_gzio_read): Change the types of OFFSET and SIZE to
grub_off_t and grub_size_t, respectively.
* include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_FORCE_LBA):
Removed.
(GRUB_BOOT_MACHINE_BOOT_DRIVE): Changed to 0x4c.
(GRUB_BOOT_MACHINE_KERNEL_ADDRESS): Changed to 0x40.
(GRUB_BOOT_MACHINE_KERNEL_SEGMENT): Changed to 0x42.
(GRUB_BOOT_MACHINE_DRIVE_CHECK): Changed to 0x4e.
(GRUB_BOOT_MACHINE_LIST_SIZE): Increased to 12.
* include/grub/types.h (grub_off_t): Unconditionally set to
grub_uint64_t.
(grub_disk_addr_t): Changed to grub_uint64_t.
* include/grub/partition.h (struct grub_partition): Change the
types of "start", "len" and "offset" to grub_disk_addr_t,
grub_uint64_t and grub_disk_addr_t, respectively.
(grub_partition_get_start): Return grub_disk_addr_t.
(grub_partition_get_len): Return grub_uint64_t.
* include/grub/misc.h (grub_strtoull): New prototype.
(grub_divmod64): Likewise.
* include/grub/fshelp.h (grub_fshelp_read_file): Change the types
of SECTOR, LEN and FILESIZE to grub_disk_addr_t, grub_size_t and
grub_off_t, respectively.
All callers and references changed.
* include/grub/fs.h (struct grub_fs): Change the type of LEN to
grub_size_t in "read".
All callers and references changed.
* include/grub/file.h (struct grub_file): Change the types of
"offset" and "size" to grub_off_t and grub_off_t,
respectively. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_file_read): Change the type of LEN to grub_size_t.
(grub_file_seek): Return grub_off_t. Change the type of OFFSET to
grub_off_t.
(grub_file_size): Return grub_off_t.
(grub_file_tell): Likewise.
All callers and references changed.
* include/grub/disk.h (struct grub_disk_dev): Change the types of
SECTOR and SIZE to grub_disk_addr_t and grub_size_t in "read" and
"write".
(struct grub_disk): Change the type of "total_sectors" to
grub_uint64_t. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_disk_read): Change the types of SECTOR, OFFSET and SIZE to
grub_disk_addr_t, grub_off_t and grub_size_t, respectively.
(grub_disk_write): Likewise.
All callers and references changed.
* fs/iso9660.c (grub_iso9660_susp_iterate): Cast parameters to
char * for grub_strncmp to silence gcc.
(grub_iso9660_mount): Likewise.
(grub_iso9660_mount): Likewise.
(grub_iso9660_read_symlink): Likewise. Also, remove the nonsense
return statement.
(grub_iso9660_iterate_dir): Likewise.
(grub_iso9660_label): Cast DATA->VOLDESC.VOLNAME to char *.
* fs/hfs.c (grub_hfs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/hfsplus.c (grub_hfsplus_read_file): Likewise.
* fs/jfs.c (grub_jfs_read_file): Likewise.
* fs/minix.c (grub_jfs_read_file): Likewise.
* fs/sfs.c (grub_jfs_read_file): Likewise.
* fs/ufs.c (grub_jfs_read_file): Likewise.
* fs/xfs.c (grub_jfs_read_file): Likewise.
* fs/fat.c (grub_fat_read_data): Change the types of SECTOR, LEN
and SIZE to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
* fs/ext2.c (grub_ext2_read_block): When an error happens, set
BLKNR to -1 instead of returning GRUB_ERRNO.
(grub_ext2_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/affs.c (grub_affs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* font/manager.c (grub_font_get_glyph): Cast BITMAP to char * for
grub_file_read.
* disk/ieee1275/ofdisk.c (grub_ofdisk_read): Fix the format
string. Do not cast SECTOR explicitly.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Change the type of
TOTAL_SECTORS to grub_uint64_t. Do not mask DRP->TOTAL_SECTORS.
(grub_biosdisk_rw): Change the types of SECTOR and SIZE to
grub_disk_addr_t and grub_size_t, respectively. If the sector is
over 2TB and LBA mode is not supported, raise an error.
(get_safe_sectors): New function.
(grub_biosdisk_read): Use get_safe_sectors.
(grub_biosdisk_write): Likewise.
* disk/efi/efidisk.c (grub_efidisk_read): Fix the format string.
(grub_efidisk_write): Likewise.
* disk/loopback.c (delete_loopback): Cosmetic changes.
(grub_cmd_loopback): Likewise. Also, test NEWDEV->FILENAME
correctly.
(grub_loopback_open): Likewise.
(grub_loopback_read): Likewise. Also, change the type of POS to
grub_off_t, and fix the usage of grub_memset.
* commands/i386/pc/play.c: Include grub/machine/time.h.
* commands/ls.c (grub_ls_list_files): Use "llu" instead of "d" to
print FILE->SIZE.
* commands/configfile.c: Include grub/env.h.
* commands/cmp.c (grub_cmd_cmp): Do not use ERR, but use
GRUB_ERRNO directly instead. Change the type of POS to
grub_off_t. Follow the coding standard.
* commands/blocklist.c: Include grub/partition.h.
(grub_cmd_blocklist): Return an error if the underlying device is
not a disk. Take the starting sector of a partition into account,
if a partition is used.
* boot/i386/pc/diskboot.S (bootloop): Adapted to the new offset of
a length field.
(lba_mode): Support 64-bit addresses.
(chs_mode): Likewise.
(copy_buffer): Adapted to the new offsets of a length field and a
segment field.
(blocklist_default_start): Allocate 64-bit space.
* boot/i386/pc/boot.S (force_lba): Removed.
(boot_drive): Moved to under KERNEL_SECTOR.
(kernel_sector): Moved to under KENREL_SEGMENT. Allocate 64-bit
space.
(real_start): Set %si earlier. Remove code for FORCE_LBA, since it
is useless.
(lba_mode): Refactored to support a 64-bit address. More size
optimization.
(setup_sectors): Likewise.
2006-06-04 15:56:55 +00:00
|
|
|
grub_off_t offset, grub_size_t len, char *buf)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2006-06-04 Yoshinori K. Okuji <okuji@enbug.org>
Clean up the code to support 64-bit addressing in disks and
files. This change is not enough for filesystems yet.
* util/i386/pc/grub-setup.c (struct boot_blocklist): Change the
type of "start" to grub_uint64_t.
(setup): Change the types of KERNEL_SECTOR and FIRST_SECTOR to
grub_disk_addr_t * and grub_disk_addr_t. Fix the format string in
save_first_sector and save_blocklists. Use grub_le_to_cpu64 to
convert addresses.
* util/i386/pc/biosdisk.c (open_device): Change the type of SECTOR
to grub_disk_addr_t.
* partmap/gpt.c (gpt_partition_map_iterate): Fix the format
string.
* partmap/pc.c (pc_partition_map_iterate): Likewise.
* partmap/amiga.c (amiga_partition_map_iterate): Cast RDSK.MAGIC
to char *.
* normal/script.c (grub_script_parse): Remove unused MEMFREE.
* normal/parser.y (YYLTYPE_IS_TRIVIAL): New macro.
* normal/lexer.c (grub_script_yyerror): Specify unused to LEX.
* loader/i386/pc/multiboot.c (grub_multiboot_load_elf64): Cast -1
to grub_off_t, to detect an error from grub_file_seek.
(grub_multiboot_load_elf32): Likewise.
* kern/misc.c (grub_strtoul): Use grub_strtoull. Return the
maximum unsigned long value when an overflow is detected.
(grub_strtoull): New function.
(grub_divmod64): Likewise.
(grub_lltoa): use grub_divmod64.
* kern/fs.c (struct grub_fs_block): Change the type of "offset" to
grub_disk_addr_t.
(grub_fs_blocklist_open): Increase P if P is not NULL to advance
the pointer to next character. Use grub_strtoull instead of
grub_strtoul.
(grub_fs_blocklist_read): Change the types of SECTOR, OFFSET and
SIZE to grub_disk_addr_t, grub_off_t and grub_size_t,
respectively.
* kern/file.c (grub_file_read): Prevent an oveflow of LEN, as the
return value is signed.
(grub_file_seek): Change the type of OLD to grub_off_t. Do not
test if OFFSET is less than zero, as OFFSET is unsigned now.
* kern/disk.c (struct grub_disk_cache): Change the type of
"sector" to grub_disk_addr_t.
(grub_disk_cache_get_index): Change the type of SECTOR to
grub_disk_addr_t. Calculate the hash with SECTOR casted to
unsigned after shifting.
(grub_disk_cache_invalidate): Change the type of SECTOR to
grub_disk_addr_t.
(grub_disk_cache_unlock): Likewise.
(grub_disk_cache_store): Likewise.
(grub_disk_check_range): Change the types of SECTOR, OFFSET, SIZE,
START and LEN to grub_disk_addr_t *, grub_off_t *, grub_size_t,
grub_disk_addr_t and grub_uint64_t, respectively.
(grub_disk_read): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of START_SECTOR, LEN and
POS to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
(grub_disk_write): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of LEN and N to
grub_size_t.
* io/gzio.c (struct grub_gzio): Change the types of "data_offset"
and "saved_offset" to grub_off_t.
(test_header): Cast BUF to char *.
(get_byte): Cast GZIO->DATA_OFFSET to grub_off_t. Cast GZIO->INBUF
to char *.
(grub_gzio_read): Change the types of OFFSET and SIZE to
grub_off_t and grub_size_t, respectively.
* include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_FORCE_LBA):
Removed.
(GRUB_BOOT_MACHINE_BOOT_DRIVE): Changed to 0x4c.
(GRUB_BOOT_MACHINE_KERNEL_ADDRESS): Changed to 0x40.
(GRUB_BOOT_MACHINE_KERNEL_SEGMENT): Changed to 0x42.
(GRUB_BOOT_MACHINE_DRIVE_CHECK): Changed to 0x4e.
(GRUB_BOOT_MACHINE_LIST_SIZE): Increased to 12.
* include/grub/types.h (grub_off_t): Unconditionally set to
grub_uint64_t.
(grub_disk_addr_t): Changed to grub_uint64_t.
* include/grub/partition.h (struct grub_partition): Change the
types of "start", "len" and "offset" to grub_disk_addr_t,
grub_uint64_t and grub_disk_addr_t, respectively.
(grub_partition_get_start): Return grub_disk_addr_t.
(grub_partition_get_len): Return grub_uint64_t.
* include/grub/misc.h (grub_strtoull): New prototype.
(grub_divmod64): Likewise.
* include/grub/fshelp.h (grub_fshelp_read_file): Change the types
of SECTOR, LEN and FILESIZE to grub_disk_addr_t, grub_size_t and
grub_off_t, respectively.
All callers and references changed.
* include/grub/fs.h (struct grub_fs): Change the type of LEN to
grub_size_t in "read".
All callers and references changed.
* include/grub/file.h (struct grub_file): Change the types of
"offset" and "size" to grub_off_t and grub_off_t,
respectively. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_file_read): Change the type of LEN to grub_size_t.
(grub_file_seek): Return grub_off_t. Change the type of OFFSET to
grub_off_t.
(grub_file_size): Return grub_off_t.
(grub_file_tell): Likewise.
All callers and references changed.
* include/grub/disk.h (struct grub_disk_dev): Change the types of
SECTOR and SIZE to grub_disk_addr_t and grub_size_t in "read" and
"write".
(struct grub_disk): Change the type of "total_sectors" to
grub_uint64_t. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_disk_read): Change the types of SECTOR, OFFSET and SIZE to
grub_disk_addr_t, grub_off_t and grub_size_t, respectively.
(grub_disk_write): Likewise.
All callers and references changed.
* fs/iso9660.c (grub_iso9660_susp_iterate): Cast parameters to
char * for grub_strncmp to silence gcc.
(grub_iso9660_mount): Likewise.
(grub_iso9660_mount): Likewise.
(grub_iso9660_read_symlink): Likewise. Also, remove the nonsense
return statement.
(grub_iso9660_iterate_dir): Likewise.
(grub_iso9660_label): Cast DATA->VOLDESC.VOLNAME to char *.
* fs/hfs.c (grub_hfs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/hfsplus.c (grub_hfsplus_read_file): Likewise.
* fs/jfs.c (grub_jfs_read_file): Likewise.
* fs/minix.c (grub_jfs_read_file): Likewise.
* fs/sfs.c (grub_jfs_read_file): Likewise.
* fs/ufs.c (grub_jfs_read_file): Likewise.
* fs/xfs.c (grub_jfs_read_file): Likewise.
* fs/fat.c (grub_fat_read_data): Change the types of SECTOR, LEN
and SIZE to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
* fs/ext2.c (grub_ext2_read_block): When an error happens, set
BLKNR to -1 instead of returning GRUB_ERRNO.
(grub_ext2_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/affs.c (grub_affs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* font/manager.c (grub_font_get_glyph): Cast BITMAP to char * for
grub_file_read.
* disk/ieee1275/ofdisk.c (grub_ofdisk_read): Fix the format
string. Do not cast SECTOR explicitly.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Change the type of
TOTAL_SECTORS to grub_uint64_t. Do not mask DRP->TOTAL_SECTORS.
(grub_biosdisk_rw): Change the types of SECTOR and SIZE to
grub_disk_addr_t and grub_size_t, respectively. If the sector is
over 2TB and LBA mode is not supported, raise an error.
(get_safe_sectors): New function.
(grub_biosdisk_read): Use get_safe_sectors.
(grub_biosdisk_write): Likewise.
* disk/efi/efidisk.c (grub_efidisk_read): Fix the format string.
(grub_efidisk_write): Likewise.
* disk/loopback.c (delete_loopback): Cosmetic changes.
(grub_cmd_loopback): Likewise. Also, test NEWDEV->FILENAME
correctly.
(grub_loopback_open): Likewise.
(grub_loopback_read): Likewise. Also, change the type of POS to
grub_off_t, and fix the usage of grub_memset.
* commands/i386/pc/play.c: Include grub/machine/time.h.
* commands/ls.c (grub_ls_list_files): Use "llu" instead of "d" to
print FILE->SIZE.
* commands/configfile.c: Include grub/env.h.
* commands/cmp.c (grub_cmd_cmp): Do not use ERR, but use
GRUB_ERRNO directly instead. Change the type of POS to
grub_off_t. Follow the coding standard.
* commands/blocklist.c: Include grub/partition.h.
(grub_cmd_blocklist): Return an error if the underlying device is
not a disk. Take the starting sector of a partition into account,
if a partition is used.
* boot/i386/pc/diskboot.S (bootloop): Adapted to the new offset of
a length field.
(lba_mode): Support 64-bit addresses.
(chs_mode): Likewise.
(copy_buffer): Adapted to the new offsets of a length field and a
segment field.
(blocklist_default_start): Allocate 64-bit space.
* boot/i386/pc/boot.S (force_lba): Removed.
(boot_drive): Moved to under KERNEL_SECTOR.
(kernel_sector): Moved to under KENREL_SEGMENT. Allocate 64-bit
space.
(real_start): Set %si earlier. Remove code for FORCE_LBA, since it
is useless.
(lba_mode): Refactored to support a 64-bit address. More size
optimization.
(setup_sectors): Likewise.
2006-06-04 15:56:55 +00:00
|
|
|
grub_size_t size;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t logical_cluster;
|
2002-12-27 08:53:07 +00:00
|
|
|
unsigned logical_cluster_bits;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_ssize_t ret = 0;
|
2002-12-27 08:53:07 +00:00
|
|
|
unsigned long sector;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifndef MODE_EXFAT
|
2002-12-27 08:53:07 +00:00
|
|
|
/* This is a special case. FAT12 and FAT16 doesn't have the root directory
|
|
|
|
in clusters. */
|
2007-05-17 15:43:32 +00:00
|
|
|
if (data->file_cluster == ~0U)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
size = (data->num_root_sectors << GRUB_DISK_SECTOR_BITS) - offset;
|
2002-12-27 08:53:07 +00:00
|
|
|
if (size > len)
|
|
|
|
size = len;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
if (grub_disk_read (disk, data->root_sector, offset, size, buf))
|
2002-12-27 08:53:07 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
/* Calculate the logical cluster number and offset. */
|
|
|
|
logical_cluster_bits = (data->cluster_bits
|
|
|
|
+ data->logical_sector_bits
|
2004-04-04 13:46:03 +00:00
|
|
|
+ GRUB_DISK_SECTOR_BITS);
|
2002-12-27 08:53:07 +00:00
|
|
|
logical_cluster = offset >> logical_cluster_bits;
|
2011-10-23 23:31:06 +00:00
|
|
|
offset &= (1ULL << logical_cluster_bits) - 1;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
if (logical_cluster < data->cur_cluster_num)
|
|
|
|
{
|
|
|
|
data->cur_cluster_num = 0;
|
|
|
|
data->cur_cluster = data->file_cluster;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
while (logical_cluster > data->cur_cluster_num)
|
|
|
|
{
|
|
|
|
/* Find next cluster. */
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t next_cluster;
|
2002-12-27 08:53:07 +00:00
|
|
|
unsigned long fat_offset;
|
|
|
|
|
|
|
|
switch (data->fat_size)
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
fat_offset = data->cur_cluster << 2;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
fat_offset = data->cur_cluster << 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* case 12: */
|
|
|
|
fat_offset = data->cur_cluster + (data->cur_cluster >> 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the FAT. */
|
2004-04-04 13:46:03 +00:00
|
|
|
if (grub_disk_read (disk, data->fat_sector, fat_offset,
|
2002-12-27 08:53:07 +00:00
|
|
|
(data->fat_size + 7) >> 3,
|
|
|
|
(char *) &next_cluster))
|
|
|
|
return -1;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
next_cluster = grub_le_to_cpu32 (next_cluster);
|
2002-12-27 08:53:07 +00:00
|
|
|
switch (data->fat_size)
|
|
|
|
{
|
|
|
|
case 16:
|
|
|
|
next_cluster &= 0xFFFF;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (data->cur_cluster & 1)
|
2003-01-02 23:46:21 +00:00
|
|
|
next_cluster >>= 4;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
next_cluster &= 0x0FFF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-15 14:45:08 +00:00
|
|
|
grub_dprintf ("fat", "fat_size=%d, next_cluster=%u\n",
|
|
|
|
data->fat_size, next_cluster);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
/* Check the end. */
|
|
|
|
if (next_cluster >= data->cluster_eof_mark)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (next_cluster < 2 || next_cluster >= data->num_clusters)
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FS, "invalid cluster %u",
|
2003-01-02 23:46:21 +00:00
|
|
|
next_cluster);
|
2002-12-27 08:53:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->cur_cluster = next_cluster;
|
|
|
|
data->cur_cluster_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the data here. */
|
|
|
|
sector = (data->cluster_sector
|
|
|
|
+ ((data->cur_cluster - 2)
|
|
|
|
<< (data->cluster_bits + data->logical_sector_bits)));
|
|
|
|
size = (1 << logical_cluster_bits) - offset;
|
|
|
|
if (size > len)
|
|
|
|
size = len;
|
|
|
|
|
|
|
|
disk->read_hook = read_hook;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_disk_read (disk, sector, offset, size, buf);
|
2002-12-27 08:53:07 +00:00
|
|
|
disk->read_hook = 0;
|
2004-04-04 13:46:03 +00:00
|
|
|
if (grub_errno)
|
2002-12-27 08:53:07 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
len -= size;
|
|
|
|
buf += size;
|
|
|
|
ret += size;
|
|
|
|
logical_cluster++;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
static grub_err_t
|
|
|
|
grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
|
|
|
|
int (*hook) (const char *filename,
|
|
|
|
grub_fat_dir_node_t *node))
|
|
|
|
{
|
|
|
|
struct grub_fat_dir_entry dir;
|
|
|
|
grub_ssize_t offset = -sizeof(dir);
|
|
|
|
grub_uint16_t *unibuf;
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
unibuf = grub_malloc (15 * 256 * 2);
|
|
|
|
filename = grub_malloc (15 * 256 * 4 + 1);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
offset += sizeof (dir);
|
|
|
|
|
|
|
|
if (grub_fat_read_data (disk, data, 0,
|
|
|
|
offset, sizeof (dir), (char *) &dir)
|
|
|
|
!= sizeof (dir))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (dir.entry_type == 0)
|
|
|
|
break;
|
|
|
|
if (!(dir.entry_type & 0x80))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dir.entry_type == 0x85)
|
|
|
|
{
|
|
|
|
unsigned i, nsec, slots = 0;
|
|
|
|
grub_fat_dir_node_t node;
|
|
|
|
|
|
|
|
nsec = dir.type_specific.file.secondary_count;
|
|
|
|
|
|
|
|
node.attr = grub_cpu_to_le32 (dir.type_specific.file.attr);
|
|
|
|
node.have_stream = 0;
|
|
|
|
for (i = 0; i < nsec; i++)
|
|
|
|
{
|
|
|
|
struct grub_fat_dir_entry sec;
|
|
|
|
offset += sizeof (sec);
|
|
|
|
if (grub_fat_read_data (disk, data, 0,
|
|
|
|
offset, sizeof (sec), (char *) &sec)
|
|
|
|
!= sizeof (sec))
|
|
|
|
break;
|
|
|
|
if (!(sec.entry_type & 0x80))
|
|
|
|
continue;
|
|
|
|
if (!(sec.entry_type & 0x40))
|
|
|
|
break;
|
|
|
|
switch (sec.entry_type)
|
|
|
|
{
|
|
|
|
case 0xc0:
|
|
|
|
node.first_cluster = grub_cpu_to_le32 (sec.type_specific.stream_extension.first_cluster);
|
|
|
|
node.valid_size
|
2011-10-23 23:31:06 +00:00
|
|
|
= grub_cpu_to_le64 (sec.type_specific.stream_extension.valid_size);
|
2011-04-11 16:13:00 +00:00
|
|
|
node.file_size
|
2011-10-23 23:31:06 +00:00
|
|
|
= grub_cpu_to_le64 (sec.type_specific.stream_extension.file_size);
|
2011-04-11 16:13:00 +00:00
|
|
|
node.have_stream = 1;
|
|
|
|
break;
|
|
|
|
case 0xc1:
|
|
|
|
grub_memcpy (unibuf + slots * 15,
|
|
|
|
sec.type_specific.file_name.str, 30);
|
|
|
|
slots++;
|
|
|
|
break;
|
|
|
|
default:
|
2011-04-11 18:38:08 +00:00
|
|
|
grub_dprintf ("exfat", "unknown secondary type 0x%02x\n",
|
|
|
|
sec.entry_type);
|
2011-04-11 16:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != nsec)
|
|
|
|
{
|
|
|
|
offset -= sizeof (dir);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*grub_utf16_to_utf8 ((grub_uint8_t *) filename, unibuf,
|
|
|
|
slots * 15) = '\0';
|
|
|
|
|
|
|
|
if (hook (filename, &node))
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Allocation bitmap. */
|
|
|
|
if (dir.entry_type == 0x81)
|
|
|
|
continue;
|
|
|
|
/* Upcase table. */
|
|
|
|
if (dir.entry_type == 0x82)
|
|
|
|
continue;
|
|
|
|
/* Volume label. */
|
|
|
|
if (dir.entry_type == 0x83)
|
|
|
|
continue;
|
2011-04-11 18:38:08 +00:00
|
|
|
grub_dprintf ("exfat", "unknown primary type 0x%02x\n", dir.entry_type);
|
2011-04-11 16:13:00 +00:00
|
|
|
}
|
|
|
|
grub_free (filename);
|
|
|
|
grub_free (unibuf);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
|
2009-06-10 21:04:23 +00:00
|
|
|
int (*hook) (const char *filename,
|
2009-04-05 15:34:30 +00:00
|
|
|
struct grub_fat_dir_entry *dir))
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_dir_entry dir;
|
2011-04-11 16:13:00 +00:00
|
|
|
char *filename;
|
|
|
|
char *filep = 0;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint16_t *unibuf;
|
2002-12-27 08:53:07 +00:00
|
|
|
int slot = -1, slots = -1;
|
|
|
|
int checksum = -1;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_ssize_t offset = -sizeof(dir);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
|
2009-04-05 15:34:30 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
/* Allocate space enough to hold a long name. */
|
2004-04-04 13:46:03 +00:00
|
|
|
filename = grub_malloc (0x40 * 13 * 4 + 1);
|
|
|
|
unibuf = (grub_uint16_t *) grub_malloc (0x40 * 13 * 2);
|
2002-12-27 08:53:07 +00:00
|
|
|
if (! filename || ! unibuf)
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (filename);
|
|
|
|
grub_free (unibuf);
|
2002-12-27 08:53:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* Adjust the offset. */
|
|
|
|
offset += sizeof (dir);
|
|
|
|
|
|
|
|
/* Read a directory entry. */
|
2011-04-11 16:13:00 +00:00
|
|
|
if (grub_fat_read_data (disk, data, 0,
|
2002-12-27 08:53:07 +00:00
|
|
|
offset, sizeof (dir), (char *) &dir)
|
2011-04-11 16:13:00 +00:00
|
|
|
!= sizeof (dir) || dir.name[0] == 0)
|
2009-04-05 15:34:30 +00:00
|
|
|
break;
|
2011-04-11 16:13:00 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
/* Handle long name entries. */
|
2004-04-04 13:46:03 +00:00
|
|
|
if (dir.attr == GRUB_FAT_ATTR_LONG_NAME)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_long_name_entry *long_name
|
|
|
|
= (struct grub_fat_long_name_entry *) &dir;
|
|
|
|
grub_uint8_t id = long_name->id;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
if (id & 0x40)
|
|
|
|
{
|
|
|
|
id &= 0x3f;
|
|
|
|
slots = slot = id;
|
|
|
|
checksum = long_name->checksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id != slot || slot == 0 || checksum != long_name->checksum)
|
|
|
|
{
|
|
|
|
checksum = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot--;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_memcpy (unibuf + slot * 13, long_name->name1, 5 * 2);
|
|
|
|
grub_memcpy (unibuf + slot * 13 + 5, long_name->name2, 6 * 2);
|
|
|
|
grub_memcpy (unibuf + slot * 13 + 11, long_name->name3, 2 * 2);
|
2002-12-27 08:53:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this entry is valid. */
|
2004-04-04 13:46:03 +00:00
|
|
|
if (dir.name[0] == 0xe5 || (dir.attr & ~GRUB_FAT_ATTR_VALID))
|
2002-12-27 08:53:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* This is a workaround for Japanese. */
|
|
|
|
if (dir.name[0] == 0x05)
|
|
|
|
dir.name[0] = 0xe5;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
if (checksum != -1 && slot == 0)
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint8_t sum;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
for (sum = 0, i = 0; i < sizeof (dir.name); i++)
|
|
|
|
sum = ((sum >> 1) | (sum << 7)) + dir.name[i];
|
|
|
|
|
|
|
|
if (sum == checksum)
|
|
|
|
{
|
2004-08-28 13:14:29 +00:00
|
|
|
int u;
|
|
|
|
|
|
|
|
for (u = 0; u < slots * 13; u++)
|
|
|
|
unibuf[u] = grub_le_to_cpu16 (unibuf[u]);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-04-26 21:58:36 +00:00
|
|
|
*grub_utf16_to_utf8 ((grub_uint8_t *) filename, unibuf,
|
|
|
|
slots * 13) = '\0';
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
if (hook (filename, &dir))
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
checksum = -1;
|
|
|
|
continue;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
checksum = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the 8.3 file name. */
|
|
|
|
filep = filename;
|
2009-04-05 15:34:30 +00:00
|
|
|
if (dir.attr & GRUB_FAT_ATTR_VOLUME_ID)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2009-06-10 21:04:23 +00:00
|
|
|
for (i = 0; i < sizeof (dir.name) && dir.name[i]
|
2009-04-05 15:34:30 +00:00
|
|
|
&& ! grub_isspace (dir.name[i]); i++)
|
|
|
|
*filep++ = dir.name[i];
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
2009-04-05 15:34:30 +00:00
|
|
|
else
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2009-04-05 15:34:30 +00:00
|
|
|
for (i = 0; i < 8 && dir.name[i] && ! grub_isspace (dir.name[i]); i++)
|
|
|
|
*filep++ = grub_tolower (dir.name[i]);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
*filep = '.';
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
for (i = 8; i < 11 && dir.name[i] && ! grub_isspace (dir.name[i]); i++)
|
|
|
|
*++filep = grub_tolower (dir.name[i]);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
if (*filep != '.')
|
|
|
|
filep++;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
2009-04-05 15:34:30 +00:00
|
|
|
*filep = '\0';
|
|
|
|
if (hook (filename, &dir))
|
|
|
|
break;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (filename);
|
2010-02-06 19:49:57 +00:00
|
|
|
grub_free (unibuf);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
return grub_errno;
|
|
|
|
}
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-04-05 15:34:30 +00:00
|
|
|
|
|
|
|
/* Find the underlying directory or file in PATH and return the
|
|
|
|
next path. If there is no next path or an error occurs, return NULL.
|
|
|
|
If HOOK is specified, call it with each file name. */
|
|
|
|
static char *
|
|
|
|
grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
|
|
|
const char *path,
|
2009-06-10 21:04:23 +00:00
|
|
|
int (*hook) (const char *filename,
|
2009-04-05 20:19:05 +00:00
|
|
|
const struct grub_dirhook_info *info))
|
2009-04-05 15:34:30 +00:00
|
|
|
{
|
|
|
|
char *dirname, *dirp;
|
2011-06-26 19:48:52 +00:00
|
|
|
char *origpath = NULL;
|
2009-04-05 15:34:30 +00:00
|
|
|
int call_hook;
|
|
|
|
int found = 0;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
auto int iter_hook (const char *filename, grub_fat_dir_node_t *dir);
|
|
|
|
int iter_hook (const char *filename, grub_fat_dir_node_t *dir)
|
2009-04-05 15:34:30 +00:00
|
|
|
{
|
2009-04-05 20:19:05 +00:00
|
|
|
struct grub_dirhook_info info;
|
|
|
|
grub_memset (&info, 0, sizeof (info));
|
|
|
|
|
|
|
|
info.dir = !! (dir->attr & GRUB_FAT_ATTR_DIRECTORY);
|
|
|
|
info.case_insensitive = 1;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
if (!dir->have_stream)
|
|
|
|
return 0;
|
|
|
|
#else
|
2009-04-05 15:34:30 +00:00
|
|
|
if (dir->attr & GRUB_FAT_ATTR_VOLUME_ID)
|
|
|
|
return 0;
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-04-05 15:34:30 +00:00
|
|
|
if (*dirname == '\0' && call_hook)
|
2009-04-05 20:19:05 +00:00
|
|
|
return hook (filename, &info);
|
2009-04-05 15:34:30 +00:00
|
|
|
|
|
|
|
if (grub_strcasecmp (dirname, filename) == 0)
|
|
|
|
{
|
|
|
|
found = 1;
|
|
|
|
data->attr = dir->attr;
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
data->file_size = dir->file_size;
|
|
|
|
data->file_cluster = dir->first_cluster;
|
|
|
|
#else
|
2009-04-05 15:34:30 +00:00
|
|
|
data->file_size = grub_le_to_cpu32 (dir->file_size);
|
|
|
|
data->file_cluster = ((grub_le_to_cpu16 (dir->first_cluster_high) << 16)
|
|
|
|
| grub_le_to_cpu16 (dir->first_cluster_low));
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-04-05 15:34:30 +00:00
|
|
|
data->cur_cluster_num = ~0U;
|
|
|
|
|
|
|
|
if (call_hook)
|
2009-04-05 20:19:05 +00:00
|
|
|
hook (filename, &info);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
|
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2011-06-26 19:48:52 +00:00
|
|
|
origpath = grub_strdup (path);
|
|
|
|
if (!origpath)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
/* Extract a directory name. */
|
|
|
|
while (*path == '/')
|
|
|
|
path++;
|
|
|
|
|
|
|
|
dirp = grub_strchr (path, '/');
|
|
|
|
if (dirp)
|
|
|
|
{
|
|
|
|
unsigned len = dirp - path;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
dirname = grub_malloc (len + 1);
|
|
|
|
if (! dirname)
|
2011-06-26 19:48:52 +00:00
|
|
|
goto fail;
|
2009-04-05 15:34:30 +00:00
|
|
|
|
|
|
|
grub_memcpy (dirname, path, len);
|
|
|
|
dirname[len] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* This is actually a file. */
|
|
|
|
dirname = grub_strdup (path);
|
|
|
|
|
|
|
|
call_hook = (! dirp && hook);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
grub_fat_iterate_dir (disk, data, iter_hook);
|
|
|
|
if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook)
|
2011-06-26 19:48:52 +00:00
|
|
|
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file `%s' not found", origpath);
|
2009-04-05 15:34:30 +00:00
|
|
|
|
2011-06-26 19:48:52 +00:00
|
|
|
fail:
|
2009-04-05 15:34:30 +00:00
|
|
|
grub_free (dirname);
|
2011-06-26 19:48:52 +00:00
|
|
|
grub_free (origpath);
|
2009-04-05 15:34:30 +00:00
|
|
|
|
|
|
|
return found ? dirp : 0;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_fat_dir (grub_device_t device, const char *path,
|
2009-06-10 21:04:23 +00:00
|
|
|
int (*hook) (const char *filename,
|
2009-04-05 20:19:05 +00:00
|
|
|
const struct grub_dirhook_info *info))
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_data *data = 0;
|
|
|
|
grub_disk_t disk = device->disk;
|
2005-07-20 20:30:46 +00:00
|
|
|
grub_size_t len;
|
2005-07-31 16:12:29 +00:00
|
|
|
char *dirname = 0;
|
2005-07-20 20:30:46 +00:00
|
|
|
char *p;
|
2003-01-06 00:01:35 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_ref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
data = grub_fat_mount (disk);
|
2002-12-27 08:53:07 +00:00
|
|
|
if (! data)
|
2003-01-06 00:01:35 +00:00
|
|
|
goto fail;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2005-07-20 20:30:46 +00:00
|
|
|
/* Make sure that DIRNAME terminates with '/'. */
|
|
|
|
len = grub_strlen (path);
|
|
|
|
dirname = grub_malloc (len + 1 + 1);
|
|
|
|
if (! dirname)
|
|
|
|
goto fail;
|
|
|
|
grub_memcpy (dirname, path, len);
|
|
|
|
p = dirname + len;
|
|
|
|
if (path[len - 1] != '/')
|
|
|
|
*p++ = '/';
|
|
|
|
*p = '\0';
|
|
|
|
p = dirname;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
do
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
p = grub_fat_find_dir (disk, data, p, hook);
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
2004-04-04 13:46:03 +00:00
|
|
|
while (p && grub_errno == GRUB_ERR_NONE);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2003-01-06 00:01:35 +00:00
|
|
|
fail:
|
2005-07-20 20:30:46 +00:00
|
|
|
|
|
|
|
grub_free (dirname);
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (data);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_unref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
return grub_errno;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_fat_open (grub_file_t file, const char *name)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_data *data = 0;
|
2002-12-27 08:53:07 +00:00
|
|
|
char *p = (char *) name;
|
2003-01-06 00:01:35 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_ref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
data = grub_fat_mount (file->device->disk);
|
2002-12-27 08:53:07 +00:00
|
|
|
if (! data)
|
2003-01-06 00:01:35 +00:00
|
|
|
goto fail;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
p = grub_fat_find_dir (file->device->disk, data, p, 0);
|
|
|
|
if (grub_errno != GRUB_ERR_NONE)
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
while (p);
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
if (data->attr & GRUB_FAT_ATTR_DIRECTORY)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a file");
|
2002-12-27 08:53:07 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->data = data;
|
|
|
|
file->size = data->file_size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
return GRUB_ERR_NONE;
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
fail:
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (data);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_unref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
return grub_errno;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_ssize_t
|
2006-06-04 Yoshinori K. Okuji <okuji@enbug.org>
Clean up the code to support 64-bit addressing in disks and
files. This change is not enough for filesystems yet.
* util/i386/pc/grub-setup.c (struct boot_blocklist): Change the
type of "start" to grub_uint64_t.
(setup): Change the types of KERNEL_SECTOR and FIRST_SECTOR to
grub_disk_addr_t * and grub_disk_addr_t. Fix the format string in
save_first_sector and save_blocklists. Use grub_le_to_cpu64 to
convert addresses.
* util/i386/pc/biosdisk.c (open_device): Change the type of SECTOR
to grub_disk_addr_t.
* partmap/gpt.c (gpt_partition_map_iterate): Fix the format
string.
* partmap/pc.c (pc_partition_map_iterate): Likewise.
* partmap/amiga.c (amiga_partition_map_iterate): Cast RDSK.MAGIC
to char *.
* normal/script.c (grub_script_parse): Remove unused MEMFREE.
* normal/parser.y (YYLTYPE_IS_TRIVIAL): New macro.
* normal/lexer.c (grub_script_yyerror): Specify unused to LEX.
* loader/i386/pc/multiboot.c (grub_multiboot_load_elf64): Cast -1
to grub_off_t, to detect an error from grub_file_seek.
(grub_multiboot_load_elf32): Likewise.
* kern/misc.c (grub_strtoul): Use grub_strtoull. Return the
maximum unsigned long value when an overflow is detected.
(grub_strtoull): New function.
(grub_divmod64): Likewise.
(grub_lltoa): use grub_divmod64.
* kern/fs.c (struct grub_fs_block): Change the type of "offset" to
grub_disk_addr_t.
(grub_fs_blocklist_open): Increase P if P is not NULL to advance
the pointer to next character. Use grub_strtoull instead of
grub_strtoul.
(grub_fs_blocklist_read): Change the types of SECTOR, OFFSET and
SIZE to grub_disk_addr_t, grub_off_t and grub_size_t,
respectively.
* kern/file.c (grub_file_read): Prevent an oveflow of LEN, as the
return value is signed.
(grub_file_seek): Change the type of OLD to grub_off_t. Do not
test if OFFSET is less than zero, as OFFSET is unsigned now.
* kern/disk.c (struct grub_disk_cache): Change the type of
"sector" to grub_disk_addr_t.
(grub_disk_cache_get_index): Change the type of SECTOR to
grub_disk_addr_t. Calculate the hash with SECTOR casted to
unsigned after shifting.
(grub_disk_cache_invalidate): Change the type of SECTOR to
grub_disk_addr_t.
(grub_disk_cache_unlock): Likewise.
(grub_disk_cache_store): Likewise.
(grub_disk_check_range): Change the types of SECTOR, OFFSET, SIZE,
START and LEN to grub_disk_addr_t *, grub_off_t *, grub_size_t,
grub_disk_addr_t and grub_uint64_t, respectively.
(grub_disk_read): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of START_SECTOR, LEN and
POS to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
(grub_disk_write): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of LEN and N to
grub_size_t.
* io/gzio.c (struct grub_gzio): Change the types of "data_offset"
and "saved_offset" to grub_off_t.
(test_header): Cast BUF to char *.
(get_byte): Cast GZIO->DATA_OFFSET to grub_off_t. Cast GZIO->INBUF
to char *.
(grub_gzio_read): Change the types of OFFSET and SIZE to
grub_off_t and grub_size_t, respectively.
* include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_FORCE_LBA):
Removed.
(GRUB_BOOT_MACHINE_BOOT_DRIVE): Changed to 0x4c.
(GRUB_BOOT_MACHINE_KERNEL_ADDRESS): Changed to 0x40.
(GRUB_BOOT_MACHINE_KERNEL_SEGMENT): Changed to 0x42.
(GRUB_BOOT_MACHINE_DRIVE_CHECK): Changed to 0x4e.
(GRUB_BOOT_MACHINE_LIST_SIZE): Increased to 12.
* include/grub/types.h (grub_off_t): Unconditionally set to
grub_uint64_t.
(grub_disk_addr_t): Changed to grub_uint64_t.
* include/grub/partition.h (struct grub_partition): Change the
types of "start", "len" and "offset" to grub_disk_addr_t,
grub_uint64_t and grub_disk_addr_t, respectively.
(grub_partition_get_start): Return grub_disk_addr_t.
(grub_partition_get_len): Return grub_uint64_t.
* include/grub/misc.h (grub_strtoull): New prototype.
(grub_divmod64): Likewise.
* include/grub/fshelp.h (grub_fshelp_read_file): Change the types
of SECTOR, LEN and FILESIZE to grub_disk_addr_t, grub_size_t and
grub_off_t, respectively.
All callers and references changed.
* include/grub/fs.h (struct grub_fs): Change the type of LEN to
grub_size_t in "read".
All callers and references changed.
* include/grub/file.h (struct grub_file): Change the types of
"offset" and "size" to grub_off_t and grub_off_t,
respectively. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_file_read): Change the type of LEN to grub_size_t.
(grub_file_seek): Return grub_off_t. Change the type of OFFSET to
grub_off_t.
(grub_file_size): Return grub_off_t.
(grub_file_tell): Likewise.
All callers and references changed.
* include/grub/disk.h (struct grub_disk_dev): Change the types of
SECTOR and SIZE to grub_disk_addr_t and grub_size_t in "read" and
"write".
(struct grub_disk): Change the type of "total_sectors" to
grub_uint64_t. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_disk_read): Change the types of SECTOR, OFFSET and SIZE to
grub_disk_addr_t, grub_off_t and grub_size_t, respectively.
(grub_disk_write): Likewise.
All callers and references changed.
* fs/iso9660.c (grub_iso9660_susp_iterate): Cast parameters to
char * for grub_strncmp to silence gcc.
(grub_iso9660_mount): Likewise.
(grub_iso9660_mount): Likewise.
(grub_iso9660_read_symlink): Likewise. Also, remove the nonsense
return statement.
(grub_iso9660_iterate_dir): Likewise.
(grub_iso9660_label): Cast DATA->VOLDESC.VOLNAME to char *.
* fs/hfs.c (grub_hfs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/hfsplus.c (grub_hfsplus_read_file): Likewise.
* fs/jfs.c (grub_jfs_read_file): Likewise.
* fs/minix.c (grub_jfs_read_file): Likewise.
* fs/sfs.c (grub_jfs_read_file): Likewise.
* fs/ufs.c (grub_jfs_read_file): Likewise.
* fs/xfs.c (grub_jfs_read_file): Likewise.
* fs/fat.c (grub_fat_read_data): Change the types of SECTOR, LEN
and SIZE to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
* fs/ext2.c (grub_ext2_read_block): When an error happens, set
BLKNR to -1 instead of returning GRUB_ERRNO.
(grub_ext2_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/affs.c (grub_affs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* font/manager.c (grub_font_get_glyph): Cast BITMAP to char * for
grub_file_read.
* disk/ieee1275/ofdisk.c (grub_ofdisk_read): Fix the format
string. Do not cast SECTOR explicitly.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Change the type of
TOTAL_SECTORS to grub_uint64_t. Do not mask DRP->TOTAL_SECTORS.
(grub_biosdisk_rw): Change the types of SECTOR and SIZE to
grub_disk_addr_t and grub_size_t, respectively. If the sector is
over 2TB and LBA mode is not supported, raise an error.
(get_safe_sectors): New function.
(grub_biosdisk_read): Use get_safe_sectors.
(grub_biosdisk_write): Likewise.
* disk/efi/efidisk.c (grub_efidisk_read): Fix the format string.
(grub_efidisk_write): Likewise.
* disk/loopback.c (delete_loopback): Cosmetic changes.
(grub_cmd_loopback): Likewise. Also, test NEWDEV->FILENAME
correctly.
(grub_loopback_open): Likewise.
(grub_loopback_read): Likewise. Also, change the type of POS to
grub_off_t, and fix the usage of grub_memset.
* commands/i386/pc/play.c: Include grub/machine/time.h.
* commands/ls.c (grub_ls_list_files): Use "llu" instead of "d" to
print FILE->SIZE.
* commands/configfile.c: Include grub/env.h.
* commands/cmp.c (grub_cmd_cmp): Do not use ERR, but use
GRUB_ERRNO directly instead. Change the type of POS to
grub_off_t. Follow the coding standard.
* commands/blocklist.c: Include grub/partition.h.
(grub_cmd_blocklist): Return an error if the underlying device is
not a disk. Take the starting sector of a partition into account,
if a partition is used.
* boot/i386/pc/diskboot.S (bootloop): Adapted to the new offset of
a length field.
(lba_mode): Support 64-bit addresses.
(chs_mode): Likewise.
(copy_buffer): Adapted to the new offsets of a length field and a
segment field.
(blocklist_default_start): Allocate 64-bit space.
* boot/i386/pc/boot.S (force_lba): Removed.
(boot_drive): Moved to under KERNEL_SECTOR.
(kernel_sector): Moved to under KENREL_SEGMENT. Allocate 64-bit
space.
(real_start): Set %si earlier. Remove code for FORCE_LBA, since it
is useless.
(lba_mode): Refactored to support a 64-bit address. More size
optimization.
(setup_sectors): Likewise.
2006-06-04 15:56:55 +00:00
|
|
|
grub_fat_read (grub_file_t file, char *buf, grub_size_t len)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
return grub_fat_read_data (file->device->disk, file->data, file->read_hook,
|
2002-12-27 08:53:07 +00:00
|
|
|
file->offset, len, buf);
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_fat_close (grub_file_t file)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (file->data);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_unref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
return grub_errno;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_fat_label (grub_device_t device, char **label)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2011-04-11 16:13:00 +00:00
|
|
|
struct grub_fat_dir_entry dir;
|
|
|
|
grub_ssize_t offset = -sizeof(dir);
|
2004-04-04 13:46:03 +00:00
|
|
|
struct grub_fat_data *data;
|
|
|
|
grub_disk_t disk = device->disk;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
data = grub_fat_mount (disk);
|
|
|
|
if (! data)
|
|
|
|
return grub_errno;
|
|
|
|
|
2011-10-23 23:31:06 +00:00
|
|
|
*label = NULL;
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
offset += sizeof (dir);
|
|
|
|
|
|
|
|
if (grub_fat_read_data (disk, data, 0,
|
|
|
|
offset, sizeof (dir), (char *) &dir)
|
|
|
|
!= sizeof (dir))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (dir.entry_type == 0)
|
|
|
|
break;
|
|
|
|
if (!(dir.entry_type & 0x80))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Volume label. */
|
|
|
|
if (dir.entry_type == 0x83)
|
|
|
|
{
|
|
|
|
grub_size_t chc;
|
|
|
|
*label = grub_malloc (11 * 4 + 1);
|
|
|
|
if (!*label)
|
|
|
|
return grub_errno;
|
|
|
|
chc = dir.type_specific.volume_label.character_count;
|
|
|
|
if (chc > ARRAY_SIZE (dir.type_specific.volume_label.str))
|
|
|
|
chc = ARRAY_SIZE (dir.type_specific.volume_label.str);
|
|
|
|
*grub_utf16_to_utf8 ((grub_uint8_t *) *label,
|
|
|
|
dir.type_specific.volume_label.str, chc) = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_fat_label (grub_device_t device, char **label)
|
|
|
|
{
|
|
|
|
struct grub_fat_data *data;
|
|
|
|
grub_disk_t disk = device->disk;
|
|
|
|
|
|
|
|
auto int iter_hook (const char *filename, grub_fat_dir_node_t *dir);
|
|
|
|
int iter_hook (const char *filename, grub_fat_dir_node_t *dir)
|
2009-04-05 15:34:30 +00:00
|
|
|
{
|
|
|
|
if (dir->attr == GRUB_FAT_ATTR_VOLUME_ID)
|
|
|
|
{
|
|
|
|
*label = grub_strdup (filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_ref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
data = grub_fat_mount (disk);
|
2003-12-03 19:17:27 +00:00
|
|
|
if (! data)
|
|
|
|
goto fail;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
2003-12-03 19:17:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*label = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-05 15:34:30 +00:00
|
|
|
grub_fat_iterate_dir (disk, data, iter_hook);
|
|
|
|
|
2003-12-03 19:17:27 +00:00
|
|
|
fail:
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_dl_unref (my_mod);
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (data);
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
return grub_errno;
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
|
|
|
|
2008-06-01 13:30:00 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_fat_uuid (grub_device_t device, char **uuid)
|
|
|
|
{
|
|
|
|
struct grub_fat_data *data;
|
|
|
|
grub_disk_t disk = device->disk;
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
data = grub_fat_mount (disk);
|
|
|
|
if (data)
|
|
|
|
{
|
2011-10-25 19:53:57 +00:00
|
|
|
char *ptr;
|
2010-01-20 08:12:47 +00:00
|
|
|
*uuid = grub_xasprintf ("%04x-%04x",
|
2009-12-29 09:04:06 +00:00
|
|
|
(grub_uint16_t) (data->uuid >> 16),
|
|
|
|
(grub_uint16_t) data->uuid);
|
2011-10-25 19:53:57 +00:00
|
|
|
for (ptr = *uuid; ptr && *ptr; ptr++)
|
|
|
|
*ptr = grub_toupper (*ptr);
|
2008-06-01 13:30:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*uuid = NULL;
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
grub_free (data);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static struct grub_fs grub_fat_fs =
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
.name = "exfat",
|
|
|
|
#else
|
2002-12-27 08:53:07 +00:00
|
|
|
.name = "fat",
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2004-04-04 13:46:03 +00:00
|
|
|
.dir = grub_fat_dir,
|
|
|
|
.open = grub_fat_open,
|
|
|
|
.read = grub_fat_read,
|
|
|
|
.close = grub_fat_close,
|
|
|
|
.label = grub_fat_label,
|
2008-06-01 13:30:00 +00:00
|
|
|
.uuid = grub_fat_uuid,
|
2009-10-25 15:23:48 +00:00
|
|
|
#ifdef GRUB_UTIL
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
/* ExFAT BPB is 30 larger than FAT32 one. */
|
|
|
|
.reserved_first_sector = 0,
|
|
|
|
#else
|
2009-10-25 15:23:48 +00:00
|
|
|
.reserved_first_sector = 1,
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2009-10-25 15:23:48 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
.next = 0
|
|
|
|
};
|
|
|
|
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
GRUB_MOD_INIT(exfat)
|
|
|
|
#else
|
2005-11-13 Marco Gerards <mgerards@xs4all.nl>
* geninit.sh: New file.
* geninitheader.sh: Likewise.
* commands/boot.c (grub_boot_init, grub_boot_fini): Removed.
* commands/cat.c (grub_cat_init, grub_cat_fini): Likewise.
* commands/cmp.c (grub_cmp_init, grub_cmp_fini): Likewise.
* commands/configfile.c (grub_configfile_init)
(grub_configfile_fini): Likewise.
* commands/default.c (grub_default_init, grub_default_fini):
Likewise.
* commands/help.c (grub_help_init, grub_help_fini): Likewise.
* commands/ls.c (grub_ls_init, grub_ls_fini): Likewise.
* commands/search.c (grub_search_init, grub_search_fini): Likewise.
* commands/terminal.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* commands/test.c (grub_test_init, grub_test_fini): Likewise.
* commands/timeout.c (grub_timeout_init, grub_timeout_fini):
Likewise.
* commands/i386/pc/halt.c (grub_halt_init, grub_halt_fini): Likewise.
* commands/iee1275/halt.c (grub_halt_init, grub_halt_fini):
Likewise.
* commands/i386/pc/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* commands/iee1275/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* disk/loopback.c (grub_loop_init, grub_loop_fini): Likewise.
* fs/affs.c (grub_affs_init, grub_affs_fini): Likewise.
* fs/ext2.c (grub_ext2_init, grub_ext2_fini): Likewise.
* fs/fat.c (grub_fat_init, grub_fat_fini): Likewise.
* fs/hfs.c (grub_hfs_init, grub_hfs_fini): Likewise.
* fs/iso9660.c (grub_iso9660_init, grub_iso9660_fini): Likewise.
* fs/jfs.c (grub_jfs_init, grub_jfs_fini): Likewise.
* fs/minix.c (grub_minix_init, grub_minix_fini): Likewise.
* fs/sfs.c (grub_sfs_init, grub_sfs_fini): Likewise.
* fs/ufs.c (grub_ufs_init, grub_ufs_fini): Likewise.
* fs/xfs.c (grub_xfs_init, grub_xfs_fini): Likewise.
* normal/main.c (grub_normal_init, grub_normal_fini): Likewise.
* partmap/amiga.c (grub_amiga_partition_map_init)
(grub_amiga_partition_map_fini): Likewise.
* partmap/apple.c (grub_apple_partition_map_init)
(grub_apple_partition_map_fini): Likewise.
* partmap/pc.c (grub_pc_partition_map_init)
(grub_pc_partition_map_fini): Likewise.
* partmap/sun.c (grub_sun_partition_map_init,
grub_sun_partition_map_fini): Likewise.
* term/terminfo.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* util/grub-emu.c: Include <grub_modules_init.h>.
(main): Don't initialize and de-initialize any modules directly,
use `grub_init_all' and `grub_fini_all' instead.
* term/i386/pc/vesafb.c (grub_vesafb_init): Renamed to
`grub_vesafb_mod_init'.
(grub_vesafb_fini): Renamed to `grub_vesafb_mod_fini'. Updated
all users.
* term/i386/pc/vga.c (grub_vga_init): Renamed to
`grub_vga_mod_init'. Updated all users.
(grub_vga_fini): Renamed to `grub_vga_mod_fini'.
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `grub_emu_init.c'.
(grub_modules_init.lst, grub_modules_init.h, grub_emu_init.c): New
rules.
* include/grub/dl.h (GRUB_MOD_INIT): Add argument `name'.
Generate a function to initialize the module in utilities.
Updated all callers.
(GRUB_MOD_FINI): Add argument `name'. Generate a function to
initialize the module in utilities. Updated all callers.
2005-11-13 15:47:09 +00:00
|
|
|
GRUB_MOD_INIT(fat)
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2011-10-19 18:19:25 +00:00
|
|
|
COMPILE_TIME_ASSERT (sizeof (struct grub_fat_dir_entry) == 32);
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_fs_register (&grub_fat_fs);
|
2003-01-06 00:01:35 +00:00
|
|
|
my_mod = mod;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
2011-04-11 16:13:00 +00:00
|
|
|
#ifdef MODE_EXFAT
|
|
|
|
GRUB_MOD_FINI(exfat)
|
|
|
|
#else
|
2005-11-13 Marco Gerards <mgerards@xs4all.nl>
* geninit.sh: New file.
* geninitheader.sh: Likewise.
* commands/boot.c (grub_boot_init, grub_boot_fini): Removed.
* commands/cat.c (grub_cat_init, grub_cat_fini): Likewise.
* commands/cmp.c (grub_cmp_init, grub_cmp_fini): Likewise.
* commands/configfile.c (grub_configfile_init)
(grub_configfile_fini): Likewise.
* commands/default.c (grub_default_init, grub_default_fini):
Likewise.
* commands/help.c (grub_help_init, grub_help_fini): Likewise.
* commands/ls.c (grub_ls_init, grub_ls_fini): Likewise.
* commands/search.c (grub_search_init, grub_search_fini): Likewise.
* commands/terminal.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* commands/test.c (grub_test_init, grub_test_fini): Likewise.
* commands/timeout.c (grub_timeout_init, grub_timeout_fini):
Likewise.
* commands/i386/pc/halt.c (grub_halt_init, grub_halt_fini): Likewise.
* commands/iee1275/halt.c (grub_halt_init, grub_halt_fini):
Likewise.
* commands/i386/pc/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* commands/iee1275/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* disk/loopback.c (grub_loop_init, grub_loop_fini): Likewise.
* fs/affs.c (grub_affs_init, grub_affs_fini): Likewise.
* fs/ext2.c (grub_ext2_init, grub_ext2_fini): Likewise.
* fs/fat.c (grub_fat_init, grub_fat_fini): Likewise.
* fs/hfs.c (grub_hfs_init, grub_hfs_fini): Likewise.
* fs/iso9660.c (grub_iso9660_init, grub_iso9660_fini): Likewise.
* fs/jfs.c (grub_jfs_init, grub_jfs_fini): Likewise.
* fs/minix.c (grub_minix_init, grub_minix_fini): Likewise.
* fs/sfs.c (grub_sfs_init, grub_sfs_fini): Likewise.
* fs/ufs.c (grub_ufs_init, grub_ufs_fini): Likewise.
* fs/xfs.c (grub_xfs_init, grub_xfs_fini): Likewise.
* normal/main.c (grub_normal_init, grub_normal_fini): Likewise.
* partmap/amiga.c (grub_amiga_partition_map_init)
(grub_amiga_partition_map_fini): Likewise.
* partmap/apple.c (grub_apple_partition_map_init)
(grub_apple_partition_map_fini): Likewise.
* partmap/pc.c (grub_pc_partition_map_init)
(grub_pc_partition_map_fini): Likewise.
* partmap/sun.c (grub_sun_partition_map_init,
grub_sun_partition_map_fini): Likewise.
* term/terminfo.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* util/grub-emu.c: Include <grub_modules_init.h>.
(main): Don't initialize and de-initialize any modules directly,
use `grub_init_all' and `grub_fini_all' instead.
* term/i386/pc/vesafb.c (grub_vesafb_init): Renamed to
`grub_vesafb_mod_init'.
(grub_vesafb_fini): Renamed to `grub_vesafb_mod_fini'. Updated
all users.
* term/i386/pc/vga.c (grub_vga_init): Renamed to
`grub_vga_mod_init'. Updated all users.
(grub_vga_fini): Renamed to `grub_vga_mod_fini'.
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `grub_emu_init.c'.
(grub_modules_init.lst, grub_modules_init.h, grub_emu_init.c): New
rules.
* include/grub/dl.h (GRUB_MOD_INIT): Add argument `name'.
Generate a function to initialize the module in utilities.
Updated all callers.
(GRUB_MOD_FINI): Add argument `name'. Generate a function to
initialize the module in utilities. Updated all callers.
2005-11-13 15:47:09 +00:00
|
|
|
GRUB_MOD_FINI(fat)
|
2011-04-11 16:13:00 +00:00
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_fs_unregister (&grub_fat_fs);
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
2005-11-13 Marco Gerards <mgerards@xs4all.nl>
* geninit.sh: New file.
* geninitheader.sh: Likewise.
* commands/boot.c (grub_boot_init, grub_boot_fini): Removed.
* commands/cat.c (grub_cat_init, grub_cat_fini): Likewise.
* commands/cmp.c (grub_cmp_init, grub_cmp_fini): Likewise.
* commands/configfile.c (grub_configfile_init)
(grub_configfile_fini): Likewise.
* commands/default.c (grub_default_init, grub_default_fini):
Likewise.
* commands/help.c (grub_help_init, grub_help_fini): Likewise.
* commands/ls.c (grub_ls_init, grub_ls_fini): Likewise.
* commands/search.c (grub_search_init, grub_search_fini): Likewise.
* commands/terminal.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* commands/test.c (grub_test_init, grub_test_fini): Likewise.
* commands/timeout.c (grub_timeout_init, grub_timeout_fini):
Likewise.
* commands/i386/pc/halt.c (grub_halt_init, grub_halt_fini): Likewise.
* commands/iee1275/halt.c (grub_halt_init, grub_halt_fini):
Likewise.
* commands/i386/pc/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* commands/iee1275/reboot.c (grub_reboot_init, grub_reboot_fini):
Likewise.
* disk/loopback.c (grub_loop_init, grub_loop_fini): Likewise.
* fs/affs.c (grub_affs_init, grub_affs_fini): Likewise.
* fs/ext2.c (grub_ext2_init, grub_ext2_fini): Likewise.
* fs/fat.c (grub_fat_init, grub_fat_fini): Likewise.
* fs/hfs.c (grub_hfs_init, grub_hfs_fini): Likewise.
* fs/iso9660.c (grub_iso9660_init, grub_iso9660_fini): Likewise.
* fs/jfs.c (grub_jfs_init, grub_jfs_fini): Likewise.
* fs/minix.c (grub_minix_init, grub_minix_fini): Likewise.
* fs/sfs.c (grub_sfs_init, grub_sfs_fini): Likewise.
* fs/ufs.c (grub_ufs_init, grub_ufs_fini): Likewise.
* fs/xfs.c (grub_xfs_init, grub_xfs_fini): Likewise.
* normal/main.c (grub_normal_init, grub_normal_fini): Likewise.
* partmap/amiga.c (grub_amiga_partition_map_init)
(grub_amiga_partition_map_fini): Likewise.
* partmap/apple.c (grub_apple_partition_map_init)
(grub_apple_partition_map_fini): Likewise.
* partmap/pc.c (grub_pc_partition_map_init)
(grub_pc_partition_map_fini): Likewise.
* partmap/sun.c (grub_sun_partition_map_init,
grub_sun_partition_map_fini): Likewise.
* term/terminfo.c (grub_terminal_init, grub_terminal_fini):
Likewise.
* util/grub-emu.c: Include <grub_modules_init.h>.
(main): Don't initialize and de-initialize any modules directly,
use `grub_init_all' and `grub_fini_all' instead.
* term/i386/pc/vesafb.c (grub_vesafb_init): Renamed to
`grub_vesafb_mod_init'.
(grub_vesafb_fini): Renamed to `grub_vesafb_mod_fini'. Updated
all users.
* term/i386/pc/vga.c (grub_vga_init): Renamed to
`grub_vga_mod_init'. Updated all users.
(grub_vga_fini): Renamed to `grub_vga_mod_fini'.
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `grub_emu_init.c'.
(grub_modules_init.lst, grub_modules_init.h, grub_emu_init.c): New
rules.
* include/grub/dl.h (GRUB_MOD_INIT): Add argument `name'.
Generate a function to initialize the module in utilities.
Updated all callers.
(GRUB_MOD_FINI): Add argument `name'. Generate a function to
initialize the module in utilities. Updated all callers.
2005-11-13 15:47:09 +00:00
|
|
|
|