3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "ps3dm_proxy.h"
26 #define PS3DM_GET_REPO_NODE_VAL_VERSION "0.0.1"
37 static struct option long_opts
[] = {
38 { "help", no_argument
, NULL
, 'h' },
39 { "verbose", no_argument
, NULL
, 'v' },
40 { "version", no_argument
, NULL
, 'V' },
47 static void usage(void) {
49 "Usage: ps3dm_get_repo_node_val [OPTIONS] DEVICE LPARID KEY0 KEY1 KEY2 KEY3\n"
52 " -h, --help Show this message and exit\n"
53 " -v, --verbose Increase verbosity\n"
54 " -V, --version Show version information and exit\n"
56 "Simple example: Get value of repository node ss.laid.1:\n"
57 " ps3dm_get_repo_node_val /dev/ps3dmproxy 1 0x0000000073730000 "
58 "0x6c61696400000000 0x0000000000000001 0x0000000000000000\n");
64 static void version(void)
67 "ps3dm_get_repo_node_val " PS3DM_GET_REPO_NODE_VAL_VERSION
"\n"
68 "Copyright (C) 2011 graf_chokolo <grafchokolo@googlemail.com>\n"
69 "This is free software. You may redistribute copies of it "
70 "under the terms of\n"
71 "the GNU General Public License 2 "
72 "<http://www.gnu.org/licenses/gpl2.html>.\n"
73 "There is NO WARRANTY, to the extent permitted by law.\n");
79 static int process_opts(int argc
, char **argv
, struct opts
*opts
)
84 while ((c
= getopt_long(argc
, argv
, "hvV", long_opts
, NULL
)) != -1) {
100 fprintf(stderr
, "Invalid command option: %c\n", c
);
105 if (optind
>= argc
) {
106 fprintf(stderr
, "No device specified\n");
110 opts
->device_name
= argv
[optind
];
113 if (optind
>= argc
) {
114 fprintf(stderr
, "No lpar id specified\n");
118 opt
= argv
[optind
++];
119 opts
->lpar_id
= strtoull(opt
, &endptr
, 0);
120 if ((*opt
== '\0') || (*endptr
!= '\0')) {
121 fprintf(stderr
, "Invalid lpar id '%s'\n", opt
);
125 for (i
= 0; i
< 4; i
++) {
126 if (optind
>= argc
) {
127 fprintf(stderr
, "No key #%d specified\n", i
);
131 opt
= argv
[optind
++];
132 opts
->key
[i
] = strtoull(opt
, &endptr
, 0);
133 if ((*opt
== '\0') || (*endptr
!= '\0')) {
134 fprintf(stderr
, "Invalid key #%d '%s'\n", i
, opt
);
145 int main(int argc
, char **argv
)
148 int fd
= 0, error
= 0;
151 memset(&opts
, 0, sizeof(opts
));
153 if (process_opts(argc
, argv
, &opts
)) {
162 } else if (opts
.do_version
) {
167 fd
= ps3dm_proxy_open(opts
.device_name
);
169 fprintf(stderr
, "%s: %s\n", opts
.device_name
, strerror(errno
));
174 if (opts
.do_verbose
) {
175 fprintf(stderr
, "lpar id 0x%016lx\n", opts
.lpar_id
);
177 fprintf(stderr
, "repo node key 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n",
178 opts
.key
[0], opts
.key
[1], opts
.key
[2], opts
.key
[3]);
181 error
= ps3dm_proxy_get_repo_node_val(fd
, opts
.lpar_id
, opts
.key
, val
);
183 fprintf(stderr
, "%s: %s\n", opts
.device_name
, strerror(errno
));
188 fprintf(stdout
, "0x%016lx 0x%016lx\n", val
[0], val
[1]);
193 ps3dm_proxy_close(fd
);