*** empty log message ***
[coreutils.git] / src / copy.h
blobeb13062b07b0792fc9745f82a50eaccd6c606623
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 struct cp_options
59 enum backup_type backup_type;
61 /* If nonzero, copy all files except (directories and, if not dereferencing
62 them, symbolic links,) as if they were regular files. */
63 int copy_as_regular;
65 /* How to handle symlinks. */
66 enum Dereference_symlink dereference;
68 /* If nonzero, remove each existing destination nondirectory before
69 trying to open it. */
70 int unlink_dest_before_opening;
72 /* If nonzero, first try to open each existing destination nondirectory,
73 then, if the open fails, unlink and try again.
74 This option must be set for `cp -f', in case the destination file
75 exists when the open is attempted. It is irrelevant to `mv' since
76 any destination is sure to be removed before the open. */
77 int unlink_dest_after_failed_open;
79 /* If nonzero, create hard links instead of copying files.
80 Create destination directories as usual. */
81 int hard_link;
83 /* This value is used to determine whether to prompt before removing
84 each existing destination file. It works differently depending on
85 whether move_mode is set. See code/comments in copy.c. */
86 enum Interactive interactive;
88 /* If nonzero, rather than copying, first attempt to use rename.
89 If that fails, then resort to copying. */
90 int move_mode;
92 /* This process's effective user ID. */
93 uid_t myeuid;
95 /* If nonzero, when copying recursively, skip any subdirectories that are
96 on different filesystems from the one we started on. */
97 int one_file_system;
99 /* If nonzero, attempt to give the copies the original files' permissions,
100 owner, group, and timestamps. */
101 int preserve_ownership;
102 int preserve_mode;
103 int preserve_timestamps;
105 /* Enabled for mv, and for cp by the --preserve=links option.
106 If nonzero, attempt to preserve in the destination files any
107 logical hard links between the source files. If used with cp's
108 --no-dereference option, and copying two hard-linked files,
109 the two corresponding destination files will also be hard linked.
111 If used with cp's --dereference (-L) option, then, as that option implies,
112 hard links are *not* preserved. However, when copying a file F and
113 a symlink S to F, the resulting S and F in the destination directory
114 will be hard links to the same file (a copy of F). */
115 int preserve_links;
117 /* If nonzero and any of the above (for preserve) file attributes cannot
118 be applied to a destination file, treat it as a failure and return
119 nonzero immediately. E.g. cp -p requires this be nonzero, mv requires
120 it be zero. */
121 int require_preserve;
123 /* If nonzero, copy directories recursively and copy special files
124 as themselves rather than copying their contents. */
125 int recursive;
127 /* If nonzero, set file mode to value of MODE. Otherwise,
128 set it based on current umask modified by UMASK_KILL. */
129 int set_mode;
131 /* Set the mode of the destination file to exactly this value
132 if USE_MODE is nonzero. */
133 mode_t mode;
135 /* Control creation of sparse files. */
136 enum Sparse_type sparse_mode;
138 /* If nonzero, create symbolic links instead of copying files.
139 Create destination directories as usual. */
140 int symbolic_link;
142 /* The bits to preserve in created files' modes. */
143 mode_t umask_kill;
145 /* If nonzero, do not copy a nondirectory that has an existing destination
146 with the same or newer modification time. */
147 int update;
149 /* If nonzero, display the names of the files before copying them. */
150 int verbose;
152 /* A pointer to either lstat or stat, depending on
153 whether the copy should dereference symlinks. */
154 int (*xstat) ();
156 /* If nonzero, stdin is a tty. */
157 int stdin_tty;
159 /* This is a set of destination name/inode/dev triples. Each such triple
160 represents a file we have created corresponding to a source file name
161 that was specified on the command line. Use it to avoid clobbering
162 source files in commands like this:
163 rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
164 For now, it protects only regular files when copying (i.e. not renaming).
165 When renaming, it protects all non-directories.
166 Use dest_info_init to initialize it, or set it to NULL to disable
167 this feature. */
168 Hash_table *dest_info;
170 /* FIXME */
171 Hash_table *src_info;
174 int stat ();
175 int lstat ();
177 /* Arrange to make lstat calls go through the wrapper function
178 on systems with an lstat function that does not dereference symlinks
179 that are specified with a trailing slash. */
180 # if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
181 int rpl_lstat PARAMS((const char *, struct stat *));
182 # undef lstat
183 # define lstat rpl_lstat
184 # endif
186 int rename ();
188 /* Arrange to make rename calls go through the wrapper function
189 on systems with a rename function that fails for a source path
190 specified with a trailing slash. */
191 # if RENAME_TRAILING_SLASH_BUG
192 int rpl_rename PARAMS((const char *, const char *));
193 # undef rename
194 # define rename rpl_rename
195 # endif
198 copy PARAMS ((const char *src_path, const char *dst_path,
199 int nonexistent_dst, const struct cp_options *options,
200 int *copy_into_self, int *rename_succeeded));
202 void
203 dest_info_init PARAMS ((struct cp_options *));
204 void
205 src_info_init PARAMS ((struct cp_options *));
207 #endif