Skip to content

Commit c6d3971

Browse files
committed
wip - I think I can write a lot of impls…
1 parent 6dbe7a8 commit c6d3971

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

mkfile.sh

+31-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,34 @@ die(){ printf 'mkfile: error: %s' "$1"; exit "${2-1}"; }
1212
usage()
1313
{
1414
echo "\
15-
Usage: mkfile [ -qnv ] [ -i INFILE ] [ -b BLOCKSIZE_MAX ] size[bkgtpe] FILES...
15+
Usage: mkfile [ -qnvp ] [-m MODE] [ -i INFILE ] [ -b BS ] size[bkgtpe] FILES...
1616
mkfile -?
1717
18-
max_blocksize is 1048576 bytes by default.
18+
blocksize is 1048576 bytes by default. By default, the remainder from size%bs
19+
is added with an additional dd pass in copy mode.
1920
2021
The \`b' suffix denotes block numbers; for compatibility, the default blocksize
2122
used for this calculation is 512."
2223
}
2324

25+
usage_more(){
26+
usage
27+
echo "Options:
28+
-q Turn off verbose output. This is the default.
29+
-v Turn on verbose output (looks like '{fn} {n}bytes @ {mode} -> {exit}')
30+
-b BS Sets blocksize for copy/pipe as well as for size calculation.
31+
-i FILE Sets the input file for dd (\`copy' mode only).
32+
-m MODE Sets the operation mode. Possible values are:
33+
copy dd-from-infile. Creates a regular file, slow. Default.
34+
seek dd-seek. Creates a sparse file (bad for swap), fast. See -n.
35+
alloc fallocate. Creates a regular file, fast.
36+
redir printf-pat-redir. Creates a regular file, slow.
37+
38+
-p PAT The byte pattern to use in pipe mode. Do not use NUL bytes.
39+
40+
".
41+
}
42+
2443
humanreadable ()
2544
{
2645
multiplier=1
@@ -42,16 +61,21 @@ humanreadable ()
4261
bs=1048576 # bigger, better, faster!
4362
hbs=512 # the bs used for humanreadable, in order to respect 'mkfile'.
4463
quiet=0
64+
method=copy # copy/seek/alloc
65+
noremain=0
66+
verbose=0
67+
keepgoing=0
4568
INFILE=/dev/zero
4669

47-
while getopts 'i:b:qnavr?' opt
70+
while getopts 'i:b:m:qnavr?' opt
4871
do
4972
case $opt in
5073
b) bs=$OPTARG hbs=$bs ;;
51-
i) INFILE=$OPTARG ;;
52-
q) quiet=1 ;;
53-
n) trunc=1 ;; # dd seek-only
54-
a) alloc=1 ;; # use fallocate instead
74+
i) INFILE=$OPTARG;;
75+
q) verbose=0 ;;
76+
k) keepgoing=1 ;;
77+
n) method=seek ;; # dd seek-only
78+
m) method=optarg ;;
5579
r) noremain=1 ;; # ignore (size % bs) difference
5680
v) verbose=1 ;; # %s %llu bytes stdout; METHOD stderr; \n stdout.
5781
\?) usage_more; exit ;;

0 commit comments

Comments
 (0)