pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


Quantron: Mount usb stick read-only by default, and only rw on demand
Posted by Anonymous on Tue 27th Aug 2019 12:34
raw | new post
view followups (newest first): Quantron+JNCG: Mount usb stick read-only by default, and only rw on demand by Anonymous

  1. diff --git a/ptxdist/local_src/eag_usbmount/root/etc/usbmount/usbmount.conf b/ptxdist/local_src/eag_usbmount/root/etc/usbmount/usbmount.conf
  2. index 20e9cf5..eb48a22 100644
  3. --- a/ptxdist/local_src/eag_usbmount/root/etc/usbmount/usbmount.conf
  4. +++ b/ptxdist/local_src/eag_usbmount/root/etc/usbmount/usbmount.conf
  5. @@ -27,7 +27,7 @@ FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus"
  6.  # Mount options: Options passed to the mount command with the -o flag.
  7.  # See the warning above regarding removing "sync" from the options, as
  8.  # it may lead to data loss.
  9. -MOUNTOPTIONS="sync,noexec,nodev,noatime,nodiratime"
  10. +MOUNTOPTIONS="ro,async,noexec,nodev,noatime,nodiratime"
  11.  
  12.  # Filesystem type specific mount options: This variable contains a space
  13.  # separated list of strings, each which the form "-fstype=TYPE,OPTIONS".
  14. diff --git a/ptxdist/local_src/ecu01-basicsys/sbin/eag_usbstick b/ptxdist/local_src/ecu01-basicsys/sbin/eag_usbstick
  15. new file mode 100755
  16. index 0000000..05cf238
  17. --- /dev/null
  18. +++ b/ptxdist/local_src/ecu01-basicsys/sbin/eag_usbstick
  19. @@ -0,0 +1,31 @@
  20. +#!/bin/bash
  21. +
  22. +export PATH='/sbin:/bin'
  23. +
  24. +usbfsmountpoint='/media/usb0'
  25. +cmd="$1"
  26. +
  27. +# use POSIX shell tracing to log trace to journalctl
  28. +# (observe with $ journalctl -f -a #)
  29. +set -o xtrace
  30. +
  31. +case "${cmd}" in
  32. +       'mount_writeable')
  33. +               mount -o rw,remount "${usbfsmountpoint}"
  34. +               exit $?
  35. +               ;;
  36. +       'mount_readonly')
  37. +               mount -o ro,remount "${usbfsmountpoint}"
  38. +               exit $?
  39. +               ;;
  40. +       'is_stick_mounted_writeable')
  41. +               grep -q -E \
  42. +                       '[[:space:]]+'"${usbfsmountpoint}"'[[:space:]]+(fat|vfat)[[:space:]]+rw,' \
  43. +                       '/proc/self/mounts'
  44. +               exit $?
  45. +               ;;
  46. +       *)
  47. +               exit 1
  48. +               ;;
  49. +esac
  50. +# EOF.
  51. diff --git a/ptxdist/local_src/ecu01-codesys/QAX/QAX.c b/ptxdist/local_src/ecu01-codesys/QAX/QAX.c
  52. index 79b1495..f52626a 100755
  53. --- a/ptxdist/local_src/ecu01-codesys/QAX/QAX.c
  54. +++ b/ptxdist/local_src/ecu01-codesys/QAX/QAX.c
  55. @@ -524,6 +524,7 @@ void CDECL CDECL_EXT usbstick_getmountpath(usbstick_getmountpath_struct *p)
  56.  /*****************************************************/
  57.  
  58.  void CDECL CDECL_EXT usbstick_mount(usbstick_mount_struct *p)
  59.  
  60.  {
  61.  
  62. +#ifdef OLD_BYZANTINE_USBSTICK_CODE
  63.  
  64.      /* mount -o bind /mnt/test /mnt/usbstick
  65.  
  66.       * Beide Ordner müssen existieren.
  67.  
  68.       * ändert man nun was in /mnt/usbstick ändert man auch in /mnt/test.
  69.  
  70. @@ -556,12 +557,23 @@ void CDECL CDECL_EXT usbstick_mount(usbstick_mount_struct *p)
  71.      /* Mountvorgang war nicht erfolgleich */
  72.  
  73.      //Log_Warning(COMPONENT_ID,"Mountvorgang fehlgeschlagen\n");
  74.  
  75.      p->USBStick_Mount = -1;
  76.  
  77. +#else
  78.  
  79. +       int ret;
  80.  
  81. +       ret = system("/sbin/eag_usbstick mount_writeable");
  82.  
  83. +       if (ret == -1)
  84.  
  85. +       {
  86.  
  87. +               perror("/sbin/eag_usbstick mount_writeable failed.");
  88.  
  89. +               p->USBStick_Mount = -1;
  90.  
  91. +               return;
  92.  
  93. +       }
  94.  
  95.  
  96.  
  97. +       p->USBStick_Mount = (ret == 0)?0:-1;
  98.  
  99. +#endif /* OLD_BYZANTINE_USBSTICK_CODE */
  100.  
  101.  }  /* eofn: usbstick_mount */
  102.  
  103.  
  104.  
  105.  void CDECL CDECL_EXT usbstick_umount(usbstick_umount_struct *p)
  106.  
  107.  {
  108.  
  109. -
  110.  
  111. +#ifdef OLD_BYZANTINE_USBSTICK_CODE
  112.  
  113.      int iRet;
  114.  
  115.  
  116.  
  117.      //Log_Warning(COMPONENT_ID,"usbstick_umount\n");
  118.  
  119. @@ -578,13 +590,23 @@ void CDECL CDECL_EXT usbstick_umount(usbstick_umount_struct *p)
  120.  
  121.  
  122.      /* Umount erfolgreich */
  123.  
  124.      p->USBStick_Umount = 0;
  125.  
  126. +#else
  127.  
  128. +       int ret;
  129.  
  130. +       ret = system("/sbin/eag_usbstick mount_readonly");
  131.  
  132. +       if (ret == -1)
  133.  
  134. +       {
  135.  
  136. +               perror("/sbin/eag_usbstick mount_readonly failed.");
  137.  
  138. +               p->USBStick_Umount = -1;
  139.  
  140. +               return;
  141.  
  142. +       }
  143.  
  144.  
  145.  
  146. -
  147.  
  148. +       p->USBStick_Umount = (ret == 0)?0:-1;
  149.  
  150. +#endif /* OLD_BYZANTINE_USBSTICK_CODE*/
  151.  
  152.  }  /* eofn: usbstick_umount */
  153.  
  154.  
  155.  
  156.  void CDECL CDECL_EXT usbstick_status(usbstick_status_struct *p)
  157.  
  158.  {
  159.  
  160. -
  161.  
  162. +#ifdef OLD_BYZANTINE_USBSTICK_CODE
  163.  
  164.      int iRet;
  165.  
  166.  
  167.  
  168.      /*******************************************************************************/
  169.  
  170. @@ -600,7 +622,18 @@ void CDECL CDECL_EXT usbstick_status(usbstick_status_struct *p)
  171.  
  172.  
  173.      /* Usbstick ist bereits gemountet */
  174.  
  175.      p->USBStick_Status = 0;
  176.  
  177. +#else
  178.  
  179. +       int ret;
  180.  
  181. +       ret = system("/sbin/eag_usbstick is_stick_mounted_writeable");
  182.  
  183. +       if (ret == -1)
  184.  
  185. +       {
  186.  
  187. +               perror("/sbin/eag_usbstick is_stick_mounted_writeable failed.");
  188.  
  189. +               p->USBStick_Status = -1;
  190.  
  191. +               return;
  192.  
  193. +       }
  194.  
  195.  
  196.  
  197. +       p->USBStick_Status = (ret == 0)?0:-1;
  198.  
  199. +#endif /* OLD_BYZANTINE_USBSTICK_CODE */
  200.  
  201.  }  /* eofn: usbstick_status */
  202.  
  203.  
  204.  
  205.  /*****************************************/

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at