Path: blob/main/tests/sys/cddl/zfs/bin/file_check.c
39536 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2007 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/252627#include "file_common.h"2829static unsigned char bigbuffer[BIGBUFFERSIZE];3031/*32* Given a filename, check that the file consists entirely33* of a particular pattern. If the pattern is not specified a34* default will be used. For default values see file_common.h35*/36int37main(int argc, char **argv)38{39int bigfd;40long i, n;41uint8_t fillchar = DATA;42int bigbuffersize = BIGBUFFERSIZE;43int64_t read_count = 0;4445/*46* Validate arguments47*/48if (argc < 2) {49(void) printf("Usage: %s filename [pattern]\n",50argv[0]);51exit(1);52}5354if (argv[2]) {55fillchar = atoi(argv[2]);56}5758/*59* Read the file contents and check every character60* against the supplied pattern. Abort if the61* pattern check fails.62*/63if ((bigfd = open(argv[1], O_RDONLY)) == -1) {64(void) printf("open %s failed %d\n", argv[1], errno);65exit(1);66}6768do {69if ((n = read(bigfd, &bigbuffer, bigbuffersize)) == -1) {70(void) printf("read failed (%ld), %d\n", n, errno);71exit(errno);72}7374for (i = 0; i < n; i++) {75if (bigbuffer[i] != fillchar) {76(void) printf("error %s: 0x%x != 0x%x)\n",77argv[1], bigbuffer[i], fillchar);78exit(1);79}80}8182read_count += n;83} while (n == bigbuffersize);8485return (0);86}878889