unsigned char* strne2a(unsigned char *dest, const unsigned char *src, size_t n) { int i; n = strnlen(src, n); for (i = 0; i < n; i++) dest[i] = e2a(src[i]); return dest; }
static int proc_viopath_show(struct seq_file *m, void *v) { char *buf; u16 vlanMap; dma_addr_t handle; HvLpEvent_Rc hvrc; DECLARE_MUTEX_LOCKED(Semaphore); buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buf) return 0; memset(buf, 0, PAGE_SIZE); handle = dma_map_single(iSeries_vio_dev, buf, PAGE_SIZE, DMA_FROM_DEVICE); hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, HvLpEvent_Type_VirtualIo, viomajorsubtype_config | vioconfigget, HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck, viopath_sourceinst(viopath_hostLp), viopath_targetinst(viopath_hostLp), (u64)(unsigned long)&Semaphore, VIOVERSION << 16, ((u64)handle) << 32, PAGE_SIZE, 0, 0); if (hvrc != HvLpEvent_Rc_Good) printk(VIOPATH_KERN_WARN "hv error on op %d\n", (int)hvrc); down(&Semaphore); vlanMap = HvLpConfig_getVirtualLanIndexMap(); buf[PAGE_SIZE-1] = '\0'; seq_printf(m, "%s", buf); seq_printf(m, "AVAILABLE_VETH=%x\n", vlanMap); seq_printf(m, "SRLNBR=%c%c%c%c%c%c%c\n", e2a(xItExtVpdPanel.mfgID[2]), e2a(xItExtVpdPanel.mfgID[3]), e2a(xItExtVpdPanel.systemSerial[1]), e2a(xItExtVpdPanel.systemSerial[2]), e2a(xItExtVpdPanel.systemSerial[3]), e2a(xItExtVpdPanel.systemSerial[4]), e2a(xItExtVpdPanel.systemSerial[5])); dma_unmap_single(iSeries_vio_dev, handle, PAGE_SIZE, DMA_FROM_DEVICE); kfree(buf); return 0; }
/** * Read the properties file specified by <tt>filename</tt> * into the array of <tt>properties</tt>, * using the specified port library to allocate memory. * The array is terminated with null-keyed element, * though one can obtain number of elements directly * via last argument. * * @param[in] portLibrary - The port library used to interact with the platform. * @param[in] filename - The file from which to read data using hyfile* functions. * @param[out] properties - An array that will contain property file entries. * @param[out] number - Optional parameter, number of elements in the returned array. * * @return JNI_OK on success, or a JNI error code on failure. */ jint properties_load(HyPortLibrary * portLibrary, const char *filename, key_value_pair** properties, U_32 *number) { PORT_ACCESS_FROM_PORT (portLibrary); void *handle; I_64 seekResult; IDATA fileSize; char *scanCursor, *scanLimit; char *start, *delim, *end; key_value_pair *props; unsigned arraySize; unsigned count = 0; jint status = JNI_OK; /* Determine the file size, fail if > 2G */ seekResult = hyfile_length (filename); if ((seekResult <= 0) || (seekResult > 0x7FFFFFFF)) { return JNI_ERR; } scanCursor = hymmap_map_file(filename, &handle); if (!scanCursor) { return JNI_ERR; } #ifdef ZOS /* Convert the scan buffer into ASCII */ scanCursor = e2a(scanCursor, seekResult); #endif fileSize = (IDATA) seekResult; arraySize = fileSize/50 + 1; props = hymem_allocate_memory(sizeof(key_value_pair)*(arraySize + 1)); if (!props) { status = JNI_ENOMEM; goto finish; } start = end = scanCursor; delim = NULL; scanLimit = scanCursor + fileSize; do { while (scanCursor < scanLimit) { switch(*scanCursor) { case '\r': case '\n': end = scanCursor; goto read_line; case '=': /* remember only first occurrence which is not key itself */ if (delim == NULL && scanCursor > start) { delim = scanCursor; } default: ++scanCursor; continue; } } read_line: if (scanCursor > start && start != delim && *start != '#' && *start != '!') /* line is not empty, well formed and not commented out */ { if (end == start) { /* the last line ends with EOF */ end = scanLimit; } if (count == arraySize) { void* re_props; arraySize += arraySize/2 + 1; re_props = hymem_reallocate_memory(props, sizeof(key_value_pair)*(arraySize + 1)); if (!re_props) { status = JNI_ENOMEM; goto finish; } props = re_props; } if (!prop_alloc(portLibrary, props + count, start, delim, end)) { status = JNI_ENOMEM; goto finish; } ++count; } start = end = ++scanCursor; delim = NULL; } while (scanCursor < scanLimit); /*set terminating NULL*/ props[count].key = NULL; finish: hymmap_unmap_file(handle); if (status != JNI_OK) { properties_free(portLibrary, props); } else { *properties = props; if (number){ *number = count; } } return status; }