Fix readonly check for vdev user properties
[zfs.git] / tests / zfs-tests / cmd / file / largest_file.c
blobd7252556b3cf5311b7699a4c60b49afd1430600f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2012 by Delphix. All rights reserved.
31 #include "file_common.h"
32 #include <sys/param.h>
33 #include <signal.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <sys/stdtypes.h>
37 #include <unistd.h>
40 * --------------------------------------------------------------
42 * Assertion:
43 * The last byte of the largest file size can be
44 * accessed without any errors. Also, the writing
45 * beyond the last byte of the largest file size
46 * will produce an errno of EFBIG.
48 * --------------------------------------------------------------
49 * If the write() system call below returns a "1",
50 * then the last byte can be accessed.
51 * --------------------------------------------------------------
53 static void sigxfsz(int);
54 static void usage(char *);
56 int
57 main(int argc, char **argv)
59 int fd = 0;
60 offset_t offset = (MAXOFFSET_T - 1);
61 offset_t llseek_ret = 0;
62 int write_ret = 0;
63 int err = 0;
64 char mybuf[5] = "aaaa\0";
65 char *testfile;
66 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
67 struct sigaction sa;
69 if (argc != 2) {
70 usage(argv[0]);
73 if (sigemptyset(&sa.sa_mask) == -1)
74 return (errno);
75 sa.sa_flags = 0;
76 sa.sa_handler = sigxfsz;
77 if (sigaction(SIGXFSZ, &sa, NULL) == -1)
78 return (errno);
80 testfile = strdup(argv[1]);
81 if (testfile == NULL)
82 return (errno);
84 fd = open(testfile, O_CREAT | O_RDWR, mode);
85 if (fd < 0) {
86 err = errno;
87 perror("Failed to create testfile");
88 free(testfile);
89 return (err);
92 llseek_ret = lseek64(fd, offset, SEEK_SET);
93 if (llseek_ret < 0) {
94 err = errno;
95 perror("Failed to seek to end of testfile");
96 goto out;
99 write_ret = write(fd, mybuf, 1);
100 if (write_ret < 0) {
101 err = errno;
102 perror("Failed to write to end of file");
103 goto out;
106 offset = 0;
107 llseek_ret = lseek64(fd, offset, SEEK_CUR);
108 if (llseek_ret < 0) {
109 err = errno;
110 perror("Failed to seek to end of file");
111 goto out;
114 write_ret = write(fd, mybuf, 1);
115 if (write_ret < 0) {
116 if (errno == EFBIG || errno == EINVAL) {
117 (void) printf("write errno=EFBIG|EINVAL: success\n");
118 err = 0;
119 } else {
120 err = errno;
121 perror("Did not receive EFBIG");
123 } else {
124 (void) printf("write completed successfully, test failed\n");
125 err = 1;
128 out:
129 (void) unlink(testfile);
130 free(testfile);
131 close(fd);
132 return (err);
135 static void
136 usage(char *name)
138 (void) printf("%s <testfile>\n", name);
139 exit(1);
142 static void
143 sigxfsz(int signo)
145 (void) signo;
146 (void) printf("\nlargest_file: sigxfsz() caught SIGXFSZ\n");