Path: blob/main/tests/sys/cddl/zfs/bin/largest_file.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"28#include <sys/param.h>29#include <signal.h>30#include <stdio.h>3132/*33* --------------------------------------------------------------34*35* Assertion:36* The last byte of the largest file size can be37* accessed without any errors. Also, the writing38* beyond the last byte of the largest file size39* will produce an errno of EFBIG.40*41* --------------------------------------------------------------42* If the write() system call below returns a "1",43* then the last byte can be accessed.44* --------------------------------------------------------------45*/46static void sigxfsz(int);47static void usage(char *);4849int50main(int argc, char **argv)51{52int fd = 0;53off_t offset = (OFF_MAX - 1);54off_t lseek_ret = 0;55int write_ret = 0;56int err = 0;57char mybuf[5];58char *testfile;5960if (argc != 2) {61usage(argv[0]);62}6364(void) sigset(SIGXFSZ, sigxfsz);6566testfile = strdup(argv[1]);6768fd = open(testfile, O_CREAT | O_RDWR);69if (fd < 0) {70perror("Failed to create testfile");71err = errno;72goto out;73}7475lseek_ret = lseek(fd, offset, SEEK_SET);76if (lseek_ret < 0) {77perror("Failed to seek to end of testfile");78err = errno;79goto out;80}8182write_ret = write(fd, mybuf, 1);83if (write_ret < 0) {84perror("Failed to write to end of file");85err = errno;86goto out;87}8889offset = 0;90lseek_ret = lseek(fd, offset, SEEK_CUR);91if (lseek_ret < 0) {92perror("Failed to seek to end of file");93err = errno;94goto out;95}9697write_ret = write(fd, mybuf, 1);98if (write_ret < 0) {99if (errno == EFBIG) {100(void) printf("write errno=EFBIG: success\n");101err = 0;102} else {103perror("Did not receive EFBIG");104err = errno;105}106} else {107(void) printf("write completed successfully, test failed\n");108err = 1;109}110111out:112(void) unlink(testfile);113free(testfile);114return (err);115}116117static void118usage(char *name)119{120(void) printf("%s <testfile>\n", name);121exit(1);122}123124/* ARGSUSED */125static void126sigxfsz(int signo)127{128(void) printf("\nlargest_file: sigxfsz() caught SIGXFSZ\n");129}130131132