]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/prealloc.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / io / prealloc.c
1 /*
2 * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include "command.h"
35 #include "init.h"
36
37 static cmdinfo_t allocsp_cmd;
38 static cmdinfo_t freesp_cmd;
39 static cmdinfo_t resvsp_cmd;
40 static cmdinfo_t unresvsp_cmd;
41
42 static int
43 offset_length(
44 char *offset,
45 char *length,
46 xfs_flock64_t *segment)
47 {
48 char *sp;
49
50 memset(segment, 0, sizeof(*segment));
51 segment->l_whence = SEEK_SET;
52 segment->l_start = strtoul(offset, &sp, 0);
53 if (!sp || sp == offset) {
54 printf(_("non-numeric offset argument -- %s\n"), offset);
55 return 0;
56 }
57 segment->l_len = strtoul(length, &sp, 0);
58 if (!sp || sp == length) {
59 printf(_("non-numeric length argument -- %s\n"), length);
60 return 0;
61 }
62 return 1;
63 }
64
65 static int
66 allocsp_f(
67 int argc,
68 char **argv)
69 {
70 xfs_flock64_t segment;
71
72 if (!offset_length(argv[1], argv[2], &segment))
73 return 0;
74
75 if (xfsctl(fname, fdesc, XFS_IOC_ALLOCSP64, &segment) < 0) {
76 perror("xfsctl(XFS_IOC_ALLOCSP64)");
77 return 0;
78 }
79 return 0;
80 }
81
82 static int
83 freesp_f(
84 int argc,
85 char **argv)
86 {
87 xfs_flock64_t segment;
88
89 if (!offset_length(argv[1], argv[2], &segment))
90 return 0;
91
92 if (xfsctl(fname, fdesc, XFS_IOC_FREESP64, &segment) < 0) {
93 perror("xfsctl(XFS_IOC_FREESP64)");
94 return 0;
95 }
96 return 0;
97 }
98
99 static int
100 resvsp_f(
101 int argc,
102 char **argv)
103 {
104 xfs_flock64_t segment;
105
106 if (!offset_length(argv[1], argv[2], &segment))
107 return 0;
108
109 if (xfsctl(fname, fdesc, XFS_IOC_RESVSP64, &segment) < 0) {
110 perror("xfsctl(XFS_IOC_RESVSP64)");
111 return 0;
112 }
113 return 0;
114 }
115
116 static int
117 unresvsp_f(
118 int argc,
119 char **argv)
120 {
121 xfs_flock64_t segment;
122
123 if (!offset_length(argv[1], argv[2], &segment))
124 return 0;
125
126 if (xfsctl(fname, fdesc, XFS_IOC_UNRESVSP64, &segment) < 0) {
127 perror("xfsctl(XFS_IOC_UNRESVSP64)");
128 return 0;
129 }
130 return 0;
131 }
132
133 void
134 prealloc_init(void)
135 {
136 allocsp_cmd.name = _("allocsp");
137 allocsp_cmd.cfunc = allocsp_f;
138 allocsp_cmd.argmin = 2;
139 allocsp_cmd.argmax = 2;
140 allocsp_cmd.args = _("off len");
141 allocsp_cmd.oneline = _("allocates zeroed space for part of a file");
142
143 freesp_cmd.name = _("freesp");
144 freesp_cmd.cfunc = freesp_f;
145 freesp_cmd.argmin = 2;
146 freesp_cmd.argmax = 2;
147 freesp_cmd.args = _("off len");
148 freesp_cmd.oneline = _("frees space associated with part of a file");
149
150 resvsp_cmd.name = _("resvsp");
151 resvsp_cmd.cfunc = resvsp_f;
152 resvsp_cmd.argmin = 2;
153 resvsp_cmd.argmax = 2;
154 resvsp_cmd.args = _("off len");
155 resvsp_cmd.oneline =
156 _("reserves space associated with part of a file");
157
158 unresvsp_cmd.name = _("unresvsp");
159 unresvsp_cmd.cfunc = unresvsp_f;
160 unresvsp_cmd.argmin = 2;
161 unresvsp_cmd.argmax = 2;
162 unresvsp_cmd.args = _("off len");
163 unresvsp_cmd.oneline =
164 _("frees reserved space associated with part of a file");
165
166 add_command(&allocsp_cmd);
167 add_command(&freesp_cmd);
168 add_command(&resvsp_cmd);
169 add_command(&unresvsp_cmd);
170 }