/** * extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus); * * flag: * 0 : bus -> valid * 1 : bus -> NULL */ int test_sysfs_get_bus_devices(int flag) { struct sysfs_bus *bus = NULL; struct dlist *list = NULL; char *bus_name = NULL; switch (flag) { case 0: bus_name = val_bus_name; bus = sysfs_open_bus(bus_name); if (bus == NULL) { dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); return 0; } break; case 1: bus = NULL; break; default: return -1; } list = sysfs_get_bus_devices(bus); switch (flag) { case 0: if (list == NULL) { if (errno == 0) dbg_print("%s: No devices registered with bus %s\n", __FUNCTION__, bus_name); else dbg_print("%s: FAILED with flag = %d errno = %d\n", __FUNCTION__, flag, errno); } else { dbg_print("%s: SUCCEEDED with flag = %d\n\n", __FUNCTION__, flag); show_device_list(list); dbg_print("\n"); } break; case 1: if (list != NULL) dbg_print("%s: FAILED with flag = %d errno = %d\n", __FUNCTION__, flag, errno); else dbg_print("%s: SUCCEEDED with flag = %d\n", __FUNCTION__, flag); break; default: return 0; } if (bus != NULL) sysfs_close_bus(bus); return 0; }
search_array_t *search_device() { int total_size, capacity = 0; list_t head, *list, *node; search_array_t *array; mb_query_t *query_handle; mb_cu_notify_t notify_handle; memset(&head, 0, sizeof(list_t)); notify_handle.user_arg = (void*)&head; notify_handle.callback = search_notify; #ifdef _DEBUG_ printf("====================== start search device ======================\n"); #endif query_handle = mb_query(J_MB_Nmp_Search_Id, ¬ify_handle); sleep(MAX_SEARCH_TIMEOUT); #ifdef _DEBUG_ printf("====================== stop search device ======================\n"); #endif mb_release(query_handle); for (list=&head; list->next; list=list->next) capacity++; printf("capacity: %d<!!!!!!!!!!!!!!!!!!!!!!!!!!\n", capacity); if (capacity) { total_size = sizeof(search_array_t) + capacity*sizeof(search_result_t); array = (search_array_t*)malloc(total_size); array->count = 0; array->capacity = capacity; for (list=head.next; node=list; list=list->next) { memcpy(&array->result[array->count++], node->data, sizeof(search_result_t)); free(node->data); free(node); } } #ifdef _DEBUG_ show_device_list(array); #endif return array; }
int main(int argc, char **argv) { int ret, i, cmd_args_len; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct ltfs_fuse_data *priv = (struct ltfs_fuse_data *) calloc(1, sizeof(struct ltfs_fuse_data)); char *lang, **mount_options, **snmp_options, *cmd_args; void *message_handle; /* Suppress warning on Windows builds. */ #ifdef HP_mingw_BUILD (void) lang; (void) mount_options; #endif /* HP_mingw_BUILD */ priv->verbose = LTFS_INFO; priv->allow_other = (geteuid() == 0) ? 1 : 0; priv->pid_orig = getpid(); #ifndef HP_mingw_BUILD /* Check for LANG variable and set it to en_US.UTF-8 if it is unset. */ lang = getenv("LANG"); if (! lang) { fprintf(stderr, "LTFS9015W Setting the locale to 'en_US.UTF-8'. If this is wrong, please set the LANG environment variable before starting ltfs.\n"); ret = setenv("LANG", "en_US.UTF-8", 1); if (ret) { fprintf(stderr, "LTFS9016E Cannot set the LANG environment variable\n"); return 1; } } #endif /* HP_mingw_BUILD */ /* Start up libltfs with the default logging level. User overrides are * processed later, after command line parsing. */ openlog("ltfs", LOG_PID, LOG_USER); ret = ltfs_init(LTFS_INFO, true, true); if (ret < 0) { /* Failed to initialize libltfs */ ltfsmsg(LTFS_ERR, "10000E", ret); } /* Register messages with libltfs */ ret = ltfsprintf_load_plugin("bin_ltfs", bin_ltfs_dat, &message_handle); if (ret < 0) { ltfsmsg(LTFS_ERR, "10012E", ret); return 1; } if (! priv) { ltfsmsg(LTFS_ERR, "10001E", "main: private data"); return 1; } /* Parse command line options to pick up the configuration file */ priv->first_parsing_pass = true; ret = fuse_opt_parse(&args, priv, ltfs_options_pass1, ltfs_parse_options); if (ret < 0) { ltfsmsg(LTFS_ERR, "9001E"); return 1; } /* Load the configuration file */ ret = config_file_load(priv->config_file, &priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, "10008E", ret); return 1; } /* We don't use this in HP-SOS. The code is present but it will always endup indicating that * snmp is disabled. */ /* Get snmp option value from configuration file */ snmp_options = config_file_get_options("snmp", priv->config); if (snmp_options) { priv->snmp_enabled = false; for (i=0; snmp_options[i]; ++i) { if (! strcmp(snmp_options[i], "enabled")) priv->snmp_enabled = true; else if (! strncmp(snmp_options[i], "deffile ", 8)) { ret = asprintf(&priv->snmp_deffile, "%s", snmp_options[i]+8); if (ret < 0) { ltfsmsg(LTFS_ERR, "10001E", "library_main: snmp_deffile"); priv->snmp_enabled = false; break; } } } if (priv->snmp_enabled) { #if 0 ltfs_snmp_init(priv->snmp_deffile); #endif /* 0 */ } } /* Not supported on Windows. TODO: Verify this again.*/ #ifndef HP_mingw_BUILD /* Bring in extra mount options set in the config file */ mount_options = config_file_get_options("single-drive", priv->config); if (! mount_options) return 1; for (i=0; mount_options[i]; ++i) { ret = fuse_opt_insert_arg(&args, i+1, mount_options[i]); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", mount_options[i], ret); return 1; } free(mount_options[i]); } free(mount_options); #endif /* HP_mingw_BUILD */ /* Parse command line options again, this time for real */ priv->first_parsing_pass = false; ret = fuse_opt_parse(&args, priv, ltfs_options, ltfs_parse_options); if (ret < 0) { ltfsmsg(LTFS_ERR, "9001E"); return 1; } /* Set the logging level */ if (priv->verbose > 100) ltfs_set_syslog_level(priv->verbose / 100); ltfs_set_log_level(priv->verbose % 100); /* LTFS starting */ #ifdef GENERIC_OEM_BUILD ltfsmsg(LTFS_INFO, "14000I", SOFTWARE_PRODUCT_NAME, PACKAGE_VERSION, priv->verbose); #else ltfsmsg(LTFS_INFO, "14000I", LTFS_VENDOR_NAME SOFTWARE_PRODUCT_NAME, PACKAGE_VERSION, priv->verbose); #endif /* GENERIC_OEM_BUILD */ ltfsmsg(LTFS_INFO, "14058I", "LTFS Format Specification", LTFS_INDEX_VERSION_STR); /* Show command line arguments */ for (i = 0, cmd_args_len = 0 ; i < argc; i++) { cmd_args_len += strlen(argv[i]) + 1; } cmd_args = calloc(1, cmd_args_len + 1); if (!cmd_args) { /* Memory allocation failed */ ltfsmsg(LTFS_ERR, "10001E", "ltfs (arguments)"); return -ENOMEM; } strcat(cmd_args, argv[0]); for (i = 1; i < argc; i++) { strcat(cmd_args, " "); strcat(cmd_args, argv[i]); } ltfsmsg(LTFS_INFO, "14104I", cmd_args); free(cmd_args); /* Show build time information */ ltfsmsg(LTFS_INFO, "14105I", BUILD_SYS_FOR); ltfsmsg(LTFS_INFO, "14106I", BUILD_SYS_GCC); /* Show run time information */ show_runtime_system_info(); /* Show avaliable tape device list */ if (priv->device_list) { ret = show_device_list(priv); ltfs_finish(); return (ret != 0) ? 0 : 1; } /* Validate sync option */ ret = validate_sync_option(priv); if (ret != 0) return 1; /* Error message was already displayed */ /* Print the active sync mode */ switch(priv->sync_type) { case LTFS_SYNC_TIME: ltfsmsg(LTFS_INFO, "14063I", "time", priv->sync_time); break; case LTFS_SYNC_CLOSE: ltfsmsg(LTFS_INFO, "14064I", "close"); break; case LTFS_SYNC_UNMOUNT: ltfsmsg(LTFS_INFO, "14064I", "unmount"); break; default: ltfsmsg(LTFS_ERR, "14065E", priv->sync_type); return 1; } /* Enable correct permissions checking in the kernel if any permission overrides are set */ ret = fuse_opt_add_arg(&args, "-odefault_permissions"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "default_permissions", ret); return 1; } /* Let all users access this filesystem by default */ if (priv->allow_other) { ret = fuse_opt_add_arg(&args, "-oallow_other"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "allow_other", ret); return 1; } } /* Unlink objects from the file system instead of having them renamed to .fuse_hidden */ ret = fuse_opt_add_arg(&args, "-ohard_remove"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "hard_remove", ret); return 1; } /* perform reads synchronously */ ret = fuse_opt_add_arg(&args, "-osync_read"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "sync_read", ret); return 1; } #ifdef __APPLE__ /* Change MacFUSE timeout from 60 secs to 3100 secs (41mins) */ /* 3100 secs comes from the timeout value of locate/space, it is the most longest timeout value */ /* in the commands used by LTFS. Actually the timeout value of locate/space is 2500 secs, */ /* we set the MacFUSE as the timeout value of locate/space + 10 mins. Because MacFUSE timeout */ /* should come after the drive command timeout. */ fuse_opt_add_arg(&args, "-odaemon_timeout=3100"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "daemon_timeout", ret); return 1; } /* * Disable vnode cache to return correct owner. * LTFS will return the owner as accessed user, vnode cache will return previous user * when the cache is hot. */ fuse_opt_add_arg(&args, "-onovncache"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "novncache", ret); return 1; } #endif #if FUSE_VERSION >= 28 /* For FUSE 2.8 or higher, automatically enable big_writes */ ret = fuse_opt_add_arg(&args, "-obig_writes"); if (ret < 0) { /* Could not enable FUSE option */ ltfsmsg(LTFS_ERR, "14001E", "big_writes", ret); return 1; } #endif /* Set up permissions based on mount options and current user information */ ret = permissions_setup(priv); if (ret < 0) { /* Failed to set up permissions */ ltfsmsg(LTFS_ERR, "14002E", ret); usage(argv[0], priv); return 1; } /* Bring in some configuration defaults if needed */ if (priv->tape_backend_name == NULL) { priv->tape_backend_name = config_file_get_default_plugin("driver", priv->config); if (priv->tape_backend_name == NULL) { /* No driver plugin configured and no default found */ ltfsmsg(LTFS_ERR, "14056E"); return 1; } } if (priv->iosched_backend_name == NULL) priv->iosched_backend_name = config_file_get_default_plugin("iosched", priv->config); if (priv->iosched_backend_name && strcmp(priv->iosched_backend_name, "none") == 0) priv->iosched_backend_name = NULL; if (priv->kmi_backend_name == NULL) priv->kmi_backend_name = config_file_get_default_plugin("kmi", priv->config); if (priv->kmi_backend_name && strcmp(priv->kmi_backend_name, "none") == 0) priv->kmi_backend_name = NULL; if (priv->work_directory == NULL || ! strcmp(priv->work_directory, "")) priv->work_directory = LTFS_DEFAULT_WORK_DIR; if (priv->force_min_pool) { priv->min_pool_size = parse_size_t(priv->force_min_pool); if (priv->min_pool_size == 0) { ltfsmsg(LTFS_ERR, "14109E"); return 1; } } else priv->min_pool_size = LTFS_MIN_CACHE_SIZE_DEFAULT; if (priv->force_max_pool) { priv->max_pool_size = parse_size_t(priv->force_max_pool); if (priv->max_pool_size == 0) { ltfsmsg(LTFS_ERR, "14110E"); return 1; } } else priv->max_pool_size = LTFS_MAX_CACHE_SIZE_DEFAULT; if (priv->min_pool_size > priv->max_pool_size) { /* Min pool size cannot be greater than max pool size */ ltfsmsg(LTFS_ERR, "14003E", priv->min_pool_size, priv->max_pool_size); return 1; } /* * Make sure at least one parameter was provided (mount point). * If exactly one param, check if it's an accessible directory. * With more than one param, have to defer to fuse_main to find if valid. */ #ifndef HP_mingw_BUILD struct stat mpstatbuf; #endif /* HP_mingw_BUILD */ if (argc < 2) { ltfsmsg(LTFS_ERR, "14200E"); /* missing mountpoint parameter */ usage (argv[0], priv); return 1; } /* OSR * * In our MinGW environment, the mount point does not exist when * the file system is executed */ #ifndef HP_mingw_BUILD if (argc == 2) { ret = stat(argv[1], &mpstatbuf); if (ret < 0) { /* Path does not exist */ ltfsmsg(LTFS_ERR, "14201E", argv[1]); return 1; } else if (! S_ISDIR(mpstatbuf.st_mode)) { /* Path exists but is not a directory */ ltfsmsg(LTFS_ERR, "14201E", argv[1]); return 1; } } #endif /* HP_mingw_BUILD */ /* Make sure work directory exists */ ret = create_workdir(priv); if (ret < 0) { if (priv->work_directory) { free((void *)priv->work_directory); priv->work_directory = NULL; priv->work_directory = LTFS_DEFAULT_WORK_DIR; } } /* Load plugins */ ret = plugin_load(&priv->driver_plugin, "driver", priv->tape_backend_name, priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, "14054E", ret); return 1; } if (priv->iosched_backend_name) { ret = plugin_load(&priv->iosched_plugin, "iosched", priv->iosched_backend_name, priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, "14055E", ret); return 1; } } if (priv->kmi_backend_name) { ret = plugin_load(&priv->kmi_plugin, "kmi", priv->kmi_backend_name, priv->config); if (ret < 0) { ltfsmsg(LTFS_ERR, "14057E", ret); return 1; } } /* Make sure we have a device name */ if (! priv->devname) { priv->devname = ltfs_default_device_name(priv->driver_plugin.ops); if (! priv->devname) { /* The backend \'%s\' does not have a default device */ ltfsmsg(LTFS_ERR, "14009E", priv->tape_backend_name); return 1; } } /* Initialize filesystem component in libltfs */ ret = ltfs_fs_init(); if (ret) return 1; /* Invoke the single drive main operations */ ret = ltfs_mutex_init(&priv->file_table_lock); if (ret) { /* Cannot initialize open file table */ ltfsmsg(LTFS_ERR, "14114E"); return 1; } ret = single_drive_main(&args, priv); /* Send a trap of LTFS termination */ #if 0 if (priv->snmp_enabled) ltfs_snmp_finish(); #endif /* 0 */ /* Unload plugins */ if (priv->iosched_backend_name) plugin_unload(&priv->iosched_plugin); if (priv->kmi_backend_name) plugin_unload(&priv->kmi_plugin); plugin_unload(&priv->driver_plugin); /* Free data structures */ ltfsprintf_unload_plugin(message_handle); ltfs_finish(); config_file_free(priv->config); free(priv); fuse_opt_free_args(&args); return ret; }