(struct cp_options): Rename members:
[platform/upstream/coreutils.git] / src / copy.h
1 #ifndef COPY_H
2 # define COPY_H
3
4 /* Control creation of sparse files (files with holes).  */
5 enum Sparse_type
6 {
7   SPARSE_UNUSED,
8
9   /* Never create holes in DEST.  */
10   SPARSE_NEVER,
11
12   /* This is the default.  Use a crude (and sometimes inaccurate)
13      heuristic to determine if SOURCE has holes.  If so, try to create
14      holes in DEST.  */
15   SPARSE_AUTO,
16
17   /* For every sufficiently long sequence of bytes in SOURCE, try to
18      create a corresponding hole in DEST.  There is a performance penalty
19      here because CP has to search for holes in SRC.  But if the holes are
20      big enough, that penalty can be offset by the decrease in the amount
21      of data written to disk.   */
22   SPARSE_ALWAYS
23 };
24
25 /* This type is used to help mv (via copy.c) distinguish these cases.  */
26 enum Interactive
27 {
28   I_ALWAYS_YES = 1,
29   I_ALWAYS_NO,
30   I_ASK_USER,
31   I_UNSPECIFIED
32 };
33
34 enum Dereference_symlink
35 {
36   DEREF_UNDEFINED = 1,
37   DEREF_ALWAYS,
38   DEREF_NEVER,
39   DEREF_COMMAND_LINE_ARGUMENTS
40 };
41
42 # define VALID_SPARSE_MODE(Mode)        \
43   ((Mode) == SPARSE_NEVER               \
44    || (Mode) == SPARSE_AUTO             \
45    || (Mode) == SPARSE_ALWAYS)
46
47 struct cp_options
48 {
49   enum backup_type backup_type;
50
51   /* If nonzero, copy all files except (directories and, if not dereferencing
52      them, symbolic links,) as if they were regular files. */
53   int copy_as_regular;
54
55   /* If nonzero, dereference symbolic links (copy the files they point to). */
56   enum Dereference_symlink dereference;
57
58   /* If nonzero, remove each existing destination nondirectory before
59      trying to open it. */
60   int unlink_dest_before_opening;
61
62   /* If nonzero, first try to open each existing destination nondirectory,
63      then, if the open fails, unlink and try again.
64      This option must be set for `cp -f', in case the destination file
65      exists when the open is attempted.  It is irrelevant to `mv' since
66      any destination is sure to be removed before the open.  */
67   int unlink_dest_after_failed_open;
68
69   /* Setting this member is meaningful only if FORCE is also set.
70      If nonzero, copy returns nonzero upon failed unlink.
71      Otherwise, the failure still elicits a diagnostic, but it doesn't
72      change copy's return value.  This is nonzero for cp and mv, and zero
73      for install.  */
74   /* FIXME: this is now unused.  */
75   int failed_unlink_is_fatal;
76
77   /* If nonzero, create hard links instead of copying files.
78      Create destination directories as usual. */
79   int hard_link;
80
81   /* This value is used to determine whether to prompt before removing
82      each existing destination file.  It works differently depending on
83      whether move_mode is set.  See code/comments in copy.c.  */
84   enum Interactive interactive;
85
86   /* If nonzero, rather than copying, first attempt to use rename.
87      If that fails, then resort to copying.  */
88   int move_mode;
89
90   /* This process's effective user ID.  */
91   uid_t myeuid;
92
93   /* If nonzero, when copying recursively, skip any subdirectories that are
94      on different filesystems from the one we started on. */
95   int one_file_system;
96
97   /* If nonzero, attempt to give the copies the original files' permissions,
98      owner, group, and timestamps. */
99   int preserve_ownership;
100   int preserve_mode;
101   int preserve_timestamps;
102
103   /* If nonzero and any of the above (for preserve) file attributes cannot
104      be applied to a destination file, treat it as a failure and return
105      nonzero immediately.  E.g. cp -p requires this be nonzero, mv requires
106      it be zero.  */
107   int require_preserve;
108
109   /* If nonzero, copy directories recursively and copy special files
110      as themselves rather than copying their contents. */
111   int recursive;
112
113   /* If nonzero, set file mode to value of MODE.  Otherwise,
114      set it based on current umask modified by UMASK_KILL.  */
115   int set_mode;
116
117   /* Set the mode of the destination file to exactly this value
118      if USE_MODE is nonzero.  */
119   mode_t mode;
120
121   /* Control creation of sparse files.  */
122   enum Sparse_type sparse_mode;
123
124   /* If nonzero, create symbolic links instead of copying files.
125      Create destination directories as usual. */
126   int symbolic_link;
127
128   /* The bits to preserve in created files' modes. */
129   mode_t umask_kill;
130
131   /* If nonzero, do not copy a nondirectory that has an existing destination
132      with the same or newer modification time. */
133   int update;
134
135   /* If nonzero, display the names of the files before copying them. */
136   int verbose;
137
138   /* A pointer to either lstat or stat, depending on
139      whether the copy should dereference symlinks.  */
140   int (*xstat) ();
141
142   /* If nonzero, stdin is a tty.  */
143   int stdin_tty;
144 };
145
146 int stat ();
147 int lstat ();
148
149 /* Arrange to make lstat calls go through the wrapper function
150    on systems with an lstat function that does not dereference symlinks
151    that are specified with a trailing slash.  */
152 # if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
153 int rpl_lstat PARAMS((const char *, struct stat *));
154 #  undef lstat
155 #  define lstat rpl_lstat
156 # endif
157
158 int rename ();
159
160 /* Arrange to make rename calls go through the wrapper function
161    on systems with a rename function that fails for a source path
162    specified with a trailing slash.  */
163 # if RENAME_TRAILING_SLASH_BUG
164 int rpl_rename PARAMS((const char *, const char *));
165 #  undef rename
166 #  define rename rpl_rename
167 # endif
168
169 int
170 copy PARAMS ((const char *src_path, const char *dst_path,
171               int nonexistent_dst, const struct cp_options *options,
172               int *copy_into_self, int *rename_succeeded));
173
174 void
175 dest_info_init PARAMS ((void));
176
177 #endif