bool grit_validate_paths(GritRec *gr) { char str[MAXPATHLEN]; // Only validate destination if there's going to be export. if(gr->bExport) { // Must have either src or dst paths if( isempty(gr->srcPath) && isempty(gr->dstPath) ) { lprintf(LOG_ERROR, " No input or output paths. Validation failed.\n"); return false; } if(gr->srcPath == NULL) { strrepl(&gr->srcPath, ""); lprintf(LOG_WARNING, " No explicit src path.\n"); } else path_fix_sep(gr->srcPath); // No dst path? Get from source if(isempty(gr->dstPath)) { strrepl(&gr->dstPath, path_get_name(gr->srcPath)); lprintf(LOG_WARNING, " No explicit dst path. Borrowing from src path.\n"); } // Fix extension path_repl_ext(str, gr->dstPath, c_fileTypes[gr->fileType], MAXPATHLEN); strrepl(&gr->dstPath, str); path_fix_sep(gr->dstPath); // If no symbol name: // - append mode : from src // - create mode : from dst if(isempty(gr->symName)) { if(gr->bAppend) { path_get_title(str, gr->srcPath, MAXPATHLEN); strrepl(&gr->symName, str); lprintf(LOG_WARNING, " No explicit symbol name. In append mode, so using src title.\n"); } else { path_get_title(str, gr->dstPath, MAXPATHLEN); strrepl(&gr->symName, str); lprintf(LOG_WARNING, " No explicit symbol name. In overwrite mode, so using dst title.\n"); } } str_fix_ident(gr->symName, gr->symName, MAXPATHLEN); } return true; }
char * dm_get_name(dm_descriptor_t desc, int *errp) { descriptor_t *dp; char *nm = NULL; char *name = NULL; dp = (descriptor_t *)(uintptr_t)desc; cache_rlock(); if (!cache_is_valid_desc(dp)) { cache_unlock(); *errp = EBADF; return (NULL); } /* verify that the descriptor is still valid */ if (dp->p.generic == NULL) { cache_unlock(); *errp = ENODEV; return (NULL); } switch (dp->type) { case DM_DRIVE: nm = (drive_get_name(dp)); break; case DM_BUS: nm = (bus_get_name(dp)); break; case DM_CONTROLLER: nm = (controller_get_name(dp)); break; case DM_MEDIA: nm = (media_get_name(dp)); break; case DM_SLICE: nm = (slice_get_name(dp)); break; case DM_PARTITION: nm = (partition_get_name(dp)); break; case DM_PATH: nm = (path_get_name(dp)); break; case DM_ALIAS: nm = (alias_get_name(dp)); break; } cache_unlock(); *errp = 0; if (nm != NULL) { name = strdup(nm); if (name == NULL) { *errp = ENOMEM; return (NULL); } return (name); } return (NULL); }