Changeset View
Changeset View
Standalone View
Standalone View
stand/uboot/lib/disk.c
Show All 40 Lines | |||||
#include "api_public.h" | #include "api_public.h" | ||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
#include "disk.h" | #include "disk.h" | ||||
#include "glue.h" | #include "glue.h" | ||||
#include "libuboot.h" | #include "libuboot.h" | ||||
#define stor_printf(fmt, args...) do { \ | #define stor_printf(fmt, args...) do { \ | ||||
printf("%s%d: ", dev->d_dev->dv_name, dev->d_unit); \ | printf("%s%d: ", dev->dd.d_dev->dv_name, dev->dd.d_unit); \ | ||||
printf(fmt, ##args); \ | printf(fmt, ##args); \ | ||||
} while (0) | } while (0) | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
#define debugf(fmt, args...) do { printf("%s(): ", __func__); \ | #define debugf(fmt, args...) do { printf("%s(): ", __func__); \ | ||||
printf(fmt,##args); } while (0) | printf(fmt,##args); } while (0) | ||||
#else | #else | ||||
#define debugf(fmt, args...) | #define debugf(fmt, args...) | ||||
#endif | #endif | ||||
static struct { | static struct { | ||||
int opened; /* device is opened */ | int opened; /* device is opened */ | ||||
int handle; /* storage device handle */ | int handle; /* storage device handle */ | ||||
int type; /* storage type */ | int type; /* storage type */ | ||||
off_t blocks; /* block count */ | off_t blocks; /* block count */ | ||||
u_int bsize; /* block size */ | u_int bsize; /* block size */ | ||||
} stor_info[UB_MAX_DEV]; | } stor_info[UB_MAX_DEV]; | ||||
#define SI(dev) (stor_info[(dev)->d_unit]) | #define SI(dev) (stor_info[(dev)->dd.d_unit]) | ||||
static int stor_info_no = 0; | static int stor_info_no = 0; | ||||
static int stor_opendev(struct disk_devdesc *); | static int stor_opendev(struct disk_devdesc *); | ||||
static int stor_readdev(struct disk_devdesc *, daddr_t, size_t, char *); | static int stor_readdev(struct disk_devdesc *, daddr_t, size_t, char *); | ||||
/* devsw I/F */ | /* devsw I/F */ | ||||
static int stor_init(void); | static int stor_init(void); | ||||
static int stor_strategy(void *, int, daddr_t, size_t, char *, size_t *); | static int stor_strategy(void *, int, daddr_t, size_t, char *, size_t *); | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | stor_open(struct open_file *f, ...) | ||||
return (stor_opendev(dev)); | return (stor_opendev(dev)); | ||||
} | } | ||||
static int | static int | ||||
stor_opendev(struct disk_devdesc *dev) | stor_opendev(struct disk_devdesc *dev) | ||||
{ | { | ||||
int err; | int err; | ||||
if (dev->d_unit < 0 || dev->d_unit >= stor_info_no) | if (dev->dd.d_unit < 0 || dev->dd.d_unit >= stor_info_no) | ||||
return (EIO); | return (EIO); | ||||
if (SI(dev).opened == 0) { | if (SI(dev).opened == 0) { | ||||
err = ub_dev_open(SI(dev).handle); | err = ub_dev_open(SI(dev).handle); | ||||
if (err != 0) { | if (err != 0) { | ||||
stor_printf("device open failed with error=%d, " | stor_printf("device open failed with error=%d, " | ||||
"handle=%d\n", err, SI(dev).handle); | "handle=%d\n", err, SI(dev).handle); | ||||
return (ENXIO); | return (ENXIO); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | stor_print(int verbose) | ||||
if (stor_info_no == 0) | if (stor_info_no == 0) | ||||
return (ret); | return (ret); | ||||
printf("%s devices:", uboot_storage.dv_name); | printf("%s devices:", uboot_storage.dv_name); | ||||
if ((ret = pager_output("\n")) != 0) | if ((ret = pager_output("\n")) != 0) | ||||
return (ret); | return (ret); | ||||
for (i = 0; i < stor_info_no; i++) { | for (i = 0; i < stor_info_no; i++) { | ||||
dev.d_dev = &uboot_storage; | dev.dd.d_dev = &uboot_storage; | ||||
dev.d_unit = i; | dev.dd.d_unit = i; | ||||
dev.d_slice = -1; | dev.d_slice = -1; | ||||
dev.d_partition = -1; | dev.d_partition = -1; | ||||
snprintf(line, sizeof(line), "\tdisk%d (%s)\n", i, | snprintf(line, sizeof(line), "\tdisk%d (%s)\n", i, | ||||
ub_stor_type(SI(&dev).type)); | ub_stor_type(SI(&dev).type)); | ||||
if ((ret = pager_output(line)) != 0) | if ((ret = pager_output(line)) != 0) | ||||
break; | break; | ||||
if (stor_opendev(&dev) == 0) { | if (stor_opendev(&dev) == 0) { | ||||
sprintf(line, "\tdisk%d", i); | sprintf(line, "\tdisk%d", i); | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |