part.c (55b1c6e7e4a6909004e13c6d2f328f911a8e7b83) part.c (48990fce8e1c5e572a91656a6f1d58dddba8a4a6)
1/*-
2 * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 23 unchanged lines hidden (view full) ---

32#include <sys/diskmbr.h>
33#include <sys/disklabel.h>
34#include <sys/endian.h>
35#include <sys/gpt.h>
36#include <sys/stddef.h>
37#include <sys/queue.h>
38#include <sys/vtoc.h>
39
1/*-
2 * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 23 unchanged lines hidden (view full) ---

32#include <sys/diskmbr.h>
33#include <sys/disklabel.h>
34#include <sys/endian.h>
35#include <sys/gpt.h>
36#include <sys/stddef.h>
37#include <sys/queue.h>
38#include <sys/vtoc.h>
39
40#include <fs/cd9660/iso.h>
41
40#include <crc32.h>
41#include <part.h>
42#include <uuid.h>
43
44#ifdef PART_DEBUG
45#define DEBUG(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)
46#else
47#define DEBUG(fmt, args...)

--- 44 unchanged lines hidden (view full) ---

92 { PART_FREEBSD_NANDFS, "FreeBSD nandfs" },
93 { PART_FREEBSD_UFS, "FreeBSD UFS" },
94 { PART_FREEBSD_ZFS, "FreeBSD ZFS" },
95 { PART_FREEBSD_SWAP, "FreeBSD swap" },
96 { PART_FREEBSD_VINUM, "FreeBSD vinum" },
97 { PART_LINUX, "Linux" },
98 { PART_LINUX_SWAP, "Linux swap" },
99 { PART_DOS, "DOS/Windows" },
42#include <crc32.h>
43#include <part.h>
44#include <uuid.h>
45
46#ifdef PART_DEBUG
47#define DEBUG(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)
48#else
49#define DEBUG(fmt, args...)

--- 44 unchanged lines hidden (view full) ---

94 { PART_FREEBSD_NANDFS, "FreeBSD nandfs" },
95 { PART_FREEBSD_UFS, "FreeBSD UFS" },
96 { PART_FREEBSD_ZFS, "FreeBSD ZFS" },
97 { PART_FREEBSD_SWAP, "FreeBSD swap" },
98 { PART_FREEBSD_VINUM, "FreeBSD vinum" },
99 { PART_LINUX, "Linux" },
100 { PART_LINUX_SWAP, "Linux swap" },
101 { PART_DOS, "DOS/Windows" },
102 { PART_ISO9660, "ISO9660" },
100};
101
102const char *
103parttype2str(enum partition_type type)
104{
105 size_t i;
106
107 for (i = 0; i < nitems(ptypes); i++)

--- 490 unchanged lines hidden (view full) ---

598 table->type = PTABLE_VTOC8;
599out:
600 free(buf);
601 return (table);
602
603}
604#endif /* LOADER_VTOC8_SUPPORT */
605
103};
104
105const char *
106parttype2str(enum partition_type type)
107{
108 size_t i;
109
110 for (i = 0; i < nitems(ptypes); i++)

--- 490 unchanged lines hidden (view full) ---

601 table->type = PTABLE_VTOC8;
602out:
603 free(buf);
604 return (table);
605
606}
607#endif /* LOADER_VTOC8_SUPPORT */
608
609#define cdb2devb(bno) ((bno) * ISO_DEFAULT_BLOCK_SIZE / table->sectorsize)
610
611static struct ptable *
612ptable_iso9660read(struct ptable *table, void *dev, diskread_t dread)
613{
614 uint8_t *buf;
615 struct iso_primary_descriptor *vd;
616 struct pentry *entry;
617
618 buf = malloc(table->sectorsize);
619 if (buf == NULL)
620 return (table);
621
622 if (dread(dev, buf, 1, cdb2devb(16)) != 0) {
623 DEBUG("read failed");
624 ptable_close(table);
625 table = NULL;
626 goto out;
627 }
628 vd = (struct iso_primary_descriptor *)buf;
629 if (bcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0)
630 goto out;
631
632 entry = malloc(sizeof(*entry));
633 if (entry == NULL)
634 goto out;
635 entry->part.start = 0;
636 entry->part.end = table->sectors;
637 entry->part.type = PART_ISO9660;
638 entry->part.index = 0;
639 STAILQ_INSERT_TAIL(&table->entries, entry, entry);
640
641 table->type = PTABLE_ISO9660;
642
643out:
644 free(buf);
645 return (table);
646}
647
606struct ptable *
607ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize,
608 diskread_t *dread)
609{
610 struct dos_partition *dp;
611 struct ptable *table;
612 uint8_t *buf;
613 int i, count;

--- 15 unchanged lines hidden (view full) ---

629 table = malloc(sizeof(*table));
630 if (table == NULL)
631 goto out;
632 table->sectors = sectors;
633 table->sectorsize = sectorsize;
634 table->type = PTABLE_NONE;
635 STAILQ_INIT(&table->entries);
636
648struct ptable *
649ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize,
650 diskread_t *dread)
651{
652 struct dos_partition *dp;
653 struct ptable *table;
654 uint8_t *buf;
655 int i, count;

--- 15 unchanged lines hidden (view full) ---

671 table = malloc(sizeof(*table));
672 if (table == NULL)
673 goto out;
674 table->sectors = sectors;
675 table->sectorsize = sectorsize;
676 table->type = PTABLE_NONE;
677 STAILQ_INIT(&table->entries);
678
679 if (ptable_iso9660read(table, dev, dread) != NULL) {
680 if (table->type == PTABLE_ISO9660)
681 goto out;
682 }
683
637#ifdef LOADER_VTOC8_SUPPORT
638 if (be16dec(buf + offsetof(struct vtoc8, magic)) == VTOC_MAGIC) {
639 if (ptable_vtoc8read(table, dev, dread) == NULL) {
640 /* Read error. */
641 table = NULL;
642 goto out;
643 } else if (table->type == PTABLE_VTOC8)
644 goto out;

--- 254 unchanged lines hidden ---
684#ifdef LOADER_VTOC8_SUPPORT
685 if (be16dec(buf + offsetof(struct vtoc8, magic)) == VTOC_MAGIC) {
686 if (ptable_vtoc8read(table, dev, dread) == NULL) {
687 /* Read error. */
688 table = NULL;
689 goto out;
690 } else if (table->type == PTABLE_VTOC8)
691 goto out;

--- 254 unchanged lines hidden ---