Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/common/disk.c
Show All 40 Lines | |||||
# define DEBUG(fmt, args...) printf("%s: " fmt "\n" , __func__ , ## args) | # define DEBUG(fmt, args...) printf("%s: " fmt "\n" , __func__ , ## args) | ||||
#else | #else | ||||
# define DEBUG(fmt, args...) | # define DEBUG(fmt, args...) | ||||
#endif | #endif | ||||
struct open_disk { | struct open_disk { | ||||
struct ptable *table; | struct ptable *table; | ||||
uint64_t mediasize; | uint64_t mediasize; | ||||
uint64_t entrysize; | |||||
u_int sectorsize; | u_int sectorsize; | ||||
u_int flags; | u_int flags; | ||||
int rcnt; | int rcnt; | ||||
}; | }; | ||||
struct print_args { | struct print_args { | ||||
struct disk_devdesc *dev; | struct disk_devdesc *dev; | ||||
const char *prefix; | const char *prefix; | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | disk_write(struct disk_devdesc *dev, void *buf, uint64_t offset, u_int blocks) | ||||
od = (struct open_disk *)dev->d_opendata; | od = (struct open_disk *)dev->d_opendata; | ||||
ret = dev->d_dev->dv_strategy(dev, F_WRITE, dev->d_offset + offset, | ret = dev->d_dev->dv_strategy(dev, F_WRITE, dev->d_offset + offset, | ||||
blocks * od->sectorsize, buf, NULL); | blocks * od->sectorsize, buf, NULL); | ||||
return (ret); | return (ret); | ||||
} | } | ||||
int | int | ||||
disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf) | disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *data) | ||||
{ | { | ||||
struct open_disk *od = dev->d_opendata; | |||||
if (dev->d_dev->dv_ioctl) | if (od == NULL) | ||||
return ((*dev->d_dev->dv_ioctl)(dev->d_opendata, cmd, buf)); | return (ENOTTY); | ||||
allanjude: Does it make sense to keep this? Do any of the classes use this? | |||||
tsoomeAuthorUnsubmitted Not Done Inline ActionsI haven't seen any need. in fact the need is reversed, the specific interfaces "extend" the disk_* api, like bd_open() does its internal thing and then calls disk_open(), bd_ioctl calls up to disk_ioctl() etc. tsoome: I haven't seen any need. in fact the need is reversed, the specific interfaces "extend" the… | |||||
return (ENXIO); | switch (cmd) { | ||||
case DIOCGSECTORSIZE: | |||||
*(u_int *)data = od->sectorsize; | |||||
break; | |||||
case DIOCGMEDIASIZE: | |||||
if (dev->d_offset == 0) | |||||
*(uint64_t *)data = od->mediasize; | |||||
else | |||||
*(uint64_t *)data = od->entrysize * od->sectorsize; | |||||
break; | |||||
default: | |||||
return (ENOTTY); | |||||
} | } | ||||
return (0); | |||||
} | |||||
int | int | ||||
disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize, | disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize, | ||||
u_int flags) | u_int flags) | ||||
{ | { | ||||
struct open_disk *od; | struct open_disk *od; | ||||
struct ptable *table; | struct ptable *table; | ||||
struct ptable_entry part; | struct ptable_entry part; | ||||
int rc, slice, partition; | int rc, slice, partition; | ||||
Show All 26 Lines | disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize, | ||||
} else { | } else { | ||||
od = (struct open_disk *)malloc(sizeof(struct open_disk)); | od = (struct open_disk *)malloc(sizeof(struct open_disk)); | ||||
if (od == NULL) { | if (od == NULL) { | ||||
DEBUG("no memory"); | DEBUG("no memory"); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
dev->d_opendata = od; | dev->d_opendata = od; | ||||
od->rcnt = 0; | od->rcnt = 0; | ||||
od->entrysize = 0; | |||||
} | } | ||||
od->mediasize = mediasize; | od->mediasize = mediasize; | ||||
od->sectorsize = sectorsize; | od->sectorsize = sectorsize; | ||||
od->flags = flags; | od->flags = flags; | ||||
DEBUG("%s unit %d, slice %d, partition %d => %p", | DEBUG("%s unit %d, slice %d, partition %d => %p", | ||||
disk_fmtdev(dev), dev->d_unit, dev->d_slice, dev->d_partition, od); | disk_fmtdev(dev), dev->d_unit, dev->d_slice, dev->d_partition, od); | ||||
/* Determine disk layout. */ | /* Determine disk layout. */ | ||||
od->table = ptable_open(dev, mediasize / sectorsize, sectorsize, | od->table = ptable_open(dev, mediasize / sectorsize, sectorsize, | ||||
ptblread); | ptblread); | ||||
if (od->table == NULL) { | if (od->table == NULL) { | ||||
DEBUG("Can't read partition table"); | DEBUG("Can't read partition table"); | ||||
rc = ENXIO; | rc = ENXIO; | ||||
goto out; | goto out; | ||||
} | } | ||||
if (ptable_getsize(od->table, &mediasize) != 0) { | |||||
rc = ENXIO; | |||||
goto out; | |||||
} | |||||
if (mediasize > od->mediasize) { | |||||
od->mediasize = mediasize; | |||||
} | |||||
opened: | opened: | ||||
rc = 0; | rc = 0; | ||||
if (ptable_gettype(od->table) == PTABLE_BSD && | if (ptable_gettype(od->table) == PTABLE_BSD && | ||||
partition >= 0) { | partition >= 0) { | ||||
/* It doesn't matter what value has d_slice */ | /* It doesn't matter what value has d_slice */ | ||||
rc = ptable_getpart(od->table, &part, partition); | rc = ptable_getpart(od->table, &part, partition); | ||||
if (rc == 0) | if (rc == 0) { | ||||
dev->d_offset = part.start; | dev->d_offset = part.start; | ||||
od->entrysize = part.end - part.start + 1; | |||||
} | |||||
} else if (slice >= 0) { | } else if (slice >= 0) { | ||||
/* Try to get information about partition */ | /* Try to get information about partition */ | ||||
if (slice == 0) | if (slice == 0) | ||||
rc = ptable_getbestpart(od->table, &part); | rc = ptable_getbestpart(od->table, &part); | ||||
else | else | ||||
rc = ptable_getpart(od->table, &part, slice); | rc = ptable_getpart(od->table, &part, slice); | ||||
if (rc != 0) /* Partition doesn't exist */ | if (rc != 0) /* Partition doesn't exist */ | ||||
goto out; | goto out; | ||||
dev->d_offset = part.start; | dev->d_offset = part.start; | ||||
od->entrysize = part.end - part.start + 1; | |||||
slice = part.index; | slice = part.index; | ||||
if (ptable_gettype(od->table) == PTABLE_GPT) { | if (ptable_gettype(od->table) == PTABLE_GPT) { | ||||
partition = 255; | partition = 255; | ||||
goto out; /* Nothing more to do */ | goto out; /* Nothing more to do */ | ||||
} else if (partition == 255) { | } else if (partition == 255) { | ||||
/* | /* | ||||
* When we try to open GPT partition, but partition | * When we try to open GPT partition, but partition | ||||
* table isn't GPT, reset d_partition value to -1 | * table isn't GPT, reset d_partition value to -1 | ||||
Show All 26 Lines | if (partition < 0) { | ||||
if (ptable_gettype(table) != PTABLE_BSD) | if (ptable_gettype(table) != PTABLE_BSD) | ||||
goto out; | goto out; | ||||
partition = 0; | partition = 0; | ||||
} | } | ||||
rc = ptable_getpart(table, &part, partition); | rc = ptable_getpart(table, &part, partition); | ||||
if (rc != 0) | if (rc != 0) | ||||
goto out; | goto out; | ||||
dev->d_offset += part.start; | dev->d_offset += part.start; | ||||
od->entrysize = part.end - part.start + 1; | |||||
} | } | ||||
out: | out: | ||||
if (table != NULL) | if (table != NULL) | ||||
ptable_close(table); | ptable_close(table); | ||||
if (rc != 0) { | if (rc != 0) { | ||||
if (od->rcnt < 1) { | if (od->rcnt < 1) { | ||||
if (od->table != NULL) | if (od->table != NULL) | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |
Does it make sense to keep this? Do any of the classes use this?