boot0cfg.c (5679e1ac37875b7536f1d5e54f0303b34df5e8a6) | boot0cfg.c (dfa5ad94211f9ff1f8f582cbc154759f5eefbad3) |
---|---|
1/* 2 * Copyright (c) 1999 Robert Nordier 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 --- 21 unchanged lines hidden (view full) --- 30#include <sys/param.h> 31#include <sys/disklabel.h> 32#include <sys/diskmbr.h> 33#include <sys/stat.h> 34 35#include <err.h> 36#include <errno.h> 37#include <fcntl.h> | 1/* 2 * Copyright (c) 1999 Robert Nordier 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 --- 21 unchanged lines hidden (view full) --- 30#include <sys/param.h> 31#include <sys/disklabel.h> 32#include <sys/diskmbr.h> 33#include <sys/stat.h> 34 35#include <err.h> 36#include <errno.h> 37#include <fcntl.h> |
38#include <libgeom.h> |
|
38#include <paths.h> 39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <unistd.h> 43 44#define MBRSIZE 512 /* master boot record size */ 45 --- 205 unchanged lines hidden (view full) --- 251 * Write out the mbr to the specified file. 252 */ 253static void 254write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size) 255{ 256 int fd, p; 257 ssize_t n; 258 char *s; | 39#include <paths.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <string.h> 43#include <unistd.h> 44 45#define MBRSIZE 512 /* master boot record size */ 46 --- 205 unchanged lines hidden (view full) --- 252 * Write out the mbr to the specified file. 253 */ 254static void 255write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size) 256{ 257 int fd, p; 258 ssize_t n; 259 char *s; |
260 const char *q; 261 struct gctl_req *grq; |
|
259 260 fd = open(fname, O_WRONLY | flags, 0666); 261 if (fd != -1) { 262 n = write(fd, mbr, mbr_size); 263 close(fd); 264 if (n != mbr_size) 265 errx(1, "%s: short write", fname); 266 return; 267 } | 262 263 fd = open(fname, O_WRONLY | flags, 0666); 264 if (fd != -1) { 265 n = write(fd, mbr, mbr_size); 266 close(fd); 267 if (n != mbr_size) 268 errx(1, "%s: short write", fname); 269 return; 270 } |
271 |
|
268 if (flags != 0) 269 err(1, "%s", fname); | 272 if (flags != 0) 273 err(1, "%s", fname); |
274 grq = gctl_get_handle(); 275 gctl_ro_param(grq, "verb", -1, "write MBR"); 276 gctl_ro_param(grq, "class", -1, "MBR"); 277 q = strrchr(fname, '/'); 278 if (q == NULL) 279 q = fname; 280 else 281 q++; 282 gctl_ro_param(grq, "geom", -1, q); 283 gctl_ro_param(grq, "data", mbr_size, mbr); 284 q = gctl_issue(grq); 285 if (q == NULL) 286 return; 287 288 warnx("%s: %s", fname, q); 289 gctl_free(grq); 290 |
|
270#ifdef DIOCSMBR 271 for (p = 1; p < 5; p++) { 272 asprintf(&s, "%ss%d", fname, p); | 291#ifdef DIOCSMBR 292 for (p = 1; p < 5; p++) { 293 asprintf(&s, "%ss%d", fname, p); |
273 fd = open(s, O_RDWR); | 294 fd = open(s, O_RDONLY); |
274 if (fd < 0) { 275 free(s); 276 continue; 277 } 278 n = ioctl(fd, DIOCSMBR, (mbr)); 279 if (n != 0) 280 err(1, "%s: ioctl DIOCSMBR", fname); 281 close(fd); --- 168 unchanged lines hidden --- | 295 if (fd < 0) { 296 free(s); 297 continue; 298 } 299 n = ioctl(fd, DIOCSMBR, (mbr)); 300 if (n != 0) 301 err(1, "%s: ioctl DIOCSMBR", fname); 302 close(fd); --- 168 unchanged lines hidden --- |