1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
13 To read unallocated disk blocks in a filesystem, do
19 extern char *sys_errlist[];
31 fprintf(stderr, "usage:\t%s [-s size] pathname\n", Progname);
32 fprintf(stderr, "\t-s size\t\tsize of file (default 10,000,000 bytes)\n");
42 char *pathname = NULL;
43 off_t size = 10000000;
45 int method = F_RESVSP;
50 Progname = strrchr(argv[0], '/');
57 /* Crack and validate the command line options. */
59 while ((opt = getopt(argc, argv, "s:")) != EOF) {
68 if (optind + 1 != argc)
70 pathname = argv[optind];
72 /* Create the file and write one byte at a large offset to create a
73 big hole in the middle of the file.
76 if ((fd = open(pathname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
77 perror("open failed");
81 /* First allocate uninitialized blocks. */
87 if (fcntl(fd, method, &flock) < 0) {
88 perror("fcntl failed");
92 /* Now seek out and write the byte. */
94 if (lseek(fd, size, 0) < 0) {
95 perror("lseek failed");
99 if (write(fd, buff, 1) != 1) {
100 perror("write failed");
103 printf("%s created\n", pathname);