2 * Copyright (c) 2012 SRI International
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/types.h>
34 #include <sys/ioctl.h>
44 /* XXXBED: should install and include sys/dev/isf.h */
46 off_t ir_off; /* Offset of range to delete (set to 0xFF) */
47 size_t ir_size; /* Size of range */
50 #define ISF_ERASE _IOW('I', 1, struct isf_range)
52 #define ISF_ERASE_BLOCK (128 * 1024)
54 static enum {UNSET, ERASE} action = UNSET;
59 fprintf(stderr, "usage: isfctl <device> erase <offset> <size>\n");
64 main(int argc, char **argv)
77 asprintf(&dev, "/dev/%s", argv[0]);
79 fd = open(dev, O_RDWR);
81 err(1, "unable to open device -- %s", dev);
83 if (strcmp(argv[0], "erase") == 0) {
87 ir.ir_off = strtol(argv[1], &p, 0);
89 errx(1, "invalid offset -- %s", argv[2]);
90 ir.ir_size = strtol(argv[2], &p, 0);
92 errx(1, "invalid size -- %s", argv[3]);
94 * If the user requests to delete less than 32K of space
95 * then assume that they want to delete a number of 128K
98 if (ir.ir_size < 32 * 1024)
99 ir.ir_size *= 128 * 1024;
104 i = ioctl(fd, ISF_ERASE, &ir);
106 err(1, "ioctl(%s, %jx, %zx)", dev,
107 (intmax_t)ir.ir_off, ir.ir_size);