xref: /plan9/sys/src/libc/9sys/iounit.c (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 #include <u.h>
2 #include <libc.h>
3 
4 /*
5  * Format:
6   3 r  M    4 (0000000000457def 11 00)   8192      512 /rc/lib/rcmain
7  */
8 
9 int
iounit(int fd)10 iounit(int fd)
11 {
12 	int i, cfd;
13 	char buf[128], *args[10];
14 
15 	snprint(buf, sizeof buf, "#d/%dctl", fd);
16 	cfd = open(buf, OREAD);
17 	if(cfd < 0)
18 		return 0;
19 	i = read(cfd, buf, sizeof buf-1);
20 	close(cfd);
21 	if(i <= 0)
22 		return 0;
23 	buf[i] = '\0';
24 	if(tokenize(buf, args, nelem(args)) != nelem(args))
25 		return 0;
26 	return atoi(args[7]);
27 }
28