2 * Copyright (c) 2000-2001 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/
35 #define FSBTOBB(f) (OFFTOBBT(FSBTOOFF(f)))
36 #define BBTOFSB(b) (OFFTOFSB(BBTOOFF(b)))
37 #define OFFTOFSB(o) ((o) / blocksize)
38 #define FSBTOOFF(f) ((f) * blocksize)
42 printf("usage: alloc [-b blocksize] [-d dir] [-f file] [-n] [-r] [-t]\n"
44 " -n - non-interractive mode\n"
45 " -r - real time file\n"
46 " -t - truncate on open\n"
49 " r [offset] [length] - reserve\n"
50 " u [offset] [length] - unreserve\n"
51 " a [offset] [length] - alloc *** identical to free\n"
52 " f [offset] [length] - free *** identical to alloc\n"
53 " m/p [offset] [length] - print map\n"
55 " t [offset] - truncate\n"
57 " h/? - this help\n");
64 /* params are in bytes */
65 void map(off64_t off, off64_t len)
67 struct getbmap bm[2]={{0}};
70 bm[0].bmv_offset = OFFTOBB(off);
71 if (len==(off64_t)-1) { /* unsigned... */
72 bm[0].bmv_length = -1;
73 printf(" MAP off=%lld, len=%lld [%lld-]\n",
74 (__s64)off, (__s64)len,
75 (__s64)BBTOFSB(bm[0].bmv_offset));
77 bm[0].bmv_length = OFFTOBB(len);
78 printf(" MAP off=%lld, len=%lld [%lld,%lld]\n",
79 (__s64)off, (__s64)len,
80 (__s64)BBTOFSB(bm[0].bmv_offset),
81 (__s64)BBTOFSB(bm[0].bmv_length));
84 printf(" [ofs,count]: start..end\n");
86 if (ioctl(fd, XFS_IOC_GETBMAP, bm) < 0) {
90 if (bm[0].bmv_entries == 0)
92 printf(" [%lld,%lld]: ",
93 (__s64)BBTOFSB(bm[1].bmv_offset),
94 (__s64)BBTOFSB(bm[1].bmv_length));
95 if (bm[1].bmv_block == -1)
99 (__s64)BBTOFSB(bm[1].bmv_block),
100 (__s64)BBTOFSB(bm[1].bmv_block +
101 bm[1].bmv_length - 1));
107 main(int argc, char **argv)
110 char *dirname = NULL;
113 char *filename = NULL;
118 static char *opnames[] =
119 { "freesp", "allocsp", "unresvsp", "resvsp" };
122 { XFS_IOC_FREESP64, XFS_IOC_ALLOCSP64, XFS_IOC_UNRESVSP64, XFS_IOC_RESVSP64 };
124 struct statvfs64 svfs;
130 while ((c = getopt(argc, argv, "b:d:f:rtn")) != -1) {
133 blocksize = atoi(optarg);
137 printf("can't specify both -d and -f\n");
144 printf("can't specify both -d and -f\n");
159 printf("unknown option\n");
164 if (!dirname && !filename)
167 static char tmpfile[] = "allocXXXXXX";
170 filename = malloc(strlen(tmpfile) + strlen(dirname) + 2);
171 sprintf(filename, "%s/%s", dirname, tmpfile);
174 oflags = O_RDWR | O_CREAT | (tflag ? O_TRUNC : 0);
175 fd = open(filename, oflags, 0666);
178 printf(" filename %s\n", filename);
187 if (fstatvfs64(fd, &svfs) < 0) {
191 blocksize = (int)svfs.f_bsize;
194 fprintf(stderr,"illegal blocksize %d\n", blocksize);
197 printf(" blocksize %d\n", blocksize);
201 if (ioctl(fd, XFS_IOC_FSGETXATTR, &a) < 0) {
202 perror("XFS_IOC_FSGETXATTR");
205 a.fsx_xflags |= XFS_XFLAG_REALTIME;
206 if (ioctl(fd, XFS_IOC_FSSETXATTR, &a) < 0) {
207 perror("XFS_IOC_FSSETXATTR");
214 if (!nflag) printf("alloc> ");
216 if (!fgets(line, 1024, stdin)) break;
219 if (p!=line&&p[-1]=='\n') p[-1]=0;
230 v = strtoll(&line[2], &p, 0);
236 f.l_whence = SEEK_SET;
241 v = strtoll(p, &p, 0);
248 printf(" CMD %s, off=%lld, len=%lld\n",
249 opnames[opno], (__s64)off, (__s64)len);
252 c = ioctl(fd, optab[opno], &f);
254 perror(opnames[opno]);
263 v = strtoll(p, &p, 0);
272 v = strtoll(p, &p, 0);
282 v = strtoll(p, &p, 0);
287 printf(" TRUNCATE off=%lld\n", (__s64)off);
288 if (ftruncate64(fd, off) < 0) {
306 printf("unknown command '%s'\n", line);
310 if (!nflag) printf("\n");