1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
8 * Create file with XFS_XFLAG_REALTIME set.
11 #include <sys/types.h>
19 /* Note: In order to figure out the filesystem geometry, you have to run this
20 program as root. Creating the file itself can be done by anyone.
29 fprintf(stderr,"Usage: %s filename\n", prog);
39 struct xfs_fsop_geom geom;
50 if (prog = strrchr(argv[0], '/')) {
60 /* Create the file. */
62 if ((fd = open(pathname, O_RDWR|O_CREAT|O_EXCL|O_DIRECT, 0600)) < 0) {
63 fprintf(stderr,"%s: Cannot open %s, %s\n", prog,
64 pathname, strerror(errno));
68 /* Determine the filesystem's realtime partition geometry. */
70 if (syssgi(SGI_XFS_FSOPERATIONS, fd, XFS_FS_GEOMETRY, NULL, &geom)) {
71 fprintf(stderr,"%s: syssgi(,XFS_FS_GEOMETRY) failed, %s\n",
72 prog, strerror(errno));
76 /* Make the file a realtime file. */
78 fsx.fsx_xflags = 1; /*XFS_XFLAG_REALTIME*/
79 fsx.fsx_extsize = 4 * geom.blocksize * geom.rtextsize;
80 if (fcntl(fd, F_FSSETXATTR, &fsx) < 0) {
81 fprintf(stderr,"%s: fcntl(,F_FSSETXATTR) failed, %s\n", prog,
86 /* Obtain the direct I/O parameters. */
88 if (fcntl(fd, F_DIOINFO, &dio) < 0) {
89 fprintf(stderr,"%s: fcntl(,F_DIOINFO) failed,%s\n",
90 prog, strerror(errno));
93 fprintf(stdout, "%s: file %s direct io requirements.\n", prog,
95 fprintf(stdout, "%7d memory alignment.\n", dio.d_mem);
96 fprintf(stdout, "%7d minimum io size.\n", dio.d_miniosz);
97 fprintf(stdout, "%7d maximum io size.\n", dio.d_maxiosz);
99 if (fcntl(fd, F_FSGETXATTR, &fsx) < 0) {
100 fprintf(stderr,"%s: fcntl(,F_FSGETXATTR) failed, %s\n", prog,
104 fprintf(stdout, "%7d realtime extent size.\n", fsx.fsx_extsize);
106 /* Malloc and zero a buffer to use for writes. */
108 buflen = dio.d_miniosz;
109 if ((buf = memalign(dio.d_mem, buflen)) == NULL) {
110 fprintf(stderr,"%s: memalign(%d,%d) returned NULL\n",
111 prog, dio.d_mem, buflen);
114 memset(buf, '\0', buflen);
116 for (i = 0; i < 10; i += 2) {
117 offset = i * fsx.fsx_extsize;
118 if (lseek(fd, offset, SEEK_SET) < 0) {
119 fprintf(stderr, "seek to %d failed, %s\n", offset,
123 if ((count = write(fd, buf, buflen)) < 0) {
124 fprintf(stderr, "write of %d bytes failed at offset "
125 "%d, , %s\n", buflen, offset, strerror(errno));
128 if (count != buflen) {
129 fprintf(stderr, "expected to write %d bytes at offset "
130 "%d, actually wrote %d\n", buflen, offset,