]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - mkfile/xfs_mkfile.c
1957b4da7f98c2bc4cad653afbcbea9e28516d34
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * Make file utility for xfs.
40 #include <sys/ioctl.h>
43 #define MAXBUFFERSIZE (256 * 1024)
45 static void usage(void);
46 static char *progname
;
49 main(int argc
, char **argv
)
66 int buflen
= 0, nbuflen
;
67 int bufalign
= 0, nbufalign
, bufmin
;
71 progname
= basename(argv
[0]);
72 while ((c
= getopt(argc
, argv
, "npvV")) != EOF
) {
84 printf("%s version %s\n", progname
, VERSION
);
92 if (argc
< optind
+ 2 || errflg
)
97 len
= strlen(argv
[optind
]);
99 if (isalpha(argv
[optind
][len
-1])) {
100 switch (argv
[optind
][len
-1]) {
121 fprintf(stderr
, "unknown size %s\n", argv
[optind
]);
125 argv
[optind
][len
-1] = '\0';
128 size
= atoll(argv
[optind
]) * mult
;
132 while (optind
< argc
) {
134 fprintf(stdout
, "%s %lld bytes %s\n",
135 argv
[optind
], (long long)size
,
140 oflags
= O_CREAT
|O_TRUNC
|O_WRONLY
|(nobytes
? 0 : O_DIRECT
);
142 fd
= open(argv
[optind
], oflags
, 0600);
144 if ( (oflags
& O_DIRECT
)
145 && ( (fd
< 0 && errno
== EINVAL
)
146 || ioctl(fd
, XFS_IOC_DIOINFO
, &da
) < 0)) {
152 fd
= open(argv
[optind
], oflags
, 0600);
156 perror(argv
[optind
]);
168 if ((result
= lseek64(fd
, size
- 1, SEEK_SET
)) < 0LL) {
170 * This check doesn't actually work for 6.2
171 * efs and nfs2, although it should.
173 fprintf(stderr
, "lseek64 error, result = %lld\n",
176 perror(argv
[optind
]);
178 } else if (nobytes
) {
179 if (write(fd
, "", 1) < 0) {
180 perror(argv
[optind
]);
184 flck
.l_whence
= SEEK_SET
;
188 (void)ioctl(fd
, XFS_IOC_RESVSP64
, &flck
);
189 if (oflags
& O_DIRECT
) {
190 nbufalign
= da
.d_mem
;
192 if ( da
.d_miniosz
<= MAXBUFFERSIZE
193 && MAXBUFFERSIZE
<= da
.d_maxiosz
)
194 nbuflen
= MAXBUFFERSIZE
;
195 else if (da
.d_maxiosz
< MAXBUFFERSIZE
)
196 nbuflen
= da
.d_maxiosz
;
198 nbuflen
= da
.d_miniosz
;
200 bufmin
= da
.d_miniosz
;
202 nbuflen
= MAXBUFFERSIZE
;
203 nbufalign
= sizeof(long);
207 if (nbuflen
> buflen
|| nbufalign
> bufalign
) {
210 buf
= memalign(nbufalign
, nbuflen
);
213 nbufalign
= bufalign
;
218 lseek64(fd
, 0LL, SEEK_SET
);
220 while (wrote
< size
) {
221 if (size
- wrote
>= buflen
)
224 bytes
= roundup(size
- wrote
, bufmin
);
226 bytes
= size
- wrote
;
228 len
= write(fd
, buf
, bytes
);
231 perror(argv
[optind
]);
232 unlink(argv
[optind
]);
240 if (wrote
> size
&& ftruncate64(fd
, size
) < 0) {
241 perror(argv
[optind
]);
242 unlink(argv
[optind
]);
247 if ( close(fd
) < 0 ) {
248 perror(argv
[optind
]);
249 unlink(argv
[optind
]);
262 fprintf(stderr
, "%s: [-npv] <size> <name1> [<name2>] ...\n", progname
);