Skip to content

Commit

Permalink
part: Add functions to iterate through partition list
Browse files Browse the repository at this point in the history
These functions will come in handy once we support more partition types.
  • Loading branch information
xobs committed May 21, 2012
1 parent 17d17cf commit 2bf7b65
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
21 changes: 20 additions & 1 deletion part.c
Expand Up @@ -70,7 +70,26 @@ static struct partition_def partitions[] = {
};


struct part *part_init(struct disk *disk, int part_id) {


/* Returns the number of partitions available */
uint32_t part_disk_count(struct disk *disk) {
return sizeof(partitions)/sizeof(*partitions);
}

/* Returns the name of the specified partition */
char *part_disk_name(struct disk *disk, uint8_t part_id) {
return part_id<part_disk_count(disk)?partitions[part_id].name:NULL;
}

/* Returns the format of the specified partition */
enum part_format part_disk_format(struct disk *disk, uint8_t part_id) {
return part_id<part_disk_count(disk)?partitions[part_id].format:0;
}



struct part *part_init(struct disk *disk, uint8_t part_id) {
struct part *part;

part = malloc(sizeof(struct part));
Expand Down
22 changes: 21 additions & 1 deletion part.h
Expand Up @@ -9,12 +9,32 @@ enum part_format {
struct disk;
struct part;

struct part *part_init(struct disk *disk, int part_id);

/* Returns the number of partitions available */
uint32_t part_disk_count(struct disk *disk);

/* Returns the name of the specified partition */
char *part_disk_name(struct disk *disk, uint8_t part_id);

/* Returns the format of the specified partition */
enum part_format part_disk_format(struct disk *disk, uint8_t part_id);




struct part *part_init(struct disk *disk, uint8_t part_id);
void part_free(struct part **part);

/* Returns the length of the selected partition */
uint64_t part_length(struct part *part);

/* Returns a pointer to the partition's data */
const uint8_t *part_data(struct part *part);

/* Returns a byte from the specified offset */
uint8_t part_byte(struct part *part, uint64_t offset);

/* Returns the format of the selected partition */
enum part_format part_format(struct part *part);

#endif //__PART_H__

0 comments on commit 2bf7b65

Please sign in to comment.