# Create file with O_EXCL|O_CREAT does not work on NFS shares



## Edelwyss (Dec 2, 2014)

Hi everyone,

I'm trying to create files on a mounted NFS share with the O_EXCL|O_CREAT flags set. If I'm not mistaken, O_EXCL should be supported since NFSv3. If I create a new file on a NFS share with the O_EXCL flag, the new file ends up with the permissions 0000.

Perl Script to reproduce this behaviour:


```
#!/usr/bin/perl

use strict;
use Fcntl;

my $file_path = "test.txt";

sysopen (Text, $file_path, O_EXCL|O_CREAT, 0666);
```

The permissions of the created test file:


```
----------  1 root  wheel  0B Dec  2 13:35 test.txt
```

The /etc/fstab entry for the NFS share:


```
10.0.0.20:/pool1/test-share  /data  nfs  rw,nfsv3,tcp,wsize=32768,rsize=32768,hard,noatime,nolockd,async  0  0
```

I also tried different mount options with no success. I tested this on FreeBSD 9.3 and 10.1 with the same results.

Any help would be appreciated

Nicolas


----------



## Edelwyss (Jan 20, 2015)

The problem only seems to occur if the exporting server is running on Solaris 11.x with ZFS (currently version 35) and the FreeBSD 9.x/10.x client is mounting the NFS share with nfsv3.

If the share is mounted with nfsv2 instead of nfsv3 the PERL script in the previous post works and the created test file has the correct permission.

Could this problem be in any way related to this older bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=135412


----------



## acheron (Jan 20, 2015)

See this PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193128 and https://lists.freebsd.org/pipermail/freebsd-fs/2014-December/020628.html for the gory details.


----------

