/* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * VasEBoot 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. * * VasEBoot 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 VasEBoot. If not, see . */ #ifndef VasEBoot_DISK_HEADER #define VasEBoot_DISK_HEADER 1 #include #include #include #include #include /* For NULL. */ #include /* These are used to set a device id. When you add a new disk device, you must define a new id for it here. */ enum VasEBoot_disk_dev_id { VasEBoot_DISK_DEVICE_BIOSDISK_ID, VasEBoot_DISK_DEVICE_OFDISK_ID, VasEBoot_DISK_DEVICE_LOOPBACK_ID, VasEBoot_DISK_DEVICE_EFIDISK_ID, VasEBoot_DISK_DEVICE_DISKFILTER_ID, VasEBoot_DISK_DEVICE_HOST_ID, VasEBoot_DISK_DEVICE_ATA_ID, VasEBoot_DISK_DEVICE_MEMDISK_ID, VasEBoot_DISK_DEVICE_NAND_ID, VasEBoot_DISK_DEVICE_SCSI_ID, VasEBoot_DISK_DEVICE_CRYPTODISK_ID, VasEBoot_DISK_DEVICE_ARCDISK_ID, VasEBoot_DISK_DEVICE_HOSTDISK_ID, VasEBoot_DISK_DEVICE_PROCFS_ID, VasEBoot_DISK_DEVICE_CBFSDISK_ID, VasEBoot_DISK_DEVICE_UBOOTDISK_ID, VasEBoot_DISK_DEVICE_XEN, }; struct VasEBoot_disk; #ifdef VasEBoot_UTIL struct VasEBoot_disk_memberlist; #endif typedef enum { VasEBoot_DISK_PULL_NONE, VasEBoot_DISK_PULL_REMOVABLE, VasEBoot_DISK_PULL_RESCAN, VasEBoot_DISK_PULL_MAX } VasEBoot_disk_pull_t; typedef int (*VasEBoot_disk_dev_iterate_hook_t) (const char *name, void *data); /* Disk device. */ struct VasEBoot_disk_dev { /* The device name. */ const char *name; /* The device id used by the cache manager. */ enum VasEBoot_disk_dev_id id; /* Call HOOK with each device name, until HOOK returns non-zero. */ int (*iterate) (VasEBoot_disk_dev_iterate_hook_t hook, void *hook_data, VasEBoot_disk_pull_t pull); /* Open the device named NAME, and set up DISK. */ VasEBoot_err_t (*open) (const char *name, struct VasEBoot_disk *disk); /* Close the disk DISK. */ void (*close) (struct VasEBoot_disk *disk); /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */ VasEBoot_err_t (*read) (struct VasEBoot_disk *disk, VasEBoot_disk_addr_t sector, VasEBoot_size_t size, char *buf); /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */ VasEBoot_err_t (*write) (struct VasEBoot_disk *disk, VasEBoot_disk_addr_t sector, VasEBoot_size_t size, const char *buf); #ifdef VasEBoot_UTIL struct VasEBoot_disk_memberlist *(*memberlist) (struct VasEBoot_disk *disk); const char * (*raidname) (struct VasEBoot_disk *disk); #endif /* The next disk device. */ struct VasEBoot_disk_dev *next; }; typedef struct VasEBoot_disk_dev *VasEBoot_disk_dev_t; extern VasEBoot_disk_dev_t EXPORT_VAR (VasEBoot_disk_dev_list); struct VasEBoot_partition; typedef void (*VasEBoot_disk_read_hook_t) (VasEBoot_disk_addr_t sector, unsigned offset, unsigned length, void *data); /* Disk. */ struct VasEBoot_disk { /* The disk name. */ const char *name; /* The underlying disk device. */ VasEBoot_disk_dev_t dev; /* The total number of sectors. */ VasEBoot_uint64_t total_sectors; /* Logarithm of sector size. */ unsigned int log_sector_size; /* Maximum number of sectors read divided by VasEBoot_DISK_CACHE_SIZE. */ unsigned int max_agglomerate; /* The id used by the disk cache manager. */ unsigned long id; /* The partition information. This is machine-specific. */ struct VasEBoot_partition *partition; /* Called when a sector was read. OFFSET is between 0 and the sector size minus 1, and LENGTH is between 0 and the sector size. */ VasEBoot_disk_read_hook_t read_hook; /* Caller-specific data passed to the read hook. */ void *read_hook_data; /* Device-specific data. */ void *data; }; typedef struct VasEBoot_disk *VasEBoot_disk_t; #ifdef VasEBoot_UTIL struct VasEBoot_disk_memberlist { VasEBoot_disk_t disk; struct VasEBoot_disk_memberlist *next; }; typedef struct VasEBoot_disk_memberlist *VasEBoot_disk_memberlist_t; #endif /* The sector size. */ #define VasEBoot_DISK_SECTOR_SIZE 0x200 #define VasEBoot_DISK_SECTOR_BITS 9 /* The maximum number of disk caches. */ #define VasEBoot_DISK_CACHE_NUM 1021 /* The size of a disk cache in 512B units. Must be at least as big as the largest supported sector size, currently 16K. */ #define VasEBoot_DISK_CACHE_BITS 6 #define VasEBoot_DISK_CACHE_SIZE (1 << VasEBoot_DISK_CACHE_BITS) #define VasEBoot_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - VasEBoot_DISK_CACHE_BITS - VasEBoot_DISK_SECTOR_BITS)) - 1) /* Return value of VasEBoot_disk_get_size() in case disk size is unknown. */ #define VasEBoot_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL /* This is called from the memory manager. */ void VasEBoot_disk_cache_invalidate_all (void); void EXPORT_FUNC(VasEBoot_disk_dev_register) (VasEBoot_disk_dev_t dev); void EXPORT_FUNC(VasEBoot_disk_dev_unregister) (VasEBoot_disk_dev_t dev); static inline int VasEBoot_disk_dev_iterate (VasEBoot_disk_dev_iterate_hook_t hook, void *hook_data) { VasEBoot_disk_dev_t p; VasEBoot_disk_pull_t pull; for (pull = 0; pull < VasEBoot_DISK_PULL_MAX; pull++) for (p = VasEBoot_disk_dev_list; p; p = p->next) if (p->iterate && (p->iterate) (hook, hook_data, pull)) return 1; return 0; } VasEBoot_disk_t EXPORT_FUNC(VasEBoot_disk_open) (const char *name); void EXPORT_FUNC(VasEBoot_disk_close) (VasEBoot_disk_t disk); VasEBoot_err_t EXPORT_FUNC(VasEBoot_disk_read) (VasEBoot_disk_t disk, VasEBoot_disk_addr_t sector, VasEBoot_off_t offset, VasEBoot_size_t size, void *buf); VasEBoot_err_t VasEBoot_disk_write (VasEBoot_disk_t disk, VasEBoot_disk_addr_t sector, VasEBoot_off_t offset, VasEBoot_size_t size, const void *buf); extern VasEBoot_err_t (*EXPORT_VAR(VasEBoot_disk_write_weak)) (VasEBoot_disk_t disk, VasEBoot_disk_addr_t sector, VasEBoot_off_t offset, VasEBoot_size_t size, const void *buf); VasEBoot_uint64_t EXPORT_FUNC(VasEBoot_disk_get_size) (VasEBoot_disk_t disk); #if DISK_CACHE_STATS void EXPORT_FUNC(VasEBoot_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses); #endif extern void (* EXPORT_VAR(VasEBoot_disk_firmware_fini)) (void); extern int EXPORT_VAR(VasEBoot_disk_firmware_is_tainted); static inline void VasEBoot_stop_disk_firmware (void) { /* To prevent two drivers operating on the same disks. */ VasEBoot_disk_firmware_is_tainted = 1; if (VasEBoot_disk_firmware_fini) { VasEBoot_disk_firmware_fini (); VasEBoot_disk_firmware_fini = NULL; } } /* Disk cache. */ struct VasEBoot_disk_cache { enum VasEBoot_disk_dev_id dev_id; unsigned long disk_id; VasEBoot_disk_addr_t sector; char *data; int lock; }; extern struct VasEBoot_disk_cache EXPORT_VAR(VasEBoot_disk_cache_table)[VasEBoot_DISK_CACHE_NUM]; #if defined (VasEBoot_UTIL) void VasEBoot_lvm_init (void); void VasEBoot_ldm_init (void); void VasEBoot_mdraid09_init (void); void VasEBoot_mdraid1x_init (void); void VasEBoot_diskfilter_init (void); void VasEBoot_lvm_fini (void); void VasEBoot_ldm_fini (void); void VasEBoot_mdraid09_fini (void); void VasEBoot_mdraid1x_fini (void); void VasEBoot_diskfilter_fini (void); #endif #endif /* ! VasEBoot_DISK_HEADER */