source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-string.c@ 2850

Last change on this file since 2850 was 2508, checked in by Bruno Cornec, 14 years ago

r3287@localhost (orig r2285): bruno | 2009-07-20 11:36:47 +0200

r3285@localhost: bruno | 2009-07-20 11:17:35 +0200
Apply fix in 2.2.10 around multi USB device handling to 2.2.9 as well


r3291@localhost (orig r2288): bruno | 2009-07-21 16:48:31 +0200
Copy 2.2.10 test script in to 2.2.9 for memory problm analysis


r3293@localhost (orig r2290): bruno | 2009-07-22 14:03:44 +0200

  • Fix a printing error in mindi for the tar command
  • Fix all mr_asprintf which had no second param as a string


r3295@localhost (orig r2292): bruno | 2009-07-22 16:55:00 +0200

  • Fix #160 and #346 by rewriting the message.txt file with more valid information gathered in mindi


r3300@localhost (orig r2294): bruno | 2009-07-23 01:58:08 +0200

Man pages patch from Joe Ross (joe.ross_at_gmail.com)


r3303@localhost (orig r2297): bruno | 2009-07-23 17:43:49 +0200
Fix a remaining display error for 2.2.9. That version has been tested OK in a lab.


r3304@localhost (orig r2298): bruno | 2009-07-23 18:18:27 +0200

  • Remove memory leak for the last modification


r3308@localhost (orig r2302): bruno | 2009-07-24 21:18:50 +0200
Improve logging of mountlist.txt


r3310@localhost (orig r2304): bruno | 2009-07-27 19:45:10 +0200

  • popup_and_get_string needs an allocated buffer for the moment so fixing the calls with dyn. ones
  • Fix a bug in mem.c for mr_strcat, which wasn't modifying the right pointer level


r3311@localhost (orig r2305): bruno | 2009-07-27 19:49:35 +0200
Avoid a memory leak in the previous patch


r3314@localhost (orig r2308): bruno | 2009-07-27 20:59:06 +0200
Fix a bug in mr_strcat backported from 2.2.10. Should solve our seg faults.


r3315@localhost (orig r2309): bruno | 2009-07-28 02:14:23 +0200
Cosmetic changes to allow for quality to not giv false positive


r3343@localhost (orig r2311): bruno | 2009-08-18 02:13:43 +0200
Fix for initramfs detection with 2.6.30 (Hugo Vanwoerkom hvw59601_at_care2.com)


r3367@localhost (orig r2333): bruno | 2009-08-18 16:26:26 +0200
Adds a precision for -U option in man page on raw device usage and not partition name


r3373@localhost (orig r2336): bruno | 2009-08-20 17:37:41 +0200

  • Precise the combined usage of -E and -I in mondoarchive (Case 4601017223)


r3379@localhost (orig r2342): bruno | 2009-08-21 16:27:10 +0200


r3383@localhost (orig r2344): bruno | 2009-08-24 13:37:09 +0200

r3382@localhost: bruno | 2009-08-24 13:30:25 +0200
In NFS mode also propose access to expert, interactive, ... entry at boot prompt


r3388@localhost (orig r2346): bruno | 2009-08-27 11:41:16 +0200
Adds fdisk -l result in Log File at restore time


r3389@localhost (orig r2347): bruno | 2009-08-27 13:51:00 +0200

  • Solve tmp dir creation which sometimes was trying to create /%xx dirs. Should fix #293 for good


r3390@localhost (orig r2348): bruno | 2009-08-27 13:54:25 +0200
Improve logging (minor)


r3394@localhost (orig r2350): bruno | 2009-08-28 02:24:19 +0200
Change inerface of evaluate_mountlist and spread_flaws_across_three_lines in order to solve bugs linked to strings management in these functions. May fix a restoration crash seen by some customers


r3397@localhost (orig r2353): bruno | 2009-08-28 19:03:45 +0200

  • Addition of a nomd option to avoid starting mdadm
  • mpath is now already started if there was a mpath entry in mountlist


r3399@localhost (orig r2355): bruno | 2009-08-29 00:56:50 +0200
Remove function spread_flaws_across_three_lines and expand it at the single place where it was useful, and fix memory allocation issues in it.


r3402@localhost (orig r2358): bruno | 2009-09-01 19:02:35 +0200
P2V doc updated (Lester Wade lester.wade_at_hp.com)


r3404@localhost (orig r2360): bruno | 2009-09-01 19:26:53 +0200
Website update to refer to new P2V document


