ubd_user.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Copyright (C) 2001 Ridgerun,Inc (glonnon@ridgerun.com)
  4. * Licensed under the GPL
  5. */
  6. #include <stddef.h>
  7. #include <unistd.h>
  8. #include <errno.h>
  9. #include <sched.h>
  10. #include <signal.h>
  11. #include <string.h>
  12. #include <netinet/in.h>
  13. #include <sys/time.h>
  14. #include <sys/socket.h>
  15. #include <sys/mman.h>
  16. #include <sys/param.h>
  17. #include <endian.h>
  18. #include <byteswap.h>
  19. #include "ubd.h"
  20. #include <os.h>
  21. int start_io_thread(unsigned long sp, int *fd_out)
  22. {
  23. int pid, fds[2], err;
  24. err = os_pipe(fds, 1, 1);
  25. if(err < 0){
  26. printk("start_io_thread - os_pipe failed, err = %d\n", -err);
  27. goto out;
  28. }
  29. kernel_fd = fds[0];
  30. *fd_out = fds[1];
  31. err = os_set_fd_block(*fd_out, 0);
  32. if (err) {
  33. printk("start_io_thread - failed to set nonblocking I/O.\n");
  34. goto out_close;
  35. }
  36. pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL);
  37. if(pid < 0){
  38. err = -errno;
  39. printk("start_io_thread - clone failed : errno = %d\n", errno);
  40. goto out_close;
  41. }
  42. return(pid);
  43. out_close:
  44. os_close_file(fds[0]);
  45. os_close_file(fds[1]);
  46. kernel_fd = -1;
  47. *fd_out = -1;
  48. out:
  49. return err;
  50. }