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
25 To read unallocated disk blocks in a filesystem, do
31 extern char *sys_errlist[];
43 fprintf(stderr, "usage:\t%s [-s size] pathname\n", Progname);
44 fprintf(stderr, "\t-s size\t\tsize of file (default 10,000,000 bytes)\n");
54 char *pathname = NULL;
55 off_t size = 10000000;
57 int method = F_RESVSP;
62 Progname = strrchr(argv[0], '/');
69 /* Crack and validate the command line options. */
71 while ((opt = getopt(argc, argv, "s:")) != EOF) {
80 if (optind + 1 != argc)
82 pathname = argv[optind];
84 /* Create the file and write one byte at a large offset to create a
85 big hole in the middle of the file.
88 if ((fd = open(pathname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
89 perror("open failed");
93 /* First allocate uninitialized blocks. */
99 if (fcntl(fd, method, &flock) < 0) {
100 perror("fcntl failed");
104 /* Now seek out and write the byte. */
106 if (lseek(fd, size, 0) < 0) {
107 perror("lseek failed");
111 if (write(fd, buff, 1) != 1) {
112 perror("write failed");
115 printf("%s created\n", pathname);