| OLD | NEW |
| 1 /*- | 1 /*- |
| 2 * Copyright (c) 2007 Yahoo!, Inc. | 2 * Copyright (c) 2007 Yahoo!, Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * Written by: John Baldwin <jhb@FreeBSD.org> | 4 * Written by: John Baldwin <jhb@FreeBSD.org> |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 static unsigned int boot_entry = 0; | 49 static unsigned int boot_entry = 0; |
| 50 static uuid_t boot_uuid = GPT_ENT_TYPE_FREEBSD_BOOT; | 50 static uuid_t boot_uuid = GPT_ENT_TYPE_FREEBSD_BOOT; |
| 51 static const char *pmbr_path = "/boot/pmbr"; | 51 static const char *pmbr_path = "/boot/pmbr"; |
| 52 static const char *gptboot_path = "/boot/gptboot"; | 52 static const char *gptboot_path = "/boot/gptboot"; |
| 53 static u_long boot_size; | 53 static u_long boot_size; |
| 54 | 54 |
| 55 static void | 55 static void |
| 56 usage_boot(void) | 56 usage_boot(void) |
| 57 { | 57 { |
| 58 | |
| 59 fprintf(stderr, | 58 fprintf(stderr, |
| 60 » "usage: %s [-b pmbr] [-g gptboot] [-s count] device ...\n", | 59 » "usage: %s [-b pmbr] [-g gptboot] [-i index ] [-s count] device ...\
n", |
| 61 getprogname()); | 60 getprogname()); |
| 62 exit(1); | 61 exit(1); |
| 63 } | 62 } |
| 64 | 63 |
| 65 static int | 64 static int |
| 66 gpt_find(unsigned int boot_entry, uuid_t *type, map_t **mapp) | 65 gpt_find(unsigned int boot_entry, uuid_t *type, map_t **mapp) |
| 67 { | 66 { |
| 68 map_t *gpt, *tbl, *map; | 67 map_t *gpt, *tbl, *map; |
| 69 struct gpt_hdr *hdr; | 68 struct gpt_hdr *hdr; |
| 70 struct gpt_ent *ent; | 69 struct gpt_ent *ent; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return 1; | 158 return 1; |
| 160 } | 159 } |
| 161 #endif | 160 #endif |
| 162 mbr = pmbr->map_data; | 161 mbr = pmbr->map_data; |
| 163 nbytes = read(bfd, mbr->mbr_code, sizeof(mbr->mbr_code)); | 162 nbytes = read(bfd, mbr->mbr_code, sizeof(mbr->mbr_code)); |
| 164 if (nbytes < 0) { | 163 if (nbytes < 0) { |
| 165 warn("unable to read PMBR boot loader"); | 164 warn("unable to read PMBR boot loader"); |
| 166 return 1; | 165 return 1; |
| 167 } | 166 } |
| 168 if (nbytes != sizeof(mbr->mbr_code)) { | 167 if (nbytes != sizeof(mbr->mbr_code)) { |
| 169 warnx("short read of PMBR boot loader code (%ld/%ld bytes)", | 168 warnx("short read of PMBR boot loader code (%zd/%zd bytes)", |
| 170 nbytes, sizeof(mbr->mbr_code)); | 169 nbytes, sizeof(mbr->mbr_code)); |
| 171 // not returning, this is usually okay. | 170 // not returning, this is usually okay. |
| 172 } | 171 } |
| 173 close(bfd); | 172 close(bfd); |
| 174 | 173 |
| 175 #ifdef LINUX | 174 #ifdef LINUX |
| 176 /* We use the syslinux GPT new protocol. This requires the GUID | 175 /* We use the syslinux GPT new protocol. This requires the GUID |
| 177 of the boot partition to be at offset 424 in the mbr. See the | 176 of the boot partition to be at offset 424 in the mbr. See the |
| 178 doc in the syslinux source: src/doc/gpt.txt */ | 177 doc in the syslinux source: src/doc/gpt.txt */ |
| 179 if (gpt_find(boot_entry, &boot_uuid, &gptboot) != 0) { | 178 if (gpt_find(boot_entry, &boot_uuid, &gptboot) != 0) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 return 1; | 301 return 1; |
| 303 } | 302 } |
| 304 | 303 |
| 305 r = boot(fd); | 304 r = boot(fd); |
| 306 | 305 |
| 307 gpt_close(fd); | 306 gpt_close(fd); |
| 308 } | 307 } |
| 309 | 308 |
| 310 return r; | 309 return r; |
| 311 } | 310 } |
| OLD | NEW |