scheme.c (254156) | scheme.c (263382) |
---|---|
1/*- 2 * Copyright (c) 2013 Juniper Networks, Inc. 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 --- 16 unchanged lines hidden (view full) --- 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 30#include <sys/types.h> 31#include <sys/diskmbr.h> 32#include <sys/diskpc98.h> | 1/*- 2 * Copyright (c) 2013 Juniper Networks, Inc. 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 --- 16 unchanged lines hidden (view full) --- 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 30#include <sys/types.h> 31#include <sys/diskmbr.h> 32#include <sys/diskpc98.h> |
33#include <sys/queue.h> |
|
33#include <sys/vtoc.h> 34#include <err.h> 35#include <errno.h> 36#include <stdint.h> 37#include <strings.h> 38#include <unistd.h> 39 | 34#include <sys/vtoc.h> 35#include <err.h> 36#include <errno.h> 37#include <stdint.h> 38#include <strings.h> 39#include <unistd.h> 40 |
41#include "mkimg.h" |
|
40#include "scheme.h" 41 | 42#include "scheme.h" 43 |
42#define MAX(a, b) ((a < b) ? b : a) 43 | |
44static struct scheme { 45 const char *lexeme; 46 u_int token; 47} schemes[] = { 48 { .lexeme = "apm", .token = SCHEME_APM }, 49 { .lexeme = "bsd", .token = SCHEME_BSD }, 50 { .lexeme = "ebr", .token = SCHEME_EBR }, 51 { .lexeme = "gpt", .token = SCHEME_GPT }, 52 { .lexeme = "mbr", .token = SCHEME_MBR }, 53 { .lexeme = "pc98", .token = SCHEME_PC98 }, 54 { .lexeme = "vtoc8", .token = SCHEME_VTOC8 }, 55 { .lexeme = NULL, .token = SCHEME_UNDEF } 56}; 57 58static u_int scheme = SCHEME_UNDEF; 59static u_int secsz = 512; | 44static struct scheme { 45 const char *lexeme; 46 u_int token; 47} schemes[] = { 48 { .lexeme = "apm", .token = SCHEME_APM }, 49 { .lexeme = "bsd", .token = SCHEME_BSD }, 50 { .lexeme = "ebr", .token = SCHEME_EBR }, 51 { .lexeme = "gpt", .token = SCHEME_GPT }, 52 { .lexeme = "mbr", .token = SCHEME_MBR }, 53 { .lexeme = "pc98", .token = SCHEME_PC98 }, 54 { .lexeme = "vtoc8", .token = SCHEME_VTOC8 }, 55 { .lexeme = NULL, .token = SCHEME_UNDEF } 56}; 57 58static u_int scheme = SCHEME_UNDEF; 59static u_int secsz = 512; |
60static u_int nparts = 0; | |
61 62int 63scheme_select(const char *spec) 64{ 65 struct scheme *s; 66 67 s = schemes; 68 while (s->lexeme != NULL) { --- 9 unchanged lines hidden (view full) --- 78u_int 79scheme_selected(void) 80{ 81 82 return (scheme); 83} 84 85int | 60 61int 62scheme_select(const char *spec) 63{ 64 struct scheme *s; 65 66 s = schemes; 67 while (s->lexeme != NULL) { --- 9 unchanged lines hidden (view full) --- 77u_int 78scheme_selected(void) 79{ 80 81 return (scheme); 82} 83 84int |
86scheme_add_part(u_int idx, const char *type, off_t offset, off_t size) | 85scheme_check_part(struct part *p __unused) |
87{ 88 | 86{ 87 |
89 warnx("part: index=%u, type=`%s', offset=%ju, size=%ju", idx, 90 type, (uintmax_t)offset, (uintmax_t)size); 91 switch (scheme) { 92 case SCHEME_APM: 93 break; 94 case SCHEME_BSD: 95 break; 96 case SCHEME_EBR: 97 break; 98 case SCHEME_GPT: 99 break; 100 case SCHEME_MBR: 101 break; 102 case SCHEME_PC98: 103 break; 104 case SCHEME_VTOC8: 105 break; 106 } | 88 warnx("part: index=%u, type=`%s', offset=%ju, size=%ju", p->index, 89 p->type, (uintmax_t)p->offset, (uintmax_t)p->size); 90 |
107 return (0); 108} 109 110u_int 111scheme_max_parts(void) 112{ 113 u_int parts; 114 --- 26 unchanged lines hidden (view full) --- 141 return (parts); 142} 143 144off_t 145scheme_first_offset(u_int parts) 146{ 147 off_t off; 148 | 91 return (0); 92} 93 94u_int 95scheme_max_parts(void) 96{ 97 u_int parts; 98 --- 26 unchanged lines hidden (view full) --- 125 return (parts); 126} 127 128off_t 129scheme_first_offset(u_int parts) 130{ 131 off_t off; 132 |
149 nparts = parts; /* Save nparts for later. */ | |
150 switch (scheme) { 151 case SCHEME_APM: 152 off = parts + 1; 153 break; 154 case SCHEME_BSD: 155 off = 16; 156 break; 157 case SCHEME_EBR: 158 off = 1; 159 break; 160 case SCHEME_GPT: | 133 switch (scheme) { 134 case SCHEME_APM: 135 off = parts + 1; 136 break; 137 case SCHEME_BSD: 138 off = 16; 139 break; 140 case SCHEME_EBR: 141 off = 1; 142 break; 143 case SCHEME_GPT: |
161 off = 2 + (MAX(128, parts) + 3) / 4; | 144 off = 2 + (parts + 3) / 4; |
162 break; 163 case SCHEME_MBR: 164 off = 1; 165 break; 166 case SCHEME_PC98: | 145 break; 146 case SCHEME_MBR: 147 off = 1; 148 break; 149 case SCHEME_PC98: |
167 off = 16; | 150 off = 2; |
168 break; 169 case SCHEME_VTOC8: 170 off = 1; 171 break; 172 default: 173 off = 0; 174 break; 175 } --- 13 unchanged lines hidden (view full) --- 189 190void 191scheme_write(int fd, off_t off) 192{ 193 off_t lim; 194 195 switch (scheme) { 196 case SCHEME_GPT: | 151 break; 152 case SCHEME_VTOC8: 153 off = 1; 154 break; 155 default: 156 off = 0; 157 break; 158 } --- 13 unchanged lines hidden (view full) --- 172 173void 174scheme_write(int fd, off_t off) 175{ 176 off_t lim; 177 178 switch (scheme) { 179 case SCHEME_GPT: |
197 lim = off + secsz * (1 + (MAX(128, nparts) + 3) / 4); | 180 lim = off + secsz * (1 + (nparts + 3) / 4); |
198 break; 199 case SCHEME_EBR: 200 off -= secsz; 201 /* FALLTHROUGH */ 202 default: 203 lim = off; 204 break; 205 } 206 ftruncate(fd, lim); 207} | 181 break; 182 case SCHEME_EBR: 183 off -= secsz; 184 /* FALLTHROUGH */ 185 default: 186 lim = off; 187 break; 188 } 189 ftruncate(fd, lim); 190} |