]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/cmd/randfree_file/randfree_file.c
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2012 by Delphix. All rights reserved.
31 #include "../file_common.h"
32 #include <sys/types.h>
35 #include <linux/falloc.h>
38 * Create a file with assigned size and then free the specified
42 static void usage(char *progname
);
47 (void) fprintf(stderr
,
48 "usage: %s [-l filesize] [-s start-offset]"
49 "[-n section-len] filename\n", progname
);
54 main(int argc
, char *argv
[])
56 char *filename
= NULL
;
62 mode_t mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
;
64 while ((ch
= getopt(argc
, argv
, "l:s:n:")) != EOF
) {
67 filesize
= atoll(optarg
);
70 start_off
= atoll(optarg
);
73 off_len
= atoll(optarg
);
81 if (optind
== argc
- 1)
82 filename
= argv
[optind
];
86 if ((fd
= open(filename
, O_RDWR
| O_CREAT
| O_TRUNC
, mode
)) < 0) {
91 buf
= (char *)malloc(filesize
);
93 if (write(fd
, buf
, filesize
) < filesize
) {
101 if (fallocate(fd
, FALLOC_FL_PUNCH_HOLE
| FALLOC_FL_KEEP_SIZE
,
102 start_off
, off_len
) < 0) {