2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * Create file with XFS_XFLAG_REALTIME set.
37 #include <sys/types.h>
38 /* #include <sys/fs/xfs_itable.h> */
41 #include <sys/syssgi.h>
43 #include <sys/fs/xfs_fsops.h>
53 /* Note: In order to figure out the filesystem geometry, you have to run this
54 program as root. Creating the file itself can be done by anyone.
63 fprintf(stderr,"Usage: %s filename\n", prog);
84 if (prog = strrchr(argv[0], '/')) {
94 /* Create the file. */
96 if ((fd = open(pathname, O_RDWR|O_CREAT|O_EXCL|O_DIRECT, 0600)) < 0) {
97 fprintf(stderr,"%s: Cannot open %s, %s\n", prog,
98 pathname, strerror(errno));
102 /* Determine the filesystem's realtime partition geometry. */
104 if (syssgi(SGI_XFS_FSOPERATIONS, fd, XFS_FS_GEOMETRY, NULL, &geom)) {
105 fprintf(stderr,"%s: syssgi(,XFS_FS_GEOMETRY) failed, %s\n",
106 prog, strerror(errno));
110 /* Make the file a realtime file. */
112 fsx.fsx_xflags = 1; /*XFS_XFLAG_REALTIME*/
113 fsx.fsx_extsize = 4 * geom.blocksize * geom.rtextsize;
114 if (fcntl(fd, F_FSSETXATTR, &fsx) < 0) {
115 fprintf(stderr,"%s: fcntl(,F_FSSETXATTR) failed, %s\n", prog,
120 /* Obtain the direct I/O parameters. */
122 if (fcntl(fd, F_DIOINFO, &dio) < 0) {
123 fprintf(stderr,"%s: fcntl(,F_DIOINFO) failed,%s\n",
124 prog, strerror(errno));
127 fprintf(stdout, "%s: file %s direct io requirements.\n", prog,
129 fprintf(stdout, "%7d memory alignment.\n", dio.d_mem);
130 fprintf(stdout, "%7d minimum io size.\n", dio.d_miniosz);
131 fprintf(stdout, "%7d maximum io size.\n", dio.d_maxiosz);
133 if (fcntl(fd, F_FSGETXATTR, &fsx) < 0) {
134 fprintf(stderr,"%s: fcntl(,F_FSGETXATTR) failed, %s\n", prog,
138 fprintf(stdout, "%7d realtime extent size.\n", fsx.fsx_extsize);
140 /* Malloc and zero a buffer to use for writes. */
142 buflen = dio.d_miniosz;
143 if ((buf = memalign(dio.d_mem, buflen)) == NULL) {
144 fprintf(stderr,"%s: memalign(%d,%d) returned NULL\n",
145 prog, dio.d_mem, buflen);
148 memset(buf, '\0', buflen);
150 for (i = 0; i < 10; i += 2) {
151 offset = i * fsx.fsx_extsize;
152 if (lseek(fd, offset, SEEK_SET) < 0) {
153 fprintf(stderr, "seek to %d failed, %s\n", offset,
157 if ((count = write(fd, buf, buflen)) < 0) {
158 fprintf(stderr, "write of %d bytes failed at offset "
159 "%d, , %s\n", buflen, offset, strerror(errno));
162 if (count != buflen) {
163 fprintf(stderr, "expected to write %d bytes at offset "
164 "%d, actually wrote %d\n", buflen, offset,