1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <zircon/device/device.h>
6 #include <zircon/status.h>
7 #include <zircon/types.h>
8
9 #include <errno.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <unistd.h>
14
main(int argc,char * argv[])15 int main(int argc, char* argv[]) {
16 if (argc < 2) {
17 fprintf(stderr, "usage: %s <device path>\n", argv[0]);
18 return -1;
19 }
20
21 int fd = open(argv[1], O_RDONLY);
22 if (fd < 0) {
23 fprintf(stderr, "could not open %s: %s\n", argv[1], strerror(errno));
24 return -1;
25 }
26
27 char path[1024];
28 ssize_t rc = ioctl_device_get_topo_path(fd, path, 1024);
29 if (rc < 0) {
30 fprintf(stderr, "could not get topological path for %s: %s\n",
31 argv[1], zx_status_get_string((zx_status_t)rc));
32 close(fd);
33 return -1;
34 }
35
36 printf("topological path for %s: %s\n", argv[1], path);
37 close(fd);
38 return 0;
39 }
40