003 File Manager
Current Path:
/usr/src/tests/sys/cddl/zfs/bin
usr
/
src
/
tests
/
sys
/
cddl
/
zfs
/
bin
/
📁
..
📄
Makefile
(1.17 KB)
📄
bsddisks.ksh
(134 B)
📄
chg_usr_exec.c
(1.86 KB)
📄
devname2devid.c
(2.83 KB)
📄
dir_rd_update.c
(2.69 KB)
📄
dircmp.ksh
(49 B)
📄
dumpadm.ksh
(135 B)
📄
ff.ksh
(55 B)
📄
file_check.c
(2.17 KB)
📄
file_common.h
(1.59 KB)
📄
file_trunc.c
(4.48 KB)
📄
file_write.c
(5.26 KB)
📄
fmadm.ksh
(55 B)
📄
fmdump.ksh
(55 B)
📄
format.ksh
(55 B)
📄
groupadd.ksh
(114 B)
📄
groupdel.ksh
(114 B)
📄
groupmod.ksh
(114 B)
📄
groupshow.ksh
(67 B)
📄
largest_file.c
(2.96 KB)
📄
mkfile.c
(4.67 KB)
📄
mktree.c
(4.36 KB)
📄
mmapwrite.c
(2.25 KB)
📄
randfree_file.c
(2.23 KB)
📄
readmmap.c
(2.91 KB)
📄
rename_dir.c
(2.13 KB)
📄
rm_lnkcnt_zero_file.c
(3.13 KB)
📄
svcs.ksh
(55 B)
📄
swap.ksh
(50 B)
📄
testenv.ksh
(188 B)
📄
useradd.ksh
(113 B)
📄
userdel.ksh
(113 B)
📄
usermod.ksh
(113 B)
📄
zfs.ksh
(1.23 KB)
📄
zfs_crypto.ksh
(1.65 KB)
📄
zfs_version.ksh
(1.47 KB)
📄
zlogin.ksh
(55 B)
📄
zoneadm.ksh
(56 B)
📄
zonecfg.ksh
(55 B)
📄
zpool.ksh
(1.29 KB)
📄
zpool_bsd.ksh
(634 B)
📄
zpool_smi.ksh
(2.83 KB)
📄
zpool_version.ksh
(1.88 KB)
Editing: mkfile.c
/*- * Copyright (c) 2001-2013 * HATANO Tomomi. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef lint static char rcsid[] = "$Id: mkfile.c,v 1.5 2013-10-26 10:11:34+09 hatanou Exp $"; #endif /* !lint */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <fcntl.h> #include <limits.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> #include <ctype.h> #include <errno.h> #define MKFILE_WBUF ((size_t)(1048576)) /* Is 1M a reasonable value? */ /* SunOS's mkfile(8) sets "sticky bit." */ #define MKFILE_FLAG (O_WRONLY | O_CREAT | O_TRUNC) #define MKFILE_MODE (S_IRUSR | S_IWUSR | S_ISVTX) static char buf[MKFILE_WBUF]; static int nofill = 0; static int verbose = 0; static void usage() { fprintf(stderr, "Usage: mkfile [-nv] <size>[e|p|t|g|m|k|b] <filename> ...\n"); } static unsigned long long getsize(char *s) { int sh; unsigned long long length; char *suffix; /* * NOTE: We don't handle 'Z' (zetta) or 'Y' (yotta) suffixes yet. * These are too large to store in unsigned long long (64bits). * In the future, we'll have to use larger type, * something like uint128_t. */ length = strtoull(s, &suffix, 10); sh = 0; switch (tolower(*suffix)) { case 'e': /* Exabytes. */ sh = 60; break; case 'p': /* Petabytes. */ sh = 50; break; case 't': /* Terabytes. */ sh = 40; break; case 'g': /* Gigabytes. */ sh = 30; break; case 'm': /* Megabytes. */ sh = 20; break; case 'k': /* Kilobytes. */ sh = 10; break; case 'b': /* Blocks. */ sh = 9; break; case '\0': /* Bytes. */ break; default: /* Unknown... */ errno = EINVAL; return 0; } if (sh) { unsigned long long l; l = length; length <<= sh; /* Check overflow. */ if ((length >> sh) != l) { errno = ERANGE; return 0; } } return length; } static int create_file(char *f, unsigned long long s) { int fd; size_t w; ssize_t ws; if (verbose) { fprintf(stdout, "%s %llu bytes\n", f, s); fflush(stdout); } /* Open file to create. */ if ((fd = open(f, MKFILE_FLAG, MKFILE_MODE)) < 0) { return -1; } /* Seek to the end and write 1 byte. */ if ((lseek(fd, (off_t)(s - 1LL), SEEK_SET) == (off_t)-1) || (write(fd, buf, (size_t)1) == (ssize_t)-1)) { /* * We don't close(fd) here to avoid overwriting errno. * This is fd-leak, but is not harmful * because returning error causes mkfile(8) to exit. */ return -1; } /* Fill. */ if (!nofill) { if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) { /* Same as above. */ return -1; } while (s) { w = (s > MKFILE_WBUF) ? MKFILE_WBUF : s; if ((ws = write(fd, buf, w)) == (ssize_t)-1) { /* Same as above. */ return -1; } s -= ws; } } close(fd); return 0; } int main(int argc, char *argv[]) { unsigned long long fsize; char ch; /* We have at least 2 arguments. */ if (argc < 3) { usage(); return EXIT_FAILURE; } /* Options. */ while ((ch = getopt(argc, argv, "nv")) != -1) { switch (ch) { case 'n': nofill = 1; break; case 'v': verbose = 1; break; default: usage(); return EXIT_FAILURE; } } argc -= optind; argv += optind; /* File size to create. */ if ((fsize = getsize(*argv)) == 0) { perror(*argv); return EXIT_FAILURE; } /* Filenames to create. */ bzero(buf, MKFILE_WBUF); while (++argv, --argc) { if (create_file(*argv, fsize) == -1) { perror(*argv); return EXIT_FAILURE; } } return EXIT_SUCCESS; }
Upload File
Create Folder