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 #pragma ident "@(#)largest_file.c 1.3 07/05/25 SMI"
28
29 #include "file_common.h"
30 #include <sys/param.h>
31 #include <signal.h>
32 #include <stdio.h>
33
34 /*
35 * --------------------------------------------------------------
36 *
37 * Assertion:
38 * The last byte of the largest file size can be
39 * accessed without any errors. Also, the writing
40 * beyond the last byte of the largest file size
41 * will produce an errno of EFBIG.
42 *
43 * --------------------------------------------------------------
44 * If the write() system call below returns a "1",
45 * then the last byte can be accessed.
46 * --------------------------------------------------------------
47 */
48 static void sigxfsz(int);
49 static void usage(char *);
50
51 int
main(int argc,char ** argv)52 main(int argc, char **argv)
53 {
54 int fd = 0;
55 off_t offset = (OFF_MAX - 1);
56 off_t lseek_ret = 0;
57 int write_ret = 0;
58 int err = 0;
59 char mybuf[5];
60 char *testfile;
61
62 if (argc != 2) {
63 usage(argv[0]);
64 }
65
66 (void) sigset(SIGXFSZ, sigxfsz);
67
68 testfile = strdup(argv[1]);
69
70 fd = open(testfile, O_CREAT | O_RDWR);
71 if (fd < 0) {
72 perror("Failed to create testfile");
73 err = errno;
74 goto out;
75 }
76
77 lseek_ret = lseek(fd, offset, SEEK_SET);
78 if (lseek_ret < 0) {
79 perror("Failed to seek to end of testfile");
80 err = errno;
81 goto out;
82 }
83
84 write_ret = write(fd, mybuf, 1);
85 if (write_ret < 0) {
86 perror("Failed to write to end of file");
87 err = errno;
88 goto out;
89 }
90
91 offset = 0;
92 lseek_ret = lseek(fd, offset, SEEK_CUR);
93 if (lseek_ret < 0) {
94 perror("Failed to seek to end of file");
95 err = errno;
96 goto out;
97 }
98
99 write_ret = write(fd, mybuf, 1);
100 if (write_ret < 0) {
101 if (errno == EFBIG) {
102 (void) printf("write errno=EFBIG: success\n");
103 err = 0;
104 } else {
105 perror("Did not receive EFBIG");
106 err = errno;
107 }
108 } else {
109 (void) printf("write completed successfully, test failed\n");
110 err = 1;
111 }
112
113 out:
114 (void) unlink(testfile);
115 free(testfile);
116 return (err);
117 }
118
119 static void
usage(char * name)120 usage(char *name)
121 {
122 (void) printf("%s <testfile>\n", name);
123 exit(1);
124 }
125
126 /* ARGSUSED */
127 static void
sigxfsz(int signo)128 sigxfsz(int signo)
129 {
130 (void) printf("\nlargest_file: sigxfsz() caught SIGXFSZ\n");
131 }
132