iounit.c 456 B

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