Lines Matching refs:table

52 #define BLKRRPART  _IO(0x12,95) /* re-read partition table */
106 #define LBA_ADDR(table, value) ((uint64_t) (table)->sector_size * (value))
108 int GPT_map_from_content(struct GPT_entry_table *table, const struct GPT_content *content)
112 if (gpt_mmap(&table->header_map, LBA_ADDR(table, content->header.current_lba),
113 table->sector_size, table->fd)) {
118 table->header = (struct GPT_header *) table->header_map.ptr;
120 table->partition_table_size = ROUND_UP(content->header.entries_count * sizeof(*table->entries),
121 table->sector_size);
123 // Mapping entry table
124 if (gpt_mmap(&table->entries_map, LBA_ADDR(table, content->header.entries_lba),
125 table->partition_table_size, table->fd)) {
130 table->entries = (struct GPT_entry_raw *) table->entries_map.ptr;
133 if (gpt_mmap(&table->sec_header_map, LBA_ADDR(table, content->header.backup_lba),
134 table->sector_size, table->fd)) {
139 // Mapping secondary entries table
140 if (gpt_mmap(&table->sec_entries_map,
141 LBA_ADDR(table, content->header.backup_lba) - table->partition_table_size,
142 table->partition_table_size, table->fd)) {
143 D(ERR, "unable to map secondary gpt table");
147 table->second_header = (struct GPT_header *) table->sec_header_map.ptr;
148 table->second_entries = (struct GPT_entry_raw *) table->sec_entries_map.ptr;
149 table->second_valid = strcmp("EFI PART", (char *) table->second_header->signature) == 0;
154 gpt_unmap(&table->sec_header_map);
156 gpt_unmap(&table->entries_map);
158 gpt_unmap(&table->header_map);
163 int GPT_map(struct GPT_entry_table *table, unsigned header_lba)
169 if (gpt_mmap(&mapping, LBA_ADDR(table, header_lba), table->sector_size, table->fd)) {
185 return GPT_map_from_content(table, &content);
188 gpt_unmap(&table->header_map);
195 struct GPT_entry_table *table;
198 table = (struct GPT_entry_table *) malloc(sizeof(*table));
199 table->fd = open(path, O_RDWR);
201 if (table->fd < 0) {
206 if (!ioctl(table->fd, BLKSSZGET, &sector_bytes)) {
207 table->sector_size = (unsigned) sector_bytes;
208 D(INFO, "Got sector size %d", table->sector_size);
211 table->sector_size = 512;
214 if (GPT_map(table, header_lba)) {
219 return table;
224 struct GPT_entry_table *table;
227 table = (struct GPT_entry_table *) malloc(sizeof(*table));
228 table->fd = open(path, O_RDWR);
230 if (table->fd < 0) {
235 if (!ioctl(table->fd, BLKSSZGET, &sector_bytes)) {
236 table->sector_size = (unsigned) sector_bytes;
237 D(INFO, "Got sector size %d", table->sector_size);
240 table->sector_size = 512;
243 if (GPT_map_from_content(table, content)) {
248 return table;
252 void GPT_release_device(struct GPT_entry_table *table)
254 gpt_unmap(&table->header_map);
255 gpt_unmap(&table->entries_map);
256 gpt_unmap(&table->sec_header_map);
257 gpt_unmap(&table->sec_entries_map);
258 close(table->fd);
259 free(table);
262 static int GPT_check_overlap(struct GPT_entry_table *table, struct GPT_entry_raw *entry);
263 static int GPT_check_overlap_except(struct GPT_entry_table *table,
267 void GPT_edit_entry(struct GPT_entry_table *table,
271 struct GPT_entry_raw *current_entry = GPT_get_pointer(table, old_entry);
273 if (GPT_check_overlap_except(table, new_entry, current_entry)) {
286 int GPT_delete_entry(struct GPT_entry_table *table, struct GPT_entry_raw *entry)
288 struct GPT_entry_raw *raw = GPT_get_pointer(table, entry);
296 // Entry in the middle of table may become empty
302 void GPT_add_entry(struct GPT_entry_table *table, struct GPT_entry_raw *entry)
306 if (GPT_check_overlap(table, entry)) {
311 if (GPT_get_pointer(table, entry) != NULL) {
316 struct GPT_entry_raw *entries = table->entries;
318 for (i = 0; i < table->header->entries_count; ++i) {
332 struct GPT_entry_raw *GPT_get_pointer_by_UTFname(struct GPT_entry_table *table, const uint16_t *name);
334 struct GPT_entry_raw *GPT_get_pointer(struct GPT_entry_table *table, struct GPT_entry_raw *entry)
337 return GPT_get_pointer_by_guid(table, (const char *) entry->partition_guid);
339 return GPT_get_pointer_by_UTFname(table, entry->name);
345 struct GPT_entry_raw *GPT_get_pointer_by_guid(struct GPT_entry_table *table, const char *name)
347 int current = (int) table->header->entries_count;
351 (char *) table->entries[current].partition_guid, 16) == 0) {
352 return &table->entries[current];
385 struct GPT_entry_raw *GPT_get_pointer_by_name(struct GPT_entry_table *table, const char *name)
387 int count = (int) table->header->entries_count;
391 if (strncmp_UTF16_char(table->entries[current].name,
393 return &table->entries[current];
400 struct GPT_entry_raw *GPT_get_pointer_by_UTFname(struct GPT_entry_table *table, const uint16_t *name)
402 int count = (int) table->header->entries_count;
406 if (strncmp_UTF16(table->entries[current].name,
408 return &table->entries[current];
415 void GPT_sync(struct GPT_entry_table *table)
421 crc = crc32(crc, (void*) table->entries, table->header->entries_count * sizeof(*table->entries));
422 table->header->partition_array_checksum = crc;
424 table->header->header_checksum = 0;
426 crc = crc32(crc, (void*) table->header, table->header->header_size);
427 table->header->header_checksum = crc;
430 if (table->second_valid) {
431 memcpy((void *)table->second_entries, (void *) table->entries, table->partition_table_size);
432 memcpy((void *)table->second_header, (void *)table->header, sizeof(*table->header));
435 if(!ioctl(table->fd, BLKRRPART, NULL)) {
436 D(WARN, "Unable to force kernel to refresh partition table");
454 static int GPT_check_overlap_except(struct GPT_entry_table *table,
457 int current = (int) table->header->entries_count;
466 current_entry = &table->entries[current];
481 static int GPT_check_overlap(struct GPT_entry_table *table, struct GPT_entry_raw *entry)
483 return GPT_check_overlap_except(table, entry, NULL);
574 void GPT_default_content(struct GPT_content *content, struct GPT_entry_table *table)
576 if (table != NULL) {
577 memcpy(&content->header, table->header, sizeof(content->header));
582 D(WARN, "Could not locate old gpt table, using default values");
700 D(ERR, "Could not find partition table");