/* Update the free space on the device */ bool DEVICE::update_freespace() { POOL_MEM ocmd(PM_FNAME); POOLMEM* results; char* icmd; int timeout; uint64_t free; char ed1[50]; bool ok = false; int status; if (!is_dvd() || is_freespace_ok()) { return true; } /* The device must be mounted in order to dvd-freespace to work */ mount(1); Dsm_check(400); icmd = device->free_space_command; if (!icmd) { free_space = 0; free_space_errno = 0; clear_freespace_ok(); /* No valid freespace */ clear_media(); Dmsg2(29, "ERROR: update_free_space_dev: free_space=%s, free_space_errno=%d (!icmd)\n", edit_uint64(free_space, ed1), free_space_errno); Mmsg(errmsg, _("No FreeSpace command defined.\n")); return false; } edit_mount_codes(ocmd, icmd); Dmsg1(29, "update_freespace: cmd=%s\n", ocmd.c_str()); results = get_pool_memory(PM_MESSAGE); /* Try at most 3 times to get the free space on the device. This should perhaps be configurable. */ timeout = 3; while (1) { berrno be; Dmsg1(20, "Run freespace prog=%s\n", ocmd.c_str()); status = run_program_full_output(ocmd.c_str(), max_open_wait/2, results); Dmsg2(500, "Freespace status=%d result=%s\n", status, results); if (status == 0) { free = str_to_int64(results); Dmsg1(400, "Free space program run: Freespace=%s\n", results); if (free >= 0) { free_space = free; free_space_errno = 0; set_freespace_ok(); /* have valid freespace */ set_media(); Mmsg(errmsg, ""); ok = true; break; } } free_space = 0; free_space_errno = EPIPE; clear_freespace_ok(); /* no valid freespace */ Mmsg2(errmsg, _("Cannot run free space command. Results=%s ERR=%s\n"), results, be.bstrerror(status)); if (--timeout > 0) { Dmsg4(40, "Cannot get free space on device %s. free_space=%s, " "free_space_errno=%d ERR=%s\n", print_name(), edit_uint64(free_space, ed1), free_space_errno, errmsg); bmicrosleep(1, 0); continue; } dev_errno = free_space_errno; Dmsg4(40, "Cannot get free space on device %s. free_space=%s, " "free_space_errno=%d ERR=%s\n", print_name(), edit_uint64(free_space, ed1), free_space_errno, errmsg); break; } free_pool_memory(results); Dmsg4(29, "leave update_freespace: free_space=%s freespace_ok=%d free_space_errno=%d have_media=%d\n", edit_uint64(free_space, ed1), !!is_freespace_ok(), free_space_errno, !!have_media()); Dsm_check(400); return ok; }
/* Update the free space on the device */ bool DEVICE::update_freespace() { POOL_MEM ocmd(PM_FNAME); POOLMEM* results; char* icmd; char* p; uint64_t free, total; char ed1[50]; bool ok = false; int status; berrno be; if (!is_file()) { Mmsg(errmsg, ""); return true; } /* The device must be mounted in order for freespace to work */ if (requires_mount()) { mount(1); } if (get_os_device_freespace()) { Dmsg4(20, "get_os_device_freespace: free_space=%s freespace_ok=%d free_space_errno=%d have_media=%d\n", edit_uint64(free_space, ed1), !!is_freespace_ok(), free_space_errno, !!have_media()); return true; } icmd = device->free_space_command; if (!icmd) { set_freespace(0, 0, 0, false); Dmsg2(20, "ERROR: update_free_space_dev: free_space=%s, free_space_errno=%d (!icmd)\n", edit_uint64(free_space, ed1), free_space_errno); Mmsg(errmsg, _("No FreeSpace command defined.\n")); return false; } edit_mount_codes(ocmd, icmd); Dmsg1(20, "update_freespace: cmd=%s\n", ocmd.c_str()); results = get_pool_memory(PM_MESSAGE); Dmsg1(20, "Run freespace prog=%s\n", ocmd.c_str()); status = run_program_full_output(ocmd.c_str(), max_open_wait/2, results); Dmsg2(20, "Freespace status=%d result=%s\n", status, results); /* Should report "1223232 12323232\n" "free total\n" */ if (status == 0) { free = str_to_int64(results) * 1024; p = results; if (skip_nonspaces(&p)) { total = str_to_int64(p) * 1024; } else { total = 0; } Dmsg1(400, "Free space program run: Freespace=%s\n", results); if (free >= 0) { set_freespace(free, total, 0, true); /* have valid freespace */ Mmsg(errmsg, ""); ok = true; } } else { set_freespace(0, 0, EPIPE, false); /* no valid freespace */ Mmsg2(errmsg, _("Cannot run free space command. Results=%s ERR=%s\n"), results, be.bstrerror(status)); dev_errno = free_space_errno; Dmsg4(20, "Cannot get free space on device %s. free_space=%s, " "free_space_errno=%d ERR=%s\n", print_name(), edit_uint64(free_space, ed1), free_space_errno, errmsg); } free_pool_memory(results); Dmsg4(20, "leave update_freespace: free_space=%s freespace_ok=%d free_space_errno=%d have_media=%d\n", edit_uint64(free_space, ed1), !!is_freespace_ok(), free_space_errno, !!have_media()); return ok; }