remove spurious SPACEs before TABs
[coreutils.git] / src / copy.h
blob10cdce9796b75c83ba796c0575ca9a0781e2920a
1 #ifndef COPY_H
2 # define COPY_H
4 # include "hash.h"
6 /* Control creation of sparse files (files with holes). */
7 enum Sparse_type
9 SPARSE_UNUSED,
11 /* Never create holes in DEST. */
12 SPARSE_NEVER,
14 /* This is the default. Use a crude (and sometimes inaccurate)
15 heuristic to determine if SOURCE has holes. If so, try to create
16 holes in DEST. */
17 SPARSE_AUTO,
19 /* For every sufficiently long sequence of bytes in SOURCE, try to
20 create a corresponding hole in DEST. There is a performance penalty
21 here because CP has to search for holes in SRC. But if the holes are
22 big enough, that penalty can be offset by the decrease in the amount
23 of data written to disk. */
24 SPARSE_ALWAYS
27 /* This type is used to help mv (via copy.c) distinguish these cases. */
28 enum Interactive
30 I_ALWAYS_YES = 1,
31 I_ALWAYS_NO,
32 I_ASK_USER,
33 I_UNSPECIFIED
36 /* How to handle symbolic links. */
37 enum Dereference_symlink
39 DEREF_UNDEFINED = 1,
41 /* Copy the symbolic link itself. -P */
42 DEREF_NEVER,
44 /* If the symbolic is a command line argument, then copy
45 its referent. Otherwise, copy the symbolic link itself. -H */
46 DEREF_COMMAND_LINE_ARGUMENTS,
48 /* Copy the referent of the symbolic link. -L */
49 DEREF_ALWAYS
52 # define VALID_SPARSE_MODE(Mode) \
53 ((Mode) == SPARSE_NEVER \
54 || (Mode) == SPARSE_AUTO \
55 || (Mode) == SPARSE_ALWAYS)
57 /* These options control how files are copied by at least the
58 following programs: mv (when rename doesn't work), cp, install.
59 So, if you add a new member, be sure to initialize it in
60 mv.c, cp.c, and install.c. */
61 struct cp_options
63 enum backup_type backup_type;
65 /* If nonzero, copy all files except (directories and, if not dereferencing
66 them, symbolic links,) as if they were regular files. */
67 int copy_as_regular;
69 /* How to handle symlinks. */
70 enum Dereference_symlink dereference;
72 /* If nonzero, remove each existing destination nondirectory before
73 trying to open it. */
74 int unlink_dest_before_opening;
76 /* If nonzero, first try to open each existing destination nondirectory,
77 then, if the open fails, unlink and try again.
78 This option must be set for `cp -f', in case the destination file
79 exists when the open is attempted. It is irrelevant to `mv' since
80 any destination is sure to be removed before the open. */
81 int unlink_dest_after_failed_open;
83 /* If nonzero, create hard links instead of copying files.
84 Create destination directories as usual. */
85 int hard_link;
87 /* This value is used to determine whether to prompt before removing
88 each existing destination file. It works differently depending on
89 whether move_mode is set. See code/comments in copy.c. */
90 enum Interactive interactive;
92 /* If nonzero, rather than copying, first attempt to use rename.
93 If that fails, then resort to copying. */
94 int move_mode;
96 /* This process's effective user ID. */
97 uid_t myeuid;
99 /* If nonzero, when copying recursively, skip any subdirectories that are
100 on different filesystems from the one we started on. */
101 int one_file_system;
103 /* If nonzero, attempt to give the copies the original files' permissions,
104 owner, group, and timestamps. */
105 int preserve_ownership;
106 int preserve_mode;
107 int preserve_timestamps;
109 /* Enabled for mv, and for cp by the --preserve=links option.
110 If nonzero, attempt to preserve in the destination files any
111 logical hard links between the source files. If used with cp's
112 --no-dereference option, and copying two hard-linked files,
113 the two corresponding destination files will also be hard linked.
115 If used with cp's --dereference (-L) option, then, as that option implies,
116 hard links are *not* preserved. However, when copying a file F and
117 a symlink S to F, the resulting S and F in the destination directory
118 will be hard links to the same file (a copy of F). */
119 int preserve_links;
121 /* If nonzero and any of the above (for preserve) file attributes cannot
122 be applied to a destination file, treat it as a failure and return
123 nonzero immediately. E.g. cp -p requires this be nonzero, mv requires
124 it be zero. */
125 int require_preserve;
127 /* If nonzero, copy directories recursively and copy special files
128 as themselves rather than copying their contents. */
129 int recursive;
131 /* If nonzero, set file mode to value of MODE. Otherwise,
132 set it based on current umask modified by UMASK_KILL. */
133 int set_mode;
135 /* Set the mode of the destination file to exactly this value
136 if USE_MODE is nonzero. */
137 mode_t mode;
139 /* Control creation of sparse files. */
140 enum Sparse_type sparse_mode;
142 /* If nonzero, create symbolic links instead of copying files.
143 Create destination directories as usual. */
144 int symbolic_link;
146 /* The bits to preserve in created files' modes. */
147 mode_t umask_kill;
149 /* If nonzero, do not copy a nondirectory that has an existing destination
150 with the same or newer modification time. */
151 int update;
153 /* If nonzero, display the names of the files before copying them. */
154 int verbose;
156 /* A pointer to either lstat or stat, depending on
157 whether the copy should dereference symlinks. */
158 int (*xstat) ();
160 /* If nonzero, stdin is a tty. */
161 int stdin_tty;
163 /* This is a set of destination name/inode/dev triples. Each such triple
164 represents a file we have created corresponding to a source file name
165 that was specified on the command line. Use it to avoid clobbering
166 source files in commands like this:
167 rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
168 For now, it protects only regular files when copying (i.e. not renaming).
169 When renaming, it protects all non-directories.
170 Use dest_info_init to initialize it, or set it to NULL to disable
171 this feature. */
172 Hash_table *dest_info;
174 /* FIXME */
175 Hash_table *src_info;
178 int stat ();
179 int lstat ();
181 /* Arrange to make lstat calls go through the wrapper function
182 on systems with an lstat function that does not dereference symlinks
183 that are specified with a trailing slash. */
184 # if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
185 int rpl_lstat (const char *, struct stat *);
186 # undef lstat
187 # define lstat rpl_lstat
188 # endif
190 int rename ();
192 /* Arrange to make rename calls go through the wrapper function
193 on systems with a rename function that fails for a source path
194 specified with a trailing slash. */
195 # if RENAME_TRAILING_SLASH_BUG
196 int rpl_rename (const char *, const char *);
197 # undef rename
198 # define rename rpl_rename
199 # endif
202 copy (const char *src_path, const char *dst_path,
203 int nonexistent_dst, const struct cp_options *options,
204 int *copy_into_self, int *rename_succeeded);
206 void
207 dest_info_init (struct cp_options *);
208 void
209 src_info_init (struct cp_options *);
211 #endif