2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Create file with XFS_XFLAG_REALTIME set.
23 #include <sys/types.h>
31 /* Note: In order to figure out the filesystem geometry, you have to run this
32 program as root. Creating the file itself can be done by anyone.
41 fprintf(stderr,"Usage: %s filename\n", prog);
62 if (prog = strrchr(argv[0], '/')) {
72 /* Create the file. */
74 if ((fd = open(pathname, O_RDWR|O_CREAT|O_EXCL|O_DIRECT, 0600)) < 0) {
75 fprintf(stderr,"%s: Cannot open %s, %s\n", prog,
76 pathname, strerror(errno));
80 /* Determine the filesystem's realtime partition geometry. */
82 if (syssgi(SGI_XFS_FSOPERATIONS, fd, XFS_FS_GEOMETRY, NULL, &geom)) {
83 fprintf(stderr,"%s: syssgi(,XFS_FS_GEOMETRY) failed, %s\n",
84 prog, strerror(errno));
88 /* Make the file a realtime file. */
90 fsx.fsx_xflags = 1; /*XFS_XFLAG_REALTIME*/
91 fsx.fsx_extsize = 4 * geom.blocksize * geom.rtextsize;
92 if (fcntl(fd, F_FSSETXATTR, &fsx) < 0) {
93 fprintf(stderr,"%s: fcntl(,F_FSSETXATTR) failed, %s\n", prog,
98 /* Obtain the direct I/O parameters. */
100 if (fcntl(fd, F_DIOINFO, &dio) < 0) {
101 fprintf(stderr,"%s: fcntl(,F_DIOINFO) failed,%s\n",
102 prog, strerror(errno));
105 fprintf(stdout, "%s: file %s direct io requirements.\n", prog,
107 fprintf(stdout, "%7d memory alignment.\n", dio.d_mem);
108 fprintf(stdout, "%7d minimum io size.\n", dio.d_miniosz);
109 fprintf(stdout, "%7d maximum io size.\n", dio.d_maxiosz);
111 if (fcntl(fd, F_FSGETXATTR, &fsx) < 0) {
112 fprintf(stderr,"%s: fcntl(,F_FSGETXATTR) failed, %s\n", prog,
116 fprintf(stdout, "%7d realtime extent size.\n", fsx.fsx_extsize);
118 /* Malloc and zero a buffer to use for writes. */
120 buflen = dio.d_miniosz;
121 if ((buf = memalign(dio.d_mem, buflen)) == NULL) {
122 fprintf(stderr,"%s: memalign(%d,%d) returned NULL\n",
123 prog, dio.d_mem, buflen);
126 memset(buf, '\0', buflen);
128 for (i = 0; i < 10; i += 2) {
129 offset = i * fsx.fsx_extsize;
130 if (lseek(fd, offset, SEEK_SET) < 0) {
131 fprintf(stderr, "seek to %d failed, %s\n", offset,
135 if ((count = write(fd, buf, buflen)) < 0) {
136 fprintf(stderr, "write of %d bytes failed at offset "
137 "%d, , %s\n", buflen, offset, strerror(errno));
140 if (count != buflen) {
141 fprintf(stderr, "expected to write %d bytes at offset "
142 "%d, actually wrote %d\n", buflen, offset,