pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


Quantron+JNCG: Mount usb stick read-only by default, and only rw on demand
Posted by Anonymous on Tue 27th Aug 2019 13:50
raw | new post
modification of post by Anonymous (view diff)

  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..bb70433 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. @@ -25,9 +25,11 @@ FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus"
  6.  # experience data loss.                                                     #
  7.  #############################################################################
  8.  # Mount options: Options passed to the mount command with the -o flag.
  9. -# See the warning above regarding removing "sync" from the options, as
  10. -# it may lead to data loss.
  11. -MOUNTOPTIONS="sync,noexec,nodev,noatime,nodiratime"
  12. +
  13. +# JNCG/Quantron: Mount USB-Stick read-only by default, use
  14. +# /sbin/eag_usbstick to make it writeable, write stuff, and then
  15. +# make it read-only again to prevent stick data corruption
  16. +MOUNTOPTIONS="ro,async,noexec,nodev,noatime,nodiratime"
  17.  
  18.  # Filesystem type specific mount options: This variable contains a space
  19.  # separated list of strings, each which the form "-fstype=TYPE,OPTIONS".
  20. diff --git a/ptxdist/local_src/eag_usbmount/root/sbin/eag_usbstick b/ptxdist/local_src/eag_usbmount/root/sbin/eag_usbstick
  21. new file mode 100755
  22. index 0000000..9eb1213
  23. --- /dev/null
  24. +++ b/ptxdist/local_src/eag_usbmount/root/sbin/eag_usbstick
  25. @@ -0,0 +1,38 @@
  26. +#!/bin/bash
  27. +
  28. +#
  29. +# EAG USBStick - Manage USB Stick status for JNCG and Quantron
  30. +#
  31. +
  32. +export PATH='/sbin:/bin'
  33. +
  34. +typeset -r usbfsmountpoint='/media/usb0'
  35. +typeset -r cmd="$1"
  36. +
  37. +# use POSIX shell tracing to log trace to journalctl
  38. +# (observe with $ journalctl -f -a #)
  39. +set -o xtrace
  40. +
  41. +case "${cmd}" in
  42. +       'mount_writeable')
  43. +               mount -o rw,remount "${usbfsmountpoint}"
  44. +               exit $?
  45. +               ;;
  46. +       'mount_readonly')
  47. +               # remounting as read-only implicitly writes all
  48. +               # pending write buffers to the media before making
  49. +               # the mount point as read-only
  50. +               mount -o ro,remount "${usbfsmountpoint}"
  51. +               exit $?
  52. +               ;;
  53. +       'is_stick_mounted_writeable')
  54. +               grep -q -E \
  55. +                       '[[:space:]]+'"${usbfsmountpoint}"'[[:space:]]+(fat|vfat)[[:space:]]+rw,' \
  56. +                       '/proc/self/mounts'
  57. +               exit $?
  58. +               ;;
  59. +       *)
  60. +               exit 1
  61. +               ;;
  62. +esac
  63. +# EOF.
  64. diff --git a/ptxdist/local_src/ecu01-codesys/QAX/QAX.c b/ptxdist/local_src/ecu01-codesys/QAX/QAX.c
  65. index 79b1495..b77e090 100755
  66. --- a/ptxdist/local_src/ecu01-codesys/QAX/QAX.c
  67. +++ b/ptxdist/local_src/ecu01-codesys/QAX/QAX.c
  68. @@ -524,83 +524,44 @@ void CDECL CDECL_EXT usbstick_getmountpath(usbstick_getmountpath_struct *p)
  69.  /*****************************************************/
  70.  
  71.  void CDECL CDECL_EXT usbstick_mount(usbstick_mount_struct *p)
  72.  
  73.  {
  74.  
  75. -    /* mount -o bind /mnt/test /mnt/usbstick
  76.  
  77. -     * Beide Ordner müssen existieren.
  78.  
  79. -     * ändert man nun was in /mnt/usbstick ändert man auch in /mnt/test.
  80.  
  81. -     * umount /mnt/usbstick
  82.  
  83. -     * /mnt/usbstick ist leer, /mnt/test ist verändert. */
  84.  
  85. -
  86.  
  87. -    int iRet;
  88.  
  89. -
  90.  
  91. -    /*********************************************/
  92.  
  93. -    /* Mount fuer Usbstick auf Media ausfuehren */
  94.  
  95. -    /*********************************************/
  96.  
  97. -    iRet = mount( "", acSettgUSBStickMountOrgPoint, "", MS_REMOUNT, "" );
  98.  
  99. -    if ( iRet != 0 )
  100.  
  101. -    {
  102.  
  103. -        p->USBStick_Mount = -1;
  104.  
  105. -        //No USB-Mount cancel,
  106.  
  107. -        return;
  108.  
  109. -    }
  110.  
  111. -
  112.  
  113. -    iRet = mount( acSettgUSBStickMountOrgPoint, acSettgUSBStickMountPoint, "", MS_BIND, "" );
  114.  
  115. -    if ( iRet == 0 ) {
  116.  
  117. -
  118.  
  119. -        /* Mountvorgang war erfolgleich */
  120.  
  121. -        //Log_Warning(COMPONENT_ID,"USB-Stick Device(%i) %s gemoutet\n", i, acSettgUSBStickDevice[i]);
  122.  
  123. -        p->USBStick_Mount = 0;
  124.  
  125. -        return;
  126.  
  127. -    }
  128.  
  129. -
  130.  
  131. -
  132.  
  133. -    /* Mountvorgang war nicht erfolgleich */
  134.  
  135. -    //Log_Warning(COMPONENT_ID,"Mountvorgang fehlgeschlagen\n");
  136.  
  137. -    p->USBStick_Mount = -1;
  138.  
  139. +       int ret;
  140.  
  141. +       ret = system("/sbin/eag_usbstick mount_writeable");
  142.  
  143. +       if (ret == -1)
  144.  
  145. +       {
  146.  
  147. +               perror("/sbin/eag_usbstick mount_writeable failed.");
  148.  
  149. +               p->USBStick_Mount = -1;
  150.  
  151. +               return;
  152.  
  153. +       }
  154.  
  155.  
  156.  
  157. +       p->USBStick_Mount = (ret == 0)?0:-1;
  158.  
  159.  }  /* eofn: usbstick_mount */
  160.  
  161.  
  162.  
  163.  void CDECL CDECL_EXT usbstick_umount(usbstick_umount_struct *p)
  164.  
  165.  {
  166.  
  167. +       int ret;
  168.  
  169. +       ret = system("/sbin/eag_usbstick mount_readonly");
  170.  
  171. +       if (ret == -1)
  172.  
  173. +       {
  174.  
  175. +               perror("/sbin/eag_usbstick mount_readonly failed.");
  176.  
  177. +               p->USBStick_Umount = -1;
  178.  
  179. +               return;
  180.  
  181. +       }
  182.  
  183.  
  184.  
  185. -    int iRet;
  186.  
  187. -
  188.  
  189. -    //Log_Warning(COMPONENT_ID,"usbstick_umount\n");
  190.  
  191. -    /************************************/
  192.  
  193. -    /* Unmount fuer Usbstick ausfuehren */
  194.  
  195. -    /************************************/
  196.  
  197. -    iRet = umount2( acSettgUSBStickMountPoint, MNT_DETACH );
  198.  
  199. -    if ( iRet != 0 ) {
  200.  
  201. -
  202.  
  203. -        /* Fehler beim Unmount */
  204.  
  205. -        p->USBStick_Umount = -1;
  206.  
  207. -        return;
  208.  
  209. -    }
  210.  
  211. -
  212.  
  213. -    /* Umount erfolgreich */
  214.  
  215. -    p->USBStick_Umount = 0;
  216.  
  217. -
  218.  
  219. -
  220.  
  221. +       p->USBStick_Umount = (ret == 0)?0:-1;
  222.  
  223.  }  /* eofn: usbstick_umount */
  224.  
  225.  
  226.  
  227.  void CDECL CDECL_EXT usbstick_status(usbstick_status_struct *p)
  228.  
  229.  {
  230.  
  231. +       int ret;
  232.  
  233. +       ret = system("/sbin/eag_usbstick is_stick_mounted_writeable");
  234.  
  235. +       if (ret == -1)
  236.  
  237. +       {
  238.  
  239. +               perror("/sbin/eag_usbstick is_stick_mounted_writeable failed.");
  240.  
  241. +               p->USBStick_Status = -1;
  242.  
  243. +               return;
  244.  
  245. +       }
  246.  
  247.  
  248.  
  249. -    int iRet;
  250.  
  251. -
  252.  
  253. -    /*******************************************************************************/
  254.  
  255. -    /* Remout mit gleichen Parameter auf Moutpoint ausfuehren um Status abzufragen */
  256.  
  257. -    /*******************************************************************************/
  258.  
  259. -    iRet = mount( "", acSettgUSBStickMountPoint, "", MS_REMOUNT | MS_BIND, "" );
  260.  
  261. -    if ( iRet != 0 ) {
  262.  
  263. -
  264.  
  265. -        /* Usbstick ist nicht gemountet */
  266.  
  267. -        p->USBStick_Status = -1;
  268.  
  269. -        return;
  270.  
  271. -    }
  272.  
  273. -
  274.  
  275. -    /* Usbstick ist bereits gemountet */
  276.  
  277. -    p->USBStick_Status = 0;
  278.  
  279. -
  280.  
  281. +       p->USBStick_Status = (ret == 0)?0:-1;
  282.  
  283.  }  /* eofn: usbstick_status */
  284.  
  285.  
  286.  
  287.  /*****************************************/
  288.  
  289. diff --git a/ptxdist/rules/usbmount.make b/ptxdist/rules/usbmount.make
  290. index c7383b7..dce2d7a 100644
  291. --- a/ptxdist/rules/usbmount.make
  292. +++ b/ptxdist/rules/usbmount.make
  293. @@ -125,6 +125,7 @@ endif
  294.  
  295.         #/sbin
  296.         @$(call install_copy, usbmount, 0, 0, 0755, $(USBMOUNT_DIR)/root/sbin/udev-trigger-massstorage.sh, /sbin/udev-trigger-massstorage.sh)
  297. +       @$(call install_copy, usbmount, 0, 0, 0755, $(USBMOUNT_DIR)/root/sbin/eag_usbstick, /sbin/eag_usbstick)
  298.  
  299.         #/systemd unitfiles
  300.  ifdef PTXCONF_USBMOUNT_SYSTEMD_UNIT

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