Skip to content

.NET on Raspberry Pi cannot write to writable network file #53182

Closed
@sba923

Description

@sba923

Description

(This is derived from PowerShell/PowerShell#15339, full details can be found there)

Context is: PowerShell 7.1.3 running on Raspberry Pi 2B+ with a network mount off an Ubuntu 20.04.2 LTS box running Samba Version 4.11.6-Ubuntu

PS /home/pi> lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster
PS /home/pi> cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
PS /home/pi> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Linux 5.10.17-v7+ #1403 SMP Mon Feb 22 11:29:51 GMT 2021
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

pi@jeedom:~ $ resolveip pnjnas
IP address of pnjnas is 192.168.1.3
pi@jeedom:~ $ mount | fgrep 192.168.1.3
//192.168.1.3/pi on /pnjnas/pi type cifs (rw,nosuid,nodev,noexec,relatime,vers=2.0,cache=strict,username=pi,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.3,file_mode=0777,dir_mode=0777,soft,nounix,serverino,mapposix,rsize=65536,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1,_netdev)
//192.168.1.3/Qdownload on /pnjnas/Qdownload type cifs (rw,nosuid,nodev,noexec,relatime,vers=2.0,cache=strict,username=pi,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.3,file_mode=0777,dir_mode=0777,soft,nounix,serverino,mapposix,rsize=65536,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1,_netdev)
//192.168.1.3/public on /pnjnas/public type cifs (rw,nosuid,nodev,noexec,relatime,vers=2.0,cache=strict,username=pi,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.3,file_mode=0777,dir_mode=0777,soft,nounix,serverino,mapposix,rsize=65536,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1,_netdev)
//192.168.1.3/sto on /pnjnas/sto type cifs (rw,nosuid,nodev,noexec,relatime,vers=2.0,cache=strict,username=sto,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.3,file_mode=0777,dir_mode=0777,soft,nounix,serverino,mapposix,rsize=65536,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1,_netdev)
pi@jeedom:~ $ ls -l /pnjnas/sto/disks/Health/foo.txt
-rwxrwxrwx 1 root root 4 May  2 21:09 /pnjnas/sto/disks/Health/foo.txt
pi@jeedom:~ $ ls -ld /pnjnas/sto/disks/Health
drwxrwxrwx 2 root root 0 May  2 21:06 /pnjnas/sto/disks/Health
pi@jeedom:~ $ echo "foo" >/pnjnas/sto/disks/Health/foo.txt
# no error since file is writable
pi@jeedom:~ $ ls -l /pnjnas/sto/disks/Health/foo.txt
-rwxrwxrwx 1 root root 4 May  3 14:16 /pnjnas/sto/disks/Health/foo.txt
pi@jeedom:~ $ cat /pnjnas/sto/disks/Health/foo.txt
foo

Writing to that same file via .NET APIs (invoked via PowerShell) doesn't work:

$fs = [IO.File]::Open("/pnjnas/sto/disks/Health/foo.txt", "Create",  "Write", "Read")
$sw = [IO.StreamWriter]::new($fs)
$sw.WriteLine("foo")
$sw.Dispose()

This fails as follows:

MethodInvocationException: /pnjnas/sto/PowerShell/test/Test-WritingToSambaShare.ps1:4
Line |
   4 |  $sw.Dispose()
     |  ~~~~~~~~~~~~~
     | Exception calling "Dispose" with "0" argument(s): "Access to the path '/pnjnas/sto/disks/Health/foo.txt' is denied."

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions