2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 To read unallocated disk blocks in a filesystem, do
34 extern char *sys_errlist[];
47 fprintf(stderr, "usage:\t%s [-s size] pathname\n", Progname);
48 fprintf(stderr, "\t-s size\t\tsize of file (default 10,000,000 bytes)\n");
58 char *pathname = NULL;
59 off_t size = 10000000;
61 int method = F_RESVSP;
66 if (Progname = strrchr(argv[0], '/')) {
72 /* Crack and validate the command line options. */
74 while ((opt = getopt(argc, argv, "s:")) != EOF) {
83 if (optind + 1 != argc)
85 pathname = argv[optind];
87 /* Create the file and write one byte at a large offset to create a
88 big hole in the middle of the file.
91 if ((fd = open(pathname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
92 perror("open failed");
95 if (lseek(fd, size, 0) < 0) {
96 perror("lseek failed");
100 if (write(fd, buff, 1) != 1) {
101 perror("write failed");
105 /* Now fill in the hole with uninitialized blocks. */
111 if (fcntl(fd, method, &flock) < 0) {
112 perror("fcntl failed");
115 printf("%s created\n", pathname);