1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
15 To read unallocated disk blocks in a filesystem, do
22 extern char *sys_errlist[];
35 fprintf(stderr, "usage:\t%s [-s size] pathname\n", Progname);
36 fprintf(stderr, "\t-s size\t\tsize of file (default 10,000,000 bytes)\n");
46 char *pathname = NULL;
47 off_t size = 10000000;
49 int method = F_RESVSP;
54 Progname = strrchr(argv[0], '/');
61 /* Crack and validate the command line options. */
63 while ((opt = getopt(argc, argv, "s:")) != EOF) {
72 if (optind + 1 != argc)
74 pathname = argv[optind];
76 /* Create the file and write one byte at a large offset to create a
77 big hole in the middle of the file.
80 if ((fd = open(pathname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
81 perror("open failed");
84 if (lseek(fd, size, 0) < 0) {
85 perror("lseek failed");
89 if (write(fd, buff, 1) != 1) {
90 perror("write failed");
94 /* Now fill in the hole with uninitialized blocks. */
100 if (fcntl(fd, method, &flock) < 0) {
101 perror("fcntl failed");
104 printf("%s created\n", pathname);