Use "file system" rather than "filesystem" in comments.
[platform/upstream/coreutils.git] / src / copy.h
1 #ifndef COPY_H
2 # define COPY_H
3
4 # include "hash.h"
5
6 /* Control creation of sparse files (files with holes).  */
7 enum Sparse_type
8 {
9   SPARSE_UNUSED,
10
11   /* Never create holes in DEST.  */
12   SPARSE_NEVER,
13
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,
18
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
25 };
26
27 /* This type is used to help mv (via copy.c) distinguish these cases.  */
28 enum Interactive
29 {
30   I_ALWAYS_YES = 1,
31   I_ALWAYS_NO,
32   I_ASK_USER,
33   I_UNSPECIFIED
34 };
35
36 /* How to handle symbolic links.  */
37 enum Dereference_symlink
38 {
39   DEREF_UNDEFINED = 1,
40
41   /* Copy the symbolic link itself.  -P  */
42   DEREF_NEVER,
43
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,
47
48   /* Copy the referent of the symbolic link.  -L  */
49   DEREF_ALWAYS
50 };
51
52 # define VALID_SPARSE_MODE(Mode)        \
53   ((Mode) == SPARSE_NEVER               \
54    || (Mode) == SPARSE_AUTO             \
55    || (Mode) == SPARSE_ALWAYS)
56
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
62 {
63   enum backup_type backup_type;
64
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;
68
69   /* How to handle symlinks.  */
70   enum Dereference_symlink dereference;
71
72   /* If nonzero, remove each existing destination nondirectory before
73      trying to open it. */
74   int unlink_dest_before_opening;
75
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;
82
83   /* If nonzero, create hard links instead of copying files.
84      Create destination directories as usual. */
85   int hard_link;
86
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;
91
92   /* If nonzero, rather than copying, first attempt to use rename.
93      If that fails, then resort to copying.  */
94   int move_mode;
95
96   /* This process's effective user ID.  */
97   uid_t myeuid;
98
99   /* If nonzero, when copying recursively, skip any subdirectories that are
100      on different file systems from the one we started on.  */
101   int one_file_system;
102
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;
108
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.
114
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;
120
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;
126
127   /* If nonzero, copy directories recursively and copy special files
128      as themselves rather than copying their contents. */
129   int recursive;
130
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;
134
135   /* Set the mode of the destination file to exactly this value
136      if USE_MODE is nonzero.  */
137   mode_t mode;
138
139   /* Control creation of sparse files.  */
140   enum Sparse_type sparse_mode;
141
142   /* If nonzero, create symbolic links instead of copying files.
143      Create destination directories as usual. */
144   int symbolic_link;
145
146   /* The bits to preserve in created files' modes. */
147   mode_t umask_kill;
148
149   /* If nonzero, do not copy a nondirectory that has an existing destination
150      with the same or newer modification time. */
151   int update;
152
153   /* If nonzero, display the names of the files before copying them. */
154   int verbose;
155
156   /* If nonzero, stdin is a tty.  */
157   int stdin_tty;
158
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;
169
170   /* FIXME */
171   Hash_table *src_info;
172 };
173
174 int stat ();
175 int lstat ();
176
177 # define XSTAT(X, Src_path, Src_sb) \
178   ((X)->dereference == DEREF_NEVER \
179    ? lstat (Src_path, Src_sb) \
180    : stat (Src_path, Src_sb))
181
182 /* Arrange to make lstat calls go through the wrapper function
183    on systems with an lstat function that does not dereference symlinks
184    that are specified with a trailing slash.  */
185 # if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
186 int rpl_lstat (const char *, struct stat *);
187 #  undef lstat
188 #  define lstat rpl_lstat
189 # endif
190
191 int rename ();
192
193 /* Arrange to make rename calls go through the wrapper function
194    on systems with a rename function that fails for a source path
195    specified with a trailing slash.  */
196 # if RENAME_TRAILING_SLASH_BUG
197 int rpl_rename (const char *, const char *);
198 #  undef rename
199 #  define rename rpl_rename
200 # endif
201
202 int
203 copy (const char *src_path, const char *dst_path,
204       int nonexistent_dst, const struct cp_options *options,
205       int *copy_into_self, int *rename_succeeded);
206
207 void
208 dest_info_init (struct cp_options *);
209 void
210 src_info_init (struct cp_options *);
211
212 #endif