|
9 | 9 | Nfsv4OpenClaimType, |
10 | 10 | Nfsv4DelegType, |
11 | 11 | Nfsv4LockType, |
| 12 | + Nfsv4OpenFlags, |
12 | 13 | } from '../../../constants'; |
13 | 14 | import {Nfsv4OperationCtx, Nfsv4Operations} from '../Nfsv4Operations'; |
14 | 15 | import * as msg from '../../../messages'; |
@@ -535,33 +536,41 @@ export class Nfsv4OperationsNode implements Nfsv4Operations { |
535 | 536 | const claimNull = request.claim.claim as struct.Nfsv4OpenClaimNull; |
536 | 537 | const filename = claimNull.file; |
537 | 538 | const filePath = NodePath.join(currentPathAbsolute, filename); |
| 539 | + let fileExists = false; |
538 | 540 | try { |
539 | 541 | const stats = await this.promises.lstat(filePath); |
540 | 542 | if (!stats.isFile()) { |
541 | 543 | return new msg.Nfsv4OpenResponse(Nfsv4Stat.NFS4ERR_ISDIR); |
542 | 544 | } |
| 545 | + fileExists = true; |
543 | 546 | } catch (err) { |
544 | | - if (isErrCode(err, 'ENOENT')) { |
545 | | - return new msg.Nfsv4OpenResponse(Nfsv4Stat.NFS4ERR_NOENT); |
| 547 | + if (isErrCode('ENOENT', err)) { |
| 548 | + if (request.openhow !== Nfsv4OpenFlags.OPEN4_CREATE) { |
| 549 | + return new msg.Nfsv4OpenResponse(Nfsv4Stat.NFS4ERR_NOENT); |
| 550 | + } |
| 551 | + } else { |
| 552 | + const status = normalizeNodeFsError(err, ctx.connection.logger); |
| 553 | + return new msg.Nfsv4OpenResponse(status); |
546 | 554 | } |
547 | | - const status = normalizeNodeFsError(err, ctx.connection.logger); |
548 | | - return new msg.Nfsv4OpenResponse(status); |
549 | 555 | } |
550 | | - if (!this.canAccessFile(filePath, request.shareAccess, request.shareDeny)) { |
| 556 | + if (fileExists && !this.canAccessFile(filePath, request.shareAccess, request.shareDeny)) { |
551 | 557 | return new msg.Nfsv4OpenResponse(Nfsv4Stat.NFS4ERR_SHARE_DENIED); |
552 | 558 | } |
553 | 559 | let flags = 0; |
554 | 560 | const isWrite = (request.shareAccess & Nfsv4OpenAccess.OPEN4_SHARE_ACCESS_WRITE) !== 0; |
555 | 561 | const isRead = (request.shareAccess & Nfsv4OpenAccess.OPEN4_SHARE_ACCESS_READ) !== 0; |
| 562 | + if (request.openhow === 1) { |
| 563 | + flags = this.fs.constants.O_CREAT; |
| 564 | + } |
556 | 565 | if (isRead && isWrite) { |
557 | | - flags = this.fs.constants.O_RDWR; |
| 566 | + flags |= this.fs.constants.O_RDWR; |
558 | 567 | } else if (isWrite) { |
559 | | - flags = this.fs.constants.O_WRONLY; |
| 568 | + flags |= this.fs.constants.O_WRONLY; |
560 | 569 | } else { |
561 | | - flags = this.fs.constants.O_RDONLY; |
| 570 | + flags |= this.fs.constants.O_RDONLY; |
562 | 571 | } |
563 | 572 | try { |
564 | | - const fd = await this.promises.open(filePath, flags); |
| 573 | + const fd = await this.promises.open(filePath, flags, 0o644); |
565 | 574 | const stateid = this.createStateid(); |
566 | 575 | const stateidKey = this.makeStateidKey(stateid); |
567 | 576 | const openFile = new OpenFileState( |
|
0 commit comments