fileopctx.h 5.3 KB

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