1 /*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27
28 #include "file_common.h"
29 #include <sys/param.h>
30 #include <signal.h>
31 #include <stdio.h>
32
33 /*
34 * --------------------------------------------------------------
35 *
36 * Assertion:
37 * The last byte of the largest file size can be
38 * accessed without any errors. Also, the writing
39 * beyond the last byte of the largest file size
40 * will produce an errno of EFBIG.
41 *
42 * --------------------------------------------------------------
43 * If the write() system call below returns a "1",
44 * then the last byte can be accessed.
45 * --------------------------------------------------------------
46 */
47 static void sigxfsz(int);
48 static void usage(char *);
49
50 int
main(int argc,char ** argv)51 main(int argc, char **argv)
52 {
53 int fd = 0;
54 off_t offset = (OFF_MAX - 1);
55 off_t lseek_ret = 0;
56 int write_ret = 0;
57 int err = 0;
58 char mybuf[5];
59 char *testfile;
60
61 if (argc != 2) {
62 usage(argv[0]);
63 }
64
65 (void) sigset(SIGXFSZ, sigxfsz);
66
67 testfile = strdup(argv[1]);
68
69 fd = open(testfile, O_CREAT | O_RDWR);
70 if (fd < 0) {
71 perror("Failed to create testfile");
72 err = errno;
73 goto out;
74 }
75
76 lseek_ret = lseek(fd, offset, SEEK_SET);
77 if (lseek_ret < 0) {
78 perror("Failed to seek to end of testfile");
79 err = errno;
80 goto out;
81 }
82
83 write_ret = write(fd, mybuf, 1);
84 if (write_ret < 0) {
85 perror("Failed to write to end of file");
86 err = errno;
87 goto out;
88 }
89
90 offset = 0;
91 lseek_ret = lseek(fd, offset, SEEK_CUR);
92 if (lseek_ret < 0) {
93 perror("Failed to seek to end of file");
94 err = errno;
95 goto out;
96 }
97
98 write_ret = write(fd, mybuf, 1);
99 if (write_ret < 0) {
100 if (errno == EFBIG) {
101 (void) printf("write errno=EFBIG: success\n");
102 err = 0;
103 } else {
104 perror("Did not receive EFBIG");
105 err = errno;
106 }
107 } else {
108 (void) printf("write completed successfully, test failed\n");
109 err = 1;
110 }
111
112 out:
113 (void) unlink(testfile);
114 free(testfile);
115 return (err);
116 }
117
118 static void
usage(char * name)119 usage(char *name)
120 {
121 (void) printf("%s <testfile>\n", name);
122 exit(1);
123 }
124
125 /* ARGSUSED */
126 static void
sigxfsz(int signo)127 sigxfsz(int signo)
128 {
129 (void) printf("\nlargest_file: sigxfsz() caught SIGXFSZ\n");
130 }
131