source: branches/2.05/mondo/mondo/common/my-stuff.h @ 128

Last change on this file since 128 was 128, checked in by bcornec, 14 years ago

indent on all the C code

  • Property svn:keywords set to Id
File size: 15.9 KB
Line 
1/* my-stuff.h
2   $Id: my-stuff.h 128 2005-11-19 01:27:41Z bcornec $
3.
4
5
607/14
7- ARCH_THREADS is now 2; buffers, 4
8
907/10
10- added acl, xattr stuff
11
1206/19
13- added AUX_VER
14
1506/14
16- added DO_MBR_PLEASE
17
1804/17
19- replaced INTERNAL_TAPE_BLK_SIZE with g_internal_tape_block_size
20  and DEFAULT_INTERNAL_TAPE_BLOCK_SIZE
21
2204/13
23- log_msg is now calling standard_log_debug_msg, not the alias (log_debug_msg)
24
2504/03/2004
26- added star and SELINUX support
27
2811/20/2003
29- boot from isolinux.bin, not mindi-boot.2880.img
30
3111/15
32- reduced SLICE_SIZE from 8192 to 4096
33
3410/08
35- set p-i-h volsize to 1GB
36
3710/21
38- added MNT_CDROM and FREELOADER
39
4010/11
41- added DEFAULT_DVD_DISK_SIZE
42- added PARTIMAGE_DEBUG_LEVEL
43
4409/27
45- better logging
46
4709/24
48- added MR_LOGFILE="/tmp/mondo-restore.log"
49
5009/22
51- added bool, FALSE, TRUE
52
5309/20
54- increasd PPCFG_RAMDISK_SIZE to 150
55
5609/12
57- reduced MAX_STR_LEN from 512 to 460
58
5909/10
60- moved PPCFG_RAMDISK_SIZE here
61
6209/05
63- better config.h stuff
64
6506/05
66- changed fgrep to grep
67
6805/19
69- added CP_BIN
70
7105/05
72- added #include <sys/param.h> and sys/sem.h and ioctl.h
73
7405/03
75- added kill_anything_like_this()
76
7704/24/2003
78- added *STUB #define's
79
8011/22/2002
81- added INTERNAL_TAPE_BLK_SIZE
82
8310/10
84- use #define to create XMondo-friendly log file name if appropriate
85
8608/30
87- changed ARBITRARY_MAXIMUM to 512
88
8908/26
90- set MAX_STR_LEN at 512 but halved it within many _structures_
91- changed ARBITRARY_MAXIMUM to 128
92
9308/08
94- added '#include <signal.h>'
95- added WELCOME_STRING
96
9706/19
98- changed tape block size from 8192 to 65536
99
10004/08
101- added manual_cd_tray flag to bkpinfo
102
10303/31
104- added restore_path to struct s_bkpinfo
105
10603/21
107- updated version# to 1.42
108
10902/20
110- added bkpinfo->using_cdstream
111
11202/06
113- added MONDO_VERSION
114
11502/02
116- added MONDO_CFG_FILE
117- added SLICE_SIZE
118
11901/31
120- removed MINDI_HOME: it is unnecessary
121- replaced MONDO_HOME with variable g_mondo_home
122
12301/25
124- added MONDO_HOME, MINDI_HOME
125
12601/21
127- added s_node{} structure
128
12901/17
130- added sys/shm.h, types.h, ipc.h
131
13201/02/2002
133- added that groovy bkpinfo{} stuff
134
13511/29/2001
136- added raidlist{} struct
137
13808/27
139- stuff
140*/
141
142#define AUX_VER "2.05"
143
144#define HAVE_MALLOC 1
145
146
147// Extra info for ACLs and SELINUX users
148#define STAR_ACL_SZ "-xfflags -acl"
149//#define STAR_ACL_SZ "-xfflags"
150//#define STAR_ACL_SZ ""
151// Enable the first line and disable the second if you are a Fedora Core 2 user
152
153/**
154 * @file
155 * The main header file for Mondo.
156 */
157
158#if !defined(bool) && !defined(__cplusplus)
159/**
160 * Create the illusion of a Boolean type.
161 */
162#define bool int
163#define TRUE 1
164#define FALSE 0
165#endif
166
167#ifndef _MY_STUFF_H_
168#define _MY_STUFF_H_
169
170#ifdef HAVE_CONFIG_H
171#include <config.h>
172#endif
173
174#ifndef __FreeBSD__
175#include <getopt.h>
176#endif
177#include <sys/types.h>
178#include <sys/shm.h>
179#include <sys/ipc.h>
180#include <sys/ioctl.h>
181#include <sys/sem.h>
182#include <sys/param.h>
183#include <stdio.h>
184#include <stdlib.h>
185#ifndef  __USE_FILE_OFFSET64
186#define  __USE_FILE_OFFSET64
187#endif
188#ifndef  __USE_LARGEFILE64
189#define  __USE_LARGEFILE64
190#endif
191#include <sys/stat.h>
192#include <fcntl.h>
193#include <errno.h>
194#include <stddef.h>
195#include <sys/stat.h>
196#include <sys/wait.h>
197#include <time.h>
198#include <unistd.h>
199#include <signal.h>
200//#include <curses.h>
201#include <newt.h>
202#include <ctype.h>
203#include <string.h>
204#include <pthread.h>
205#include <assert.h>
206
207#if defined(DEBUG) && !__cplusplus
208int count;
209char trace_log[255];            /*buffer for logging */
210char *trace_log_ptr;
211#endif                          /* DEBUG */
212
213#define IA64_BOOT_SIZE "8192"   /* Should be coherent with mindi */
214
215/**
216 * The biggielist stub (appended to the directory where all.tar.gz was unpacked).
217 */
218#define BIGGIELIST_TXT_STUB "tmp/biggielist.txt"
219
220/**
221 * The filelist stub (appended to the directory where all.tar.gz was unpacked).
222 */
223#define FILELIST_FULL_STUB "tmp/filelist.full.gz"
224
225/**
226 * The mountlist stub (appended to the directory where all.tar.gz was unpacked).
227 */
228#define MOUNTLIST_FNAME_STUB "tmp/mountlist.txt"
229
230/**
231 * The mondo-restore.cfg stub (appended to the directory where all.tar.gz was unpacked).
232 */
233#define MONDO_CFG_FILE_STUB "tmp/mondo-restore.cfg"
234
235/**
236 * @bug Apparently unused.
237 */
238#define MONDO_TRACEFILE "/var/log/mondo-tracefile.log"
239
240#undef assert
241
242extern void _mondo_assert_fail(const char *file, const char *function,
243                               int line, const char *exp);
244
245/**
246 * An assert macro that calls _mondo_assert_fail() when it fails.
247 */
248#ifdef NDEBUG
249#define assert(exp) ((void)0)
250#else
251#define assert(exp) ((exp)?((void)0):_mondo_assert_fail(__FILE__, __FUNCTION__, __LINE__, #exp))
252#endif
253
254#define CRC_M16 0xA001          ///< Mask for crc16.
255#define CRC_MTT 0x1021          ///< Mask for crc-ccitt.
256
257#define FALSE 0                 ///< The ubiquitous FALSE macro.
258#define TRUE 1                  ///< The even more ubiquitous TRUE macro.
259
260#define SCREEN_LENGTH 25        ///< The default size of the screen.
261#define NOOF_ERR_LINES 6        ///< The number of lines of log output to keep at the bottom of the screen.
262#define ARBITRARY_MAXIMUM 500   ///< The maximum number of items showing at once in the mountlist or filelist editor.
263#define MAX_TAPECATALOG_ENTRIES 4096    ///< The maximum number of entries in the tape catalog.
264#define MAX_STR_LEN 380         ///< The maximum length of almost all @p char buffers in Mondo.
265#define MAXIMUM_RAID_DEVS 32    ///< The maximum number of RAID devices in the raidlist.
266#define MAXIMUM_ADDITIONAL_RAID_VARS 32 ///< The maximum number of additional RAID variables per RAID device in the raidlist.
267#define MAXIMUM_DISKS_PER_RAID_DEV 32   ///< The maximum number of disks per RAID device in the raidtab.
268
269#define RAIDTAB_FNAME "/etc/raidtab"    ///< The filename of the raidtab file, at least on Linux.
270
271#define BLK_START_OF_BACKUP     1   ///< Marker block: start a backup.
272#define BLK_START_OF_TAPE       2   ///< Marker block: start a tape.
273#define BLK_START_AFIOBALLS 10  ///< Marker block: start the afioball section.
274#define BLK_STOP_AFIOBALLS  19  ///< Marker block: stop the afioball section.
275#define BLK_START_AN_AFIO_OR_SLICE      20  ///< Marker block: start an afioball or a slice.
276#define BLK_STOP_AN_AFIO_OR_SLICE   29  ///< Marker block: stop an afioball or a slice.
277#define BLK_START_BIGGIEFILES   30  ///< Marker block: start the biggiefile section.
278#define BLK_STOP_BIGGIEFILES    39  ///< Marker block: stop the biggiefile section.
279#define BLK_START_A_NORMBIGGIE  40  ///< Marker block: start a normal biggiefile.
280#define BLK_START_A_PIHBIGGIE   41  ///< Marker block: start a partimagehack'd biggiefile
281#define BLK_START_EXTENDED_ATTRIBUTES 45    ///< Marker block: start xattr/acl info
282#define BLK_STOP_EXTENDED_ATTRIBUTES 46 ///< Marker block: stop xattr/acl info
283#define BLK_START_EXAT_FILE     47
284#define BLK_STOP_EXAT_FILE      48
285#define BLK_STOP_A_BIGGIE   59  ///< Marker block: stop a biggiefile.
286#define BLK_START_FILE          80  ///< Marker block: start a file (non-afio or slice).
287#define BLK_STOP_FILE           89  ///< Marker block: stop a file (non-afio or slice).
288#define BLK_END_OF_TAPE         100 ///< Marker block: end of tape.
289#define BLK_END_OF_BACKUP       101 ///< Marker block: end of backup.
290#define BLK_ABORTED_BACKUP      102 ///< Marker block: backup was aborted.
291
292/// The external tape blocksize.
293#ifdef EXTTAPE
294#define TAPE_BLOCK_SIZE (long)EXTTAPE
295#else
296#define TAPE_BLOCK_SIZE 131072L /* was 8192; 06/2002-->65536; 11/2002-->131072 */
297#endif
298
299#define DEFAULT_INTERNAL_TAPE_BLOCK_SIZE 32768  // Nov 2003?
300
301
302
303
304#define SLICE_SIZE 4096         ///< The size of a slice of a biggiefile.
305
306
307
308
309
310
311/**
312 * Determine whether @p x (t_bkptype) is a streaming backup.
313 */
314#define IS_THIS_A_STREAMING_BACKUP(x) (x == tape || x == udev || x == cdstream)
315
316
317/**
318 * @c mkisofs command to generate a nonbootable CD, except for -o option and the directory to image.
319 */
320#define MONDO_MKISOFS_NONBOOT   "mkisofs -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL_Version -V _CD#_"
321
322/**
323 * @c mkisofs command to generate a bootable CD using isolinux, except for -o option and the directory to image.
324 */
325#define MONDO_MKISOFS_REGULAR_SYSLINUX  "mkisofs -J -boot-info-table -no-emul-boot -b isolinux.bin -c boot.cat -boot-load-size 4 -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL_Version -V _CD#_"
326
327/**
328 * @c mkisofs command to generate a bootable CD using LILO, except for -o option and the directory to image.
329 */
330// -b images/mindi-boot.2880.img
331#define MONDO_MKISOFS_REGULAR_LILO      "mkisofs -boot-info-table -no-emul-boot -b isolinux.bin -c boot.cat -boot-load-size 4 -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_"
332
333/**
334 * @c mkisofs command to generate a bootable CD using ELILO, except for -o option and the directory to image.
335 */
336// -b images/mindi-boot.2880.img
337// Should replace 8192 by IA64_BOOT_SIZE
338#define MONDO_MKISOFS_REGULAR_ELILO      "mkisofs -no-emul-boot -b images/mindi-bootroot.8192.img -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_"
339
340/**
341 * The stub name of the temporary ISO image to create, burn, and remove.
342 */
343#define MONDO_TMPISOS "/temporary.iso"
344
345/**
346 * @c growisofs command to generate a bootable DVD using isolinux, except for the directory to image.
347 */
348#define MONDO_GROWISOFS_REGULAR_SYSLINUX "growisofs -speed=1 -use-the-force-luke -J -no-emul-boot -boot-load-size 4 -b isolinux.bin --boot-info-table -c boot.cat -boot-load-size 4 -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL_Version -V _CD#_ -v"
349
350/**
351 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image.
352     */// -b images/mindi-boot.2880.img
353#define MONDO_GROWISOFS_REGULAR_ELILO     "growisofs -speed=1 -use-the-force-luke -no-emul-boot -b images/mindi-boot.2880.img -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v"
354
355/**
356 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image.
357     */// -b images/mindi-boot.2880.img
358#define MONDO_GROWISOFS_REGULAR_LILO     "growisofs -speed=1 -no-emul-boot -b isolinux.bin -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v"
359
360/**
361 * @c growisofs command to generate a nonbootable DVD, except for the directory to image.
362 */
363#define MONDO_GROWISOFS_NONBOOT          "growisofs -speed=1 -use-the-force-luke -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v"
364
365/**
366 * Welcome string displayed at the top of the newt interface.
367 */
368#define WELCOME_STRING "W E L C O M E   T O   M O N D O   R E S C U E"
369
370/**
371 * The maximum length of a filename in the tape catalog.
372 */
373#define MAX_TAPECAT_FNAME_LEN 32
374
375//#define strcpy(y,x) strncpy(y, x, sizeof(y)-1)
376
377
378/**
379 * Compatibility #define to ease the transition to logfile-in-a-variable.
380 */
381#define MONDO_LOGFILE    "/var/log/mondo-archive.log"
382
383/**
384 * Assert that (@p x != NULL) and (@p x[0] != '\\0').
385 */
386#define assert_string_is_neither_NULL_nor_zerolength(x) {assert(x!=NULL);assert(x[0]!='\0');}
387
388/**
389 * Log the file, line, Mondo error message, and OS error message (errno).
390 */
391#define log_OS_error(x) {log_msg(0, "%s, line %ld: %s (%s)", __FILE__, __LINE__, x, strerror(errno));}
392
393/**
394 * Assert that (@p x != NULL).
395 */
396#define assert_pointer_is_not_NULL(x) {assert(x!=NULL);}
397
398/**
399 * close() @p x and log a message if it fails.
400 */
401#define paranoid_close(x) {if(close(x)) {log_msg(5, "close err");} x=-999; }
402
403/**
404 * fclose() @p x and log a message if it fails.
405 */
406#define paranoid_fclose(x) {if(fclose(x)) {log_msg(5, "fclose err");} x=NULL; }
407
408/**
409 * pclose() @p x and log a message if it fails.
410 */
411#define paranoid_pclose(x) {if(pclose(x)) {log_msg(5, "pclose err");} x=NULL; }
412
413/**
414 * Run the command @p x and log it if it fails.
415 */
416#define paranoid_system(x) {if(system(x)) log_msg(4, x); }
417
418/**
419 * Free @p x and set it to NULL.
420 */
421#define paranoid_free(x) {if (x != NULL) free(x); x=NULL;}
422
423/**
424 * Free variables and call finish(@p x).
425 */
426#define paranoid_MR_finish(x) {free_MR_global_filenames (); if (g_bkpinfo_DONTUSETHIS) paranoid_free ( g_bkpinfo_DONTUSETHIS ); finish(x); }
427
428/**
429 * Log file, function, line, and @p x.
430 */
431#define iamhere(x) {log_it("%s, %s, %ld: %s", __FILE__, __FUNCTION__, __LINE__, x);}
432
433/**
434 * Yes, we want malloc() to help us fix bugs.
435 */
436#define MALLOC_CHECK_ 1
437
438/**
439 * Kill any process containing the string @p x surrounded by spaces in its commandline.
440 */
441#define kill_anything_like_this(x) {run_program_and_log_output("kill `ps wax | grep \"" x "\" | awk '{print $1;}' | grep -vx \"\\?\"`", TRUE);}
442
443/**
444 * Malloc @p x to be MAX_STR_LEN bytes and call fatal_error() if we're out of memory.
445 */
446#define malloc_string(x) { x = malloc(MAX_STR_LEN); if (!x) { fatal_error("Unable to malloc"); } x[0] = x[1] = '\0'; }
447
448/**
449 * Path to the location the hard drive is mounted on during a restore.
450 */
451#define MNT_RESTORING "/mnt/RESTORING"
452
453/** @def VANILLA_SCSI_CDROM The first SCSI CD-ROM in the system (most likely to be the one to write to). */
454/** @def VANILLA_SCSI_TAPE  The first SCSI tape in the system (most likely to be the one towrite to. */
455/** @def DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE A string whose presence in a device name indicates the
456 * inability to check this device for errors in the mountlist. */
457/** @def RAID_DEVICE_STUB The stub of a RAID device (set up RAID if we find it). */
458/** @def SANE_FORMATS Sane formats for this OS, separated by spaces. */
459/** @def ALT_TAPE The first IDE tape in the system. */
460/** @def MKE2FS_OR_NEWFS @c mke2fs or @c newfs, depending on the OS. */
461/** @def CP_BIN The GNU @c cp binary to use. */
462#ifdef __FreeBSD__
463#define VANILLA_SCSI_CDROM  "/dev/cd0"
464#define VANILLA_SCSI_TAPE   "/dev/sa0"
465#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/vinum/"
466#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
467#define SANE_FORMATS        "swap image msdosfs nfs ntfs raid lvm ffs ufs ext2fs"
468#define ALT_TAPE        "/dev/ast0"
469#define MKE2FS_OR_NEWFS "newfs"
470#define CP_BIN      "gcp"
471#else
472#define VANILLA_SCSI_CDROM  "/dev/scd0"
473#define VANILLA_SCSI_TAPE   "/dev/st0"
474#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/md"
475#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
476#define SANE_FORMATS        "swap image vfat ext2 ext3 xfs vfs jfs reiserfs dos minix coda nfs ntfs hpfs raid lvm"
477#define ALT_TAPE        "/dev/ht0"
478#define MKE2FS_OR_NEWFS "mke2fs"
479#define CP_BIN      "cp"
480#endif
481
482
483/**
484 * The template for a filelist filename.
485 * The first argument (%s) is the tempdir and the second (%d) is the filelist number.
486 */
487#define FILELIST_FNAME_RAW_SZ "%s/filelist.%ld"
488
489#define XATTR_LIST_FNAME_RAW_SZ      "%s/xattr_list.%ld.gz"
490#define XATTR_BIGGLST_FNAME_RAW_SZ   "%s/xattr_list.big.gz"
491#define ACL_LIST_FNAME_RAW_SZ        "%s/acl_list.%ld.gz"
492#define ACL_BIGGLST_FNAME_RAW_SZ     "%s/acl_list.big.gz"
493
494/**
495 * The template for an afioball filename.
496 * The first argument (%s) is the tempdir and the second (%d) is the filelist number.
497 */
498#define AFIOBALL_FNAME_RAW_SZ (bkpinfo->use_star)?"%s/tmpfs/%ld.star.%s":"%s/tmpfs/%ld.afio.%s"
499#define ARCH_THREADS 2          ///< The number of simultaneous threads running afio in the background.
500#define ARCH_BUFFER_NUM (ARCH_THREADS*4)    // Number of permissible queued afio files
501#define FORTY_SPACES "                                         "    ///< 40 spaces.
502#define PPCFG_RAMDISK_SIZE 250  ///< Size of the tmpfs, in megabytes, to attempt to mount (to speed up Mondo).
503
504#define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE"
505
506
507/**
508 * Compatibility define to change log_it() calls to log_debug_msg() calls.
509 */
510#define log_it(format, args...) log_debug_msg(2, __FILE__, __FUNCTION__, __LINE__, format, ## args)
511
512/**
513 * Macro to log a message along with file, line, and function information.
514 */
515#define log_msg(level, format, args...) log_debug_msg(level, __FILE__, __FUNCTION__, __LINE__, format, ## args)
516
517#define DEFAULT_DVD_DISK_SIZE 4380  ///< The default size (in MB) of a DVD disk, unless the user says otherwise.
518
519#define DEFAULT_DEBUG_LEVEL 4   ///< By default, don't log messages with a loglevel higher than this.
520
521#define SZ_PARTIMAGE_VOLSIZE "1048576"  // was 4096
522#define PARTIMAGE_PARAMS "-z0 -V" SZ_PARTIMAGE_VOLSIZE " -o -b -d -g1"
523
524#define MNT_CDROM "/mnt/cdrom"
525#define MNT_FLOPPY "/mnt/floppy"
526
527#define FREELOADER              // You're not a paying customer
528#define DEFAULT_MR_LOGLEVEL 4
529
530#endif                          /* _MY_STUFF_H_ */
Note: See TracBrowser for help on using the repository browser.