1 /* Remove directory entries.
2 
3    Copyright (C) 1998-2023 Free Software Foundation, Inc.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef REMOVE_H
19 # define REMOVE_H
20 
21 # include "dev-ino.h"
22 
23 enum rm_interactive
24 {
25   /* Start with any number larger than 1, so that any legacy tests
26      against values of 0 or 1 will fail.  */
27   RMI_ALWAYS = 3,
28   RMI_SOMETIMES,
29   RMI_NEVER
30 };
31 
32 struct rm_options
33 {
34   /* If true, ignore nonexistent files.  */
35   bool ignore_missing_files;
36 
37   /* If true, query the user about whether to remove each file.  */
38   enum rm_interactive interactive;
39 
40   /* FIXME: remove  */
41   /* If true, do not traverse into (or remove) any directory that is
42      on a file system (i.e., that has a different device number) other
43      than that of the corresponding command line argument.  Note that
44      even without this option, rm will fail in the end, due to its
45      probable inability to remove the mount point.  But there, the
46      diagnostic comes too late -- after removing all contents.  */
47   bool one_file_system;
48 
49   /* If true, recursively remove directories.  */
50   bool recursive;
51 
52   /* If true, remove empty directories.  */
53   bool remove_empty_directories;
54 
55   /* Pointer to the device and inode numbers of '/', when --recursive
56      and preserving '/'.  Otherwise null.  */
57   struct dev_ino *root_dev_ino;
58 
59   /* If true, do not traverse into (or remove) any directory that is
60      the root of a file system.  I.e., a separate device.  */
61   bool preserve_all_root;
62 
63   /* If nonzero, stdin is a tty.  */
64   bool stdin_tty;
65 
66   /* If true, display the name of each file removed.  */
67   bool verbose;
68 
69   /* If true, treat the failure by the rm function to restore the
70      current working directory as a fatal error.  I.e., if this field
71      is true and the rm function cannot restore cwd, it must exit with
72      a nonzero status.  Some applications require that the rm function
73      restore cwd (e.g., mv) and some others do not (e.g., rm,
74      in many cases).  */
75   bool require_restore_cwd;
76 };
77 
78 enum RM_status
79 {
80   /* These must be listed in order of increasing seriousness. */
81   RM_OK = 2,
82   RM_USER_ACCEPTED,
83   RM_USER_DECLINED,
84   RM_ERROR,
85   RM_NONEMPTY_DIR
86 };
87 
88 # define VALID_STATUS(S) \
89   ((S) == RM_OK || (S) == RM_USER_ACCEPTED || (S) == RM_USER_DECLINED \
90    || (S) == RM_ERROR)
91 
92 # define UPDATE_STATUS(S, New_value)				\
93   do								\
94     {								\
95       if ((New_value) == RM_ERROR				\
96           || ((New_value) == RM_USER_DECLINED && (S) == RM_OK))	\
97         (S) = (New_value);					\
98     }								\
99   while (0)
100 
101 extern enum RM_status rm (char *const *file, struct rm_options const *x);
102 
103 #endif
104