pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for global mount service, 2024-09-23
Posted by Anonymous on Mon 23rd Sep 2024 17:30
raw | new post

  1. From f3d37c4ac61e6c1206589dd744f5ce487a01476d Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 23 Sep 2024 18:08:19 +0200
  4. Subject: [PATCH] cygwin: RFE: ms-nfs41-client should have a service to mount
  5.  global mounts
  6.  
  7. RFE: ms-nfs41-client should have a service to mount global mounts.
  8.  
  9. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. cygwin/Makefile.install                       |   4 +
  13.  cygwin/README.bintarball.txt                  |  18 ++
  14.  cygwin/devel/msnfs41client.bash               |  73 +++++---
  15.  .../mountall_msnfs41client.ksh                | 164 ++++++++++++++++++
  16.  4 files changed, 236 insertions(+), 23 deletions(-)
  17.  create mode 100644 cygwin/utils/mountall_msnfs41client/mountall_msnfs41client.ksh
  18.  
  19. diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
  20. index 68f2b63..8c31d71 100644
  21. --- a/cygwin/Makefile.install
  22. +++ b/cygwin/Makefile.install
  23. @@ -55,6 +55,10 @@ installdest:
  24.         git diff -w     >"$(DESTDIR)/$(CYGWIN_BASEPATH)/usr/src/msnfs41client/msnfs41client_diff_w.diff"
  25.         git diff        >"$(DESTDIR)/$(CYGWIN_BASEPATH)/usr/src/msnfs41client/msnfs41client_diff.diff"
  26.         @ printf "# Package utilties\n"
  27. +       cp $(CYGWIN_MAKEFILE_DIR)/utils/mountall_msnfs41client/mountall_msnfs41client.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/mountall_msnfs41client
  28. +       chmod a+x $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/mountall_msnfs41client
  29. +       PATH+=":$(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/" \
  30. +               /usr/bin/ksh93 $(CYGWIN_MAKEFILE_DIR)/utils/mountall_msnfs41client/mountall_msnfs41client.ksh --nroff 2>"$(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/man/man1/mountall_msnfs41client.1" || true
  31.         cp $(CYGWIN_MAKEFILE_DIR)/utils/cygwinaccount2nfs4account/cygwinaccount2nfs4account.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/cygwinaccount2nfs4account
  32.         chmod a+x $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/cygwinaccount2nfs4account
  33.         PATH+=":$(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/" \
  34. diff --git a/cygwin/README.bintarball.txt b/cygwin/README.bintarball.txt
  35. index f5d4438..52b99a6 100644
  36. --- a/cygwin/README.bintarball.txt
  37. +++ b/cygwin/README.bintarball.txt
  38. @@ -262,6 +262,24 @@ $ net use N: /delete
  39.  $ /sbin/nfs_mount
  40.  
  41.  
  42. +# Global/System-wide mounts:
  43. +Mounts created by user "SYSTEM" are useable by all users in a system.
  44. +Example usage:
  45. +---- snip ----
  46. +# Create a file /etc/fstab.msnfs41client, which list the mounts
  47. +# which should be available system-wide
  48. +$ cat /etc/fstab.msnfs41client
  49. +nfs://[fe80::21b:1bff:fec3:7713]//bigdisk       V       nfs     rw      0       0
  50. +# run "ms-nfs41-client-globalmountall-service", which runs
  51. +# /sbin/mountall_msnfs41client as user "SYSTEM" to read
  52. +# /etc/fstab.msnfs41client and mount the matching filesystems
  53. +sc start ms-nfs41-client-globalmountall-service
  54. +---- snip ----
  55. +
  56. +BUG: Note that "ms-nfs41-client-globalmountall-service" currently
  57. +does not wait until nfsd*.exe is available for accepting mounts.
  58. +
  59. +
  60.  #
  61.  # 9. Notes:
  62.  #
  63. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  64. index 14bbd9c..0ce778a 100755
  65. --- a/cygwin/devel/msnfs41client.bash
  66. +++ b/cygwin/devel/msnfs41client.bash
  67. @@ -185,6 +185,52 @@ function nfsclient_install
  68.         # query new 'ms-nfs41-client-service'
  69.         sc query 'ms-nfs41-client-service'
  70.  
  71. +       #
  72. +       # install "mountall_msnfs41client" as system service
  73. +       # 'ms-nfs41-client-globalmountall-service'
  74. +       # "off" by default, requires manual starting
  75. +       #
  76. +
  77. +       # remove 'ms-nfs41-client-globalmountall-service'
  78. +       sc stop 'ms-nfs41-client-globalmountall-service' || true
  79. +       cygrunsrv --remove 'ms-nfs41-client-globalmountall-service' || true
  80. +       if [[ -f '/var/log/ms-nfs41-client-globalmountall-service.log' ]] ; then
  81. +               mv \
  82. +                       '/var/log/ms-nfs41-client-globalmountall-service.log' \
  83. +                       "/var/log/ms-nfs41-client-globalmountall-service.log.old$(date +%Y%m%d_%Hh%Mm)"
  84. +       fi
  85. +
  86. +       #
  87. +       # create new '/var/log/ms-nfs41-client-globalmountall-service.log'
  88. +       # so users can do a $ tail -f
  89. +       # '/var/log/ms-nfs41-client-globalmountall-service.log' at any time
  90. +       #
  91. +       touch '/var/log/ms-nfs41-client-globalmountall-service.log'
  92. +       chown SYSTEM:SYSTEM '/var/log/ms-nfs41-client-globalmountall-service.log'
  93. +       chmod u+w,go-w '/var/log/ms-nfs41-client-globalmountall-service.log'
  94. +
  95. +       # install new 'ms-nfs41-client-globalmountall-service'
  96. +       cygrunsrv --install \
  97. +               'ms-nfs41-client-globalmountall-service' \
  98. +               --path "$PWD/msnfs41client" \
  99. +               --args 'sys_mount_globaldirs' \
  100. +               --type 'manual' \
  101. +               --chdir "$PWD"
  102. +
  103. +       # install dummy /etc/fstab.msnfs41client if system does not have one
  104. +       if [[ ! -f '/etc/fstab.msnfs41client' ]] ; then
  105. +               {
  106. +                       printf '#\n'
  107. +                       printf '# /etc/fstab.msnfs41client - used by /sbin/mountall_msnfs41client\n'
  108. +                       printf '#\n\n'
  109. +                       printf '# nfs://[fe80::21b:1bff:fec3:7713]//bigdisk\tV\tnfs\trw\t0\t0\n\n'
  110. +                       printf '# EOF.\n'
  111. +               } >'/etc/fstab.msnfs41client'
  112. +       fi
  113. +
  114. +       # query new 'ms-nfs41-client-globalmountall-service'
  115. +       sc query 'ms-nfs41-client-globalmountall-service'
  116. +
  117.         #
  118.         # check whether ksh93 works
  119.         # (The ms-nfs41-client cygwin idmapper uses ksh93 scripts for
  120. @@ -552,35 +598,15 @@ function nfsclient_system_mount_globaldirs
  121.         set -o nounset
  122.         set -o errexit
  123.  
  124. -       #
  125. -       # ToDo: Add a /etc/fstab.msnfs41client file
  126. -       # which is parsed for NFSv4.1 mounts like Linux/etc/fstab
  127. -       # or SysV/Solaris/Illumos /etc/vfstab
  128. -       #
  129. -
  130. -       # purge any leftover persistent mappings to device P:
  131. -       su_system net use 'P:' /delete || true
  132. -       su_system nfs_mount -o sec=sys,rw 'P' 'nfs://derfwnb4966_ipv6linklocal//bigdisk'
  133. +       mountall_msnfs41client
  134.  
  135.         return $?
  136.  }
  137.  
  138.  function nfsclient_system_umount_globaldirs
  139.  {
  140. -       set -o xtrace
  141. -       set -o nounset
  142. -       set -o errexit
  143. -
  144. -       #
  145. -       # ToDo: Add a /etc/fstab.msnfs41client file
  146. -       # which is parsed for NFSv4.1 mounts like Linux/etc/fstab
  147. -       # or SysV/Solaris/Illumos /etc/vfstab
  148. -       #
  149. -
  150. -       # purge any leftover persistent mappings to device P:
  151. -       su_system net use 'P:' /delete || true
  152. -
  153. -       return $?
  154. +       # fixme: needs to be implemented
  155. +       return 1
  156.  }
  157.  
  158.  function nfsclient_mount_homedir
  159. @@ -765,6 +791,7 @@ function main
  160.                 'sys_mount_globaldirs')
  161.                         check_machine_arch || (( numerr++ ))
  162.                         require_cmd 'nfs_mount.exe' || (( numerr++ ))
  163. +                       require_cmd 'mountall_msnfs41client' || (( numerr++ ))
  164.                         require_cmd 'PsExec.exe' || (( numerr++ ))
  165.                         if ! is_windows_admin_account ; then
  166.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  167. diff --git a/cygwin/utils/mountall_msnfs41client/mountall_msnfs41client.ksh b/cygwin/utils/mountall_msnfs41client/mountall_msnfs41client.ksh
  168. new file mode 100644
  169. index 0000000..be19983
  170. --- /dev/null
  171. +++ b/cygwin/utils/mountall_msnfs41client/mountall_msnfs41client.ksh
  172. @@ -0,0 +1,164 @@
  173. +#!/bin/ksh93
  174. +
  175. +#
  176. +# MIT License
  177. +#
  178. +# Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org>
  179. +#
  180. +# Permission is hereby granted, free of charge, to any person obtaining a copy
  181. +# of this software and associated documentation files (the "Software"), to deal
  182. +# in the Software without restriction, including without limitation the rights
  183. +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  184. +# copies of the Software, and to permit persons to whom the Software is
  185. +# furnished to do so, subject to the following conditions:
  186. +#
  187. +# The above copyright notice and this permission notice shall be included in all
  188. +# copies or substantial portions of the Software.
  189. +#
  190. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  191. +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  192. +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  193. +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  194. +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  195. +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  196. +# SOFTWARE.
  197. +#
  198. +
  199. +#
  200. +# mountall_msnfs41client.ksh93 - mount all msnfs41client NFSv4.1
  201. +# filesystems listed in /etc/fstab.msnfs41client
  202. +#
  203. +
  204. +#
  205. +# Written by Roland Mainz <roland.mainz@nrubsig.org>
  206. +#
  207. +
  208. +
  209. +function parse_fstab_data
  210. +{
  211. +       nameref fstab_entries=$1
  212. +       integer currline=0
  213. +       typeset leftover
  214. +       typeset s
  215. +
  216. +       for ((currline=0 ; ; currline++ )) ; do
  217. +               read -r s || break
  218. +               # skip empty lines+lines with spaces only
  219. +               if [[ "$s" == ~(Elr)[[:space:]]* ]] ; then
  220. +                       continue
  221. +               fi
  222. +
  223. +               IFS=$' \t\n' read -r \
  224. +                       fs_spec \
  225. +                       fs_file \
  226. +                       fs_vfstype \
  227. +                       fs_mntops \
  228. +                       fs_freq \
  229. +                       fs_passno leftover <<<"$s" || break
  230. +               if [[ "${fs_spec}" == ~(El)[[:space:]]*# ]] ; then
  231. +                       continue
  232. +               fi
  233. +               if [[ $leftover != '' ]] ; then
  234. +                       print -u2 -f $"%s: Parsing error in line %d\n" "$0" currline
  235. +                       continue
  236. +               fi
  237. +
  238. +               fstab_entries+=(
  239. +                       fs_spec="$fs_spec"
  240. +                       fs_file="$fs_file"
  241. +                       fs_vfstype="$fs_vfstype"
  242. +                       fs_mntops="$fs_mntops"
  243. +                       fs_freq="$fs_freq"
  244. +                       fs_passno="$fs_passno"
  245. +               )
  246. +       done
  247. +
  248. +       return 0
  249. +}
  250. +
  251. +function read_etc_fstab
  252. +{
  253. +       nameref arr=$1
  254. +
  255. +       if [[ ! -r "$2" ]] ; then
  256. +               print -u2 -f $"%s: Cannot open file %q\n" "$0" "$2"
  257. +               return 1
  258. +       fi
  259. +
  260. +       parse_fstab_data arr <"$2"
  261. +       return $?
  262. +}
  263. +
  264. +function fstabentries2nfs_mount_lines
  265. +{
  266. +       nameref arr=$1
  267. +       typeset i
  268. +
  269. +       for i in "${!arr[@]}" ; do
  270. +               nameref currfstabentry=arr[$i]
  271. +
  272. +               #print -v currfstabentry
  273. +
  274. +               if [[ "${currfstabentry.fs_vfstype}" != 'nfs' ]] ; then
  275. +                       continue
  276. +               fi
  277. +
  278. +               printf 'nfs_mount -o %q %q %q\n' \
  279. +                       "${currfstabentry.fs_mntops}" \
  280. +                       "${currfstabentry.fs_file}" \
  281. +                       "${currfstabentry.fs_spec}"
  282. +       done
  283. +       return 0
  284. +}
  285. +
  286. +function main
  287. +{
  288. +       set -o errexit
  289. +       compound c
  290. +       compound -a c.fstab_entries
  291. +
  292. +       # fixme: not implemented yet
  293. +       if [[ "$1" == '--nroff' ]] ; then
  294. +               return 0
  295. +       fi
  296. +
  297. +       printf $"# Start.\n"
  298. +
  299. +       id -a
  300. +
  301. +       read_etc_fstab c.fstab_entries '/etc/fstab.msnfs41client'
  302. +
  303. +       cmdline="${ fstabentries2nfs_mount_lines c.fstab_entries ; }"
  304. +
  305. +       #
  306. +       # FIXME: We should wait until nfsd*.exe is
  307. +       # running
  308. +       #
  309. +
  310. +       set -o xtrace
  311. +       source '/dev/stdin' <<<"$cmdline"
  312. +       set +o xtrace
  313. +
  314. +       printf $"# Done.\n"
  315. +       return 0
  316. +}
  317. +
  318. +
  319. +#
  320. +# Main
  321. +#
  322. +
  323. +export PATH='/bin:/usr/bin:/sbin:/usr/sbin'
  324. +# add dir (usually "/sbin") in front of PATH so we pick-up
  325. +# nfs_mount.
  326. +PATH="$(dirname "${.sh.file}"):$PATH"
  327. +printf '# PATH=%q\n' "$PATH"
  328. +
  329. +builtin basename
  330. +builtin dirname
  331. +builtin id
  332. +
  333. +main "$@"
  334. +exit $?
  335. +
  336. +# EOF.
  337. --
  338. 2.45.1

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