Improved partion manager prints.
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 10 Sep 2008 16:09:29 +0000 (16:09 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 10 Sep 2008 16:09:29 +0000 (16:09 +0000)
signed off by: Slava Strebkov [slavas@voltaire.com]

git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1587 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

tools/part_man/user/part_man.c

index db3a5d1..cf39779 100644 (file)
@@ -35,7 +35,7 @@ static const char IBBUS_SERV_KEY[] = {"SYSTEM\\CurrentControlSet\\Services\\ibbu
 \r
 void show_help()\r
 {\r
-       printf("Usage : part_man.exe <show|add|rem> <port_guid> <pkey1, pkey2, ...>\n");\r
+       printf("Usage : part_man.exe <show|add|rem> <port_guid> <pkey1 pkey2 ...>\n");\r
 }\r
 \r
 /********************************************************************\r
@@ -50,7 +50,8 @@ static int reg_ibbus_pkey_show(IN BOOLEAN show,OUT char *partKey, OUT HKEY *reg_
        LONG   ret;\r
        int retval;\r
        DWORD  read_length = DEFAULT_BUFER_SIZE;\r
-\r
+       const char *sep_group = ";";\r
+       const char *sep_guid_pkey = ":,";\r
        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,IBBUS_SERV_KEY,0,KEY_SET_VALUE | KEY_QUERY_VALUE ,reg_handle);\r
        if (ERROR_SUCCESS != ret)\r
        {\r
@@ -75,7 +76,57 @@ static int reg_ibbus_pkey_show(IN BOOLEAN show,OUT char *partKey, OUT HKEY *reg_
                if(retval > 4)\r
                {\r
                        if(show)\r
-                               printf("Existing Pkey(s): %s\n",partKey);\r
+                       {\r
+                               char *pkey_group, *pkey_group_next, *pkey_guid, tmp;\r
+                               int i,j,k;\r
+                               unsigned short *guid_vstat;\r
+                               pkey_group = partKey;\r
+                               while(pkey_group && (*pkey_group != '\0'))\r
+                               {\r
+                                       pkey_group_next = strstr(pkey_group,sep_group);\r
+                                       if(pkey_group_next)\r
+                                               *pkey_group_next = '\0';\r
+                                       pkey_guid = strtok(pkey_group,sep_guid_pkey);\r
+                                       i = 0;\r
+                                       while(pkey_guid)\r
+                                       {\r
+                                               if(i == 0)\r
+                                               {\r
+                                                       j = 1;\r
+                                                       for (k = strlen(pkey_guid) -1; k > 1; k--)\r
+                                                       {\r
+                                                               if (j%2)\r
+                                                               {\r
+                                                                       tmp = pkey_guid[k -1];\r
+                                                                       pkey_guid[k -1] = pkey_guid[k];\r
+                                                                       pkey_guid[k] = tmp;\r
+                                                               }\r
+                                                               printf("%c",pkey_guid[k]);\r
+                                                               if ((j%4 == 0) && (k > 2))\r
+                                                               {\r
+                                                                       printf(":");\r
+                                                                       j = 1;\r
+                                                               }\r
+                                                               else\r
+                                                                       j++;\r
+                                                       }\r
+                                                       printf("\t");\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       printf("%s\t",pkey_guid);\r
+                                               }\r
+                                               pkey_guid = strtok(NULL,sep_guid_pkey);\r
+                                               if((++i)%5 == 0)\r
+                                                       printf("\n\t\t\t");\r
+                                       }\r
+                                       printf("\n\n");\r
+                                       if(pkey_group_next)\r
+                                               pkey_group = pkey_group_next + 1;\r
+                                       else\r
+                                               pkey_group = NULL;\r
+                               }\r
+                       }\r
                }\r
                else\r
                        retval = 0;\r
@@ -404,7 +455,6 @@ boolean_t reg_pkey_operation(const REQUEST_IN *input)
                        if( 0 == send_pdo_req(&pkeys,UAL_REQ_CREATE_PDO))\r
                        {\r
                                ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,IBBUS_SERV_KEY,0,KEY_SET_VALUE | KEY_QUERY_VALUE ,&reg_handle);\r
-\r
                                ret = RegSetValueEx(reg_handle,"PartitionKey",0,REG_SZ,(BYTE*)p_reg_string,reg_length);\r
                                RegCloseKey( reg_handle );\r
                                if (ERROR_SUCCESS == ret)\r
@@ -459,16 +509,21 @@ int prepare_reg_pkey_input(OUT REQUEST_IN *input,char* cmd[],int num)
                int i;\r
                unsigned short *guid_vstat;\r
                guid_vstat = (unsigned short*)&input->u.guid_pkey.port_guid;\r
-               sscanf(cmd[2],"%x:%x:%x:%x",&guid_vstat[0],&guid_vstat[1],&guid_vstat[2],&guid_vstat[3]);\r
-               for( i = 0; i < 4; i++)\r
-                       guid_vstat[i] = (guid_vstat[i] << 8) | (guid_vstat[i] >> 8);\r
+               if (4 == sscanf(cmd[2],"%x:%x:%x:%x",&guid_vstat[0],&guid_vstat[1],&guid_vstat[2],&guid_vstat[3]))\r
+               {\r
+                       for( i = 0; i < 4; i++)\r
+                               guid_vstat[i] = (guid_vstat[i] << 8) | (guid_vstat[i] >> 8);\r
+               }\r
+               else\r
+               {\r
+                       goto bad_inp;\r
+               }\r
        }\r
        else\r
        {\r
-               printf("port guid %s - illegal string format\n",cmd[2]);\r
-               return 0;\r
+               goto bad_inp;\r
        }\r
-       \r
+\r
        for( i = 3; i < num; i++)\r
        {\r
                if((strstr(cmd[i],"ffff")) || (strstr(cmd[i],"FFFF")))\r
@@ -480,6 +535,9 @@ int prepare_reg_pkey_input(OUT REQUEST_IN *input,char* cmd[],int num)
                input->u.guid_pkey.pkey_num++;\r
        }\r
        return 1;\r
+bad_inp:\r
+       printf("port guid %s - illegal port guid format, expected xxxx:xxxx:xxxx:xxxx\n",cmd[2]);\r
+       return 0;       \r
 }\r
 \r
 void partition_operation(char* cmd[],int num)\r