diff options
| author | 2015-10-07 03:06:46 +0000 | |
|---|---|---|
| committer | 2015-10-07 03:06:46 +0000 | |
| commit | f66515a4f4169a0418f77e7642b5703eebe055be (patch) | |
| tree | 647b6050d4aef64ebf409cf0974d03f0fd3e269c /usr.sbin/installboot/util.c | |
| parent | don't try to change tun device flags if they are already what (diff) | |
| download | wireguard-openbsd-f66515a4f4169a0418f77e7642b5703eebe055be.tar.xz wireguard-openbsd-f66515a4f4169a0418f77e7642b5703eebe055be.zip | |
Add initial support for installing UEFI boot files to a GTP EFI System
Partition. Further work to be done in-tree.
ok deraadt@
Diffstat (limited to 'usr.sbin/installboot/util.c')
| -rw-r--r-- | usr.sbin/installboot/util.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/usr.sbin/installboot/util.c b/usr.sbin/installboot/util.c index 05c63e38acd..6d939e0902b 100644 --- a/usr.sbin/installboot/util.c +++ b/usr.sbin/installboot/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.5 2015/01/16 00:05:12 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.6 2015/10/07 03:06:46 krw Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> @@ -18,6 +18,7 @@ #include <sys/stat.h> #include <err.h> +#include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -53,7 +54,8 @@ filecopy(const char *srcfile, const char *dstfile) if (dfd == -1) err(1, "open %s", dstfile); if (fchown(dfd, 0, 0) == -1) - err(1, "chown"); + if (errno != EINVAL) + err(1, "chown"); if (fchmod(dfd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) err(1, "chmod"); @@ -90,3 +92,34 @@ fileprefix(const char *base, const char *path) return r; } + +/* + * Adapted from Hacker's Delight crc32b(). + * + * To quote http://www.hackersdelight.org/permissions.htm : + * + * "You are free to use, copy, and distribute any of the code on + * this web site, whether modified by you or not. You need not give + * attribution. This includes the algorithms (some of which appear + * in Hacker's Delight), the Hacker's Assistant, and any code submitted + * by readers. Submitters implicitly agree to this." + */ +u_int32_t +crc32(const u_char *buf, const u_int32_t size) +{ + int j; + u_int32_t i, byte, crc, mask; + + crc = 0xFFFFFFFF; + + for (i = 0; i < size; i++) { + byte = buf[i]; /* Get next byte. */ + crc = crc ^ byte; + for (j = 7; j >= 0; j--) { /* Do eight times. */ + mask = -(crc & 1); + crc = (crc >> 1) ^ (0xEDB88320 & mask); + } + } + + return ~crc; +} |