r3405@localhost (orig r2361): bruno | 2009-09-03 13:54:25 +0200

  • Fix a case where the NFS dir in restore mode was mounted rw (linked to bug #291 could create a huge problem)


r3407@localhost (orig r2363): bruno | 2009-09-03 14:46:46 +0200
More verbose at installation of additional tools


r3409@localhost (orig r2365): bruno | 2009-09-03 18:08:32 +0200

  • New update from Lester Wade (lester.wade_at_hp.com) for P2V doc


r3410@localhost (orig r2366): bruno | 2009-09-05 01:28:18 +0200
place the code of mondo_makefilelist before its call



r3411@localhost (orig r2367): bruno | 2009-09-06 01:51:26 +0200

  • Advertising for project-builder on the website added


r3412@localhost (orig r2368): bruno | 2009-09-07 15:36:23 +0200
Fix compilation issue


r3413@localhost (orig r2369): bruno | 2009-09-07 18:03:40 +0200
Another compilation issue fixed.


r3415@localhost (orig r2371): bruno | 2009-09-08 13:40:25 +0200

  • Fix a problem a error detection in evaluate_mountlist which casued nuke mode to abort. Error string should also be better now.


r3417@localhost (orig r2373): bruno | 2009-09-08 13:55:31 +0200
Avoid asking the Prefix name in NFS mode twice


r3418@localhost (orig r2374): bruno | 2009-09-08 20:04:07 +0200

  • Try to fix garbled screen progression in text mode based on 2.2.10 modifications which are working


r3424@localhost (orig r2380): bruno | 2009-09-09 20:30:47 +0200

  • Change NFS support into a NetFS support to allow for multiple protocol in addition to NFS (NEEDS TESTING)
  • Better logging to detect a potential nuke issue


r3425@localhost (orig r2381): bruno | 2009-09-10 02:05:55 +0200
Fix a missing param for sshfs call


r3428@localhost (orig r2384): bruno | 2009-09-10 13:02:56 +0200

  • Remove separate function look_for_duplicate_mountpoints used only once and whose interface created problems with caller


r3430@localhost (orig r2386): bruno | 2009-09-10 16:06:52 +0200
Be compatible on backup type by making old nfs recognized as netfs and proto forced


r3431@localhost (orig r2387): bruno | 2009-09-10 18:40:47 +0200
Fix a problem in netfs analysis in mondoarchive


r3432@localhost (orig r2388): bruno | 2009-09-10 20:25:13 +0200
Fix mondoarchive CLI analysis for NETFS type of requests


r3434@localhost (orig r2390): bruno | 2009-09-11 03:05:20 +0200

  • Adds ext3 initrd support for 2.6.30


r3437@localhost (orig r2393): bruno | 2009-09-11 11:56:52 +0200

  • Tries to add support for bzip2 and lzma initramfs (preliminary, not tested) for 2.6.30


r3438@localhost (orig r2394): bruno | 2009-09-12 02:53:02 +0200
Fix interface of evaluate_mountlist (remove 2nd param useless) and fix nuke mode which wasn't working.


r3441@localhost (orig r2397): bruno | 2009-09-14 18:54:34 +0200
Fix a format issue in text mode on percentage


r3452@localhost (orig r2398): bruno | 2009-09-15 16:00:13 +0200

  • Fix a bug where flaws_str could be NULL and wasn't tested correctly.


r3453@localhost (orig r2399): bruno | 2009-09-15 19:28:39 +0200

  • Use protocol name when displaying restore progress instead of netfs
  • Ask for network protocol name at restore time


r3455@localhost (orig r2401): bruno | 2009-09-15 19:34:19 +0200
Wrong structure member name was used


r3456@localhost (orig r2402): bruno | 2009-09-16 13:04:17 +0200
Use dir for shell related commands and dir1 for C related actions in open_and_list_dir to avoid missing some files with { in names e.g.


r3457@localhost (orig r2403): bruno | 2009-09-16 16:32:03 +0200

  • At restore time read the netfs protocol in the conf file


r3462@localhost (orig r2408): bruno | 2009-09-18 15:17:08 +0200
Remove useless script


r3463@localhost (orig r2409): bruno | 2009-09-18 15:25:35 +0200

  • Split deplist.txt into multiple conf files under deplist.d in the conf dir. This will allow to have a minimal.conf file for initrd content to analyze to improve support of new embedded feature in the future (sshfs, live install). The other conf files contain the additional commands to put in the all.tar.gz. For the moment, mindi is still working the same. THis infra will allow that support in a near future. deplist.txt is now reserved for the admin additional commands.


r3465@localhost (orig r2410): bruno | 2009-09-18 19:10:54 +0200

  • Better list of mandatory tools
  • Adds fuse and sshfs support in initrd


r3466@localhost (orig r2411): bruno | 2009-09-18 20:32:47 +0200
sshfs also needs ssh at restore time in initrd


r3478@localhost (orig r2418): bruno | 2009-09-23 23:22:39 +0200
Modify getfattr call to have all extended attributes, including non user ones. (patch from Kevin Ritzenthaler Kevin.Ritzenthaler_at_hp.com) and fix #357


r3479@localhost (orig r2419): bruno | 2009-09-23 23:50:34 +0200
star only supports ACL when used with exustar mode. Fix #356.


r3482@localhost (orig r2422): bruno | 2009-09-24 16:53:24 +0200

  • Adds support for bnx2x (BL 460 G6) and auth_rpcgss (Debian 2.6.31)


r3485@localhost (orig r2423): bruno | 2009-09-25 16:38:40 +0200
Fix an issue in is_this_device_mounted (string freed before last usage)


r3486@localhost (orig r2424): bruno | 2009-09-25 18:44:01 +0200

  • analyze-my-lvm now removes excluded devices from list coming from mondoarchive
  • new mr_make_devlist_from_pathlist which handle the new bkpinfo->exclude_devs field containing the excluded devices and remove corresponding code from libmondo-cli.c
  • Move DSF code into libmondo-devices.c for coherency, and only the previous function is made externally available
  • Remove dev_to_exclude in libmondo-archive.c which wasn't working correctly and replace it with bkpinfo->exclude_devs


r3487@localhost (orig r2425): bruno | 2009-09-25 18:58:23 +0200

  • Improving ssh support at restore time by providing a shadow file


r3489@localhost (orig r2426): bruno | 2009-09-25 19:42:09 +0200

  • Attempt to stay backward compatible without protocol for -n option


r3490@localhost (orig r2427): bruno | 2009-09-28 02:08:06 +0200
Avoids null param for excludes_devs for mindi call


r3492@localhost (orig r2429): bruno | 2009-09-28 11:46:16 +0200

  • Simplify GetInitrdFilesystemToUse which doesn't need to detect everything, but just know if it's initramfs (new mode) or a compressed FS ext2/3 (older mode) as initrd is anyway re-made by mindi. Should fix #353


r3494@localhost (orig r2431): bruno | 2009-09-28 13:16:18 +0200

  • Use only the AWK veriable everywhere and not the awk command


r3495@localhost (orig r2432): bruno | 2009-09-28 14:16:31 +0200
Warning emited in case of duplicate mountpoints or devices in fstab found


r3496@localhost (orig r2433): bruno | 2009-09-28 15:55:17 +0200
ssh in the restore env needs some dlopened libs (libnss_compat|files)


r3497@localhost (orig r2434): bruno | 2009-09-28 16:33:14 +0200
Compiler warning fixed


r3498@localhost (orig r2435): bruno | 2009-09-28 17:55:26 +0200
Improve user management for NetFS cases


r3499@localhost (orig r2436): bruno | 2009-09-29 01:48:32 +0200

  • Improve deplist.d/* files
  • adds libnss for ssh support in boot disk
  • Solve a memory management issue in DSF module (strtok => mr_strtok)
  • DSF now also supports partitions in addition to full disks
  • Adds debug in open_and_list_dir


r3500@localhost (orig r2437): bruno | 2009-09-29 10:41:56 +0200

  • Fix udev support in init for Mandriva 2009.1 (udevadm settle is blocking)


r3501@localhost (orig r2438): bruno | 2009-09-29 14:41:36 +0200

  • Improvements on sshfs/ssh management in restore mode
  • Include now all minimal requirements for sshfs


r3502@localhost (orig r2439): bruno | 2009-09-29 18:46:08 +0200

  • Avoids error message if some ssh conf files do not exist


r3503@localhost (orig r2440): bruno | 2009-09-29 18:57:13 +0200

  • Avoids comment analysis in the new code handling deplist.d


r3504@localhost (orig r2441): bruno | 2009-09-29 19:34:34 +0200

  • fuse device is needed at restore time for sshfs


r3505@localhost (orig r2442): bruno | 2009-09-29 20:02:36 +0200

  • Improves udev timeout handling


r3506@localhost (orig r2443): bruno | 2009-09-29 20:43:38 +0200

  • priority given to env var for tmpdir
  • fuse FS excluded from tmpdir computation


r3518@localhost (orig r2447): bruno | 2009-10-04 01:58:08 +0200

  • Iprove USB log in case of error by adding the conf file


r3519@localhost (orig r2448): bruno | 2009-10-05 11:06:13 +0200


r3520@localhost (orig r2449): bruno | 2009-10-06 01:10:35 +0200

  • Adds support for grub2 conf file grub.cfg in addition to menu.lst


r3521@localhost (orig r2450): bruno | 2009-10-06 01:24:02 +0200

  • Fix a mr_asprintf usage without & causing a seg fault.


r3523@localhost (orig r2452): bruno | 2009-10-06 12:47:56 +0200
CIFS mounts shouldn't be part of the mountlist analysis (should help solving #288)


r3524@localhost (orig r2453): bruno | 2009-10-07 10:17:03 +0200

  • Fix a bug in handling of -E option with real devices (bad report in function mr_make_devlist_from_pathlist of the test between -E and -I)


r3525@localhost (orig r2454): bruno | 2009-10-07 10:19:02 +0200

  • Fix an error in the test for grub conf files (or used instead of and)


r3526@localhost (orig r2455): bruno | 2009-10-07 16:14:59 +0200
afio is under /bin on Debian


r3527@localhost (orig r2456): bruno | 2009-10-07 17:31:26 +0200

  • Adds support for libcrc32c (needed by bnx2x)


r3532@localhost (orig r2457): bruno | 2009-10-09 13:33:44 +0200

  • Apply path from Matthew Cline (matt_at_nightrealms.com) in order to fix #359


r3533@localhost (orig r2458): bruno | 2009-10-09 13:41:02 +0200
Adds a conf file example for mindi and fix #360


r3535@localhost (orig r2459): bruno | 2009-10-09 15:13:01 +0200
MOde of conf file


r3546@localhost (orig r2461): bruno | 2009-10-14 01:12:24 +0200

  • umount freshly created VFAT partition on USB key as Ubunu has an automounter mounting it as soon as created (Steffen Neumann sneumann_at_ipb-halle.de)


r3566@localhost (orig r2463): bruno | 2009-10-26 01:34:16 +0100

  • Reset an error counter before blanking a DVD to avoid always returning an error (Vincent Raman vincent.raman_at_macqel.eu)


r3567@localhost (orig r2464): bruno | 2009-10-26 13:57:14 +0100
bzip2 is under /bin on Debian


r3568@localhost (orig r2465): bruno | 2009-10-28 01:46:30 +0100
some distro hold lvm commands under /usr/sbin


r3595@localhost (orig r2469): bruno | 2009-11-10 12:22:10 +0100
/dev/shm is now part of the default exclude list


r3596@localhost (orig r2470): bruno | 2009-11-10 12:32:40 +0100
Remove useless pb_log and MONDO_TRACEFILE


r3597@localhost (orig r2471): bruno | 2009-11-10 12:57:58 +0100
Improve analysis of kernel modules by printing whether it's a live or extra module which has not been found (Matthew Cline) as reported in #362


r3598@localhost (orig r2472): bruno | 2009-11-10 13:21:46 +0100

  • Default to DVD size when in iso or netfs mode


r3599@localhost (orig r2473): bruno | 2009-11-10 14:13:10 +0100

  • Fix #363 where exclude_paths was extended up to memory limit dumping core


r3600@localhost (orig r2474): bruno | 2009-11-10 14:31:14 +0100

  • Update deplist for Debian support


r3602@localhost (orig r2476): bruno | 2009-11-11 02:44:42 +0100

  • small improvement for loging in USB case


r3603@localhost (orig r2477): bruno | 2009-11-11 13:29:27 +0100

  • Adds a nolvm boot option at restore time


r3604@localhost (orig r2478): bruno | 2009-11-11 19:54:51 +0100

  • Fix #367 - the for loop doesn't make any test now, as it was computed before entering the loop, leading to an error, and was also made inside the loop anyway.


r3605@localhost (orig r2479): bruno | 2009-11-12 00:32:45 +0100

  • Add support for diskdumplib driver useful for RHEL 3 and IBM xseries 336


r3606@localhost (orig r2480): bruno | 2009-11-12 01:09:40 +0100

  • If using nolvm, mondorestore should also not nalyze and handle i-want-my-lvm


r3608@localhost (orig r2482): bruno | 2009-11-14 12:54:11 +0100
Fix bunzip2 on debian as well


r3610@localhost (orig r2484): bruno | 2009-11-15 00:44:19 +0100

  • Adds support for variable serial port console, with defalut to /dev/ttyS0, and a boot param to change it with serial=/dev/ttySx


r3615@localhost (orig r2485): bruno | 2009-11-15 01:34:33 +0100

r3614@localhost: bruno | 2009-11-15 01:34:12 +0100
Adds a space in exclude paths


r3623@localhost (orig r2487): bruno | 2009-11-18 20:41:40 +0100

r3620@localhost: bruno | 2009-11-18 10:31:36 +0100

  • Only link /dev/tty to serial port when there is indeed a serial port. If not breaks mondorestore on normal console


r3631@localhost (orig r2490): bruno | 2009-11-24 01:48:29 +0100
Put news below in the main page to make it more readable


r3648@localhost (orig r2492): bruno | 2009-11-25 23:50:13 +0100

r3647@localhost: bruno | 2009-11-25 23:49:11 +0100

  • Add warning for -f and SW Raid as in 2.2.10


r3650@localhost (orig r2493): bruno | 2009-11-26 00:19:52 +0100

r3649@localhost: bruno | 2009-11-26 00:18:27 +0100

  • Addition of the german translation made by Magnus Rasche (Magnus.rasche_at_gmx.de) and Website inclusion


r3652@localhost (orig r2495): bruno | 2009-11-27 15:55:55 +0100
cosmetic display fix
r3659@localhost (orig r2498): bruno | 2009-12-05 17:53:03 +0100
nfsopt restore boot time option added to support custom mount options for network restore


r3684@localhost (orig r2501): bruno | 2009-12-17 00:35:08 +0100
Fix #375 mondo will segfault if the partition in sensibly_set_tmpdir_and_scratchdir() is read-only (cylau)


r3685@localhost (orig r2502): bruno | 2009-12-17 01:02:47 +0100

  • Fix an issue in the function listing kernel modules when not found


r3686@localhost (orig r2503): bruno | 2009-12-17 01:15:01 +0100
Adds scsi_dump_register to mindi SCSI_MODS for RHEL3 + IBM servers


r3701@localhost (orig r2504): bruno | 2009-12-23 02:24:33 +0100

  • Addition of the Lab for Mondorescue


r3702@localhost (orig r2505): bruno | 2009-12-23 02:41:17 +0100
Web site update for Lab MondoRescue delivery


r3706@localhost (orig r2506): bruno | 2010-01-04 11:31:53 +0100

  • Fix a bug when isodir is / only when splitting it in iso_path and iso_mnt


r3707@localhost (orig r2507): bruno | 2010-01-04 13:22:49 +0100

  • Fix #377: Segfault in pause_and_ask_for_cdr() (ggeens)


  • Property svn:keywords set to Id
File size: 28.3 KB
Line 
1/* $Id: libmondo-string.c 2508 2010-01-04 18:21:55Z bruno $ */
2
3
4/**
5 * @file
6 * Functions for handling strings.
7 */
8
9#include "my-stuff.h"
10#include "mr_mem.h"
11#include "mondostructures.h"
12#include "libmondo-string.h"
13#include "lib-common-externs.h"
14#include "libmondo-files-EXT.h"
15#include "libmondo-gui-EXT.h"
16#include "libmondo-tools-EXT.h"
17
18/*@unused@*/
19//static char cvsid[] = "$Id: libmondo-string.c 2508 2010-01-04 18:21:55Z bruno $";
20
21extern int g_current_media_number;
22extern long long g_tape_posK;
23
24/* Reference to global bkpinfo */
25extern struct s_bkpinfo *bkpinfo;
26
27
28/**
29 * @addtogroup stringGroup
30 * @{
31 */
32/**
33 * Build a partition name from a drive and a partition number.
34 * @param drive The drive basename of the partition name (e.g. /dev/hda)
35 * @param partno The partition number (e.g. 1)
36 * @return @p partition.
37 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
38 */
39char *build_partition_name(const char *drive, int partno)
40{
41 char *c = NULL;
42 char *partition = NULL;
43
44 assert_string_is_neither_NULL_nor_zerolength(drive);
45 assert(partno >= 0);
46
47 mr_asprintf(partition, "%s", drive);
48 /* is this a devfs device path? */
49 c = strrchr(partition, '/');
50 if (c && strncmp(c, "/disc", 5) == 0) {
51 /* yup it's devfs, return the "part" path */
52 /* This strcpy is safe */
53 strcpy(c + 1, "part");
54 } else {
55 if (isdigit(partition[-1])) {
56 mr_strcat(partition, "%c",
57#ifdef BSD
58 's');
59#else
60 'p');
61#endif
62 }
63 }
64 mr_strcat(partition, "%d", partno);
65 return(partition);
66}
67
68
69/**
70 * Pad a string on both sides so it appears centered.
71 * @param in_out The string to be center-padded (modified).
72 * @param width The width of the final result.
73 */
74void center_string(char *in_out, int width)
75{
76 char scratch[MAX_STR_LEN];
77 char *p;
78 int i; /* purpose */
79 int len; /* purpose */
80 int mid; /* purpose */
81 int x; /* purpose */
82
83 assert(in_out != NULL);
84 assert(width > 2);
85
86 if (strlen(in_out) == 0) {
87 return;
88 }
89 for (p = in_out; *p == ' '; p++);
90 strcpy(scratch, p);
91 strip_spaces (scratch);
92 len = (int) strlen(scratch);
93 mid = width / 2;
94 x = mid - len / 2;
95 for (i = 0; i < x; i++) {
96 in_out[i] = ' ';
97 }
98 in_out[i] = '\0';
99 strcat(in_out, scratch);
100 for (i = x + len ; i < width - 1; i++) {
101 in_out[i] = ' ';
102 }
103 in_out[i] = '\0';
104}
105
106
107/**
108 * Add commas every third place in @p input.
109 * @param input The string to commarize.
110 * @return The string with commas.
111 * @note The returned string points to static storage that will be overwritten with each call.
112 */
113char *commarize(char *input)
114{
115 char pos_w_commas[MAX_STR_LEN];
116 static char output[MAX_STR_LEN];
117 char tmp[MAX_STR_LEN];
118 int j;
119
120 assert(input != NULL);
121
122 strcpy(tmp, input);
123 if (strlen(tmp) > 6) {
124 strcpy(pos_w_commas, tmp);
125 j = (int) strlen(pos_w_commas);
126 tmp[j - 6] = ',';
127 strcpy(tmp + j - 5, pos_w_commas + j - 6);
128 strcpy(pos_w_commas, tmp);
129 }
130 if (strlen(tmp) > 3) {
131 j = (int) strlen(tmp);
132 strcpy(pos_w_commas, tmp);
133 pos_w_commas[j - 3] = ',';
134 strcpy(pos_w_commas + j - 2, tmp + j - 3);
135 } else {
136 strcpy(pos_w_commas, tmp);
137 }
138 strcpy(output, pos_w_commas);
139 return (output);
140}
141
142
143
144
145
146
147
148
149
150/**
151 * Turn an entry from the RAID editor's disklist into a GUI-friendly string.
152 * The format is: the device left-aligned and padded to 24 places, followed by a space and the
153 * index, right-aligned and padded to eight places. The total string length
154 * is exactly 33.
155 * @param disklist The disklist to operate on.
156 * @param lino The line number from @p disklist to convert to a string.
157 * @return The string form of the disklist entry.
158 * @note The returned string points to static storage and will be overwritten with each call.
159 */
160char *disklist_entry_to_string(struct list_of_disks *disklist, int lino)
161{
162
163 /*@ buffers ********************************************************** */
164 static char output[MAX_STR_LEN];
165
166 assert(disklist != NULL);
167
168 sprintf(output, "%-24s %8d", disklist->el[lino].device,
169 disklist->el[lino].index);
170 return (output);
171}
172
173
174
175
176
177/**
178 * Turn a "friendly" sizestring into a number of megabytes.
179 * Supports the suffixes 'k'/'K', 'm'/'M', and 'g'/'G'. Calls
180 * fatal_error() if an unknown suffix is encountered.
181 * @param incoming The sizestring to convert (e.g. "40m", "2g").
182 * @return The size in megabytes.
183 */
184long friendly_sizestr_to_sizelong(char *incoming)
185{
186 long outval;
187 int i;
188 char *tmp1 = NULL;
189 char ch;
190
191 assert_string_is_neither_NULL_nor_zerolength(incoming);
192
193 if (!incoming[0]) {
194 return (0);
195 }
196 if (strchr(incoming, '.')) {
197 fatal_error("Please use integers only. No decimal points.");
198 }
199
200 mr_asprintf(tmp1, "%s", incoming);
201 i = (int) strlen(tmp1);
202 if (tmp1[i - 1] == 'B' || tmp1[i - 1] == 'b') {
203 tmp1[i - 1] = '\0';
204 }
205 for (i = 0; i < (int) strlen(tmp1) && isdigit(tmp1[i]); i++);
206 ch = tmp1[i];
207 tmp1[i] = '\0';
208 outval = atol(tmp1);
209 paranoid_free(tmp1);
210
211 if (ch == 'g' || ch == 'G') {
212 outval = outval * 1024;
213 } else if (ch == 'k' || ch == 'K') {
214 outval = outval / 1024;
215 } else if (ch == 't' || ch == 'T') // terabyte
216 {
217 outval *= 1048576;
218 } else if (ch == 'Y' || ch == 'y') // yottabyte - the biggest measure in the info file
219 {
220 log_it
221 ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
222 popup_and_OK
223 ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
224 fatal_error("Integer overflow.");
225 } else if (ch != 'm' && ch != 'M') {
226 mr_asprintf(tmp1, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch);
227 fatal_error(tmp1);
228 }
229 return (outval);
230}
231
232
233
234/**
235 * Add spaces to the right of @p incoming to make it @p width characters wide.
236 * @param incoming The string to left-pad.
237 * @param width The width to pad it to.
238 * @return The left-padded string.
239 * @note The returned string points to static storage that will be overwritten with each call.
240 * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?
241 */
242char *leftpad_string(char *incoming, int width)
243{
244 /*@ buffers ***************************************************** */
245 static char output[MAX_STR_LEN];
246
247 /*@ ints ******************************************************** */
248 int i;
249
250 /*@ end vars **************************************************** */
251 assert(incoming != NULL);
252 assert(width > 2);
253
254 strcpy(output, incoming);
255 for (i = (int) strlen(output); i < width; i++) {
256 output[i] = ' ';
257 }
258 output[i] = '\0';
259 return (output);
260}
261
262
263
264/**
265 * Turn a marker byte (e.g. BLK_START_OF_BACKUP) into a string (e.g. "BLK_START_OF_BACKUP").
266 * Unknown markers are identified as "BLK_UNKNOWN (%d)" where %d is the decimal value.
267 * @param marker The marker byte to stringify.
268 * @return @p marker as a string.
269 * @note The returned string points to static storage that will be overwritten with each call.
270 */
271char *marker_to_string(int marker)
272{
273 /*@ buffer ****************************************************** */
274 static char outstr[MAX_STR_LEN];
275
276
277 /*@ end vars *************************************************** */
278
279 switch (marker) {
280 case BLK_START_OF_BACKUP:
281 strcpy(outstr, "BLK_START_OF_BACKUP");
282 break;
283 case BLK_START_OF_TAPE:
284 strcpy(outstr, "BLK_START_OF_TAPE");
285 break;
286 case BLK_START_AN_AFIO_OR_SLICE:
287 strcpy(outstr, "BLK_START_AN_AFIO_OR_SLICE");
288 break;
289 case BLK_STOP_AN_AFIO_OR_SLICE:
290 strcpy(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
291 break;
292 case BLK_START_AFIOBALLS:
293 strcpy(outstr, "BLK_START_AFIOBALLS");
294 break;
295 case BLK_STOP_AFIOBALLS:
296 strcpy(outstr, "BLK_STOP_AFIOBALLS");
297 break;
298 case BLK_STOP_BIGGIEFILES:
299 strcpy(outstr, "BLK_STOP_BIGGIEFILES");
300 break;
301 case BLK_START_A_NORMBIGGIE:
302 strcpy(outstr, "BLK_START_A_NORMBIGGIE");
303 break;
304 case BLK_START_A_PIHBIGGIE:
305 strcpy(outstr, "BLK_START_A_PIHBIGGIE");
306 break;
307 case BLK_START_EXTENDED_ATTRIBUTES:
308 strcpy(outstr, "BLK_START_EXTENDED_ATTRIBUTES");
309 break;
310 case BLK_STOP_EXTENDED_ATTRIBUTES:
311 strcpy(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
312 break;
313 case BLK_START_EXAT_FILE:
314 strcpy(outstr, "BLK_START_EXAT_FILE");
315 break;
316 case BLK_STOP_EXAT_FILE:
317 strcpy(outstr, "BLK_STOP_EXAT_FILE");
318 break;
319 case BLK_START_BIGGIEFILES:
320 strcpy(outstr, "BLK_START_BIGGIEFILES");
321 break;
322 case BLK_STOP_A_BIGGIE:
323 strcpy(outstr, "BLK_STOP_A_BIGGIE");
324 break;
325 case BLK_END_OF_TAPE:
326 strcpy(outstr, "BLK_END_OF_TAPE");
327 break;
328 case BLK_END_OF_BACKUP:
329 strcpy(outstr, "BLK_END_OF_BACKUP");
330 break;
331 case BLK_ABORTED_BACKUP:
332 strcpy(outstr, "BLK_ABORTED_BACKUP");
333 break;
334 case BLK_START_FILE:
335 strcpy(outstr, "BLK_START_FILE");
336 break;
337 case BLK_STOP_FILE:
338 strcpy(outstr, "BLK_STOP_FILE");
339 break;
340 default:
341 sprintf(outstr, "BLK_UNKNOWN (%d)", marker);
342 break;
343 }
344 return (outstr);
345}
346
347
348
349
350/**
351 * Turn a line from the mountlist into a GUI-friendly string.
352 * The format is as follows: the left-aligned @p device field padded to 24 places,
353 * a space, the left-aligned @p mountpoint field again padded to 24 places, a space,
354 * the left-aligned @p format field padded to 10 places, a space, and the right-aligned
355 * @p size field (in MB) padded to 8 places. The total string length is exactly 69.
356 * @param mountlist The mountlist to operate on.
357 * @param lino The line number in @p mountlist to stringify.
358 * @return The string form of <tt>mountlist</tt>-\>el[<tt>lino</tt>].
359 * @note The returned string points to static storage and will be overwritten with each call.
360 */
361char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
362 int lino)
363{
364
365 /*@ buffer *********************************************************** */
366 static char output[MAX_STR_LEN];
367
368 assert(mountlist != NULL);
369
370 sprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
371 mountlist->el[lino].mountpoint, mountlist->el[lino].format,
372 mountlist->el[lino].size / 1024L);
373 return (output);
374}
375
376
377
378
379
380
381/**
382 * Generate a friendly string containing "X blah blah disk(s)"
383 * @param noof_disks The number of disks (the X).
384 * @param label The "blah blah" part in the middle. If you leave this blank
385 * there will be a weird double space in the middle, so pass *something*.
386 * @return The string containing "X blah blah disk(s)".
387 * @note The returned string points to static storage and will be overwritten with each call.
388 */
389char *number_of_disks_as_string(int noof_disks, char *label)
390{
391
392 /*@ buffers ********************************************************* */
393 char *output = NULL;
394
395 /*@ char ******************************************************** */
396 char p;
397
398 assert(label != NULL);
399
400 if (noof_disks > 1) {
401 p = 's';
402 } else {
403 p = ' ';
404 }
405 mr_asprintf(output, "%d %s disk%c", noof_disks, label, p);
406 while (strlen(output) < 14) {
407 mr_strcat(output, " ");
408 }
409 return (output);
410}
411
412
413
414/**
415 * Change @p i into a friendly string. If @p i is \<= 10 then write out the
416 * number (e.g. "one", "two", ..., "nine", "ten", "11", ...).
417 * @param i The number to stringify.
418 * @return The string form of @p i.
419 * @note The returned value points to static strorage that will be overwritten with each call.
420 */
421char *number_to_text(int i)
422{
423
424 /*@ buffers ***************************************************** */
425 static char output[MAX_STR_LEN];
426
427
428 /*@ end vars *************************************************** */
429
430 switch (i) {
431 case 0:
432 strcpy(output, "zero");
433 break;
434 case 1:
435 strcpy(output, "one");
436 break;
437 case 2:
438 strcpy(output, "two");
439 break;
440 case 3:
441 strcpy(output, "three");
442 break;
443 case 4:
444 strcpy(output, "four");
445 break;
446 case 5:
447 strcpy(output, "five");
448 break;
449 case 6:
450 strcpy(output, "six");
451 break;
452 case 7:
453 strcpy(output, "seven");
454 break;
455 case 8:
456 strcpy(output, "eight");
457 break;
458 case 9:
459 strcpy(output, "nine");
460 case 10:
461 strcpy(output, "ten");
462 default:
463 sprintf(output, "%d", i);
464 }
465 return (output);
466}
467
468
469
470
471/**
472 * Replace all occurences of @p token with @p value while copying @p ip to @p output.
473 * @param ip The input string containing zero or more <tt>token</tt>s. The string will be altered by this function
474 * @param output The output string written with the <tt>token</tt>s replaced by @p value.
475 * @param token The token to be relaced with @p value.
476 * @param value The value to replace @p token.
477 */
478char *resolve_naff_tokens(char *ip, char *value, char *token)
479{
480 /*@ buffers *** */
481 char *output = NULL;
482
483 /*@ pointers * */
484 char *p = NULL; /* points to token to modify */
485 char *q = NULL; /* points to start of string/new string */
486
487 assert_string_is_neither_NULL_nor_zerolength(token);
488 assert(value != NULL);
489
490 q = ip;
491 while ((p = strstr(q, token)) != NULL) {
492 *p = '\0';
493 if (output) {
494 mr_strcat(output, "%s%s", q, value);
495 } else {
496 mr_asprintf(output, "%s%s", q, value);
497 }
498 p+= strlen(token);
499 q = p;
500 }
501 if (output) {
502 mr_strcat(output, "%s", q);
503 } else {
504 /* just in case the token doesn't appear in string at all */
505 mr_asprintf(output, "%s", q);
506 }
507 return(output);
508}
509
510
511
512
513
514/**
515 * Generate the filename of slice @p sliceno of biggiefile @p bigfileno
516 * in @p path with suffix @p s. The format is as follows: @p path, followed
517 * by "/slice-" and @p bigfileno zero-padded to 7 places, followed by
518 * a dot and @p sliceno zero-padded to 5 places, followed by ".dat" and the
519 * suffix. The string is a minimum of 24 characters long.
520 * @param bigfileno The biggiefile number. Starts from 0.
521 * @param sliceno The slice number of biggiefile @p bigfileno. 0 is a "header"
522 * slice (no suffix) containing the biggiestruct, then are the compressed
523 * slices, then an empty uncompressed "trailer" slice.
524 * @param path The path to append (with a / in the middle) to the slice filename.
525 * @param s If not "" then add a "." and this to the end.
526 * @return The slice filename.
527 * @note The returned value points to static storage and will be overwritten with each call.
528 */
529char *slice_fname(long bigfileno, long sliceno, char *path, char *s)
530{
531
532 /*@ buffers **************************************************** */
533 static char output[MAX_STR_LEN];
534 char *suffix = NULL;
535
536 /*@ end vars *************************************************** */
537
538 assert_string_is_neither_NULL_nor_zerolength(path);
539 if (s[0] != '\0') {
540 mr_asprintf(suffix, ".%s", s);
541 } else {
542 mr_asprintf(suffix, "");
543 }
544 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, suffix);
545 mr_free(suffix);
546 return (output);
547}
548
549
550/**
551 * Generate a spinning symbol based on integer @p i.
552 * The symbol rotates through the characters / - \ | to form an ASCII "spinner"
553 * if successively written to the same location on screen.
554 * @param i The amount of progress or whatever else to use to determine the character
555 * for this iteration of the spinner.
556 * @return The character for this iteration.
557 */
558int special_dot_char(int i)
559{
560 switch (i % 4) {
561 case 0:
562 return ('/');
563 case 1:
564 return ('-');
565 case 2:
566 return ('\\');
567 case 3:
568 return ('|');
569 default:
570 return ('.');
571 }
572 return ('.');
573}
574
575
576/**
577 * Compare @p stringA and @p stringB. This uses an ASCII sort for everything
578 * up to the digits on the end but a numerical sort for the digits on the end.
579 * @param stringA The first string to compare.
580 * @param stringB The second string to compare.
581 * @return The same as strcmp() - <0 if A<B, 0 if A=B, >0 if A>B.
582 * @note This function only does a numerical sort on the @e last set of numbers. If
583 * there are any in the middle those will be sorted ASCIIbetically.
584 */
585int strcmp_inc_numbers(char *stringA, char *stringB)
586{
587 /*@ int ********************************************************* */
588 int i;
589 int start_of_numbers_in_A;
590 int start_of_numbers_in_B;
591 int res;
592
593 /*@ long ******************************************************* */
594 long numA;
595 long numB;
596
597 /*@ end vars *************************************************** */
598 assert(stringA != NULL);
599 assert(stringB != NULL);
600
601 if (strlen(stringA) == strlen(stringB)) {
602 return (strcmp(stringA, stringB));
603 }
604 for (i = (int) strlen(stringA); i > 0 && isdigit(stringA[i - 1]); i--);
605 if (i == (int) strlen(stringA)) {
606 return (strcmp(stringA, stringB));
607 }
608 start_of_numbers_in_A = i;
609 for (i = (int) strlen(stringB); i > 0 && isdigit(stringB[i - 1]); i--);
610 if (i == (int) strlen(stringB)) {
611 return (strcmp(stringA, stringB));
612 }
613 start_of_numbers_in_B = i;
614 if (start_of_numbers_in_A != start_of_numbers_in_B) {
615 return (strcmp(stringA, stringB));
616 }
617 res = strncmp(stringA, stringB, (size_t) i);
618 if (res) {
619 return (res);
620 }
621 numA = atol(stringA + start_of_numbers_in_A);
622 numB = atol(stringB + start_of_numbers_in_B);
623 return ((int) (numA - numB));
624}
625
626
627
628/**
629 * Strip excess baggage from @p input, which should be a line from afio.
630 * For now this copies the whole line unless it finds a set of quotes, in which case
631 * it copies their contents only.
632 * @param input The input line (presumably from afio).
633 * @return The stripped line.
634 * @note The returned string points to static storage that will be overwritten with each call.
635 */
636char *strip_afio_output_line(char *input)
637{
638 /*@ buffer ****************************************************** */
639 static char output[MAX_STR_LEN];
640
641 /*@ pointers **************************************************** */
642 char *p;
643 char *q;
644 /*@ end vars *************************************************** */
645
646 assert(input != NULL);
647 strcpy(output, input);
648 p = strchr(input, '\"');
649 if (p) {
650 q = strchr(++p, '\"');
651 if (q) {
652 strcpy(output, p);
653 *(strchr(output, '\"')) = '\0';
654 }
655 }
656 return (output);
657}
658
659
660
661/**
662 * Remove all characters whose ASCII value is less than or equal to 32
663 * (spaces and control characters) from both sides of @p in_out.
664 * @param in_out The string to strip spaces/control characters from (modified).
665 */
666void strip_spaces(char *in_out)
667{
668 /*@ buffers ***************************************************** */
669 char *tmp;
670
671 /*@ pointers **************************************************** */
672 char *p;
673
674 /*@ int ******************************************************** */
675 int i;
676 int original_incoming_length;
677
678 /*@ end vars *************************************************** */
679
680 assert(in_out != NULL);
681 malloc_string(tmp);
682 original_incoming_length = (int) strlen(in_out);
683 for (i = 0; in_out[i] <= ' ' && i < (int) strlen(in_out); i++);
684 strcpy(tmp, in_out + i);
685 for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);
686 tmp[i] = '\0';
687 for (i = 0; i < original_incoming_length && MAX_STR_LEN; i++) {
688 in_out[i] = ' ';
689 }
690 in_out[i] = '\0';
691 i = 0;
692 p = tmp;
693 while (*p != '\0') {
694 in_out[i] = *(p++);
695 in_out[i + 1] = '\0';
696 if (in_out[i] < 32 && i > 0) {
697 if (in_out[i] == 8) {
698 i--;
699 } else if (in_out[i] == 9) {
700 in_out[i++] = ' ';
701 } else if (in_out[i] == '\r') // added 1st October 2003 -- FIXME
702 {
703 strcpy(tmp, in_out + i);
704 strcpy(in_out, tmp);
705 i = -1;
706 continue;
707 } else if (in_out[i] == '\t') {
708 for (i++; i % 5; i++);
709 } else if (in_out[i] >= 10 && in_out[i] <= 13) {
710 break;
711 } else {
712 i--;
713 }
714 } else {
715 i++;
716 }
717 }
718 in_out[i] = '\0';
719 paranoid_free(tmp);
720}
721
722
723/**
724 * If there are double quotes "" around @p incoming then remove them.
725 * This does not affect other quotes that may be embedded within the string.
726 * @param incoming The string to trim quotes from (modified).
727 * @return @p incoming.
728 */
729char *trim_empty_quotes(char *incoming)
730{
731 /*@ buffer ****************************************************** */
732 static char outgoing[MAX_STR_LEN];
733
734 /*@ end vars *************************************************** */
735 assert(incoming != NULL);
736
737 if (incoming[0] == '\"' && incoming[strlen(incoming) - 1] == '\"') {
738 strcpy(outgoing, incoming + 1);
739 outgoing[strlen(outgoing) - 1] = '\0';
740 } else {
741 strcpy(outgoing, incoming);
742 }
743 return (outgoing);
744}
745
746
747
748
749/**
750 * Remove any partition info from @p partition, leaving just the drive name.
751 * @param partition The partition name soon-to-become drive name. (modified)
752 * @return @p partition.
753 */
754char *truncate_to_drive_name(char *partition)
755{
756 int i = strlen(partition) - 1;
757 char *c;
758 char *trunc = NULL;
759
760 assert_string_is_neither_NULL_nor_zerolength(partition);
761 mr_asprintf(trunc, "%s", partition);
762
763#ifdef __FreeBSD__
764
765 if (islower(trunc[i])) // BSD subpartition
766 i--;
767 if (trunc[i-1] == 's') {
768 while (isdigit(trunc[i]))
769 i--;
770 i--;
771 }
772 trunc[i+1] = '\0';
773
774#else
775
776 /* first see if it's a devfs style device */
777 c = strrchr(trunc, '/');
778 if (c && strncmp(c, "/part", 5) == 0) {
779 /* yup it's devfs, return the "disc" path */
780 strcpy(c + 1, "disc");
781 return trunc;
782 }
783 /* then see if it's a dm style device */
784 if (c && strncmp(c, "/dm-", 4) == 0) {
785 /* yup it's dm, return the full path */
786 return trunc;
787 }
788
789
790 for (i = strlen(trunc); isdigit(trunc[i-1]); i--)
791 continue;
792 if (trunc[i-1] == 'p' && isdigit(trunc[i-2])) {
793 i--;
794 } else {
795 /* Some full devices like this /dev/mapper/mpath0
796 /dev/cciss/c0d0 may be used as partition names */
797 if ((strstr(trunc,"/dev/mapper/mpath") != NULL) ||
798 (strstr(trunc,"/dev/cciss/c") != NULL) ||
799 (strstr(trunc,"/dev/rd/") != NULL)) {
800 return trunc;
801 }
802 }
803 trunc[i] = '\0';
804
805#endif
806
807 return trunc;
808}
809
810
811
812
813
814/**
815 * Turn a RAID level number (-1 to 5) into a friendly string. The string
816 * is either "Linear RAID" for -1, or " RAID %-2d " (%d = @p raid_level)
817 * for anything else.
818 * @param raid_level The RAID level to stringify.
819 * @return The string form of @p raid_level.
820 * @note The returned value points to static storage that will be overwritten with each call.
821 */
822char *turn_raid_level_number_to_string(int raid_level)
823{
824
825 /*@ buffer ********************************************************** */
826 static char output[MAX_STR_LEN];
827
828
829
830 if (raid_level >= 0) {
831 sprintf(output, " RAID %-2d ", raid_level);
832 } else {
833 sprintf(output, "Linear RAID");
834 }
835 return (output);
836}
837
838
839
840
841
842
843
844
845
846/**
847 * Determine the severity (1-3, 1 being low) of the fact that
848 * @p fn changed in the live filesystem (verify/compare).
849 * @param fn The filename that changed.
850 * @param out_reason If non-NULL, a descriptive reason for the difference will be copied here.
851 * @return The severity (1-3).
852 */
853int severity_of_difference(char *fn, char **out_reason) {
854
855 int sev = 3;
856 char *reason = NULL;
857 char *filename = NULL;
858
859 // out_reason might be null on purpose, so don't bomb if it is :) OK?
860 assert_string_is_neither_NULL_nor_zerolength(fn);
861 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
862 mr_asprintf(filename, "%s", fn + strlen(MNT_RESTORING));
863 } else if (fn[0] != '/') {
864 mr_asprintf(filename, "/%s", fn);
865 } else {
866 mr_asprintf(filename, "%s", fn);
867 }
868
869 mr_asprintf(reason, "Changed since backup. Consider running a differential backup in a day or two.");
870
871 if (!strncmp(filename, "/var/", 5)) {
872 sev = 2;
873 mr_free(reason);
874 mr_asprintf(reason, "/var's contents will change regularly, inevitably.");
875 }
876 if (!strncmp(filename, "/home", 5)) {
877 sev = 2;
878 mr_free(reason);
879 mr_asprintf(reason, "It's in your /home directory. Therefore, it is important.");
880 }
881 if (!strncmp(filename, "/usr/", 5)) {
882 sev = 3;
883 mr_free(reason);
884 mr_asprintf(reason, "You may have installed/removed software during the backup.");
885 }
886 if (!strncmp(filename, "/etc/", 5)) {
887 sev = 3;
888 mr_free(reason);
889 mr_asprintf(reason, "Do not edit config files while backing up your PC.");
890 }
891 if (!strcmp(filename, "/etc/adjtime")
892 || !strcmp(filename, "/etc/mtab")) {
893 sev = 1;
894 mr_free(reason);
895 mr_asprintf(reason, "This file changes all the time. It's OK.");
896 }
897 if (!strncmp(filename, "/root/", 6)) {
898 sev = 3;
899 mr_free(reason);
900 mr_asprintf(reason, "Were you compiling/editing something in /root?");
901 }
902 if (!strncmp(filename, "/root/.", 7)) {
903 sev = 2;
904 mr_free(reason);
905 mr_asprintf(reason, "Temp or 'dot' files changed in /root.");
906 }
907 if (!strncmp(filename, "/var/lib/", 9)) {
908 sev = 2;
909 mr_free(reason);
910 mr_asprintf(reason, "Did you add/remove software during backing?");
911 }
912 if (!strncmp(filename, "/var/lib/rpm", 12)) {
913 sev = 3;
914 mr_free(reason);
915 mr_asprintf(reason, "Did you add/remove software during backing?");
916 }
917 if (!strncmp(filename, "/var/lib/slocate", 16)) {
918 sev = 1;
919 mr_free(reason);
920 mr_asprintf(reason, "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");
921 }
922 if (!strncmp(filename, "/var/log/", 9)
923 || strstr(filename, "/.xsession")
924 || !strcmp(filename + strlen(filename) - 4, ".log")) {
925 sev = 1;
926 mr_free(reason);
927 mr_asprintf(reason, "Log files change frequently as the computer runs. Fret not.");
928 }
929 if (!strncmp(filename, "/var/spool", 10)) {
930 sev = 1;
931 mr_free(reason);
932 mr_asprintf(reason, "Background processes or printers were active. This does not affect the integrity of your backup.");
933 }
934 if (!strncmp(filename, "/var/spool/mail", 10)) {
935 sev = 2;
936 mr_free(reason);
937 mr_asprintf(reason, "Mail was sent/received during backup.");
938 }
939 if (filename[strlen(filename) - 1] == '~') {
940 sev = 1;
941 mr_free(reason);
942 mr_asprintf(reason, "Backup copy of another file which was modified recently.");
943 }
944 if (strstr(filename, "cache")) {
945 sev = 1;
946 mr_free(reason);
947 mr_asprintf(reason, "Part of a cache of data. Caches change from time to time. Don't worry.");
948 }
949 if (!strncmp(filename, "/var/run/", 9)
950 || !strncmp(filename, "/var/lock", 8)
951 || strstr(filename, "/.DCOPserver") || strstr(filename, "/.MCOP")
952 || strstr(filename, "/.Xauthority")) {
953 sev = 1;
954 mr_free(reason);
955 mr_asprintf(reason, "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
956 }
957
958 if (reason != NULL) {
959 *out_reason = reason;
960 }
961 mr_free(filename);
962 return (sev);
963}
964
965
966
967/**
968 * Compare the filenames in two filelist entries (s_filelist_entry*) casted
969 * to void*.
970 * @param va The first filelist entry, cast as a @c void pointer.
971 * @param vb The second filelist entry, cast as a @c void pointer.
972 * @return The return value of strcmp().
973 */
974int compare_two_filelist_entries(void *va, void *vb)
975{
976 static int res;
977 struct s_filelist_entry *fa, *fb;
978
979 assert(va != NULL);
980 assert(vb != NULL);
981 fa = (struct s_filelist_entry *) va;
982 fb = (struct s_filelist_entry *) vb;
983 res = strcmp(fa->filename, fb->filename);
984 return (res);
985}
986
987
988
989
990
991
992
993/**
994 * Generate a line intended to be passed to update_evalcall_form(), indicating
995 * the current media fill percentage (or number of kilobytes if size is not known).
996 * @param bkpinfo The backup media structure. Fields used:
997 * - @c bkpinfo->backup_media_type
998 * - @c bkpinfo->media_size
999 * - @c bkpinfo->scratchdir
1000 * @return The string indicating media fill.
1001 * @note The returned string points to static storage that will be overwritten with each call.
1002 */
1003char *percent_media_full_comment()
1004{
1005 /*@ int *********************************************** */
1006 int percentage;
1007 int j;
1008
1009 /*@ buffers ******************************************* */
1010 char *outstr = NULL;
1011 char *pos_w_commas = NULL;
1012 char *mds = NULL;
1013 char *tmp = NULL;
1014
1015 assert(bkpinfo != NULL);
1016
1017 if (bkpinfo->media_size[g_current_media_number] <= 0) {
1018 mr_asprintf(tmp, "%lld", g_tape_posK);
1019 mr_asprintf(pos_w_commas, "%s", commarize(tmp));
1020 mr_free(tmp);
1021 mr_asprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
1022 mr_free(pos_w_commas);
1023 return (outstr);
1024 }
1025
1026/* update screen */
1027 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1028 percentage =
1029 (int) (g_tape_posK / 10 /
1030 bkpinfo->media_size[g_current_media_number]);
1031 if (percentage > 100) {
1032 percentage = 100;
1033 }
1034 mr_asprintf(outstr, "Volume %d: [", g_current_media_number);
1035 } else {
1036 percentage =
1037 (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 /
1038 bkpinfo->media_size[g_current_media_number]);
1039 mds = media_descriptor_string(bkpinfo->backup_media_type);
1040 mr_asprintf(outstr, "%s %d: [", mds, g_current_media_number);
1041 mr_free(mds);
1042 }
1043 for (j = 0; j < percentage; j += 5) {
1044 mr_strcat(outstr, "*");
1045 }
1046 for (; j < 100; j += 5) {
1047 mr_strcat(outstr, ".");
1048 }
1049 mr_strcat(outstr, "] %d%% used", percentage);
1050 return (outstr);
1051}
1052
1053/**
1054 * Get a string form of @p type_of_bkp.
1055 * @param type_of_bkp The backup type to stringify.
1056 * @return The stringification of @p type_of_bkp.
1057 * @note The returned string points to static storage that will be overwritten with each call.
1058 */
1059char *media_descriptor_string(t_bkptype type_of_bkp) {
1060
1061 char *type_of_backup = NULL;
1062
1063 switch (type_of_bkp) {
1064 case dvd:
1065 mr_asprintf(type_of_backup, "DVD");
1066 break;
1067 case cdr:
1068 mr_asprintf(type_of_backup, "CDR");
1069 break;
1070 case cdrw:
1071 mr_asprintf(type_of_backup, "CDRW");
1072 break;
1073 case tape:
1074 mr_asprintf(type_of_backup, "tape");
1075 break;
1076 case cdstream:
1077 mr_asprintf(type_of_backup, "CDR");
1078 break;
1079 case udev:
1080 mr_asprintf(type_of_backup, "udev");
1081 break;
1082 case iso:
1083 mr_asprintf(type_of_backup, "ISO");
1084 break;
1085 case netfs:
1086 mr_asprintf(type_of_backup, "%s", bkpinfo->netfs_proto);
1087 break;
1088 case usb:
1089 mr_asprintf(type_of_backup, "USB");
1090 break;
1091 default:
1092 mr_asprintf(type_of_backup, "ISO");
1093 }
1094 return (type_of_backup);
1095}
Note: See TracBrowser for help on using the repository browser.