1 /** \file fileopctx.h 2 * \brief Header: file operation contexts 3 * \date 1998 4 * \author Federico Mena <federico@nuclecu.unam.mx> 5 * \author Miguel de Icaza <miguel@nuclecu.unam.mx> 6 */ 7 8 #ifndef MC__FILEOPCTX_H 9 #define MC__FILEOPCTX_H 10 11 #include <sys/stat.h> 12 #include <sys/types.h> 13 #include <inttypes.h> /* uintmax_t */ 14 15 #include "lib/global.h" 16 #include "lib/vfs/vfs.h" 17 18 19 /*** typedefs(not structures) and defined constants **********************************************/ 20 21 typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf); 22 23 /*** enums ***************************************************************************************/ 24 25 typedef enum 26 { 27 FILEGUI_DIALOG_ONE_ITEM, 28 FILEGUI_DIALOG_MULTI_ITEM, 29 FILEGUI_DIALOG_DELETE_ITEM 30 } filegui_dialog_type_t; 31 32 typedef enum 33 { 34 OP_COPY = 0, 35 OP_MOVE = 1, 36 OP_DELETE = 2 37 } FileOperation; 38 39 typedef enum 40 { 41 RECURSIVE_YES = 0, 42 RECURSIVE_NO = 1, 43 RECURSIVE_ALWAYS = 2, 44 RECURSIVE_NEVER = 3, 45 RECURSIVE_ABORT = 4 46 } FileCopyMode; 47 48 /* ATTENTION: avoid overlapping with B_* values (lib/widget/dialog.h) */ 49 typedef enum 50 { 51 FILE_CONT = 10, 52 FILE_RETRY, 53 FILE_SKIP, 54 FILE_ABORT, 55 FILE_SKIPALL, 56 FILE_SUSPEND 57 } FileProgressStatus; 58 59 /* First argument passed to real functions */ 60 enum OperationMode 61 { 62 Foreground, 63 Background 64 }; 65 66 /*** structures declarations (and typedefs of structures)*****************************************/ 67 68 struct mc_search_struct; 69 70 /* This structure describes a context for file operations. It is used to update 71 * the progress windows and pass around options. 72 */ 73 typedef struct 74 { 75 /* Operation type (copy, move, delete) */ 76 FileOperation operation; 77 78 /* The estimated time of arrival in seconds */ 79 double eta_secs; 80 81 /* Transferred bytes per second */ 82 long bps; 83 84 /* Transferred seconds */ 85 long bps_time; 86 87 /* Whether the panel total has been computed */ 88 gboolean progress_totals_computed; 89 filegui_dialog_type_t dialog_type; 90 91 /* Counters for progress indicators */ 92 size_t progress_count; 93 uintmax_t progress_bytes; 94 95 /* The value of the "preserve Attributes" checkbox in the copy file dialog. 96 * We can't use the value of "ctx->preserve" because it can change in order 97 * to preserve file attributes when moving files across filesystem boundaries 98 * (we want to keep the value of the checkbox between copy operations). 99 */ 100 gboolean op_preserve; 101 102 /* Result from the recursive query */ 103 FileCopyMode recursive_result; 104 105 /* Whether to do a reget */ 106 off_t do_reget; 107 108 /* Controls appending to files */ 109 gboolean do_append; 110 111 /* Whether to stat or lstat */ 112 gboolean follow_links; 113 114 /* Pointer to the stat function we will use */ 115 mc_stat_fn stat_func; 116 117 /* Whether to recompute symlinks */ 118 gboolean stable_symlinks; 119 120 /* Preserve the original files' owner, group, permissions, and 121 * timestamps (owner, group only as root). 122 */ 123 gboolean preserve; 124 125 /* If running as root, preserve the original uid/gid (we don't want to 126 * try chown for non root) preserve_uidgid = preserve && uid == 0 127 */ 128 gboolean preserve_uidgid; 129 130 /* The bits to preserve in created files' modes on file copy */ 131 mode_t umask_kill; 132 133 /* The mask of files to actually operate on */ 134 char *dest_mask; 135 136 /* search handler */ 137 struct mc_search_struct *search_handle; 138 139 /* Whether to dive into subdirectories for recursive operations */ 140 gboolean dive_into_subdirs; 141 142 /* When moving directories cross filesystem boundaries delete the 143 * successfully copied files when all files below the directory and its 144 * subdirectories were processed. 145 * 146 * If erase_at_end is FALSE files will be deleted immediately after their 147 * successful copy (Note: this behavior is not tested and at the moment 148 * it can't be changed at runtime). 149 */ 150 gboolean erase_at_end; 151 152 /* PID of the child for background operations */ 153 pid_t pid; 154 155 /* toggle if all errors should be ignored */ 156 gboolean skip_all; 157 158 /* Whether the file operation is in pause */ 159 gboolean suspended; 160 161 /* User interface data goes here */ 162 void *ui; 163 } file_op_context_t; 164 165 typedef struct 166 { 167 size_t progress_count; 168 size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */ 169 uintmax_t progress_bytes; 170 uintmax_t copied_bytes; 171 size_t bps; 172 size_t bps_count; 173 gint64 transfer_start; 174 double eta_secs; 175 176 gboolean ask_overwrite; 177 } file_op_total_context_t; 178 179 /*** global variables defined in .c file *********************************************************/ 180 181 extern const char *op_names[3]; 182 183 /*** declarations of public functions ************************************************************/ 184 185 file_op_context_t *file_op_context_new (FileOperation op); 186 void file_op_context_destroy (file_op_context_t * ctx); 187 188 file_op_total_context_t *file_op_total_context_new (void); 189 void file_op_total_context_destroy (file_op_total_context_t * tctx); 190 191 /* The following functions are implemented separately by each port */ 192 FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx, 193 enum OperationMode mode, const char *src, 194 struct stat *src_stat, const char *dst, 195 struct stat *dst_stat); 196 197 /*** inline functions ****************************************************************************/ 198 #endif /* MC__FILEOPCTX_H */