11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 */
30
31 #include "../file_common.h"
32
33 /*
34 * Create a file with assigned size and then free the specified
35 * section of the file
36 */
37
38 static void usage(char *progname);
39
40 static void
41 usage(char *progname)
42 {
43 (void) fprintf(stderr,
44 "usage: %s [-l filesize] [-s start-offset]"
45 "[-n section-len] filename\n", progname);
46 exit(1);
47 }
48
49 int
50 main(int argc, char *argv[])
67 start_off = atoll(optarg);
68 break;
69 case 'n':
70 off_len = atoll(optarg);
71 break;
72 default:
73 usage(argv[0]);
74 break;
75 }
76 }
77
78 if (optind == argc - 1)
79 filename = argv[optind];
80 else
81 usage(argv[0]);
82
83 buf = (char *)malloc(filesize);
84
85 if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) {
86 perror("open");
87 return (1);
88 }
89 if (write(fd, buf, filesize) < filesize) {
90 perror("write");
91 return (1);
92 }
93 fl.l_whence = SEEK_SET;
94 fl.l_start = start_off;
95 fl.l_len = off_len;
96 if (fcntl(fd, F_FREESP, &fl) != 0) {
97 perror("fcntl");
98 return (1);
99 }
100
101 free(buf);
102 return (0);
103 }
|
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 */
30
31 /*
32 * Copyright (c) 2018, Joyent, Inc.
33 */
34
35 #include "../file_common.h"
36
37 /*
38 * Create a file with assigned size and then free the specified
39 * section of the file
40 */
41
42 static void usage(char *progname);
43
44 static void
45 usage(char *progname)
46 {
47 (void) fprintf(stderr,
48 "usage: %s [-l filesize] [-s start-offset]"
49 "[-n section-len] filename\n", progname);
50 exit(1);
51 }
52
53 int
54 main(int argc, char *argv[])
71 start_off = atoll(optarg);
72 break;
73 case 'n':
74 off_len = atoll(optarg);
75 break;
76 default:
77 usage(argv[0]);
78 break;
79 }
80 }
81
82 if (optind == argc - 1)
83 filename = argv[optind];
84 else
85 usage(argv[0]);
86
87 buf = (char *)malloc(filesize);
88
89 if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) {
90 perror("open");
91 free(buf);
92 return (1);
93 }
94 if (write(fd, buf, filesize) < filesize) {
95 perror("write");
96 free(buf);
97 return (1);
98 }
99 fl.l_whence = SEEK_SET;
100 fl.l_start = start_off;
101 fl.l_len = off_len;
102 if (fcntl(fd, F_FREESP, &fl) != 0) {
103 perror("fcntl");
104 free(buf);
105 return (1);
106 }
107
108 free(buf);
109 return (0);
110 }
|