ubd_user.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. void ignore_sigwinch_sig(void)
  22. {
  23. signal(SIGWINCH, SIG_IGN);
  24. }
  25. int start_io_thread(unsigned long sp, int *fd_out)
  26. {
  27. int pid, fds[2], err;
  28. err = os_pipe(fds, 1, 1);
  29. if(err < 0){
  30. printk("start_io_thread - os_pipe failed, err = %d\n", -err);
  31. goto out;
  32. }
  33. kernel_fd = fds[0];
  34. *fd_out = fds[1];
  35. err = os_set_fd_block(*fd_out, 0);
  36. if (err) {
  37. printk("start_io_thread - failed to set nonblocking I/O.\n");
  38. goto out_close;
  39. }
  40. pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL);
  41. if(pid < 0){
  42. err = -errno;
  43. printk("start_io_thread - clone failed : errno = %d\n", errno);
  44. goto out_close;
  45. }
  46. return(pid);
  47. out_close:
  48. os_close_file(fds[0]);
  49. os_close_file(fds[1]);
  50. kernel_fd = -1;
  51. *fd_out = -1;
  52. out:
  53. return err;
  54. }