1/* 2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#include <stdio.h> 25#include <string.h> 26#include <stdlib.h> 27#include <fcntl.h> 28#include <err.h> 29#include <unistd.h> 30 31#include "util.h" 32 33void 34doDestroy(const char *dev) { 35 int bs; 36 if (gVerbose) { 37 fprintf(stderr, "Destroying device %s", dev); 38 } 39 40 if (!IsAppleLabel(dev)) { 41 errx(4,"doDestroy: device %s is not an Apple Label device", dev); 42 } 43 44 bs = GetBlockSize(dev); 45 if (bs != 0) { 46 int fd; 47 char bz[bs]; 48 memset(bz, 0, bs); 49 50 fd = open(dev, O_WRONLY); 51 if (fd == -1) { 52 err(1, "doDestroy: cannot open device %s for writing", dev); 53 } 54 if (write(fd, bz, bs) != bs) { 55 err(2, "doDestroy: cannot write %d bytes onto device %s", bs, dev); 56 } 57 close(fd); 58 } else { 59 errx(3, "doDestroy: cannot get blocksize for device %s", dev); 60 } 61} 62