Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/minmax.h>
0003 #include <linux/string.h>
0004 #include <asm/ebcdic.h>
0005 #include <asm/ipl.h>
0006 
0007 /* VM IPL PARM routines */
0008 size_t ipl_block_get_ascii_vmparm(char *dest, size_t size,
0009                   const struct ipl_parameter_block *ipb)
0010 {
0011     int i;
0012     size_t len;
0013     char has_lowercase = 0;
0014 
0015     len = 0;
0016     if ((ipb->ccw.vm_flags & IPL_PB0_CCW_VM_FLAG_VP) &&
0017         (ipb->ccw.vm_parm_len > 0)) {
0018 
0019         len = min_t(size_t, size - 1, ipb->ccw.vm_parm_len);
0020         memcpy(dest, ipb->ccw.vm_parm, len);
0021         /* If at least one character is lowercase, we assume mixed
0022          * case; otherwise we convert everything to lowercase.
0023          */
0024         for (i = 0; i < len; i++)
0025             if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
0026                 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
0027                 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
0028                 has_lowercase = 1;
0029                 break;
0030             }
0031         if (!has_lowercase)
0032             EBC_TOLOWER(dest, len);
0033         EBCASC(dest, len);
0034     }
0035     dest[len] = 0;
0036 
0037     return len;
0038 }