chiark / gitweb /
Fix memory management of argument to open_input_file
[inn-innduct.git] / doc / pod / fastrm.pod
1 =head1 NAME
2
3 fastrm - Quickly remove a list of files
4
5 =head1 SYNOPSIS
6
7 B<fastrm> [B<-de>] [B<-u>|B<-u>I<N>] [B<-s>|B<-s>I<M>] [B<-c>|B<-c>I<I>]
8 I<base-directory>
9
10 =head1 DESCRIPTION
11
12 B<fastrm> reads a list of either file names or storage API tokens, one per
13 line, from its standard input and removes them.  Storage API tokens are
14 removed via the SMcancel() interface.  B<fastrm> does not delete files
15 safely or with an eye to security, but rather cuts every corner it can to
16 delete files as fast as it can.  It should therefore never be run on
17 publically writable directories, or in any other environment where a
18 hostile party may control the directory structure in which it is working.
19
20 If a file name is not an absolute path name, it is considered to be
21 relative to I<base-directory> as given on the command line.  The
22 I<base-directory> parameter must be a simple absolute pathname (it must
23 not contain multiple consecutive slashes or references to the special
24 directories C<.> or C<..>).
25
26 B<fastrm> is designed to be faster than the typical C<| xargs rm> pipeline
27 when given a sorted list of file names as input.  For example, B<fastrm>
28 will usually chdir(2) into a directory before removing files from it,
29 meaning that if its input is sorted, most names passed to unlink(2) will
30 be simple names.  This can substantially reduce the operating system
31 overhead from directory lookups.
32
33 B<fastrm> assumes that its input is valid and that it is safe to call
34 unlink(2) on every file name it is given.  As a safety measure, however,
35 B<fastrm> when running as root will check with stat(2) that a file name
36 doesn't specify a directory before removing it.  (In some operating
37 systems, root is allowed to unlink directories, even directories which
38 aren't empty, which can cause file system corruption.)
39
40 The input to B<fastrm> should always be sorted -- or even better be in the
41 order file names are output by find(1) -- if speed is an issue and the
42 input isn't solely storage API tokens.  (It deals fine with unsorted
43 input, but is unlikely to be any faster in that case than a simple C<xargs
44 rm> command.)  Sorting may even slightly speed up the removal of storage
45 API tokens due to caching effects, since sorting will tend to keep all of
46 the tokens from a particular storage method together.
47
48 Various additional optimizations for removing files can be turned on
49 and/or tuned with options (see below).  Which options will be most
50 effective depends heavily on the underlying structure of the file system,
51 the way in which directories are stored and searched, and similar, often
52 underdocumented, operating system implementation details.  The more
53 sophisticated the underlying operating system and file system, the more
54 likely that it will already perform the equivalent of these optimizations
55 internally.
56
57 =head1 OPTIONS
58
59 =over 4
60
61 =item B<-d>
62
63 Don't remove any files.  Instead, print a list of the files that would be
64 removed to standard output.  Each line contains either the current
65 directory of B<fastrm> at the time it would do the unlink and the relative
66 path name it would pass to unlink(2) as two fields separated by whitespace
67 and a C</>, the absolute path name (as a single field) that would be
68 passed to unlink(2), or the string C<Token> and the storage API token that
69 would be removed.
70
71 =item B<-e>
72
73 Treat an empty input file as an error.  This is most useful when B<fastrm>
74 is last in a pipeline after a preceding sort(1) command, ensuring that
75 B<fastrm> will fail if the sort fails.
76
77 =item B<-c>I<I>
78
79 Controls when B<fastrm> calls chdir(2).  If the number of files to be
80 unlinked from a given directory is at least I<I>, then B<fastrm> will
81 change to that directory before unlinking those files.  Otherwise, it will
82 use either the absolute path names or a path name relative to the current
83 directory (whichever is likely more efficient).  The I<I> parameter is
84 optional; if just B<-c> is given, B<-c1> is assumed, which will cause
85 B<fastrm> to always chdir before calling unlink(2).  The default is
86 B<-c3>.  Use B<-c0> to prevent B<fastrm> from ever using chdir(2).
87
88 =item B<-s>I<M>
89
90 When B<-s> is given and the number of files to remove in a directory is
91 greater than I<M>, rather than remove files in the order given, B<fastrm>
92 will open the directory and read it, unlinking files in the order that
93 they appear in the directory.  On systems with a per-process directory
94 cache or that use a linear search to find files in a directory, this
95 should make directory lookups faster.  The I<M> parameter is optional; if
96 just B<-s> is given, B<-s5> is assumed.
97
98 When this option is in effect, B<fastrm> won't attempt to remove files
99 that it doesn't see in the directory, possibly significantly speeding it
100 up if most of the files to be removed have already been deleted.  However,
101 using this option requires B<fastrm> to do more internal work and it also
102 assumes that the order of directory listings is stable in the presence of
103 calls to unlink(2) between calls to readdir(3).  This may be a dangerous
104 assumption with some sophisticated file systems (and in general this
105 option is only useful with file systems that use unindexed linear searches
106 to find files in directories or when most of the files to be removed have
107 already been deleted).
108
109 This optimization is off by default.
110
111 =item B<-u>I<N>
112
113 Specifying this option promises that there are no symbolic links in the
114 directory tree from which files are being removed.  This allows B<fastrm>
115 to make an additional optimization to its calls to chdir(2), constructing
116 a relative path using C<../..> and the like to pass to chdir(2) rather
117 than always using absolute paths.  Since this reduces the number of
118 directory lookups needed with deeply nested directory structures (such as
119 that typically created by traditional news spool storage), it can be a
120 significant optimization, but it breaks horribly in the presence of
121 symbolic links to directories.
122
123 When B<-u> is given, B<fastrm> will use at most I<N> levels of C<..>
124 segments to construct paths.  I<N> is optional; if just B<-u> is given,
125 B<-u1> is assumed.
126
127 This optimization is off by default.
128
129 =back
130
131 B<fastrm> also accepts B<-a> and B<-r> options, which do nothing at all
132 except allow you to say C<fastrm -usa>, C<fastrm -ussr>, or C<fastrm
133 -user>.  These happen to often be convenient sets of options to use.
134
135 =head1 EXIT STATUS
136
137 B<fastrm> exits with a status of zero if there were no problems, and an
138 exit status of 1 if something went wrong.  Attempting to remove a file
139 that does not exist is not considered a problem.
140
141 =head1 EXAMPLES
142
143 B<fastrm> is typically invoked by INN via expirerm(8) using a command
144 like:
145
146     fastrm -e /usr/local/news/spool/articles < expire.list
147
148 To enable all optimizations and see the affect on the order of removal
149 caused by B<-s>, use:
150
151     fastrm -d -s -e -u ~news/spool/articles < expire.list
152
153 If your file system has indexed directory lookups, but you have a deeply
154 nested directory structure, you may want to use a set of flags like:
155
156     fastrm -e -u3 ~news/spool/articles < expire.list
157
158 to strongly prefer relative paths but not to use readdir(2) to order the
159 calls to unlink(2).
160
161 You may want to edit expirerm(8) to change the flags passed to B<fastrm>.
162
163 =head1 WARNINGS
164
165 B<fastrm> cuts corners and does not worry about security, so it does not
166 use chdir(2) safely and could be tricked into removing files other than
167 those that were intended if run on a specially constructed file tree or a
168 file tree that is being modified while it is running.  It should therefore
169 never be used with world-writable directories or any other directory that
170 might be controlled or modified by an attacker.
171
172 =head1 NOTES
173
174 B<fastrm> defers opening the storage subsystem or attempting to parse any
175 INN configuration files until it encounters a token in the list of files
176 to remove.  It's therefore possible to use B<fastrm> outside of INN as a
177 general fast file removal program.
178
179 =head1 HISTORY
180
181 B<fastrm> was originally written by kre@munnari.oz.au.  This manual page
182 rewritten in POD by Russ Allbery <rra@stanford.edu> for InterNetNews.
183
184 $Id: fastrm.pod 7422 2005-10-09 04:46:53Z eagle $
185
186 =head1 SEE ALSO
187
188 expirerm(8)
189
190 =cut