static bool ask_for_fileregex(UAContext *ua, RESTORE_CTX *rx) { if (find_arg(ua, NT_("all")) >= 0) { /* if user enters all on command line */ return true; /* select everything */ } ua->send_msg(_("\n\nFor one or more of the JobIds selected, no files were found,\n" "so file selection is not possible.\n" "Most likely your retention policy pruned the files.\n")); if (get_yesno(ua, _("\nDo you want to restore all the files? (yes|no): "))) { if (ua->pint32_val == 1) return true; while (get_cmd(ua, _("\nRegexp matching files to restore? (empty to abort): "))) { if (ua->cmd[0] == '\0') { break; } else { regex_t *fileregex_re = NULL; int rc; char errmsg[500] = ""; fileregex_re = (regex_t *)bmalloc(sizeof(regex_t)); rc = regcomp(fileregex_re, ua->cmd, REG_EXTENDED|REG_NOSUB); if (rc != 0) { regerror(rc, fileregex_re, errmsg, sizeof(errmsg)); } regfree(fileregex_re); free(fileregex_re); if (*errmsg) { ua->send_msg(_("Regex compile error: %s\n"), errmsg); } else { rx->bsr->fileregex = bstrdup(ua->cmd); return true; } } } } return false; }
int main(int argc, char **argv) { stm_display_plane_t *pPlane; stm_display_buffer_t buffer_setup; char *fbuffer; void *fbufferphys; interrupt_t *vsync_interrupt=0; interrupt_t *hdmi_interrupt=0; int err; int seconds; int clip; int rgb; int dvi; stm_plane_id_t planeid; osclock_t lasttime; kernel_initialize(NULL); kernel_start(); kernel_timeslice(OS21_TRUE); framerate_sem = semaphore_create_fifo(0); frameupdate_sem = semaphore_create_fifo(0); hotplug_sem = semaphore_create_fifo(0); task_create(displayupdate_task_fn, 0, OS21_DEF_MIN_STACK_SIZE, MAX_USER_PRIORITY, "displayupdate", 0); pDev = stm_display_get_device(0); if(!pDev) { printf("Unable to create device instance\n"); return 1; } if(argc<2) usage(); argc--; argv++; seconds = 60; rgb = 0; dvi = 0; clip = 0; while(argc>0) { switch(**argv) { case 'C': { printf("Clipping video signal selected\n"); clip = 1; break; } case 'd': { printf("Setting DVI mode on HDMI output\n"); dvi = 1; break; } case 'h': { int refresh; argc--; argv++; if(argc <= 0) { fprintf(stderr,"Missing HD vertical refresh frequency\n"); usage(); } refresh = atoi(*argv); switch(refresh) { case 50: printf("Setting 1280x720-50\n"); MODE = STVTG_TIMING_MODE_720P50000_74250; STANDARD = STM_OUTPUT_STD_SMPTE296M; framerate = 50; break; case 59: printf("Setting 1280x720-59\n"); MODE = STVTG_TIMING_MODE_720P59940_74176; STANDARD = STM_OUTPUT_STD_SMPTE296M; framerate = 60; break; case 60: printf("Setting 1280x720-60\n"); MODE = STVTG_TIMING_MODE_720P60000_74250; STANDARD = STM_OUTPUT_STD_SMPTE296M; framerate = 60; break; default: fprintf(stderr,"Unsupported HD vertical refresh frequency\n"); usage(); } break; } case 'r': { printf("Setting Component RGB Outputs\n"); rgb = 1; break; } case 'p': { int refresh; argc--; argv++; if(argc <= 0) { fprintf(stderr,"Missing 1080p vertical refresh frequency\n"); usage(); } refresh = atoi(*argv); switch(refresh) { case 23: printf("Setting 1920x1080-23\n"); MODE = STVTG_TIMING_MODE_1080P23976_74176; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 24; break; case 24: printf("Setting 1920x1080-24\n"); MODE = STVTG_TIMING_MODE_1080P24000_74250; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 24; break; case 25: printf("Setting 1920x1080-25\n"); MODE = STVTG_TIMING_MODE_1080P25000_74250; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 25; break; case 29: printf("Setting 1920x1080-29\n"); MODE = STVTG_TIMING_MODE_1080P29970_74176; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 30; break; case 30: printf("Setting 1920x1080-30\n"); MODE = STVTG_TIMING_MODE_1080P30000_74250; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 30; break; case 50: printf("Setting 1920x1080-50\n"); MODE = STVTG_TIMING_MODE_1080P50000_148500; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 50; break; case 59: printf("Setting 1920x1080-59\n"); MODE = STVTG_TIMING_MODE_1080P59940_148352; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 60; break; case 60: printf("Setting 1920x1080-60\n"); MODE = STVTG_TIMING_MODE_1080P60000_148500; STANDARD = STM_OUTPUT_STD_SMPTE274M; framerate = 60; break; default: fprintf(stderr,"Unsupported HD vertical refresh frequency\n"); usage(); } break; } case 's': { int refresh; argc--; argv++; if(argc <= 0) { fprintf(stderr,"Missing SD vertical refresh frequency\n"); usage(); } refresh = atoi(*argv); switch(refresh) { case 50: printf("Setting 720x576-50\n"); MODE = STVTG_TIMING_MODE_576P50000_27000; STANDARD = STM_OUTPUT_STD_SMPTE293M; framerate = 50; break; case 59: printf("Setting 720x480-59\n"); MODE = STVTG_TIMING_MODE_480P59940_27000; STANDARD = STM_OUTPUT_STD_SMPTE293M; framerate = 60; break; case 60: printf("Setting 720x480-60\n"); MODE = STVTG_TIMING_MODE_480P60000_27027; STANDARD = STM_OUTPUT_STD_SMPTE293M; framerate = 60; break; default: fprintf(stderr,"Unsupported SD vertical refresh frequency\n"); usage(); } break; } case 't': { argc--; argv++; if(argc <= 0) { fprintf(stderr,"Missing seconds\n"); usage(); } seconds = atoi(*argv); if(seconds<0) usage(); break; } case 'v': { int refresh; argc--; argv++; if(argc <= 0) { fprintf(stderr,"Missing vertical refresh frequency\n"); usage(); } refresh = atoi(*argv); switch(refresh) { case 59: printf("Setting 640x480-59\n"); MODE = STVTG_TIMING_MODE_480P59940_25180; STANDARD = STM_OUTPUT_STD_VESA; framerate = 60; break; case 60: printf("Setting 640x480-60\n"); MODE = STVTG_TIMING_MODE_480P60000_25200; STANDARD = STM_OUTPUT_STD_VESA; framerate = 60; break; default: fprintf(stderr,"Unsupported vertical refresh frequency\n"); usage(); } break; } default: fprintf(stderr,"Unknown option '%s'\n",*argv); usage(); } argc--; argv++; } planeid = OUTPUT_GDP1; vsync_interrupt = get_main_vtg_interrupt(); setup_soc(); if(!vsync_interrupt) { printf("Cannot find VSYNC interrupt handler\n"); return 1; } err = interrupt_install(vsync_interrupt, vsync_isr, pDev); err += interrupt_enable(vsync_interrupt); if(err>0) { printf("Unable to install and enable VSYNC interrupt\n"); return 1; } fbuffer = (char *)malloc(FBSIZE); if(!fbuffer) { printf("Unable to allocate framebuffer\n"); return 1; } memset(fbuffer, 0x00, FBSIZE); create_test_pattern(fbuffer, FBWIDTH, FBHEIGHT, FBSTRIDE); cache_purge_data(fbuffer, FBSIZE); pOutput = stm_display_get_output(pDev, 0); if(!pOutput) { printf("Unable to get output\n"); return 1; } setup_analogue_voltages(pOutput); stm_display_output_set_control(pOutput, STM_CTRL_SIGNAL_RANGE, clip?STM_SIGNAL_VIDEO_RANGE:STM_SIGNAL_FILTER_SAV_EAV); pDVO = get_dvo_output(pDev); { pHDMI = get_hdmi_output(pDev); if(pHDMI) { /* * Now we have a HDMI output pointer to handle hotplug interrupts, * we can enable the interrupt handlers. */ hdmi_interrupt = get_hdmi_interrupt(); if(hdmi_interrupt) { err = interrupt_install(hdmi_interrupt, hdmi_isr, pHDMI); err += interrupt_enable(hdmi_interrupt); } if(err>0) { printf("Unable to install and enable hdmi interrupts\n"); return 1; } stm_display_output_set_control(pHDMI, STM_CTRL_SIGNAL_RANGE, clip?STM_SIGNAL_VIDEO_RANGE:STM_SIGNAL_FILTER_SAV_EAV); } else { printf("Hmmm, no HDMI output available\n"); } } pModeLine = stm_display_output_get_display_mode(pOutput, MODE); if(!pModeLine) { printf("Unable to use requested display mode\n"); return 1; } pPlane = stm_display_get_plane(pDev, planeid); if(!pPlane) { printf("Unable to get graphics plane\n"); return 1; } if(stm_display_plane_connect_to_output(pPlane, pOutput)<0) { printf("Unable to display plane on output\n"); return 1; } if(stm_display_plane_lock(pPlane)<0) { printf("Unable to lock plane's buffer queue\n"); return 1; } memset(&buffer_setup, 0, sizeof(buffer_setup)); vmem_virt_to_phys(fbuffer, &fbufferphys); buffer_setup.src.ulVideoBufferAddr = (ULONG)fbufferphys; buffer_setup.src.ulVideoBufferSize = FBSIZE; buffer_setup.src.ulStride = FBSTRIDE; buffer_setup.src.ulPixelDepth = FBDEPTH; buffer_setup.src.ulColorFmt = FBPIXFMT; buffer_setup.src.Rect.width = FBWIDTH; buffer_setup.src.Rect.height = FBHEIGHT; buffer_setup.dst.Rect.width = FBWIDTH; buffer_setup.dst.Rect.height = FBHEIGHT; buffer_setup.info.ulFlags = STM_PLANE_PRESENTATION_PERSISTENT; printf("Clock is running at %ld ticks per second\n",(long)time_ticks_per_sec()); ULONG format=0; format = rgb?STM_VIDEO_OUT_RGB:STM_VIDEO_OUT_YUV; stm_display_output_set_control(pOutput, STM_CTRL_VIDEO_OUT_SELECT, format); if(pHDMI) { ULONG format = 0; format |= rgb?STM_VIDEO_OUT_RGB:STM_VIDEO_OUT_YUV; format |= dvi?STM_VIDEO_OUT_DVI:STM_VIDEO_OUT_HDMI; stm_display_output_set_control(pHDMI, STM_CTRL_VIDEO_OUT_SELECT, format); } if(stm_display_output_start(pOutput, pModeLine, STANDARD)<0) { printf("Unable to start display\n"); return 1; } if(pDVO) { printf("Info: Attempting to start DVO\n"); if(stm_display_output_start(pDVO, pModeLine, STANDARD)<0) { printf("Info: Unable to start DVO\n"); } } lasttime = time_now(); // VTG Start time (approx) if(stm_display_plane_queue_buffer(pPlane, &buffer_setup)<0) { printf("Unable to queue framebuffer for display on graphics plane\n"); return 1; } task_create(hotplug_task_fn, 0, OS21_DEF_MIN_STACK_SIZE, MIN_USER_PRIORITY, "hotplug", 0); if(seconds == 0) { task_delay(time_ticks_per_sec()*5); task_priority_set(NULL,MIN_USER_PRIORITY); silent_hotplug = 1; err = get_yesno(); } else { while(seconds>0) { osclock_t now,delta; semaphore_wait(framerate_sem); now = time_now(); delta = time_minus(now,lasttime); printf("%d frames took %ld ticks.\n",framerate, (long)delta); lasttime = now; seconds--; } err = 0; } stm_display_plane_flush(pPlane); stm_display_plane_disconnect_from_output(pPlane, pOutput); stm_display_output_stop(pOutput); interrupt_disable(vsync_interrupt); interrupt_disable(hdmi_interrupt); stm_display_plane_release(pPlane); if(pDVO) stm_display_output_release(pDVO); if(pHDMI) stm_display_output_release(pHDMI); stm_display_output_release(pOutput); stm_display_release_device(pDev); return err; }
/* * Update a media record -- allows you to change the * Volume status. E.g. if you want Bacula to stop * writing on the volume, set it to anything other * than Append. */ static int update_volume(UAContext *ua) { MEDIA_DBR mr; POOL *pool; POOL_DBR pr; POOLMEM *query; POOL_MEM ret; char buf[1000]; char ed1[130]; bool done = false; int i; const char *kw[] = { NT_("VolStatus"), /* 0 */ NT_("VolRetention"), /* 1 */ NT_("VolUse"), /* 2 */ NT_("MaxVolJobs"), /* 3 */ NT_("MaxVolFiles"), /* 4 */ NT_("MaxVolBytes"), /* 5 */ NT_("Recycle"), /* 6 */ NT_("InChanger"), /* 7 */ NT_("Slot"), /* 8 */ NT_("Pool"), /* 9 */ NT_("FromPool"), /* 10 */ NT_("AllFromPool"), /* 11 !!! see below !!! */ NT_("Enabled"), /* 12 */ NT_("RecyclePool"), /* 13 */ NT_("ActionOnPurge"), /* 14 */ NULL }; #define AllFromPool 11 /* keep this updated with above */ for (i=0; kw[i]; i++) { int j; POOL_DBR pr; if ((j=find_arg_with_value(ua, kw[i])) > 0) { /* If all from pool don't select a media record */ if (i != AllFromPool && !select_media_dbr(ua, &mr)) { return 0; } switch (i) { case 0: update_volstatus(ua, ua->argv[j], &mr); break; case 1: update_volretention(ua, ua->argv[j], &mr); break; case 2: update_voluseduration(ua, ua->argv[j], &mr); break; case 3: update_volmaxjobs(ua, ua->argv[j], &mr); break; case 4: update_volmaxfiles(ua, ua->argv[j], &mr); break; case 5: update_volmaxbytes(ua, ua->argv[j], &mr); break; case 6: update_volrecycle(ua, ua->argv[j], &mr); break; case 7: update_volinchanger(ua, ua->argv[j], &mr); break; case 8: update_volslot(ua, ua->argv[j], &mr); break; case 9: memset(&pr, 0, sizeof(POOL_DBR)); pr.PoolId = mr.PoolId; if (!db_get_pool_record(ua->jcr, ua->db, &pr)) { ua->error_msg("%s", db_strerror(ua->db)); break; } update_vol_pool(ua, ua->argv[j], &mr, &pr); break; case 10: update_vol_from_pool(ua, &mr); return 1; case 11: update_all_vols_from_pool(ua, ua->argv[j]); return 1; case 12: update_volenabled(ua, ua->argv[j], &mr); break; case 13: update_vol_recyclepool(ua, ua->argv[j], &mr); break; case 14: update_vol_actiononpurge(ua, ua->argv[j], &mr); break; } done = true; } } /* Allow user to simply update all volumes */ if (find_arg(ua, NT_("fromallpools")) > 0) { update_all_vols(ua); return 1; } for ( ; !done; ) { start_prompt(ua, _("Parameters to modify:\n")); add_prompt(ua, _("Volume Status")); /* 0 */ add_prompt(ua, _("Volume Retention Period")); /* 1 */ add_prompt(ua, _("Volume Use Duration")); /* 2 */ add_prompt(ua, _("Maximum Volume Jobs")); /* 3 */ add_prompt(ua, _("Maximum Volume Files")); /* 4 */ add_prompt(ua, _("Maximum Volume Bytes")); /* 5 */ add_prompt(ua, _("Recycle Flag")); /* 6 */ add_prompt(ua, _("Slot")); /* 7 */ add_prompt(ua, _("InChanger Flag")); /* 8 */ add_prompt(ua, _("Volume Files")); /* 9 */ add_prompt(ua, _("Pool")); /* 10 */ add_prompt(ua, _("Volume from Pool")); /* 11 */ add_prompt(ua, _("All Volumes from Pool")); /* 12 */ add_prompt(ua, _("All Volumes from all Pools")); /* 13 */ add_prompt(ua, _("Enabled")), /* 14 */ add_prompt(ua, _("RecyclePool")), /* 15 */ add_prompt(ua, _("Action On Purge")), /* 16 */ add_prompt(ua, _("Done")); /* 17 */ i = do_prompt(ua, "", _("Select parameter to modify"), NULL, 0); /* For All Volumes, All Volumes from Pool, and Done, we don't need * a Volume record */ if ( i != 12 && i != 13 && i != 17) { if (!select_media_dbr(ua, &mr)) { /* Get Volume record */ return 0; } ua->info_msg(_("Updating Volume \"%s\"\n"), mr.VolumeName); } switch (i) { case 0: /* Volume Status */ /* Modify Volume Status */ ua->info_msg(_("Current Volume status is: %s\n"), mr.VolStatus); start_prompt(ua, _("Possible Values are:\n")); add_prompt(ua, NT_("Append")); add_prompt(ua, NT_("Archive")); add_prompt(ua, NT_("Disabled")); add_prompt(ua, NT_("Full")); add_prompt(ua, NT_("Used")); add_prompt(ua, NT_("Cleaning")); if (strcmp(mr.VolStatus, NT_("Purged")) == 0) { add_prompt(ua, NT_("Recycle")); } add_prompt(ua, NT_("Read-Only")); if (do_prompt(ua, "", _("Choose new Volume Status"), ua->cmd, sizeof(mr.VolStatus)) < 0) { return 1; } update_volstatus(ua, ua->cmd, &mr); break; case 1: /* Retention */ ua->info_msg(_("Current retention period is: %s\n"), edit_utime(mr.VolRetention, ed1, sizeof(ed1))); if (!get_cmd(ua, _("Enter Volume Retention period: "))) { return 0; } update_volretention(ua, ua->cmd, &mr); break; case 2: /* Use Duration */ ua->info_msg(_("Current use duration is: %s\n"), edit_utime(mr.VolUseDuration, ed1, sizeof(ed1))); if (!get_cmd(ua, _("Enter Volume Use Duration: "))) { return 0; } update_voluseduration(ua, ua->cmd, &mr); break; case 3: /* Max Jobs */ ua->info_msg(_("Current max jobs is: %u\n"), mr.MaxVolJobs); if (!get_pint(ua, _("Enter new Maximum Jobs: "))) { return 0; } update_volmaxjobs(ua, ua->cmd, &mr); break; case 4: /* Max Files */ ua->info_msg(_("Current max files is: %u\n"), mr.MaxVolFiles); if (!get_pint(ua, _("Enter new Maximum Files: "))) { return 0; } update_volmaxfiles(ua, ua->cmd, &mr); break; case 5: /* Max Bytes */ ua->info_msg(_("Current value is: %s\n"), edit_uint64(mr.MaxVolBytes, ed1)); if (!get_cmd(ua, _("Enter new Maximum Bytes: "))) { return 0; } update_volmaxbytes(ua, ua->cmd, &mr); break; case 6: /* Recycle */ ua->info_msg(_("Current recycle flag is: %s\n"), mr.Recycle==1?_("yes"):_("no")); if (!get_yesno(ua, _("Enter new Recycle status: "))) { return 0; } update_volrecycle(ua, ua->cmd, &mr); break; case 7: /* Slot */ ua->info_msg(_("Current Slot is: %d\n"), mr.Slot); if (!get_pint(ua, _("Enter new Slot: "))) { return 0; } update_volslot(ua, ua->cmd, &mr); break; case 8: /* InChanger */ ua->info_msg(_("Current InChanger flag is: %d\n"), mr.InChanger); bsnprintf(buf, sizeof(buf), _("Set InChanger flag for Volume \"%s\": yes/no: "), mr.VolumeName); if (!get_yesno(ua, buf)) { return 0; } mr.InChanger = ua->pint32_val; /* * Make sure to use db_update... rather than doing this directly, * so that any Slot is handled correctly. */ if (!db_update_media_record(ua->jcr, ua->db, &mr)) { ua->error_msg(_("Error updating media record Slot: ERR=%s"), db_strerror(ua->db)); } else { ua->info_msg(_("New InChanger flag is: %d\n"), mr.InChanger); } break; case 9: /* Volume Files */ int32_t VolFiles; ua->warning_msg(_("Warning changing Volume Files can result\n" "in loss of data on your Volume\n\n")); ua->info_msg(_("Current Volume Files is: %u\n"), mr.VolFiles); if (!get_pint(ua, _("Enter new number of Files for Volume: "))) { return 0; } VolFiles = ua->pint32_val; if (VolFiles != (int)(mr.VolFiles + 1)) { ua->warning_msg(_("Normally, you should only increase Volume Files by one!\n")); if (!get_yesno(ua, _("Increase Volume Files? (yes/no): ")) || ua->pint32_val == 0) { break; } } query = get_pool_memory(PM_MESSAGE); Mmsg(query, "UPDATE Media SET VolFiles=%u WHERE MediaId=%s", VolFiles, edit_int64(mr.MediaId, ed1)); if (!db_sql_query(ua->db, query, NULL, NULL)) { ua->error_msg("%s", db_strerror(ua->db)); } else { ua->info_msg(_("New Volume Files is: %u\n"), VolFiles); } free_pool_memory(query); break; case 10: /* Volume's Pool */ memset(&pr, 0, sizeof(POOL_DBR)); pr.PoolId = mr.PoolId; if (!db_get_pool_record(ua->jcr, ua->db, &pr)) { ua->error_msg("%s", db_strerror(ua->db)); return 0; } ua->info_msg(_("Current Pool is: %s\n"), pr.Name); if (!get_cmd(ua, _("Enter new Pool name: "))) { return 0; } update_vol_pool(ua, ua->cmd, &mr, &pr); return 1; case 11: update_vol_from_pool(ua, &mr); return 1; case 12: pool = select_pool_resource(ua); if (pool) { update_all_vols_from_pool(ua, pool->name()); } return 1; case 13: update_all_vols(ua); return 1; case 14: ua->info_msg(_("Current Enabled is: %d\n"), mr.Enabled); if (!get_cmd(ua, _("Enter new Enabled: "))) { return 0; } if (strcasecmp(ua->cmd, "yes") == 0 || strcasecmp(ua->cmd, "true") == 0) { mr.Enabled = 1; } else if (strcasecmp(ua->cmd, "no") == 0 || strcasecmp(ua->cmd, "false") == 0) { mr.Enabled = 0; } else if (strcasecmp(ua->cmd, "archived") == 0) { mr.Enabled = 2; } else { mr.Enabled = atoi(ua->cmd); } update_volenabled(ua, ua->cmd, &mr); break; case 15: memset(&pr, 0, sizeof(POOL_DBR)); pr.PoolId = mr.RecyclePoolId; if (db_get_pool_record(ua->jcr, ua->db, &pr)) { ua->info_msg(_("Current RecyclePool is: %s\n"), pr.Name); } else { ua->info_msg(_("No current RecyclePool\n")); } if (!select_pool_dbr(ua, &pr, NT_("recyclepool"))) { return 0; } update_vol_recyclepool(ua, pr.Name, &mr); return 1; case 16: pm_strcpy(ret, ""); ua->info_msg(_("Current ActionOnPurge is: %s\n"), action_on_purge_to_string(mr.ActionOnPurge, ret)); if (!get_cmd(ua, _("Enter new ActionOnPurge (one of: Truncate, None): "))) { return 0; } update_vol_actiononpurge(ua, ua->cmd, &mr); break; default: /* Done or error */ ua->info_msg(_("Selection terminated.\n")); return 1; } } return 1; }
/* * Request SD to send us the slot:barcodes, then wiffle * through them all labeling them. */ static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt) { STORERES *store = ua->jcr->res.wstore; POOL_DBR pr; MEDIA_DBR mr, omr; vol_list_t *vl; dlist *vol_list = NULL; bool media_record_exists; char *slot_list; int max_slots; max_slots = get_num_slots_from_SD(ua); if (max_slots <= 0) { ua->warning_msg(_("No slots in changer to scan.\n")); return; } slot_list = (char *)malloc(nbytes_for_bits(max_slots)); clear_all_bits(max_slots, slot_list); if (!get_user_slot_list(ua, slot_list, "slots", max_slots)) { goto bail_out; } vol_list = get_vol_list_from_SD(ua, store, false /* no listall */ , false /*no scan*/); if (!vol_list) { ua->warning_msg(_("No Volumes found to label, or no barcodes.\n")); goto bail_out; } /* * Display list of Volumes and ask if he really wants to proceed */ ua->send_msg(_("The following Volumes will be labeled:\n" "Slot Volume\n" "==============\n")); foreach_dlist(vl, vol_list) { if (!vl->VolName || !bit_is_set(vl->Slot - 1, slot_list)) { continue; } ua->send_msg("%4d %s\n", vl->Slot, vl->VolName); } if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) || (ua->pint32_val == 0)) { goto bail_out; } /* * Select a pool */ memset(&pr, 0, sizeof(pr)); if (!select_pool_dbr(ua, &pr)) { goto bail_out; } /* * Fire off the label requests */ foreach_dlist(vl, vol_list) { if (!vl->VolName || !bit_is_set(vl->Slot - 1, slot_list)) { continue; } mr.clear(); bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName)); media_record_exists = false; if (db_get_media_record(ua->jcr, ua->db, &mr)) { if (mr.VolBytes != 0) { ua->warning_msg(_("Media record for Slot %d Volume \"%s\" already exists.\n"), vl->Slot, mr.VolumeName); mr.Slot = vl->Slot; mr.InChanger = mr.Slot > 0; /* if slot give assume in changer */ set_storageid_in_mr(store, &mr); if (!db_update_media_record(ua->jcr, ua->db, &mr)) { ua->error_msg(_("Error setting InChanger: ERR=%s"), db_strerror(ua->db)); } continue; } media_record_exists = true; } mr.InChanger = mr.Slot > 0; /* if slot give assume in changer */ set_storageid_in_mr(store, &mr); /* * Deal with creating cleaning tape here. Normal tapes created in send_label_request() below */ if (is_cleaning_tape(ua, &mr, &pr)) { if (media_record_exists) { /* we update it */ mr.VolBytes = 1; /* any bytes to indicate it exists */ bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus)); mr.MediaType[0] = 0; set_storageid_in_mr(store, &mr); if (!db_update_media_record(ua->jcr, ua->db, &mr)) { ua->error_msg("%s", db_strerror(ua->db)); } } else { /* create the media record */ if (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) { ua->error_msg(_("Maximum pool Volumes=%d reached.\n"), pr.MaxVols); goto bail_out; } set_pool_dbr_defaults_in_media_dbr(&mr, &pr); bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus)); mr.MediaType[0] = 0; set_storageid_in_mr(store, &mr); if (db_create_media_record(ua->jcr, ua->db, &mr)) { ua->send_msg(_("Catalog record for cleaning tape \"%s\" successfully created.\n"), mr.VolumeName); pr.NumVols++; /* this is a bit suspect */ if (!db_update_pool_record(ua->jcr, ua->db, &pr)) { ua->error_msg("%s", db_strerror(ua->db)); } } else { ua->error_msg(_("Catalog error on cleaning tape: %s"), db_strerror(ua->db)); } } continue; /* done, go handle next volume */ } bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType)); /* * See if we need to generate a new passphrase for hardware encryption. */ if (label_encrypt) { if (!generate_new_encryption_key(ua, &mr)) { continue; } } mr.Slot = vl->Slot; send_label_request(ua, &mr, &omr, &pr, false, media_record_exists, drive); } bail_out: free(slot_list); if (vol_list) { free_vol_list(vol_list); } close_sd_bsock(ua); return; }
/* * The main configuration routine. Its implementation is hugely inspired by the * the same routine implementation in Solaris NSCD. */ int parse_config_file(struct configuration *config, const char *fname, char const **error_str, int *error_line) { FILE *fin; char buffer[255]; char *fields[128]; int field_count, line_num, value; int res; TRACE_IN(parse_config_file); assert(config != NULL); assert(fname != NULL); fin = fopen(fname, "r"); if (fin == NULL) { TRACE_OUT(parse_config_file); return (-1); } res = 0; line_num = 0; memset(buffer, 0, sizeof(buffer)); while ((res == 0) && (fgets(buffer, sizeof(buffer) - 1, fin) != NULL)) { field_count = strbreak(buffer, fields, sizeof(fields)); ++line_num; if (field_count == 0) continue; switch (fields[0][0]) { case '#': case '\0': continue; case 'e': if ((field_count == 3) && (strcmp(fields[0], "enable-cache") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_yesno(fields[2])) != -1)) { enable_cache(config, fields[1], value); continue; } break; case 'd': if ((field_count == 2) && (strcmp(fields[0], "debug-level") == 0) && ((value = get_number(fields[1], 0, 10)) != -1)) { continue; } break; case 'p': if ((field_count == 3) && (strcmp(fields[0], "positive-time-to-live") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { set_positive_time_to_live(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "positive-confidence-threshold") == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { set_positive_confidence_threshold(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "positive-policy") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_policy(fields[2])) != -1)) { set_positive_policy(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "perform-actual-lookups") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_yesno(fields[2])) != -1)) { set_perform_actual_lookups(config, fields[1], value); continue; } break; case 'n': if ((field_count == 3) && (strcmp(fields[0], "negative-time-to-live") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { set_negative_time_to_live(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "negative-confidence-threshold") == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { set_negative_confidence_threshold(config, fields[1], value); continue; } else if ((field_count == 3) && (strcmp(fields[0], "negative-policy") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_policy(fields[2])) != -1)) { set_negative_policy(config, fields[1], value); continue; } break; case 's': if ((field_count == 3) && (strcmp(fields[0], "suggested-size") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 1, -1)) != -1)) { set_suggested_size(config, fields[1], value); continue; } break; case 't': if ((field_count == 2) && (strcmp(fields[0], "threads") == 0) && ((value = get_number(fields[1], 1, -1)) != -1)) { set_threads_num(config, value); continue; } break; case 'k': if ((field_count == 3) && (strcmp(fields[0], "keep-hot-count") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_number(fields[2], 0, -1)) != -1)) { set_keep_hot_count(config, fields[1], value); continue; } break; case 'c': if ((field_count == 3) && (strcmp(fields[0], "check-files") == 0) && (check_cachename(fields[1]) == 0) && ((value = get_yesno(fields[2])) != -1)) { check_files(config, fields[1], value); continue; } break; default: break; } LOG_ERR_2("config file parser", "error in file " "%s on line %d", fname, line_num); *error_str = "syntax error"; *error_line = line_num; res = -1; } fclose(fin); TRACE_OUT(parse_config_file); return (res); }
int exec_menu(MENU menu) { int i=0, cidx=0, fine; int off, ecnt=1; char tmp[MAXLEN]; char output[MAXLEN]; MENU tmenu = menu; int ret; int cpid; fine=1; while(cidx < tmenu.ncmd && fine) { off=1; switch(tmenu.cmd[cidx][0]) { case '-': if(*(tmenu.cmd[cidx] + off)=='!') off++; parsecmd(tmenu.cmd[cidx] +off, tmp); cpid = fork(); if(cpid) { waitpid(cpid,&ret,0); if(ret!=-1 && WIFEXITED(ret)) ret = WEXITSTATUS(ret); } else { close(comport); ret=system(tmp); if(ret!=-1 && WIFEXITED(ret)) ret = WEXITSTATUS(ret); exit(ret); } if(off==1) ret=1; break; case '+': if(*(tmenu.cmd[cidx] + off)=='!') off++; parsecmd(tmenu.cmd[cidx] +off, tmp); ret=execute(tmp, output, MAXLEN); sprintf(tmp, "$%d", ecnt++); setvar(tmp, output); if(off==1) ret=1; break; case '<': argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN); substvar(args[0], MAXARGS, MAXARGLEN); /*for(i=0; i<argcnt; i++) printf("%d: --%s--\n",i,args[i]);*/ if(strcmp(args[0],"YesNo")==0 && argcnt==2) { ret=get_yesno(args[1]); sprintf(output,"%d",ret-1); setvar("$YesNo",output); } if(strcmp(args[0],"OnOff")==0 && argcnt==3) { ret=get_onoff(args[1], atoi(args[2])); sprintf(output,"%d",ret-1); setvar("$OnOff",output); } if(strcmp(args[0],"Percent")==0 && argcnt==4) { ret=get_percent(args[1], atoi(args[2]), atoi(args[3])); sprintf(output,"%d",ret-1); setvar("$Percent",output); } if(strcmp(args[0],"Choice")==0 && argcnt>=4) { init_choice(); for(i=3; i<argcnt; i++) addchoice(args[i]); ret=get_choice(args[1], atoi(args[2])); sprintf(output,"%d",ret); setvar("$Choice",output); } if(strcmp(args[0],"Real")==0 && (argcnt==4 || argcnt==5)) { if(argcnt==4) strcpy(args[4],""); ret=get_real(output, args[1], args[2], args[3], args[4]); setvar("$Real",output); } if(strcmp(args[0],"Int")==0 && (argcnt==5 || argcnt==6)) { if(argcnt==5) strcpy(args[5],"0"); ret=get_integer(output, args[1], args[2], atoi(args[3]), atoi(args[4]), atoi(args[5])); setvar("$Int",output); } if(strcmp(args[0],"Phone")==0 && (argcnt==3 || argcnt==4)) { if(argcnt==3) strcpy(args[3],""); ret=get_phone(output, args[1], args[2], args[3]); setvar("$Phone",output); } if(strcmp(args[0],"Date")==0 && argcnt==2) { ret=get_date(output, args[1]); setvar("$Date",output); } if(strcmp(args[0],"Text")==0 && (argcnt==4 || argcnt==5)) { if(argcnt==4) strcpy(args[4],""); ret=get_text(output, args[1], args[2], atoi(args[3]), args[4]); setvar("$Text",output); } if(strcmp(args[0],"Secret")==0 && argcnt==4) { ret=get_secret(output, args[1], args[2], atoi(args[3])); setvar("$Secret",output); } break; case '>': argcnt = split(tmenu.cmd[cidx]+1, args[0], MAXARGS, MAXARGLEN); substvar(args[0], MAXARGS, MAXARGLEN); /*for(i=0; i<argcnt; i++) printf("%d: --%s--\n",i,args[i]);*/ if(strcmp(args[0],"MsgBox")==0 && (argcnt==2 || argcnt==3)) { if(argcnt==2) strcpy(args[2],""); ret=msgbox(args[1], atoi(args[2])); } if(strcmp(args[0],"Info")==0 && argcnt>=3) ret=info(args[1], args[2]); if(strcmp(args[0],"Status")==0 && argcnt>=2) ret=status(args[1]); break; case ':': for(i=0; i<fncnt; i++) if(strcmp(tmenu.cmd[cidx]+1,flist[i].name)==0) ret = flist[i].fn(); break; } if(ret<=0) fine=0; cidx++; } return 0; }
/* * Prune Directory meta data records from the database. */ static bool prune_directory(UAContext *ua, CLIENTRES *client) { int i, len; CLIENT_DBR cr; char *prune_topdir = NULL; POOL_MEM query(PM_MESSAGE), temp(PM_MESSAGE); bool recursive = false; bool retval = false; /* * See if a client was selected. */ if (!client) { if (!get_yesno(ua, _("No client restriction given really remove " "directory for all clients (yes/no): ")) || ua->pint32_val == 0) { if (!(client = get_client_resource(ua))) { return false; } } } /* * See if we need to recursively remove all directories under a certain path. */ recursive = find_arg(ua, NT_("recursive")) >= 0; /* * Get the directory to prune. */ i = find_arg_with_value(ua, NT_("directory")); if (i >= 0) { pm_strcpy(temp, ua->argv[i]); } else { if (recursive) { if (!get_cmd(ua, _("Please enter the full path prefix to remove: "), false)) { return false; } } else { if (!get_cmd(ua, _("Please enter the full path to remove: "), false)) { return false; } } pm_strcpy(temp, ua->cmd); } /* * See if the directory ends in a / and escape it for usage in a database query. */ len = strlen(temp.c_str()); if (*(temp.c_str() + len - 1) != '/') { pm_strcat(temp, "/"); len++; } prune_topdir = (char *)malloc(len * 2 + 1); db_escape_string(ua->jcr, ua->db, prune_topdir, temp.c_str(), len); /* * Remove all files in particular directory. */ if (recursive) { Mmsg(query, "DELETE FROM file WHERE pathid IN (" "SELECT pathid FROM path " "WHERE path LIKE '%s%%'" ")", prune_topdir); } else { Mmsg(query, "DELETE FROM file WHERE pathid IN (" "SELECT pathid FROM path " "WHERE path LIKE '%s'" ")", prune_topdir); } if (client) { char ed1[50]; memset(&cr, 0, sizeof(cr)); bstrncpy(cr.Name, client->name(), sizeof(cr.Name)); if (!db_create_client_record(ua->jcr, ua->db, &cr)) { goto bail_out; } Mmsg(temp, " AND JobId IN (" "SELECT JobId FROM Job " "WHERE ClientId=%s" ")", edit_int64(cr.ClientId, ed1)); pm_strcat(query, temp.c_str()); } db_lock(ua->db); db_sql_query(ua->db, query.c_str()); db_unlock(ua->db); /* * If we removed the entries from the file table without limiting it to a * certain client we created orphaned path entries as no one is referencing * them anymore. */ if (!client) { if (!get_yesno(ua, _("Cleanup orphaned path records (yes/no):")) || ua->pint32_val == 0) { retval = true; goto bail_out; } if (recursive) { Mmsg(query, "DELETE FROM path " "WHERE path LIKE '%s%%'", prune_topdir); } else { Mmsg(query, "DELETE FROM path " "WHERE path LIKE '%s'", prune_topdir); } db_lock(ua->db); db_sql_query(ua->db, query.c_str()); db_unlock(ua->db); } retval = true; bail_out: if (prune_topdir) { free(prune_topdir); } return retval; }