Changeset 1156 in MondoRescue
- Timestamp:
- Feb 13, 2007, 2:04:40 AM (18 years ago)
- Location:
- branches/stable/mondo/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-devices-EXT.h
r1127 r1156 33 33 extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo 34 34 *, bool); 35 36 37 extern void make_fifo(char *store_name_here, char *stub);38 39 40 35 extern void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, 41 36 int cd_number_i_want); … … 47 42 extern int eject_device(char *); 48 43 49 extern char *list_of_NFS_devices_and_mounts();50 44 extern char *list_of_NFS_mounts_only(void); 51 45 -
branches/stable/mondo/src/common/libmondo-devices.c
r1130 r1156 93 93 log_it("rctada: Unmounting all CD drives", __LINE__); 94 94 run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5); 95 } 96 97 98 /** 99 * Mount the CD-ROM at @p mountpoint. 100 * @param device The device (or file if g_ISO_restore_mode) to mount. 101 * @param mountpoint The place to mount it. 102 * @return 0 for success, nonzero for failure. 103 */ 104 int mount_CDROM_here(char *device, char *mountpoint) 105 { 106 /*@ buffer ****************************************************** */ 107 char *command = NULL; 108 char *dev; 109 int retval = 0; 110 111 malloc_string(dev); 112 assert_string_is_neither_NULL_nor_zerolength(device); 113 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 114 115 make_hole_for_dir(mountpoint); 116 if (isdigit(device[0])) { 117 find_cdrom_device(device, FALSE); 118 } else { 119 strcpy(dev, device); 120 } 121 if (g_ISO_restore_mode) { 122 123 #ifdef __FreeBSD__ 124 strcpy(dev, make_vn(device)); 125 if (!dev) { 126 sprintf(command, "Unable to mount ISO (make_vn(%s) failed)", 127 device); 128 fatal_error(command); 129 } 130 strcpy(device, dev); 131 #endif 132 } 133 134 mr_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 135 mountpoint); 136 /*@ end vars *************************************************** */ 137 138 #ifdef __FreeBSD__ 139 mr_asprintf(&command, "mount_cd9660 -r %s %s 2>> %s", 140 device, mountpoint, MONDO_LOGFILE); 141 #else 142 mr_asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s", 143 device, mountpoint, MONDO_LOGFILE); 144 #endif 145 146 mr_msg(4, command); 147 if (strncmp(device, "/dev/", 5) == 0) { 148 retract_CD_tray_and_defeat_autorun(); 149 } 150 retval = system(command); 151 mr_msg(1, "system(%s) returned %d", command, retval); 152 mr_free(command); 153 154 mr_free(dev); 155 return (retval); 95 156 } 96 157 … … 1249 1310 1250 1311 /** 1251 * Mount the CD-ROM at @p mountpoint.1252 * @param device The device (or file if g_ISO_restore_mode) to mount.1253 * @param mountpoint The place to mount it.1254 * @return 0 for success, nonzero for failure.1255 */1256 int mount_CDROM_here(char *device, char *mountpoint)1257 {1258 /*@ buffer ****************************************************** */1259 char *command;1260 char *dev;1261 char *options;1262 int retval;1263 1264 malloc_string(command);1265 malloc_string(dev);1266 malloc_string(options);1267 assert_string_is_neither_NULL_nor_zerolength(device);1268 assert_string_is_neither_NULL_nor_zerolength(mountpoint);1269 1270 make_hole_for_dir(mountpoint);1271 strcpy(options, "ro");1272 if (isdigit(device[0])) {1273 find_cdrom_device(device, FALSE);1274 } else {1275 strcpy(dev, device);1276 }1277 if (g_ISO_restore_mode) {1278 1279 #ifdef __FreeBSD__1280 strcpy(dev, make_vn(device));1281 if (!dev) {1282 sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",1283 device);1284 fatal_error(command);1285 }1286 strcpy(device, dev);1287 #else1288 strcat(options, ",loop");1289 #endif1290 1291 }1292 mr_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,1293 mountpoint);1294 /*@ end vars *************************************************** */1295 1296 #ifdef __FreeBSD__1297 sprintf(command, "mount_cd9660 -r %s %s 2>> %s",1298 device, mountpoint, MONDO_LOGFILE);1299 1300 #else1301 sprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s",1302 device, options, mountpoint, MONDO_LOGFILE);1303 #endif1304 1305 mr_msg(4, command);1306 if (strncmp(device, "/dev/", 5) == 0) {1307 retract_CD_tray_and_defeat_autorun();1308 }1309 retval = system(command);1310 mr_msg(1, "system(%s) returned %d", command, retval);1311 1312 mr_free(command);1313 mr_free(dev);1314 mr_free(options);1315 return (retval);1316 }1317 1318 1319 /**1320 1312 * Ask the user for CD number @p cd_number_i_want. 1321 1313 * Sets g_current_media_number once the correct CD is inserted. … … 2025 2017 2026 2018 /** 2027 * @addtogroup utilityGroup2028 * @{2029 */2030 /**2031 * Get a space-separated list of NFS devices and mounts.2032 * @return The list created.2033 * @note The return value points to static data that will be overwritten with each call.2034 */2035 char *list_of_NFS_devices_and_mounts(void)2036 {2037 char *exclude_these_devices;2038 char *exclude_these_directories;2039 static char result_sz[512];2040 2041 malloc_string(exclude_these_devices);2042 malloc_string(exclude_these_directories);2043 strcpy(exclude_these_directories,2044 call_program_and_get_last_line_of_output2045 ("mount -t coda,ncpfs,nfs,smbfs,cifs,afs,mvfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));2046 strcpy(exclude_these_devices,2047 call_program_and_get_last_line_of_output2048 ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs|mvfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));2049 sprintf(result_sz, "%s %s", exclude_these_directories,2050 exclude_these_devices);2051 mr_free(exclude_these_devices);2052 mr_free(exclude_these_directories);2053 return (result_sz);2054 }2055 2056 2057 /**2058 2019 * Get a space-separated list of NFS mounts. 2059 2020 * @return The list created. … … 2084 2045 2085 2046 /** 2086 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where2087 * [random] is a random number between 1 and 32767.2088 * @param store_name_here Where to store the new filename.2089 * @param stub A random number will be appended to this to make the FIFO's name.2090 * @ingroup deviceGroup2091 */2092 void make_fifo(char *store_name_here, char *stub)2093 {2094 char *tmp;2095 2096 malloc_string(tmp);2097 assert_string_is_neither_NULL_nor_zerolength(stub);2098 2099 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),2100 (int) (random() % 32768));2101 make_hole_for_file(store_name_here);2102 mkfifo(store_name_here, S_IRWXU | S_IRWXG);2103 sprintf(tmp, "chmod 770 %s", store_name_here);2104 paranoid_system(tmp);2105 mr_free(tmp);2106 }2107 2108 2109 /**2110 2047 * Set the tmpdir and scratchdir to reside on the partition with the most free space. 2111 2048 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems. … … 2115 2052 void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo) 2116 2053 { 2117 char *tmp, *command, *sz; 2118 2119 malloc_string(tmp); 2054 char *tmp = NULL; 2055 char *command = NULL; 2056 char *sz = NULL; 2057 int i = 0; 2058 2120 2059 malloc_string(command); 2121 malloc_string(sz);2122 2060 assert(bkpinfo != NULL); 2123 2061 2124 2062 #ifdef __FreeBSD__ 2125 strcpy(tmp,2063 mr_asprintf(&tmp, 2126 2064 call_program_and_get_last_line_of_output 2127 2065 ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs,afs,mvfs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2128 2066 #else 2129 strcpy(tmp,2067 mr_asprintf(&tmp, 2130 2068 call_program_and_get_last_line_of_output 2131 2069 ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs -x afs -x mvfs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); … … 2133 2071 2134 2072 if (tmp[0] != '/') { 2135 strcpy(sz, tmp);2136 strcpy(tmp, "/");2137 strcat(tmp, sz);2073 mr_asprintf(&sz, "/%s", tmp); 2074 mr_free(tmp); 2075 tmp = sz; 2138 2076 } 2139 2077 if (!tmp[0]) { 2140 2078 fatal_error("I couldn't figure out the tempdir!"); 2141 2079 } 2142 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,2143 (int) (random() % 32768));2080 i = (int) (random() % 32768); 2081 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, i); 2144 2082 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2145 2083 2146 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, 2147 (int) (random() % 32768)); 2084 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i); 2148 2085 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2149 2086 … … 2151 2088 bkpinfo->scratchdir); 2152 2089 2153 sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2090 mr_asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2091 mr_free(tmp); 2092 2154 2093 paranoid_system(command); 2155 mr_free(tmp);2156 2094 mr_free(command); 2157 mr_free(sz);2158 2095 } 2159 2096 … … 2172 2109 bool set_dev_to_this_if_rx_OK(char *output, char *dev) 2173 2110 { 2174 char *command; 2175 2176 malloc_string(command); 2111 char *command = NULL; 2112 2177 2113 if (!dev || dev[0] == '\0') { 2178 2114 output[0] = '\0'; 2179 2115 return (FALSE); 2180 2116 } 2181 // assert_string_is_neither_NULL_nor_zerolength(dev);2182 2117 mr_msg(10, "Injecting %s", dev); 2183 2118 inject_device(dev); … … 2186 2121 return (FALSE); 2187 2122 } 2188 sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",2123 mr_asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 2189 2124 512L, dev); 2190 2125 if (!run_program_and_log_output(command, FALSE) … … 2192 2127 strcpy(output, dev); 2193 2128 mr_msg(4, "Found it - %s", dev); 2129 mr_free(command); 2194 2130 return (TRUE); 2195 2131 } else { 2196 2132 output[0] = '\0'; 2197 2133 mr_msg(4, "It's not %s", dev); 2134 mr_free(command); 2198 2135 return (FALSE); 2199 2136 } … … 2211 2148 { 2212 2149 int cd_number = -1; 2213 char *mountdev; 2214 char *tmp; 2215 2216 malloc_string(mountdev); 2217 malloc_string(tmp); 2150 char *mountdev = NULL; 2151 char *tmp = NULL; 2152 char *tmp1 = NULL; 2153 2218 2154 assert(bkpinfo != NULL); 2219 // log_it("Asking what_number_cd_is_this");2220 2155 if (g_ISO_restore_mode) { 2221 sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2222 // log_it("tmp = %s", tmp); 2223 2224 strcpy(mountdev, call_program_and_get_last_line_of_output(tmp)); 2225 strcat(mountdev, "/archives/THIS-CD-NUMBER"); 2226 // log_it("mountdev = %s", mountdev); 2156 mr_asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2157 2158 mr_asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp)); 2227 2159 cd_number = atoi(last_line_of_file(mountdev)); 2228 // log_it("cd_number = %d", cd_number);2229 2160 mr_free(mountdev); 2230 2161 mr_free(tmp); … … 2232 2163 } 2233 2164 2234 strcpy(mountdev, bkpinfo->media_device);2165 mr_asprintf(&mountdev, bkpinfo->media_device); 2235 2166 if (!mountdev[0]) { 2236 2167 log_it … … 2243 2174 cd_number = 2244 2175 atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 2245 // log_it("cd_number..later.. = %d", cd_number);2246 2176 mr_free(mountdev); 2247 mr_free(tmp);2248 2177 return (cd_number); 2249 2178 } … … 2499 2428 char *command = NULL; 2500 2429 char *fdisk = NULL; 2501 #ifdef __IA64__ 2502 struct stat buf; 2503 #endif 2504 malloc_string(tmp); 2430 2505 2431 mr_msg(0, "Looking for partition table format type"); 2506 2432 mr_asprintf(&fdisk, "/sbin/parted2fdisk"); … … 2509 2435 mr_free(fdisk); 2510 2436 2511 strcpy(tmp, call_program_and_get_last_line_of_output(command));2437 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2512 2438 mr_free(command); 2513 2439 … … 2517 2443 strcpy(output, "GPT"); 2518 2444 } 2445 mr_free(tmp); 2519 2446 mr_msg(0, "Found %s partition table format type", output); 2520 mr_free(tmp);2521 2447 return(output); 2522 2448 } -
branches/stable/mondo/src/common/libmondo-devices.h
r1101 r1156 31 31 bool); 32 32 33 34 35 void make_fifo(char *store_name_here, char *stub);36 37 33 void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, 38 34 int cd_number_i_want); … … 42 38 int eject_device(char *); 43 39 44 char *list_of_NFS_devices_and_mounts(void);45 40 char *list_of_NFS_mounts_only(void); 46 41 -
branches/stable/mondo/src/lib/mr_mem.c
r1152 r1156 103 103 mr_exit(-1, "Unable to affect a NULL variable"); 104 104 } 105 if ( mr_setenv(name, value, 1) != 0) {105 if (setenv(name, value, 1) != 0) { 106 106 mr_msg_int(1,line,file,"Unable to put %s in environment", name); 107 107 mr_exit(-1,"Unable to put in environment"); -
branches/stable/mondo/src/mondoarchive/mondo-cli.c
r1149 r1156 587 587 if (flag_set['N']) // exclude NFS mounts & devices 588 588 { 589 // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);590 589 strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN); 591 590 if (bkpinfo->exclude_paths[0]) {
Note:
See TracChangeset
for help on using the changeset viewer.