|
1 | 1 | import {attrNumsToBitmap} from './attributes'; |
2 | 2 | import * as msg from './messages'; |
3 | 3 | import * as structs from './structs'; |
4 | | -import {Nfsv4FType} from './constants'; |
| 4 | +import {Nfsv4CreateMode, Nfsv4FType, Nfsv4OpenFlags} from './constants'; |
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * Static builder helpers for NFS v4 operations. |
@@ -252,15 +252,15 @@ export const nfs = { |
252 | 252 | * @param shareAccess - Share access mode (OPEN4_SHARE_ACCESS_*) |
253 | 253 | * @param shareDeny - Share deny mode (OPEN4_SHARE_DENY_*) |
254 | 254 | * @param owner - Open owner (clientid + owner bytes) |
255 | | - * @param openhow - Open mode (0 for OPEN4_NOCREATE) |
| 255 | + * @param openhow - Open how structure (use OpenHow helper) |
256 | 256 | * @param claim - Open claim (use OpenClaim helper) |
257 | 257 | */ |
258 | 258 | OPEN( |
259 | 259 | seqid: number, |
260 | 260 | shareAccess: number, |
261 | 261 | shareDeny: number, |
262 | 262 | owner: structs.Nfsv4OpenOwner, |
263 | | - openhow: number, |
| 263 | + openhow: structs.Nfsv4OpenHow, |
264 | 264 | claim: structs.Nfsv4OpenClaim, |
265 | 265 | ): msg.Nfsv4OpenRequest { |
266 | 266 | return new msg.Nfsv4OpenRequest(seqid, shareAccess, shareDeny, owner, openhow, claim); |
@@ -455,6 +455,42 @@ export const nfs = { |
455 | 455 | return new structs.Nfsv4OpenClaim(0, new structs.Nfsv4OpenClaimNull(filename)); |
456 | 456 | }, |
457 | 457 |
|
| 458 | + /** |
| 459 | + * Create Nfsv4OpenHow for OPEN4_NOCREATE (open existing file). |
| 460 | + */ |
| 461 | + OpenHowNoCreate(): structs.Nfsv4OpenHow { |
| 462 | + return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_NOCREATE); |
| 463 | + }, |
| 464 | + |
| 465 | + /** |
| 466 | + * Create Nfsv4OpenHow for OPEN4_CREATE with UNCHECKED4 mode. |
| 467 | + * @param createattrs - Optional file attributes to set on create |
| 468 | + */ |
| 469 | + OpenHowCreateUnchecked(createattrs?: structs.Nfsv4Fattr): structs.Nfsv4OpenHow { |
| 470 | + const attrs = createattrs || new structs.Nfsv4Fattr(new structs.Nfsv4Bitmap([]), new Uint8Array(0)); |
| 471 | + const how = new structs.Nfsv4CreateHow(Nfsv4CreateMode.UNCHECKED4, new structs.Nfsv4CreateAttrs(attrs)); |
| 472 | + return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_CREATE, how); |
| 473 | + }, |
| 474 | + |
| 475 | + /** |
| 476 | + * Create Nfsv4OpenHow for OPEN4_CREATE with GUARDED4 mode. |
| 477 | + * @param createattrs - Optional file attributes to set on create |
| 478 | + */ |
| 479 | + OpenHowCreateGuarded(createattrs?: structs.Nfsv4Fattr): structs.Nfsv4OpenHow { |
| 480 | + const attrs = createattrs || new structs.Nfsv4Fattr(new structs.Nfsv4Bitmap([]), new Uint8Array(0)); |
| 481 | + const how = new structs.Nfsv4CreateHow(Nfsv4CreateMode.GUARDED4, new structs.Nfsv4CreateAttrs(attrs)); |
| 482 | + return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_CREATE, how); |
| 483 | + }, |
| 484 | + |
| 485 | + /** |
| 486 | + * Create Nfsv4OpenHow for OPEN4_CREATE with EXCLUSIVE4 mode. |
| 487 | + * @param verifier - 8-byte verifier for exclusive create |
| 488 | + */ |
| 489 | + OpenHowCreateExclusive(verifier: structs.Nfsv4Verifier): structs.Nfsv4OpenHow { |
| 490 | + const how = new structs.Nfsv4CreateHow(Nfsv4CreateMode.EXCLUSIVE4, new structs.Nfsv4CreateVerf(verifier)); |
| 491 | + return new structs.Nfsv4OpenHow(Nfsv4OpenFlags.OPEN4_CREATE, how); |
| 492 | + }, |
| 493 | + |
458 | 494 | /** |
459 | 495 | * Create Nfsv4LockOwner (lock owner identifier). |
460 | 496 | * @param clientid - Client ID |
|
0 commit comments