source: rtems-libbsd/freebsd/sbin/nvmecontrol/nsid.c @ e6acc15

5
Last change on this file since e6acc15 was e6acc15, checked in by Sebastian Huber <sebastian.huber@…>, on 09/20/19 at 05:57:01

NVMECONTROL(8): Port to RTEMS

Update #3821.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*-
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (C) 2019 Alexander Motin <mav@FreeBSD.org>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifdef __rtems__
31#include <machine/rtems-bsd-program.h>
32#endif /* __rtems__ */
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD$");
35
36#include <sys/param.h>
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <unistd.h>
41
42#include "nvmecontrol.h"
43#include "comnd.h"
44
45/* Tables for command line parsing */
46
47static cmd_fn_t gnsid;
48
49static struct nsid_options {
50        const char      *dev;
51} nsid_opt = {
52        .dev = NULL,
53};
54
55static const struct args nsid_args[] = {
56        { arg_string, &nsid_opt.dev, "namespace-id" },
57        { arg_none, NULL, NULL },
58};
59
60static struct cmd nsid_cmd = {
61        .name = "nsid",
62        .fn = gnsid,
63        .descr = "Get controller and NSID for namespace",
64        .ctx_size = sizeof(nsid_opt),
65        .opts = NULL,
66        .args = nsid_args,
67};
68
69CMD_COMMAND(nsid_cmd);
70
71static void
72gnsid(const struct cmd *f, int argc, char *argv[])
73{
74        char            *path;
75        int             fd;
76        uint32_t        nsid;
77
78        arg_parse(argc, argv, f);
79
80        open_dev(nsid_opt.dev, &fd, 1, 1);
81        get_nsid(fd, &path, &nsid);
82        close(fd);
83        printf("%s\t%u\n", path, nsid);
84        free(path);
85}
Note: See TracBrowser for help on using the repository browser.