]>
Commit | Line | Data |
---|---|---|
e246ba5f | 1 | /* |
f72d20ad | 2 | * Copyright (c) 2003-2004 Silicon Graphics, Inc. All Rights Reserved. |
dfc130f3 | 3 | * |
e246ba5f NS |
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. | |
dfc130f3 | 7 | * |
e246ba5f NS |
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. | |
dfc130f3 | 11 | * |
e246ba5f NS |
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. | |
dfc130f3 | 18 | * |
e246ba5f NS |
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. | |
dfc130f3 | 22 | * |
e246ba5f NS |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
24 | * Mountain View, CA 94043, or: | |
dfc130f3 RC |
25 | * |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
e246ba5f NS |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ |
31 | */ | |
32 | ||
1d7e80ee | 33 | #include <xfs/libxfs.h> |
e246ba5f | 34 | #include "command.h" |
638473d8 | 35 | #include "input.h" |
e246ba5f NS |
36 | #include "init.h" |
37 | ||
38 | static cmdinfo_t truncate_cmd; | |
39 | ||
40 | static int | |
41 | truncate_f( | |
42 | int argc, | |
43 | char **argv) | |
44 | { | |
45 | off64_t offset; | |
f72d20ad | 46 | unsigned int blocksize, sectsize; |
e246ba5f | 47 | |
f72d20ad NS |
48 | if (foreign) { |
49 | blocksize = 4096; | |
50 | sectsize = 512; | |
51 | } else { | |
52 | blocksize = fgeom.blocksize; | |
53 | sectsize = fgeom.sectsize; | |
54 | } | |
55 | offset = cvtnum(blocksize, sectsize, argv[1]); | |
638473d8 | 56 | if (offset < 0) { |
e246ba5f NS |
57 | printf(_("non-numeric truncate argument -- %s\n"), argv[1]); |
58 | return 0; | |
59 | } | |
60 | ||
61 | if (ftruncate64(fdesc, offset) < 0) { | |
62 | perror("ftruncate"); | |
63 | return 0; | |
64 | } | |
65 | return 0; | |
66 | } | |
67 | ||
68 | void | |
69 | truncate_init(void) | |
70 | { | |
71 | truncate_cmd.name = _("truncate"); | |
72 | truncate_cmd.cfunc = truncate_f; | |
73 | truncate_cmd.argmin = 1; | |
74 | truncate_cmd.argmax = 1; | |
f72d20ad | 75 | truncate_cmd.foreign = 1; |
e246ba5f NS |
76 | truncate_cmd.args = _("off"); |
77 | truncate_cmd.oneline = | |
78 | _("truncates the current file at the given offset"); | |
79 | ||
80 | add_command(&truncate_cmd); | |
81 | } |