source: MondoRescue/branches/3.3/mondo/src/include/my-stuff.h@ 3883

Last change on this file since 3883 was 3883, checked in by Bruno Cornec, 2 months ago

Remove the possibility to have non bootable media

  • Property svn:keywords set to Id
File size: 12.7 KB
Line 
1/* my-stuff.h
2 $Id: my-stuff.h 3883 2024-03-09 23:58:41Z bruno $
3*/
4
5#define HAVE_MALLOC 1
6
7/**
8 * @file
9 * The main header file for Mondo.
10 */
11
12#if !defined(bool) && !defined(__cplusplus)
13/**
14 * Create the illusion of a Boolean type.
15 */
16#define bool int
17#define TRUE 1
18#define FALSE 0
19#endif
20
21#ifndef _MY_STUFF_H_
22#define _MY_STUFF_H_
23
24#ifndef __FreeBSD__
25#include <getopt.h>
26#endif
27#include <sys/types.h>
28#include <sys/ipc.h>
29#include <sys/ioctl.h>
30#include <sys/sem.h>
31#include <sys/param.h>
32#include <stdio.h>
33#include <stdlib.h>
34#ifndef __USE_FILE_OFFSET64
35#define __USE_FILE_OFFSET64
36#endif
37#ifndef __USE_LARGEFILE64
38#define __USE_LARGEFILE64
39#endif
40#include <sys/stat.h>
41#include <fcntl.h>
42#include <errno.h>
43#include <stddef.h>
44#include <sys/stat.h>
45#include <sys/wait.h>
46#include <time.h>
47#include <unistd.h>
48#include <signal.h>
49//#include <curses.h>
50#include <newt.h>
51#include <ctype.h>
52#include <string.h>
53#include <pthread.h>
54#include <assert.h>
55
56#if defined(DEBUG) && !__cplusplus
57int count;
58char trace_log[255]; /*buffer for logging */
59char *trace_log_ptr;
60#endif /* DEBUG */
61
62#define IA64_BOOT_SIZE "16384" /* Should be coherent with mindi */
63#define STD_PREFIX "mondorescue" /* Should be coherent with mindi */
64
65/**
66 * The location where mindi media images are stored.
67 */
68#define MINDI_CACHE_REL "var/cache/mindi" /* Should be coherent with mindi */
69#define MINDI_CACHE "/"MINDI_CACHE_REL
70#define MINDI_LOGFILE "/var/log/mindi.log"
71#define MINDI_RUNFILE "/var/log/mindi.run"
72
73/**
74 * The location where mondo changed info are stored.
75 */
76#define MONDO_CACHE "/var/cache/mondo"
77#define ARCHIVES_PATH MNT_CDROM"/archives"
78#define BIGGIELIST ARCHIVES_PATH"/biggielist.txt"
79
80/**
81 * The RAID kernel proc file
82 */
83#define MDSTAT_FILE "/proc/mdstat"
84
85#ifdef __FreeBSD__
86#define CMDLINE "/tmp/cmdline"
87#else
88// Default Linux
89#define CMDLINE "/proc/cmdline"
90#endif
91
92#undef assert
93
94extern void _mondo_assert_fail(const char *file, const char *function,
95 int line, const char *exp);
96
97/**
98 * An assert macro that calls _mondo_assert_fail() when it fails.
99 */
100#ifdef NDEBUG
101#define assert(exp) ((void)0)
102#else
103#define assert(exp) ((exp)?((void)0):_mondo_assert_fail(__FILE__, __FUNCTION__, __LINE__, #exp))
104#endif
105
106// Extra info for ACLs and SELINUX users
107#define STAR_ACL_SZ "-xattr -acl"
108
109#define CRC_M16 0xA001 ///< Mask for crc16.
110#define CRC_MTT 0x1021 ///< Mask for crc-ccitt.
111
112#define FALSE 0 ///< The ubiquitous FALSE macro.
113#define TRUE 1 ///< The even more ubiquitous TRUE macro.
114
115#define SCREEN_LENGTH 25 ///< The default size of the screen.
116#define NOOF_ERR_LINES 6 ///< The number of lines of log output to keep at the bottom of the screen.
117#define ARBITRARY_MAXIMUM 2000 ///< The maximum number of items showing at once in the mountlist or filelist editor.
118#define MAX_TAPECATALOG_ENTRIES 16384 ///< The maximum number of entries in the tape catalog.
119#define MAX_MOUNTLIST_ENTRIES 8192 ///< The maximum number of entries in the mountlist.
120#define MAX_STR_LEN 512 ///< The maximum length of almost all @p char buffers in Mondo.
121 /// Note: Make this divisible by eight to avoid aligment issues
122 /// on 64bit platforms like ia64.
123#define MAXIMUM_RAID_DEVS 32 ///< The maximum number of RAID devices in the raidlist.
124#define MAXIMUM_ADDITIONAL_RAID_VARS 32 ///< The maximum number of additional RAID variables per RAID device in the raidlist.
125#define MAXIMUM_DISKS_PER_RAID_DEV 1024 ///< The maximum number of disks per RAID device in the raidtab.
126
127#define RAIDTAB_FNAME "/etc/raidtab" ///< The filename of the raidtab file, at least on Linux.
128
129#define BLK_START_OF_BACKUP 1 ///< Marker block: start a backup.
130#define BLK_START_OF_TAPE 2 ///< Marker block: start a tape.
131#define BLK_START_AFIOBALLS 10 ///< Marker block: start the afioball section.
132#define BLK_STOP_AFIOBALLS 19 ///< Marker block: stop the afioball section.
133#define BLK_START_AN_AFIO_OR_SLICE 20 ///< Marker block: start an afioball or a slice.
134#define BLK_STOP_AN_AFIO_OR_SLICE 29 ///< Marker block: stop an afioball or a slice.
135#define BLK_START_BIGGIEFILES 30 ///< Marker block: start the biggiefile section.
136#define BLK_STOP_BIGGIEFILES 39 ///< Marker block: stop the biggiefile section.
137#define BLK_START_A_NORMBIGGIE 40 ///< Marker block: start a normal biggiefile.
138#define BLK_START_A_PIHBIGGIE 41 ///< Marker block: start a ntfsprog'd biggiefile
139#define BLK_START_EXTENDED_ATTRIBUTES 45 ///< Marker block: start xattr/acl info
140#define BLK_STOP_EXTENDED_ATTRIBUTES 46 ///< Marker block: stop xattr/acl info
141#define BLK_START_EXAT_FILE 47
142#define BLK_STOP_EXAT_FILE 48
143#define BLK_STOP_A_BIGGIE 59 ///< Marker block: stop a biggiefile.
144#define BLK_START_FILE 80 ///< Marker block: start a file (non-afio or slice).
145#define BLK_STOP_FILE 89 ///< Marker block: stop a file (non-afio or slice).
146#define BLK_END_OF_TAPE 100 ///< Marker block: end of tape.
147#define BLK_END_OF_BACKUP 101 ///< Marker block: end of backup.
148#define BLK_ABORTED_BACKUP 102 ///< Marker block: backup was aborted.
149
150/// The external tape blocksize.
151#ifdef EXTTAPE
152#define TAPE_BLOCK_SIZE (long)EXTTAPE
153#else
154#define TAPE_BLOCK_SIZE 131072L /* was 8192; 06/2002-->65536; 11/2002-->131072 */
155#endif
156
157#define DEFAULT_INTERNAL_TAPE_BLOCK_SIZE 32768 // Nov 2003?
158
159
160
161
162#define SLICE_SIZE 4096 ///< The size of a slice of a biggiefile.
163
164
165
166
167
168
169/**
170 * Determine whether @p x (t_bkptype) is a streaming backup.
171 */
172#define IS_THIS_A_STREAMING_BACKUP(x) (x == tape || x == udev)
173
174
175#define MONDO_MKISOFS_CMD "mkisofs"
176#define MONDO_MKISOFS_OPT ""
177#define MONDO_WODIM_OPT ""
178#define MONDO_GENISOIMAGE_OPT ""
179#define MONDO_XORRISO_OPT "-as mkisofs"
180#define MONDO_MKISOFS " -J -r -v -p MondoRescue -publisher http://www.mondorescue.org -A MondoRescue -V _CD#_ "
181#define MONDO_MKISOFS_CMS " -b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table "
182#define MONDO_UEFI_PREFIX " -b EFI/isolinux.bin -c EFI/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot "
183/* No space before this one as we may want to add another '-' before it */
184#define MONDO_MKISOFS_UEFI "-efi-boot images/mindi-bootroot.img -no-emul-boot "
185
186/**
187 * @c mkisofs command to generate a bootable CD using isolinux, except for -o option and the directory to image.
188 */
189#define MONDO_MKISOFS_REGULAR_SYSLINUX MONDO_MKISOFS
190
191/**
192 * @c mkisofs command to generate a bootable CD using LILO, except for -o option and the directory to image.
193 */
194#define MONDO_MKISOFS_REGULAR_LILO MONDO_MKISOFS_REGULAR_SYSLINUX
195
196/**
197 * @c mkisofs command to generate a bootable CD using ELILO, except for -o option and the directory to image.
198 */
199#define MONDO_MKISOFS_REGULAR_ELILO MONDO_MKISOFS"-no-emul-boot -b images/mindi-bootroot.img -c images/boot.cat "
200
201/**
202 * The stub name of the temporary ISO image to create, burn, and remove.
203 */
204#define MONDO_TMPISOS "temporary.iso"
205
206/**
207 * @c growisofs command to generate a bootable DVD using isolinux, except for the directory to image.
208 */
209#define MONDO_GROWISOFS_REGULAR_SYSLINUX "growisofs -use-the-force-luke "MONDO_MKISOFS_REGULAR_SYSLINUX
210
211/**
212 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image.
213 */
214#define MONDO_GROWISOFS_REGULAR_ELILO "growisofs -use-the-force-luke "MONDO_MKISOFS_REGULAR_ELILO
215
216/**
217 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image.
218 */
219#define MONDO_GROWISOFS_REGULAR_LILO "growisofs "MONDO_MKISOFS_REGULAR_SYSLINUX
220
221/**
222 * Welcome string displayed at the top of the newt interface.
223 */
224#define WELCOME_STRING "W E L C O M E T O M O N D O R E S C U E"
225
226/**
227 * The maximum length of a filename in the tape catalog.
228 */
229#define MAX_TAPECAT_FNAME_LEN 32
230
231/**
232 * Assert that (@p x != NULL) and (@p x[0] != '\\0').
233 */
234#define assert_string_is_neither_NULL_nor_zerolength(x) {assert(x!=NULL);assert(x[0]!='\0');}
235
236/**
237 * Log the file, line, Mondo error message, and OS error message (errno).
238 */
239#define log_OS_error(x) {log_msg(0, "%s (%s)", x, strerror(errno));}
240
241/**
242 * Assert that (@p x != NULL).
243 */
244#define assert_pointer_is_not_NULL(x) {assert(x!=NULL);}
245
246/**
247 * close() @p x and log a message if it fails.
248 */
249#define paranoid_close(x) {if(close(x)) {log_msg(5, "close err");} x=-999; }
250
251/**
252 * fclose() @p x and log a message if it fails.
253 */
254#define paranoid_fclose(x) {if(fclose(x)) {log_msg(5, "fclose err");} x=NULL; }
255
256/**
257 * pclose() @p x and log a message if it fails.
258 */
259#define paranoid_pclose(x) {if(pclose(x)) {log_msg(5, "pclose err");} x=NULL; }
260
261/**
262 * Run the command @p x and log it if it fails.
263 */
264#define paranoid_system(x) {if(system(x)) log_msg(4, x); }
265
266/**
267 * Free @p x and set it to NULL.
268 */
269#define paranoid_free(x) {if (x != NULL) free(x); x=NULL;}
270
271/**
272 * Free variables and call finish(@p x).
273 */
274#define paranoid_MR_finish(x) {free_MR_global_filenames (); finish(x); }
275
276/**
277 * Yes, we want malloc() to help us fix bugs.
278 */
279#define MALLOC_CHECK_ 1
280
281/**
282 * Malloc @p x to be MAX_STR_LEN bytes and call fatal_error() if we're out of memory.
283 */
284#define malloc_string(x) { x = (char *)malloc(MAX_STR_LEN); if (!x) { fatal_error("Unable to malloc"); } x[0] = x[1] = '\0'; }
285
286/**
287 * Path to the location the hard drive is mounted on during a restore.
288 */
289#define MNT_RESTORING "/mnt/RESTORING"
290
291/** @def VANILLA_SCSI_CDROM The first SCSI CD-ROM in the system (most likely to be the one to write to). */
292/** @def VANILLA_SCSI_TAPE The first SCSI tape in the system (most likely to be the one towrite to. */
293/** @def DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE A string whose presence in a device name indicates the
294 * inability to check this device for errors in the mountlist. */
295/** @def RAID_DEVICE_STUB The stub of a RAID device (set up RAID if we find it). */
296/** @def ALT_TAPE The first IDE tape in the system. */
297/** @def MKE2FS_OR_NEWFS @c mke2fs or @c newfs, depending on the OS. */
298/** @def CP_BIN The GNU @c cp binary to use. */
299#ifdef __FreeBSD__
300#define VANILLA_SCSI_CDROM "/dev/cd0"
301#define ALT_CDROM "/dev/ad0"
302#define VANILLA_SCSI_TAPE "/dev/sa0"
303#define VANILLA_USB_DEVICE "tobegivenbybsdguru"
304#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE "/dev/vinum/"
305#define RAID_DEVICE_STUB DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
306#define ALT_TAPE "/dev/ast0"
307#define MKE2FS_OR_NEWFS "newfs"
308#define CP_BIN "gcp"
309#else
310#define VANILLA_SCSI_CDROM "/dev/sr0"
311#define ALT_CDROM "/dev/scd0"
312#define VANILLA_SCSI_TAPE "/dev/st0"
313#define VANILLA_USB_DEVICE "/dev/hda"
314#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE "/dev/md"
315#define RAID_DEVICE_STUB DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
316#define ALT_TAPE "/dev/ht0"
317#define MKE2FS_OR_NEWFS "mke2fs"
318#define CP_BIN "cp"
319#endif
320
321
322/**
323 * The template for a filelist filename.
324 * The first argument (%s) is the tempdir and the second (%d) is the filelist number.
325 */
326#define FILELIST_FNAME_RAW_SZ "%s/filelist.%ld"
327
328#define XATTR_LIST_FNAME_RAW_SZ "%s/xattr_list.%ld.gz"
329#define XATTR_BIGGLST_FNAME_RAW_SZ "%s/xattr_list.big.gz"
330#define ACL_LIST_FNAME_RAW_SZ "%s/acl_list.%ld.gz"
331#define ACL_BIGGLST_FNAME_RAW_SZ "%s/acl_list.big.gz"
332
333#define BIGGIEMAXSIZE 64L*1024L
334/**
335 * The template for an afioball filename.
336 * The first argument (%s) is the tempdir and the second (%d) is the filelist number.
337 */
338#define AFIOBALL_FNAME_RAW_SZ (bkpinfo->use_star)?"%s/tmpfs/%ld.star.%s":"%s/tmpfs/%ld.afio.%s"
339#define ARCH_THREADS 2 ///< The number of simultaneous threads running afio in the background.
340#define ARCH_BUFFER_NUM (ARCH_THREADS*4) // Number of permissible queued afio files
341#define FORTY_SPACES " " ///< 40 spaces.
342#define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE"
343#define MONDO_MNTLISTCHG "/tmp/mountlist.changed"
344
345extern void (*log_debug_msg) (int debug_level, const char *szFile,
346 const char *szFunction, int nLine,
347 const char *fmt, ...);
348extern void standard_log_debug_msg(int debug_level, const char *szFile,
349 const char *szFunction, int nLine,
350 const char *fmt, ...);
351
352/**
353 * Compatibility define to change log_it() calls to log_debug_msg() calls.
354 */
355#define log_it(format, args...) log_debug_msg(2, __FILE__, __FUNCTION__, __LINE__, format, ## args)
356
357/**
358 * Macro to log a message along with file, line, and function information.
359 */
360#define log_msg(level, format, args...) log_debug_msg(level, __FILE__, __FUNCTION__, __LINE__, format, ## args)
361
362#define DEFAULT_DVD_DISK_SIZE 4480 ///< The default size (in MB) of a DVD disk, unless the user says otherwise.
363
364#define DEFAULT_DEBUG_LEVEL 4 ///< By default, don't log messages with a loglevel higher than this.
365
366#define SZ_NTFSPROG_VOLSIZE "1048576" // was 4096
367#define NTFSPROG_PARAMS "-z0 -V" SZ_NTFSPROG_VOLSIZE " -o -b -d -g1"
368
369#define MNT_CDROM "/mnt/cdrom"
370
371#define DEFAULT_MR_LOGLEVEL 4
372
373#endif /* _MY_STUFF_H_ */
Note: See TracBrowser for help on using the repository browser.