File: | modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c |
Warning: | line 3183, column 15 Copies out a struct with a union element with different sizes |
1 | /*- | |||
2 | * Copyright (c) 1989, 1993 | |||
3 | * The Regents of the University of California. All rights reserved. | |||
4 | * | |||
5 | * This code is derived from software contributed to Berkeley by | |||
6 | * Rick Macklem at The University of Guelph. | |||
7 | * | |||
8 | * Redistribution and use in source and binary forms, with or without | |||
9 | * modification, are permitted provided that the following conditions | |||
10 | * are met: | |||
11 | * 1. Redistributions of source code must retain the above copyright | |||
12 | * notice, this list of conditions and the following disclaimer. | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | |||
14 | * notice, this list of conditions and the following disclaimer in the | |||
15 | * documentation and/or other materials provided with the distribution. | |||
16 | * 4. Neither the name of the University nor the names of its contributors | |||
17 | * may be used to endorse or promote products derived from this software | |||
18 | * without specific prior written permission. | |||
19 | * | |||
20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
30 | * SUCH DAMAGE. | |||
31 | * | |||
32 | */ | |||
33 | ||||
34 | #include <sys/cdefs.h> | |||
35 | __FBSDID("$FreeBSD: releng/11.0/sys/fs/nfsserver/nfs_nfsdport.c 298788 2016-04-29 16:07:25Z pfg $")__asm__(".ident\t\"" "$FreeBSD: releng/11.0/sys/fs/nfsserver/nfs_nfsdport.c 298788 2016-04-29 16:07:25Z pfg $" "\""); | |||
36 | ||||
37 | #include <sys/capsicum.h> | |||
38 | ||||
39 | /* | |||
40 | * Functions that perform the vfs operations required by the routines in | |||
41 | * nfsd_serv.c. It is hoped that this change will make the server more | |||
42 | * portable. | |||
43 | */ | |||
44 | ||||
45 | #include <fs/nfs/nfsport.h> | |||
46 | #include <sys/hash.h> | |||
47 | #include <sys/sysctl.h> | |||
48 | #include <nlm/nlm_prot.h> | |||
49 | #include <nlm/nlm.h> | |||
50 | ||||
51 | FEATURE(nfsd, "NFSv4 server")static struct sysctl_oid sysctl___kern_features_nfsd = { .oid_parent = ((&(&sysctl___kern_features)->oid_children)), . oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | (0x80000000 | 0x00008000)), .oid_arg1 = ( ((int *)((void *)0))), .oid_arg2 = (1), .oid_name = ("nfsd"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "NFSv4 server" }; __asm__(".globl " "__start_set_sysctl_set" ); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___kern_features_nfsd __attribute__ ((__section__("set_" "sysctl_set"))) __attribute__((__used__) ) = &(sysctl___kern_features_nfsd); _Static_assert((((0x80000000 | 0x00008000) & 0xf) == 0 || ((0x80000000 | 0x00008000) & 0xf) == 2) && sizeof(int) == sizeof(*(((int *)((void *)0)))), "compile-time assertion failed"); | |||
52 | ||||
53 | extern u_int32_t newnfs_true, newnfs_false, newnfs_xdrneg1; | |||
54 | extern int nfsrv_useacl; | |||
55 | extern int newnfs_numnfsd; | |||
56 | extern struct mount nfsv4root_mnt; | |||
57 | extern struct nfsrv_stablefirst nfsrv_stablefirst; | |||
58 | extern void (*nfsd_call_servertimer)(void); | |||
59 | extern SVCPOOL *nfsrvd_pool; | |||
60 | extern struct nfsv4lock nfsd_suspend_lock; | |||
61 | extern struct nfsclienthashhead *nfsclienthash; | |||
62 | extern struct nfslockhashhead *nfslockhash; | |||
63 | extern struct nfssessionhash *nfssessionhash; | |||
64 | extern int nfsrv_sessionhashsize; | |||
65 | struct vfsoptlist nfsv4root_opt, nfsv4root_newopt; | |||
66 | NFSDLOCKMUTEXextern struct mtx newnfsd_mtx; | |||
67 | struct nfsrchash_bucket nfsrchash_table[NFSRVCACHE_HASHSIZE500]; | |||
68 | struct nfsrchash_bucket nfsrcahash_table[NFSRVCACHE_HASHSIZE500]; | |||
69 | struct mtx nfsrc_udpmtx; | |||
70 | struct mtx nfs_v4root_mutex; | |||
71 | struct nfsrvfh nfs_rootfh, nfs_pubfh; | |||
72 | int nfs_pubfhset = 0, nfs_rootfhset = 0; | |||
73 | struct proc *nfsd_master_proc = NULL((void *)0); | |||
74 | int nfsd_debuglevel = 0; | |||
75 | static pid_t nfsd_master_pid = (pid_t)-1; | |||
76 | static char nfsd_master_comm[MAXCOMLEN19 + 1]; | |||
77 | static struct timeval nfsd_master_start; | |||
78 | static uint32_t nfsv4_sysid = 0; | |||
79 | ||||
80 | static int nfssvc_srvcall(struct thread *, struct nfssvc_args *, | |||
81 | struct ucred *); | |||
82 | ||||
83 | int nfsrv_enable_crossmntpt = 1; | |||
84 | static int nfs_commit_blks; | |||
85 | static int nfs_commit_miss; | |||
86 | extern int nfsrv_issuedelegs; | |||
87 | extern int nfsrv_dolocallocks; | |||
88 | extern int nfsd_enable_stringtouid; | |||
89 | ||||
90 | SYSCTL_NODE(_vfs, OID_AUTO, nfsd, CTLFLAG_RW, 0, "NFS server")struct sysctl_oid sysctl___vfs_nfsd = { .oid_parent = ((& (&sysctl___vfs)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (1|((0x80000000|0x40000000 ))), .oid_arg1 = (((void *)0)), .oid_arg2 = (0), .oid_name = ( "nfsd"), .oid_handler = (0), .oid_fmt = ("N"), .oid_descr = "NFS server" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd); _Static_assert((((0x80000000 |0x40000000)) & 0xf) == 0 || (((0x80000000|0x40000000)) & 0xf) == 1, "compile-time assertion failed"); | |||
91 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, mirrormnt, CTLFLAG_RW,static struct sysctl_oid sysctl___vfs_nfsd_mirrormnt = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfsrv_enable_crossmntpt ), .oid_arg2 = (0), .oid_name = ("mirrormnt"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to cross mount points" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_mirrormnt __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_mirrormnt); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsrv_enable_crossmntpt)), "compile-time assertion failed" ) | |||
92 | &nfsrv_enable_crossmntpt, 0, "Enable nfsd to cross mount points")static struct sysctl_oid sysctl___vfs_nfsd_mirrormnt = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfsrv_enable_crossmntpt ), .oid_arg2 = (0), .oid_name = ("mirrormnt"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to cross mount points" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_mirrormnt __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_mirrormnt); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsrv_enable_crossmntpt)), "compile-time assertion failed" ); | |||
93 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks,static struct sysctl_oid sysctl___vfs_nfsd_commit_blks = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfs_commit_blks ), .oid_arg2 = (0), .oid_name = ("commit_blks"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "" }; __asm__ (".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set" ); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_commit_blks __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_commit_blks); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfs_commit_blks)), "compile-time assertion failed") | |||
94 | 0, "")static struct sysctl_oid sysctl___vfs_nfsd_commit_blks = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfs_commit_blks ), .oid_arg2 = (0), .oid_name = ("commit_blks"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "" }; __asm__ (".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set" ); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_commit_blks __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_commit_blks); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfs_commit_blks)), "compile-time assertion failed"); | |||
95 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss,static struct sysctl_oid sysctl___vfs_nfsd_commit_miss = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfs_commit_miss ), .oid_arg2 = (0), .oid_name = ("commit_miss"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "" }; __asm__ (".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set" ); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_commit_miss __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_commit_miss); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfs_commit_miss)), "compile-time assertion failed") | |||
96 | 0, "")static struct sysctl_oid sysctl___vfs_nfsd_commit_miss = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfs_commit_miss ), .oid_arg2 = (0), .oid_name = ("commit_miss"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "" }; __asm__ (".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set" ); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_commit_miss __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_commit_miss); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfs_commit_miss)), "compile-time assertion failed"); | |||
97 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, issue_delegations, CTLFLAG_RW,static struct sysctl_oid sysctl___vfs_nfsd_issue_delegations = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children )), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = ( &nfsrv_issuedelegs), .oid_arg2 = (0), .oid_name = ("issue_delegations" ), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to issue delegations" }; __asm__(".globl " "__start_set_sysctl_set" ); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_issue_delegations __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_issue_delegations); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsrv_issuedelegs)), "compile-time assertion failed") | |||
98 | &nfsrv_issuedelegs, 0, "Enable nfsd to issue delegations")static struct sysctl_oid sysctl___vfs_nfsd_issue_delegations = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children )), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = ( &nfsrv_issuedelegs), .oid_arg2 = (0), .oid_name = ("issue_delegations" ), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to issue delegations" }; __asm__(".globl " "__start_set_sysctl_set" ); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_issue_delegations __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_issue_delegations); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsrv_issuedelegs)), "compile-time assertion failed"); | |||
99 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_locallocks, CTLFLAG_RW,static struct sysctl_oid sysctl___vfs_nfsd_enable_locallocks = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children )), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = ( &nfsrv_dolocallocks), .oid_arg2 = (0), .oid_name = ("enable_locallocks" ), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to acquire local locks on files" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set" ); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_enable_locallocks __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_enable_locallocks); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsrv_dolocallocks)), "compile-time assertion failed" ) | |||
100 | &nfsrv_dolocallocks, 0, "Enable nfsd to acquire local locks on files")static struct sysctl_oid sysctl___vfs_nfsd_enable_locallocks = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children )), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = ( &nfsrv_dolocallocks), .oid_arg2 = (0), .oid_name = ("enable_locallocks" ), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to acquire local locks on files" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set" ); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_enable_locallocks __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_enable_locallocks); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsrv_dolocallocks)), "compile-time assertion failed" ); | |||
101 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, debuglevel, CTLFLAG_RW, &nfsd_debuglevel,static struct sysctl_oid sysctl___vfs_nfsd_debuglevel = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfsd_debuglevel ), .oid_arg2 = (0), .oid_name = ("debuglevel"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Debug level for NFS server" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_debuglevel __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_debuglevel); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsd_debuglevel)), "compile-time assertion failed") | |||
102 | 0, "Debug level for NFS server")static struct sysctl_oid sysctl___vfs_nfsd_debuglevel = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children)), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = (&nfsd_debuglevel ), .oid_arg2 = (0), .oid_name = ("debuglevel"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Debug level for NFS server" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_debuglevel __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_debuglevel); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsd_debuglevel)), "compile-time assertion failed"); | |||
103 | SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_stringtouid, CTLFLAG_RW,static struct sysctl_oid sysctl___vfs_nfsd_enable_stringtouid = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children )), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = ( &nfsd_enable_stringtouid), .oid_arg2 = (0), .oid_name = ( "enable_stringtouid"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to accept numeric owner_names" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_enable_stringtouid __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_enable_stringtouid); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsd_enable_stringtouid)), "compile-time assertion failed" ) | |||
104 | &nfsd_enable_stringtouid, 0, "Enable nfsd to accept numeric owner_names")static struct sysctl_oid sysctl___vfs_nfsd_enable_stringtouid = { .oid_parent = ((&(&sysctl___vfs_nfsd)->oid_children )), .oid_children = { ((void *)0) }, .oid_number = ((-1)), .oid_kind = (2 | 0x00040000 | ((0x80000000|0x40000000))), .oid_arg1 = ( &nfsd_enable_stringtouid), .oid_arg2 = (0), .oid_name = ( "enable_stringtouid"), .oid_handler = (sysctl_handle_int), .oid_fmt = ("I"), .oid_descr = "Enable nfsd to accept numeric owner_names" }; __asm__(".globl " "__start_set_sysctl_set"); __asm__(".globl " "__stop_set_sysctl_set"); static void const * const __set_sysctl_set_sym_sysctl___vfs_nfsd_enable_stringtouid __attribute__((__section__("set_" "sysctl_set"))) __attribute__ ((__used__)) = &(sysctl___vfs_nfsd_enable_stringtouid); _Static_assert (((((0x80000000|0x40000000)) & 0xf) == 0 || (((0x80000000 |0x40000000)) & 0xf) == 2) && sizeof(int) == sizeof (*(&nfsd_enable_stringtouid)), "compile-time assertion failed" ); | |||
105 | ||||
106 | #define MAX_REORDERED_RPC16 16 | |||
107 | #define NUM_HEURISTIC1031 1031 | |||
108 | #define NHUSE_INIT64 64 | |||
109 | #define NHUSE_INC16 16 | |||
110 | #define NHUSE_MAX2048 2048 | |||
111 | ||||
112 | static struct nfsheur { | |||
113 | struct vnode *nh_vp; /* vp to match (unreferenced pointer) */ | |||
114 | off_t nh_nextoff; /* next offset for sequential detection */ | |||
115 | int nh_use; /* use count for selection */ | |||
116 | int nh_seqcount; /* heuristic */ | |||
117 | } nfsheur[NUM_HEURISTIC1031]; | |||
118 | ||||
119 | ||||
120 | /* | |||
121 | * Heuristic to detect sequential operation. | |||
122 | */ | |||
123 | static struct nfsheur * | |||
124 | nfsrv_sequential_heuristic(struct uio *uio, struct vnode *vp) | |||
125 | { | |||
126 | struct nfsheur *nh; | |||
127 | int hi, try; | |||
128 | ||||
129 | /* Locate best candidate. */ | |||
130 | try = 32; | |||
131 | hi = ((int)(vm_offset_t)vp / sizeof(struct vnode)) % NUM_HEURISTIC1031; | |||
132 | nh = &nfsheur[hi]; | |||
133 | while (try--) { | |||
134 | if (nfsheur[hi].nh_vp == vp) { | |||
135 | nh = &nfsheur[hi]; | |||
136 | break; | |||
137 | } | |||
138 | if (nfsheur[hi].nh_use > 0) | |||
139 | --nfsheur[hi].nh_use; | |||
140 | hi = (hi + 1) % NUM_HEURISTIC1031; | |||
141 | if (nfsheur[hi].nh_use < nh->nh_use) | |||
142 | nh = &nfsheur[hi]; | |||
143 | } | |||
144 | ||||
145 | /* Initialize hint if this is a new file. */ | |||
146 | if (nh->nh_vp != vp) { | |||
147 | nh->nh_vp = vp; | |||
148 | nh->nh_nextoff = uio->uio_offset; | |||
149 | nh->nh_use = NHUSE_INIT64; | |||
150 | if (uio->uio_offset == 0) | |||
151 | nh->nh_seqcount = 4; | |||
152 | else | |||
153 | nh->nh_seqcount = 1; | |||
154 | } | |||
155 | ||||
156 | /* Calculate heuristic. */ | |||
157 | if ((uio->uio_offset == 0 && nh->nh_seqcount > 0) || | |||
158 | uio->uio_offset == nh->nh_nextoff) { | |||
159 | /* See comments in vfs_vnops.c:sequential_heuristic(). */ | |||
160 | nh->nh_seqcount += howmany(uio->uio_resid, 16384)(((uio->uio_resid)+((16384)-1))/(16384)); | |||
161 | if (nh->nh_seqcount > IO_SEQMAX0x7F) | |||
162 | nh->nh_seqcount = IO_SEQMAX0x7F; | |||
163 | } else if (qabs(uio->uio_offset - nh->nh_nextoff) <= MAX_REORDERED_RPC16 * | |||
164 | imax(vp->v_mount->mnt_stat.f_iosize, uio->uio_resid)) { | |||
165 | /* Probably a reordered RPC, leave seqcount alone. */ | |||
166 | } else if (nh->nh_seqcount > 1) { | |||
167 | nh->nh_seqcount /= 2; | |||
168 | } else { | |||
169 | nh->nh_seqcount = 0; | |||
170 | } | |||
171 | nh->nh_use += NHUSE_INC16; | |||
172 | if (nh->nh_use > NHUSE_MAX2048) | |||
173 | nh->nh_use = NHUSE_MAX2048; | |||
174 | return (nh); | |||
175 | } | |||
176 | ||||
177 | /* | |||
178 | * Get attributes into nfsvattr structure. | |||
179 | */ | |||
180 | int | |||
181 | nfsvno_getattr(struct vnode *vp, struct nfsvattr *nvap, struct ucred *cred, | |||
182 | struct thread *p, int vpislocked) | |||
183 | { | |||
184 | int error, lockedit = 0; | |||
185 | ||||
186 | if (vpislocked == 0) { | |||
187 | /* | |||
188 | * When vpislocked == 0, the vnode is either exclusively | |||
189 | * locked by this thread or not locked by this thread. | |||
190 | * As such, shared lock it, if not exclusively locked. | |||
191 | */ | |||
192 | if (NFSVOPISLOCKED(vp)VOP_ISLOCKED((vp)) != LK_EXCLUSIVE0x080000) { | |||
193 | lockedit = 1; | |||
194 | NFSVOPLOCK(vp, LK_SHARED | LK_RETRY)_vn_lock((vp), (0x200000 | 0x000400), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 194); | |||
195 | } | |||
196 | } | |||
197 | error = VOP_GETATTR(vp, &nvap->na_vattr, cred); | |||
198 | if (lockedit != 0) | |||
199 | NFSVOPUNLOCK(vp, 0)VOP_UNLOCK((vp), (0)); | |||
200 | ||||
201 | NFSEXITCODE(error); | |||
202 | return (error); | |||
203 | } | |||
204 | ||||
205 | /* | |||
206 | * Get a file handle for a vnode. | |||
207 | */ | |||
208 | int | |||
209 | nfsvno_getfh(struct vnode *vp, fhandle_t *fhp, struct thread *p) | |||
210 | { | |||
211 | int error; | |||
212 | ||||
213 | NFSBZERO((caddr_t)fhp, sizeof(fhandle_t))bzero(((caddr_t)fhp), (sizeof(fhandle_t))); | |||
214 | fhp->fh_fsid = vp->v_mount->mnt_stat.f_fsid; | |||
215 | error = VOP_VPTOFH(vp, &fhp->fh_fid); | |||
216 | ||||
217 | NFSEXITCODE(error); | |||
218 | return (error); | |||
219 | } | |||
220 | ||||
221 | /* | |||
222 | * Perform access checking for vnodes obtained from file handles that would | |||
223 | * refer to files already opened by a Unix client. You cannot just use | |||
224 | * vn_writechk() and VOP_ACCESSX() for two reasons. | |||
225 | * 1 - You must check for exported rdonly as well as MNT_RDONLY for the write | |||
226 | * case. | |||
227 | * 2 - The owner is to be given access irrespective of mode bits for some | |||
228 | * operations, so that processes that chmod after opening a file don't | |||
229 | * break. | |||
230 | */ | |||
231 | int | |||
232 | nfsvno_accchk(struct vnode *vp, accmode_t accmode, struct ucred *cred, | |||
233 | struct nfsexstuff *exp, struct thread *p, int override, int vpislocked, | |||
234 | u_int32_t *supportedtypep) | |||
235 | { | |||
236 | struct vattr vattr; | |||
237 | int error = 0, getret = 0; | |||
238 | ||||
239 | if (vpislocked == 0) { | |||
240 | if (NFSVOPLOCK(vp, LK_SHARED)_vn_lock((vp), (0x200000), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 240) != 0) { | |||
241 | error = EPERM1; | |||
242 | goto out; | |||
243 | } | |||
244 | } | |||
245 | if (accmode & VWRITE000000000200) { | |||
246 | /* Just vn_writechk() changed to check rdonly */ | |||
247 | /* | |||
248 | * Disallow write attempts on read-only file systems; | |||
249 | * unless the file is a socket or a block or character | |||
250 | * device resident on the file system. | |||
251 | */ | |||
252 | if (NFSVNO_EXRDONLY(exp)((exp)->nes_exflag & 0x0000000000000080ULL) || | |||
253 | (vp->v_mount->mnt_flag & MNT_RDONLY0x0000000000000001ULL)) { | |||
254 | switch (vp->v_type) { | |||
255 | case VREG: | |||
256 | case VDIR: | |||
257 | case VLNK: | |||
258 | error = EROFS30; | |||
259 | default: | |||
260 | break; | |||
261 | } | |||
262 | } | |||
263 | /* | |||
264 | * If there's shared text associated with | |||
265 | * the inode, try to free it up once. If | |||
266 | * we fail, we can't allow writing. | |||
267 | */ | |||
268 | if (VOP_IS_TEXT(vp) && error == 0) | |||
269 | error = ETXTBSY26; | |||
270 | } | |||
271 | if (error != 0) { | |||
272 | if (vpislocked == 0) | |||
273 | NFSVOPUNLOCK(vp, 0)VOP_UNLOCK((vp), (0)); | |||
274 | goto out; | |||
275 | } | |||
276 | ||||
277 | /* | |||
278 | * Should the override still be applied when ACLs are enabled? | |||
279 | */ | |||
280 | error = VOP_ACCESSX(vp, accmode, cred, p); | |||
281 | if (error != 0 && (accmode & (VDELETE000010000000 | VDELETE_CHILD000001000000))) { | |||
282 | /* | |||
283 | * Try again with VEXPLICIT_DENY, to see if the test for | |||
284 | * deletion is supported. | |||
285 | */ | |||
286 | error = VOP_ACCESSX(vp, accmode | VEXPLICIT_DENY000000100000, cred, p); | |||
287 | if (error == 0) { | |||
288 | if (vp->v_type == VDIR) { | |||
289 | accmode &= ~(VDELETE000010000000 | VDELETE_CHILD000001000000); | |||
290 | accmode |= VWRITE000000000200; | |||
291 | error = VOP_ACCESSX(vp, accmode, cred, p); | |||
292 | } else if (supportedtypep != NULL((void *)0)) { | |||
293 | *supportedtypep &= ~NFSACCESS_DELETE0x10; | |||
294 | } | |||
295 | } | |||
296 | } | |||
297 | ||||
298 | /* | |||
299 | * Allow certain operations for the owner (reads and writes | |||
300 | * on files that are already open). | |||
301 | */ | |||
302 | if (override != NFSACCCHK_NOOVERRIDE0 && | |||
303 | (error == EPERM1 || error == EACCES13)) { | |||
304 | if (cred->cr_uid == 0 && (override & NFSACCCHK_ALLOWROOT1)) | |||
305 | error = 0; | |||
306 | else if (override & NFSACCCHK_ALLOWOWNER2) { | |||
307 | getret = VOP_GETATTR(vp, &vattr, cred); | |||
308 | if (getret == 0 && cred->cr_uid == vattr.va_uid) | |||
309 | error = 0; | |||
310 | } | |||
311 | } | |||
312 | if (vpislocked == 0) | |||
313 | NFSVOPUNLOCK(vp, 0)VOP_UNLOCK((vp), (0)); | |||
314 | ||||
315 | out: | |||
316 | NFSEXITCODE(error); | |||
317 | return (error); | |||
318 | } | |||
319 | ||||
320 | /* | |||
321 | * Set attribute(s) vnop. | |||
322 | */ | |||
323 | int | |||
324 | nfsvno_setattr(struct vnode *vp, struct nfsvattr *nvap, struct ucred *cred, | |||
325 | struct thread *p, struct nfsexstuff *exp) | |||
326 | { | |||
327 | int error; | |||
328 | ||||
329 | error = VOP_SETATTR(vp, &nvap->na_vattr, cred); | |||
330 | NFSEXITCODE(error); | |||
331 | return (error); | |||
332 | } | |||
333 | ||||
334 | /* | |||
335 | * Set up nameidata for a lookup() call and do it. | |||
336 | */ | |||
337 | int | |||
338 | nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, | |||
339 | struct vnode *dp, int islocked, struct nfsexstuff *exp, struct thread *p, | |||
340 | struct vnode **retdirp) | |||
341 | { | |||
342 | struct componentname *cnp = &ndp->ni_cnd; | |||
343 | int i; | |||
344 | struct iovec aiov; | |||
345 | struct uio auio; | |||
346 | int lockleaf = (cnp->cn_flags & LOCKLEAF0x0004) != 0, linklen; | |||
347 | int error = 0, crossmnt; | |||
348 | char *cp; | |||
349 | ||||
350 | *retdirp = NULL((void *)0); | |||
351 | cnp->cn_nameptr = cnp->cn_pnbuf; | |||
352 | ndp->ni_strictrelative = 0; | |||
353 | /* | |||
354 | * Extract and set starting directory. | |||
355 | */ | |||
356 | if (dp->v_type != VDIR) { | |||
357 | if (islocked) | |||
358 | vput(dp); | |||
359 | else | |||
360 | vrele(dp); | |||
361 | nfsvno_relpathbuf(ndp); | |||
362 | error = ENOTDIR20; | |||
363 | goto out1; | |||
364 | } | |||
365 | if (islocked) | |||
366 | NFSVOPUNLOCK(dp, 0)VOP_UNLOCK((dp), (0)); | |||
367 | VREF(dp)vref(dp); | |||
368 | *retdirp = dp; | |||
369 | if (NFSVNO_EXRDONLY(exp)((exp)->nes_exflag & 0x0000000000000080ULL)) | |||
370 | cnp->cn_flags |= RDONLY0x00000200; | |||
371 | ndp->ni_segflg = UIO_SYSSPACE; | |||
372 | crossmnt = 1; | |||
373 | ||||
374 | if (nd->nd_flag & ND_PUBLOOKUP0x00000800) { | |||
375 | ndp->ni_loopcnt = 0; | |||
376 | if (cnp->cn_pnbuf[0] == '/') { | |||
377 | vrele(dp); | |||
378 | /* | |||
379 | * Check for degenerate pathnames here, since lookup() | |||
380 | * panics on them. | |||
381 | */ | |||
382 | for (i = 1; i < ndp->ni_pathlen; i++) | |||
383 | if (cnp->cn_pnbuf[i] != '/') | |||
384 | break; | |||
385 | if (i == ndp->ni_pathlen) { | |||
386 | error = NFSERR_ACCES13; | |||
387 | goto out; | |||
388 | } | |||
389 | dp = rootvnode; | |||
390 | VREF(dp)vref(dp); | |||
391 | } | |||
392 | } else if ((nfsrv_enable_crossmntpt == 0 && NFSVNO_EXPORTED(exp)((exp)->nes_exflag & 0x0000000000000100ULL)) || | |||
393 | (nd->nd_flag & ND_NFSV40x00000010) == 0) { | |||
394 | /* | |||
395 | * Only cross mount points for NFSv4 when doing a | |||
396 | * mount while traversing the file system above | |||
397 | * the mount point, unless nfsrv_enable_crossmntpt is set. | |||
398 | */ | |||
399 | cnp->cn_flags |= NOCROSSMOUNT0x00400000; | |||
400 | crossmnt = 0; | |||
401 | } | |||
402 | ||||
403 | /* | |||
404 | * Initialize for scan, set ni_startdir and bump ref on dp again | |||
405 | * because lookup() will dereference ni_startdir. | |||
406 | */ | |||
407 | ||||
408 | cnp->cn_thread = p; | |||
409 | ndp->ni_startdir = dp; | |||
410 | ndp->ni_rootdir = rootvnode; | |||
411 | ndp->ni_topdir = NULL((void *)0); | |||
412 | ||||
413 | if (!lockleaf) | |||
414 | cnp->cn_flags |= LOCKLEAF0x0004; | |||
415 | for (;;) { | |||
416 | cnp->cn_nameptr = cnp->cn_pnbuf; | |||
417 | /* | |||
418 | * Call lookup() to do the real work. If an error occurs, | |||
419 | * ndp->ni_vp and ni_dvp are left uninitialized or NULL and | |||
420 | * we do not have to dereference anything before returning. | |||
421 | * In either case ni_startdir will be dereferenced and NULLed | |||
422 | * out. | |||
423 | */ | |||
424 | error = lookup(ndp); | |||
425 | if (error) | |||
426 | break; | |||
427 | ||||
428 | /* | |||
429 | * Check for encountering a symbolic link. Trivial | |||
430 | * termination occurs if no symlink encountered. | |||
431 | */ | |||
432 | if ((cnp->cn_flags & ISSYMLINK0x00010000) == 0) { | |||
433 | if ((cnp->cn_flags & (SAVENAME0x00000800 | SAVESTART0x00001000)) == 0) | |||
434 | nfsvno_relpathbuf(ndp); | |||
435 | if (ndp->ni_vp && !lockleaf) | |||
436 | NFSVOPUNLOCK(ndp->ni_vp, 0)VOP_UNLOCK((ndp->ni_vp), (0)); | |||
437 | break; | |||
438 | } | |||
439 | ||||
440 | /* | |||
441 | * Validate symlink | |||
442 | */ | |||
443 | if ((cnp->cn_flags & LOCKPARENT0x0008) && ndp->ni_pathlen == 1) | |||
444 | NFSVOPUNLOCK(ndp->ni_dvp, 0)VOP_UNLOCK((ndp->ni_dvp), (0)); | |||
445 | if (!(nd->nd_flag & ND_PUBLOOKUP0x00000800)) { | |||
446 | error = EINVAL22; | |||
447 | goto badlink2; | |||
448 | } | |||
449 | ||||
450 | if (ndp->ni_loopcnt++ >= MAXSYMLINKS32) { | |||
451 | error = ELOOP62; | |||
452 | goto badlink2; | |||
453 | } | |||
454 | if (ndp->ni_pathlen > 1) | |||
455 | cp = uma_zalloc(namei_zone, M_WAITOK0x0002); | |||
456 | else | |||
457 | cp = cnp->cn_pnbuf; | |||
458 | aiov.iov_base = cp; | |||
459 | aiov.iov_len = MAXPATHLEN1024; | |||
460 | auio.uio_iov = &aiov; | |||
461 | auio.uio_iovcnt = 1; | |||
462 | auio.uio_offset = 0; | |||
463 | auio.uio_rw = UIO_READ; | |||
464 | auio.uio_segflg = UIO_SYSSPACE; | |||
465 | auio.uio_td = NULL((void *)0); | |||
466 | auio.uio_resid = MAXPATHLEN1024; | |||
467 | error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred); | |||
468 | if (error) { | |||
469 | badlink1: | |||
470 | if (ndp->ni_pathlen > 1) | |||
471 | uma_zfree(namei_zone, cp); | |||
472 | badlink2: | |||
473 | vrele(ndp->ni_dvp); | |||
474 | vput(ndp->ni_vp); | |||
475 | break; | |||
476 | } | |||
477 | linklen = MAXPATHLEN1024 - auio.uio_resid; | |||
478 | if (linklen == 0) { | |||
479 | error = ENOENT2; | |||
480 | goto badlink1; | |||
481 | } | |||
482 | if (linklen + ndp->ni_pathlen >= MAXPATHLEN1024) { | |||
483 | error = ENAMETOOLONG63; | |||
484 | goto badlink1; | |||
485 | } | |||
486 | ||||
487 | /* | |||
488 | * Adjust or replace path | |||
489 | */ | |||
490 | if (ndp->ni_pathlen > 1) { | |||
491 | NFSBCOPY(ndp->ni_next, cp + linklen, ndp->ni_pathlen)bcopy((ndp->ni_next), (cp + linklen), (ndp->ni_pathlen) ); | |||
492 | uma_zfree(namei_zone, cnp->cn_pnbuf); | |||
493 | cnp->cn_pnbuf = cp; | |||
494 | } else | |||
495 | cnp->cn_pnbuf[linklen] = '\0'; | |||
496 | ndp->ni_pathlen += linklen; | |||
497 | ||||
498 | /* | |||
499 | * Cleanup refs for next loop and check if root directory | |||
500 | * should replace current directory. Normally ni_dvp | |||
501 | * becomes the new base directory and is cleaned up when | |||
502 | * we loop. Explicitly null pointers after invalidation | |||
503 | * to clarify operation. | |||
504 | */ | |||
505 | vput(ndp->ni_vp); | |||
506 | ndp->ni_vp = NULL((void *)0); | |||
507 | ||||
508 | if (cnp->cn_pnbuf[0] == '/') { | |||
509 | vrele(ndp->ni_dvp); | |||
510 | ndp->ni_dvp = ndp->ni_rootdir; | |||
511 | VREF(ndp->ni_dvp)vref(ndp->ni_dvp); | |||
512 | } | |||
513 | ndp->ni_startdir = ndp->ni_dvp; | |||
514 | ndp->ni_dvp = NULL((void *)0); | |||
515 | } | |||
516 | if (!lockleaf) | |||
517 | cnp->cn_flags &= ~LOCKLEAF0x0004; | |||
518 | ||||
519 | out: | |||
520 | if (error) { | |||
521 | nfsvno_relpathbuf(ndp); | |||
522 | ndp->ni_vp = NULL((void *)0); | |||
523 | ndp->ni_dvp = NULL((void *)0); | |||
524 | ndp->ni_startdir = NULL((void *)0); | |||
525 | } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT0x0010|LOCKPARENT0x0008)) == 0) { | |||
526 | ndp->ni_dvp = NULL((void *)0); | |||
527 | } | |||
528 | ||||
529 | out1: | |||
530 | NFSEXITCODE2(error, nd); | |||
531 | return (error); | |||
532 | } | |||
533 | ||||
534 | /* | |||
535 | * Set up a pathname buffer and return a pointer to it and, optionally | |||
536 | * set a hash pointer. | |||
537 | */ | |||
538 | void | |||
539 | nfsvno_setpathbuf(struct nameidata *ndp, char **bufpp, u_long **hashpp) | |||
540 | { | |||
541 | struct componentname *cnp = &ndp->ni_cnd; | |||
542 | ||||
543 | cnp->cn_flags |= (NOMACCHECK0x00800000 | HASBUF0x00000400); | |||
544 | cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK0x0002); | |||
545 | if (hashpp != NULL((void *)0)) | |||
546 | *hashpp = NULL((void *)0); | |||
547 | *bufpp = cnp->cn_pnbuf; | |||
548 | } | |||
549 | ||||
550 | /* | |||
551 | * Release the above path buffer, if not released by nfsvno_namei(). | |||
552 | */ | |||
553 | void | |||
554 | nfsvno_relpathbuf(struct nameidata *ndp) | |||
555 | { | |||
556 | ||||
557 | if ((ndp->ni_cnd.cn_flags & HASBUF0x00000400) == 0) | |||
558 | panic("nfsrelpath"); | |||
559 | uma_zfree(namei_zone, ndp->ni_cnd.cn_pnbuf); | |||
560 | ndp->ni_cnd.cn_flags &= ~HASBUF0x00000400; | |||
561 | } | |||
562 | ||||
563 | /* | |||
564 | * Readlink vnode op into an mbuf list. | |||
565 | */ | |||
566 | int | |||
567 | nfsvno_readlink(struct vnode *vp, struct ucred *cred, struct thread *p, | |||
568 | struct mbuf **mpp, struct mbuf **mpendp, int *lenp) | |||
569 | { | |||
570 | struct iovec iv[(NFS_MAXPATHLEN1024+MLEN((int)(256 - __builtin_offsetof(struct mbuf, m_dat)))-1)/MLEN((int)(256 - __builtin_offsetof(struct mbuf, m_dat)))]; | |||
571 | struct iovec *ivp = iv; | |||
572 | struct uio io, *uiop = &io; | |||
573 | struct mbuf *mp, *mp2 = NULL((void *)0), *mp3 = NULL((void *)0); | |||
574 | int i, len, tlen, error = 0; | |||
575 | ||||
576 | len = 0; | |||
577 | i = 0; | |||
578 | while (len < NFS_MAXPATHLEN1024) { | |||
579 | NFSMGET(mp)do { (((mp)) = m_get((0x0002), (1))); while ((mp) == ((void * )0) ) { (void) nfs_catnap(((80) + 20), 0, "nfsmget"); (((mp)) = m_get((0x0002), (1))); } } while (0); | |||
580 | MCLGET(mp, M_WAITOK)m_clget((mp), (0x0002)); | |||
581 | mp->m_len = M_SIZE(mp)(((mp)->m_flags & 0x00000001) ? (mp)->m_ext.ext_size : ((mp)->m_flags & 0x00000002) ? ((int)(256 - __builtin_offsetof (struct mbuf, m_pktdat))) : ((int)(256 - __builtin_offsetof(struct mbuf, m_dat)))); | |||
582 | if (len == 0) { | |||
583 | mp3 = mp2 = mp; | |||
584 | } else { | |||
585 | mp2->m_next = mp; | |||
586 | mp2 = mp; | |||
587 | } | |||
588 | if ((len + mp->m_len) > NFS_MAXPATHLEN1024) { | |||
589 | mp->m_len = NFS_MAXPATHLEN1024 - len; | |||
590 | len = NFS_MAXPATHLEN1024; | |||
591 | } else { | |||
592 | len += mp->m_len; | |||
593 | } | |||
594 | ivp->iov_base = mtod(mp, caddr_t)((caddr_t)((mp)->m_data)); | |||
595 | ivp->iov_len = mp->m_len; | |||
596 | i++; | |||
597 | ivp++; | |||
598 | } | |||
599 | uiop->uio_iov = iv; | |||
600 | uiop->uio_iovcnt = i; | |||
601 | uiop->uio_offset = 0; | |||
602 | uiop->uio_resid = len; | |||
603 | uiop->uio_rw = UIO_READ; | |||
604 | uiop->uio_segflg = UIO_SYSSPACE; | |||
605 | uiop->uio_td = NULL((void *)0); | |||
606 | error = VOP_READLINK(vp, uiop, cred); | |||
607 | if (error) { | |||
608 | m_freem(mp3); | |||
609 | *lenp = 0; | |||
610 | goto out; | |||
611 | } | |||
612 | if (uiop->uio_resid > 0) { | |||
613 | len -= uiop->uio_resid; | |||
614 | tlen = NFSM_RNDUP(len)(((len)+3)&(~0x3)); | |||
615 | nfsrv_adj(mp3, NFS_MAXPATHLEN1024 - tlen, tlen - len); | |||
616 | } | |||
617 | *lenp = len; | |||
618 | *mpp = mp3; | |||
619 | *mpendp = mp; | |||
620 | ||||
621 | out: | |||
622 | NFSEXITCODE(error); | |||
623 | return (error); | |||
624 | } | |||
625 | ||||
626 | /* | |||
627 | * Read vnode op call into mbuf list. | |||
628 | */ | |||
629 | int | |||
630 | nfsvno_read(struct vnode *vp, off_t off, int cnt, struct ucred *cred, | |||
631 | struct thread *p, struct mbuf **mpp, struct mbuf **mpendp) | |||
632 | { | |||
633 | struct mbuf *m; | |||
634 | int i; | |||
635 | struct iovec *iv; | |||
636 | struct iovec *iv2; | |||
637 | int error = 0, len, left, siz, tlen, ioflag = 0; | |||
638 | struct mbuf *m2 = NULL((void *)0), *m3; | |||
639 | struct uio io, *uiop = &io; | |||
640 | struct nfsheur *nh; | |||
641 | ||||
642 | len = left = NFSM_RNDUP(cnt)(((cnt)+3)&(~0x3)); | |||
643 | m3 = NULL((void *)0); | |||
644 | /* | |||
645 | * Generate the mbuf list with the uio_iov ref. to it. | |||
646 | */ | |||
647 | i = 0; | |||
648 | while (left > 0) { | |||
649 | NFSMGET(m)do { (((m)) = m_get((0x0002), (1))); while ((m) == ((void *)0 ) ) { (void) nfs_catnap(((80) + 20), 0, "nfsmget"); (((m)) = m_get ((0x0002), (1))); } } while (0); | |||
650 | MCLGET(m, M_WAITOK)m_clget((m), (0x0002)); | |||
651 | m->m_len = 0; | |||
652 | siz = min(M_TRAILINGSPACE(m)((!((m)->m_flags & 0x00000008) && (!(((m)-> m_flags & 0x00000001)) || (m_extrefcnt(m) == 1))) ? ((((( m)->m_flags & 0x00000001) ? (m)->m_ext.ext_buf : (( m)->m_flags & 0x00000002) ? &(m)->m_pktdat[0] : &(m)->m_dat[0]) + (((m)->m_flags & 0x00000001) ? (m)->m_ext.ext_size : ((m)->m_flags & 0x00000002 ) ? ((int)(256 - __builtin_offsetof(struct mbuf, m_pktdat))) : ((int)(256 - __builtin_offsetof(struct mbuf, m_dat))))) - (( m)->m_data + (m)->m_len)) : 0), left); | |||
653 | left -= siz; | |||
654 | i++; | |||
655 | if (m3) | |||
656 | m2->m_next = m; | |||
657 | else | |||
658 | m3 = m; | |||
659 | m2 = m; | |||
660 | } | |||
661 | MALLOC(iv, struct iovec *, i * sizeof (struct iovec),((iv) = (struct iovec *)malloc((u_long)(i * sizeof (struct iovec )), (M_TEMP), (0x0002))) | |||
662 | M_TEMP, M_WAITOK)((iv) = (struct iovec *)malloc((u_long)(i * sizeof (struct iovec )), (M_TEMP), (0x0002))); | |||
663 | uiop->uio_iov = iv2 = iv; | |||
664 | m = m3; | |||
665 | left = len; | |||
666 | i = 0; | |||
667 | while (left > 0) { | |||
668 | if (m == NULL((void *)0)) | |||
669 | panic("nfsvno_read iov"); | |||
670 | siz = min(M_TRAILINGSPACE(m)((!((m)->m_flags & 0x00000008) && (!(((m)-> m_flags & 0x00000001)) || (m_extrefcnt(m) == 1))) ? ((((( m)->m_flags & 0x00000001) ? (m)->m_ext.ext_buf : (( m)->m_flags & 0x00000002) ? &(m)->m_pktdat[0] : &(m)->m_dat[0]) + (((m)->m_flags & 0x00000001) ? (m)->m_ext.ext_size : ((m)->m_flags & 0x00000002 ) ? ((int)(256 - __builtin_offsetof(struct mbuf, m_pktdat))) : ((int)(256 - __builtin_offsetof(struct mbuf, m_dat))))) - (( m)->m_data + (m)->m_len)) : 0), left); | |||
671 | if (siz > 0) { | |||
672 | iv->iov_base = mtod(m, caddr_t)((caddr_t)((m)->m_data)) + m->m_len; | |||
673 | iv->iov_len = siz; | |||
674 | m->m_len += siz; | |||
675 | left -= siz; | |||
676 | iv++; | |||
677 | i++; | |||
678 | } | |||
679 | m = m->m_next; | |||
680 | } | |||
681 | uiop->uio_iovcnt = i; | |||
682 | uiop->uio_offset = off; | |||
683 | uiop->uio_resid = len; | |||
684 | uiop->uio_rw = UIO_READ; | |||
685 | uiop->uio_segflg = UIO_SYSSPACE; | |||
686 | uiop->uio_td = NULL((void *)0); | |||
687 | nh = nfsrv_sequential_heuristic(uiop, vp); | |||
688 | ioflag |= nh->nh_seqcount << IO_SEQSHIFT16; | |||
689 | error = VOP_READ(vp, uiop, IO_NODELOCKED0x0008 | ioflag, cred); | |||
690 | FREE((caddr_t)iv2, M_TEMP)free(((caddr_t)iv2), (M_TEMP)); | |||
691 | if (error) { | |||
692 | m_freem(m3); | |||
693 | *mpp = NULL((void *)0); | |||
694 | goto out; | |||
695 | } | |||
696 | nh->nh_nextoff = uiop->uio_offset; | |||
697 | tlen = len - uiop->uio_resid; | |||
698 | cnt = cnt < tlen ? cnt : tlen; | |||
699 | tlen = NFSM_RNDUP(cnt)(((cnt)+3)&(~0x3)); | |||
700 | if (tlen == 0) { | |||
701 | m_freem(m3); | |||
702 | m3 = NULL((void *)0); | |||
703 | } else if (len != tlen || tlen != cnt) | |||
704 | nfsrv_adj(m3, len - tlen, tlen - cnt); | |||
705 | *mpp = m3; | |||
706 | *mpendp = m2; | |||
707 | ||||
708 | out: | |||
709 | NFSEXITCODE(error); | |||
710 | return (error); | |||
711 | } | |||
712 | ||||
713 | /* | |||
714 | * Write vnode op from an mbuf list. | |||
715 | */ | |||
716 | int | |||
717 | nfsvno_write(struct vnode *vp, off_t off, int retlen, int cnt, int stable, | |||
718 | struct mbuf *mp, char *cp, struct ucred *cred, struct thread *p) | |||
719 | { | |||
720 | struct iovec *ivp; | |||
721 | int i, len; | |||
722 | struct iovec *iv; | |||
723 | int ioflags, error; | |||
724 | struct uio io, *uiop = &io; | |||
725 | struct nfsheur *nh; | |||
726 | ||||
727 | MALLOC(ivp, struct iovec *, cnt * sizeof (struct iovec), M_TEMP,((ivp) = (struct iovec *)malloc((u_long)(cnt * sizeof (struct iovec)), (M_TEMP), (0x0002))) | |||
728 | M_WAITOK)((ivp) = (struct iovec *)malloc((u_long)(cnt * sizeof (struct iovec)), (M_TEMP), (0x0002))); | |||
729 | uiop->uio_iov = iv = ivp; | |||
730 | uiop->uio_iovcnt = cnt; | |||
731 | i = mtod(mp, caddr_t)((caddr_t)((mp)->m_data)) + mp->m_len - cp; | |||
732 | len = retlen; | |||
733 | while (len > 0) { | |||
734 | if (mp == NULL((void *)0)) | |||
735 | panic("nfsvno_write"); | |||
736 | if (i > 0) { | |||
737 | i = min(i, len); | |||
738 | ivp->iov_base = cp; | |||
739 | ivp->iov_len = i; | |||
740 | ivp++; | |||
741 | len -= i; | |||
742 | } | |||
743 | mp = mp->m_next; | |||
744 | if (mp) { | |||
745 | i = mp->m_len; | |||
746 | cp = mtod(mp, caddr_t)((caddr_t)((mp)->m_data)); | |||
747 | } | |||
748 | } | |||
749 | ||||
750 | if (stable == NFSWRITE_UNSTABLE0) | |||
751 | ioflags = IO_NODELOCKED0x0008; | |||
752 | else | |||
753 | ioflags = (IO_SYNC0x0080 | IO_NODELOCKED0x0008); | |||
754 | uiop->uio_resid = retlen; | |||
755 | uiop->uio_rw = UIO_WRITE; | |||
756 | uiop->uio_segflg = UIO_SYSSPACE; | |||
757 | NFSUIOPROC(uiop, p)((uiop)->uio_td = ((void *)0)); | |||
758 | uiop->uio_offset = off; | |||
759 | nh = nfsrv_sequential_heuristic(uiop, vp); | |||
760 | ioflags |= nh->nh_seqcount << IO_SEQSHIFT16; | |||
761 | error = VOP_WRITE(vp, uiop, ioflags, cred); | |||
762 | if (error == 0) | |||
763 | nh->nh_nextoff = uiop->uio_offset; | |||
764 | FREE((caddr_t)iv, M_TEMP)free(((caddr_t)iv), (M_TEMP)); | |||
765 | ||||
766 | NFSEXITCODE(error); | |||
767 | return (error); | |||
768 | } | |||
769 | ||||
770 | /* | |||
771 | * Common code for creating a regular file (plus special files for V2). | |||
772 | */ | |||
773 | int | |||
774 | nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp, | |||
775 | struct vnode **vpp, struct nfsvattr *nvap, int *exclusive_flagp, | |||
776 | int32_t *cverf, NFSDEV_Tdev_t rdev, struct thread *p, struct nfsexstuff *exp) | |||
777 | { | |||
778 | u_quad_t tempsize; | |||
779 | int error; | |||
780 | ||||
781 | error = nd->nd_repstat; | |||
782 | if (!error && ndp->ni_vp == NULL((void *)0)) { | |||
783 | if (nvap->na_typena_vattr.va_type == VREG || nvap->na_typena_vattr.va_type == VSOCK) { | |||
784 | vrele(ndp->ni_startdir); | |||
785 | error = VOP_CREATE(ndp->ni_dvp, | |||
786 | &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr); | |||
787 | vput(ndp->ni_dvp); | |||
788 | nfsvno_relpathbuf(ndp); | |||
789 | if (!error) { | |||
790 | if (*exclusive_flagp) { | |||
791 | *exclusive_flagp = 0; | |||
792 | NFSVNO_ATTRINIT(nvap)((*(&((nvap)->na_vattr)) = va_null)); | |||
793 | nvap->na_atimena_vattr.va_atime.tv_sec = cverf[0]; | |||
794 | nvap->na_atimena_vattr.va_atime.tv_nsec = cverf[1]; | |||
795 | error = VOP_SETATTR(ndp->ni_vp, | |||
796 | &nvap->na_vattr, nd->nd_cred); | |||
797 | if (error != 0) { | |||
798 | vput(ndp->ni_vp); | |||
799 | ndp->ni_vp = NULL((void *)0); | |||
800 | error = NFSERR_NOTSUPP10004; | |||
801 | } | |||
802 | } | |||
803 | } | |||
804 | /* | |||
805 | * NFS V2 Only. nfsrvd_mknod() does this for V3. | |||
806 | * (This implies, just get out on an error.) | |||
807 | */ | |||
808 | } else if (nvap->na_typena_vattr.va_type == VCHR || nvap->na_typena_vattr.va_type == VBLK || | |||
809 | nvap->na_typena_vattr.va_type == VFIFO) { | |||
810 | if (nvap->na_typena_vattr.va_type == VCHR && rdev == 0xffffffff) | |||
811 | nvap->na_typena_vattr.va_type = VFIFO; | |||
812 | if (nvap->na_typena_vattr.va_type != VFIFO && | |||
813 | (error = priv_check_cred(nd->nd_cred, | |||
814 | PRIV_VFS_MKNOD_DEV331, 0))) { | |||
815 | vrele(ndp->ni_startdir); | |||
816 | nfsvno_relpathbuf(ndp); | |||
817 | vput(ndp->ni_dvp); | |||
818 | goto out; | |||
819 | } | |||
820 | nvap->na_rdevna_vattr.va_rdev = rdev; | |||
821 | error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp, | |||
822 | &ndp->ni_cnd, &nvap->na_vattr); | |||
823 | vput(ndp->ni_dvp); | |||
824 | nfsvno_relpathbuf(ndp); | |||
825 | vrele(ndp->ni_startdir); | |||
826 | if (error) | |||
827 | goto out; | |||
828 | } else { | |||
829 | vrele(ndp->ni_startdir); | |||
830 | nfsvno_relpathbuf(ndp); | |||
831 | vput(ndp->ni_dvp); | |||
832 | error = ENXIO6; | |||
833 | goto out; | |||
834 | } | |||
835 | *vpp = ndp->ni_vp; | |||
836 | } else { | |||
837 | /* | |||
838 | * Handle cases where error is already set and/or | |||
839 | * the file exists. | |||
840 | * 1 - clean up the lookup | |||
841 | * 2 - iff !error and na_size set, truncate it | |||
842 | */ | |||
843 | vrele(ndp->ni_startdir); | |||
844 | nfsvno_relpathbuf(ndp); | |||
845 | *vpp = ndp->ni_vp; | |||
846 | if (ndp->ni_dvp == *vpp) | |||
847 | vrele(ndp->ni_dvp); | |||
848 | else | |||
849 | vput(ndp->ni_dvp); | |||
850 | if (!error && nvap->na_sizena_vattr.va_size != VNOVAL(-1)) { | |||
851 | error = nfsvno_accchk(*vpp, VWRITE000000000200, | |||
852 | nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE0, | |||
853 | NFSACCCHK_VPISLOCKED1, NULL((void *)0)); | |||
854 | if (!error) { | |||
855 | tempsize = nvap->na_sizena_vattr.va_size; | |||
856 | NFSVNO_ATTRINIT(nvap)((*(&((nvap)->na_vattr)) = va_null)); | |||
857 | nvap->na_sizena_vattr.va_size = tempsize; | |||
858 | error = VOP_SETATTR(*vpp, | |||
859 | &nvap->na_vattr, nd->nd_cred); | |||
860 | } | |||
861 | } | |||
862 | if (error) | |||
863 | vput(*vpp); | |||
864 | } | |||
865 | ||||
866 | out: | |||
867 | NFSEXITCODE(error); | |||
868 | return (error); | |||
869 | } | |||
870 | ||||
871 | /* | |||
872 | * Do a mknod vnode op. | |||
873 | */ | |||
874 | int | |||
875 | nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred, | |||
876 | struct thread *p) | |||
877 | { | |||
878 | int error = 0; | |||
879 | enum vtype vtyp; | |||
880 | ||||
881 | vtyp = nvap->na_typena_vattr.va_type; | |||
882 | /* | |||
883 | * Iff doesn't exist, create it. | |||
884 | */ | |||
885 | if (ndp->ni_vp) { | |||
886 | vrele(ndp->ni_startdir); | |||
887 | nfsvno_relpathbuf(ndp); | |||
888 | vput(ndp->ni_dvp); | |||
889 | vrele(ndp->ni_vp); | |||
890 | error = EEXIST17; | |||
891 | goto out; | |||
892 | } | |||
893 | if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) { | |||
894 | vrele(ndp->ni_startdir); | |||
895 | nfsvno_relpathbuf(ndp); | |||
896 | vput(ndp->ni_dvp); | |||
897 | error = NFSERR_BADTYPE10007; | |||
898 | goto out; | |||
899 | } | |||
900 | if (vtyp == VSOCK) { | |||
901 | vrele(ndp->ni_startdir); | |||
902 | error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, | |||
903 | &ndp->ni_cnd, &nvap->na_vattr); | |||
904 | vput(ndp->ni_dvp); | |||
905 | nfsvno_relpathbuf(ndp); | |||
906 | } else { | |||
907 | if (nvap->na_typena_vattr.va_type != VFIFO && | |||
908 | (error = priv_check_cred(cred, PRIV_VFS_MKNOD_DEV331, 0))) { | |||
909 | vrele(ndp->ni_startdir); | |||
910 | nfsvno_relpathbuf(ndp); | |||
911 | vput(ndp->ni_dvp); | |||
912 | goto out; | |||
913 | } | |||
914 | error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp, | |||
915 | &ndp->ni_cnd, &nvap->na_vattr); | |||
916 | vput(ndp->ni_dvp); | |||
917 | nfsvno_relpathbuf(ndp); | |||
918 | vrele(ndp->ni_startdir); | |||
919 | /* | |||
920 | * Since VOP_MKNOD returns the ni_vp, I can't | |||
921 | * see any reason to do the lookup. | |||
922 | */ | |||
923 | } | |||
924 | ||||
925 | out: | |||
926 | NFSEXITCODE(error); | |||
927 | return (error); | |||
928 | } | |||
929 | ||||
930 | /* | |||
931 | * Mkdir vnode op. | |||
932 | */ | |||
933 | int | |||
934 | nfsvno_mkdir(struct nameidata *ndp, struct nfsvattr *nvap, uid_t saved_uid, | |||
935 | struct ucred *cred, struct thread *p, struct nfsexstuff *exp) | |||
936 | { | |||
937 | int error = 0; | |||
938 | ||||
939 | if (ndp->ni_vp != NULL((void *)0)) { | |||
940 | if (ndp->ni_dvp == ndp->ni_vp) | |||
941 | vrele(ndp->ni_dvp); | |||
942 | else | |||
943 | vput(ndp->ni_dvp); | |||
944 | vrele(ndp->ni_vp); | |||
945 | nfsvno_relpathbuf(ndp); | |||
946 | error = EEXIST17; | |||
947 | goto out; | |||
948 | } | |||
949 | error = VOP_MKDIR(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd, | |||
950 | &nvap->na_vattr); | |||
951 | vput(ndp->ni_dvp); | |||
952 | nfsvno_relpathbuf(ndp); | |||
953 | ||||
954 | out: | |||
955 | NFSEXITCODE(error); | |||
956 | return (error); | |||
957 | } | |||
958 | ||||
959 | /* | |||
960 | * symlink vnode op. | |||
961 | */ | |||
962 | int | |||
963 | nfsvno_symlink(struct nameidata *ndp, struct nfsvattr *nvap, char *pathcp, | |||
964 | int pathlen, int not_v2, uid_t saved_uid, struct ucred *cred, struct thread *p, | |||
965 | struct nfsexstuff *exp) | |||
966 | { | |||
967 | int error = 0; | |||
968 | ||||
969 | if (ndp->ni_vp) { | |||
970 | vrele(ndp->ni_startdir); | |||
971 | nfsvno_relpathbuf(ndp); | |||
972 | if (ndp->ni_dvp == ndp->ni_vp) | |||
973 | vrele(ndp->ni_dvp); | |||
974 | else | |||
975 | vput(ndp->ni_dvp); | |||
976 | vrele(ndp->ni_vp); | |||
977 | error = EEXIST17; | |||
978 | goto out; | |||
979 | } | |||
980 | ||||
981 | error = VOP_SYMLINK(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd, | |||
982 | &nvap->na_vattr, pathcp); | |||
983 | vput(ndp->ni_dvp); | |||
984 | vrele(ndp->ni_startdir); | |||
985 | nfsvno_relpathbuf(ndp); | |||
986 | /* | |||
987 | * Although FreeBSD still had the lookup code in | |||
988 | * it for 7/current, there doesn't seem to be any | |||
989 | * point, since VOP_SYMLINK() returns the ni_vp. | |||
990 | * Just vput it for v2. | |||
991 | */ | |||
992 | if (!not_v2 && !error) | |||
993 | vput(ndp->ni_vp); | |||
994 | ||||
995 | out: | |||
996 | NFSEXITCODE(error); | |||
997 | return (error); | |||
998 | } | |||
999 | ||||
1000 | /* | |||
1001 | * Parse symbolic link arguments. | |||
1002 | * This function has an ugly side effect. It will MALLOC() an area for | |||
1003 | * the symlink and set iov_base to point to it, only if it succeeds. | |||
1004 | * So, if it returns with uiop->uio_iov->iov_base != NULL, that must | |||
1005 | * be FREE'd later. | |||
1006 | */ | |||
1007 | int | |||
1008 | nfsvno_getsymlink(struct nfsrv_descript *nd, struct nfsvattr *nvap, | |||
1009 | struct thread *p, char **pathcpp, int *lenp) | |||
1010 | { | |||
1011 | u_int32_t *tl; | |||
1012 | char *pathcp = NULL((void *)0); | |||
1013 | int error = 0, len; | |||
1014 | struct nfsv2_sattr *sp; | |||
1015 | ||||
1016 | *pathcpp = NULL((void *)0); | |||
1017 | *lenp = 0; | |||
1018 | if ((nd->nd_flag & ND_NFSV30x00000008) && | |||
1019 | (error = nfsrv_sattr(nd, NULL((void *)0), nvap, NULL((void *)0), NULL((void *)0), p))) | |||
1020 | goto nfsmout; | |||
1021 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
1022 | len = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
1023 | if (len > NFS_MAXPATHLEN1024 || len <= 0) { | |||
1024 | error = EBADRPC72; | |||
1025 | goto nfsmout; | |||
1026 | } | |||
1027 | MALLOC(pathcp, caddr_t, len + 1, M_TEMP, M_WAITOK)((pathcp) = (caddr_t)malloc((u_long)(len + 1), (M_TEMP), (0x0002 ))); | |||
1028 | error = nfsrv_mtostr(nd, pathcp, len); | |||
1029 | if (error) | |||
1030 | goto nfsmout; | |||
1031 | if (nd->nd_flag & ND_NFSV20x00000004) { | |||
1032 | NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR)do { (sp) = (struct nfsv2_sattr *)nfsm_dissect(nd, (32)); if ( (sp) == ((void *)0)) { error = 72; goto nfsmout; } } while (0 ); | |||
1033 | nvap->na_modena_vattr.va_mode = fxdr_unsigned(u_int16_t, sp->sa_mode)((u_int16_t)(__builtin_constant_p((int32_t)(sp->sa_mode)) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)(sp->sa_mode))) & 0xffff) ? (__uint16_t)((( __uint16_t)(((__uint32_t)((int32_t)(sp->sa_mode))) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(sp-> sa_mode))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )((int32_t)(sp->sa_mode))) & 0xffff))) << 16) | ( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(sp-> sa_mode))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)(sp->sa_mode))) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(sp->sa_mode))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp->sa_mode))) >> 16)))) : __bswap32_var((int32_t)(sp->sa_mode)))); | |||
1034 | } | |||
1035 | *pathcpp = pathcp; | |||
1036 | *lenp = len; | |||
1037 | NFSEXITCODE2(0, nd); | |||
1038 | return (0); | |||
1039 | nfsmout: | |||
1040 | if (pathcp) | |||
1041 | free(pathcp, M_TEMP); | |||
1042 | NFSEXITCODE2(error, nd); | |||
1043 | return (error); | |||
1044 | } | |||
1045 | ||||
1046 | /* | |||
1047 | * Remove a non-directory object. | |||
1048 | */ | |||
1049 | int | |||
1050 | nfsvno_removesub(struct nameidata *ndp, int is_v4, struct ucred *cred, | |||
1051 | struct thread *p, struct nfsexstuff *exp) | |||
1052 | { | |||
1053 | struct vnode *vp; | |||
1054 | int error = 0; | |||
1055 | ||||
1056 | vp = ndp->ni_vp; | |||
1057 | if (vp->v_type == VDIR) | |||
1058 | error = NFSERR_ISDIR21; | |||
1059 | else if (is_v4) | |||
1060 | error = nfsrv_checkremove(vp, 1, p); | |||
1061 | if (!error) | |||
1062 | error = VOP_REMOVE(ndp->ni_dvp, vp, &ndp->ni_cnd); | |||
1063 | if (ndp->ni_dvp == vp) | |||
1064 | vrele(ndp->ni_dvp); | |||
1065 | else | |||
1066 | vput(ndp->ni_dvp); | |||
1067 | vput(vp); | |||
1068 | if ((ndp->ni_cnd.cn_flags & SAVENAME0x00000800) != 0) | |||
1069 | nfsvno_relpathbuf(ndp); | |||
1070 | NFSEXITCODE(error); | |||
1071 | return (error); | |||
1072 | } | |||
1073 | ||||
1074 | /* | |||
1075 | * Remove a directory. | |||
1076 | */ | |||
1077 | int | |||
1078 | nfsvno_rmdirsub(struct nameidata *ndp, int is_v4, struct ucred *cred, | |||
1079 | struct thread *p, struct nfsexstuff *exp) | |||
1080 | { | |||
1081 | struct vnode *vp; | |||
1082 | int error = 0; | |||
1083 | ||||
1084 | vp = ndp->ni_vp; | |||
1085 | if (vp->v_type != VDIR) { | |||
1086 | error = ENOTDIR20; | |||
1087 | goto out; | |||
1088 | } | |||
1089 | /* | |||
1090 | * No rmdir "." please. | |||
1091 | */ | |||
1092 | if (ndp->ni_dvp == vp) { | |||
1093 | error = EINVAL22; | |||
1094 | goto out; | |||
1095 | } | |||
1096 | /* | |||
1097 | * The root of a mounted filesystem cannot be deleted. | |||
1098 | */ | |||
1099 | if (vp->v_vflag & VV_ROOT0x0001) | |||
1100 | error = EBUSY16; | |||
1101 | out: | |||
1102 | if (!error) | |||
1103 | error = VOP_RMDIR(ndp->ni_dvp, vp, &ndp->ni_cnd); | |||
1104 | if (ndp->ni_dvp == vp) | |||
1105 | vrele(ndp->ni_dvp); | |||
1106 | else | |||
1107 | vput(ndp->ni_dvp); | |||
1108 | vput(vp); | |||
1109 | if ((ndp->ni_cnd.cn_flags & SAVENAME0x00000800) != 0) | |||
1110 | nfsvno_relpathbuf(ndp); | |||
1111 | NFSEXITCODE(error); | |||
1112 | return (error); | |||
1113 | } | |||
1114 | ||||
1115 | /* | |||
1116 | * Rename vnode op. | |||
1117 | */ | |||
1118 | int | |||
1119 | nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp, | |||
1120 | u_int32_t ndstat, u_int32_t ndflag, struct ucred *cred, struct thread *p) | |||
1121 | { | |||
1122 | struct vnode *fvp, *tvp, *tdvp; | |||
1123 | int error = 0; | |||
1124 | ||||
1125 | fvp = fromndp->ni_vp; | |||
1126 | if (ndstat) { | |||
1127 | vrele(fromndp->ni_dvp); | |||
1128 | vrele(fvp); | |||
1129 | error = ndstat; | |||
1130 | goto out1; | |||
1131 | } | |||
1132 | tdvp = tondp->ni_dvp; | |||
1133 | tvp = tondp->ni_vp; | |||
1134 | if (tvp != NULL((void *)0)) { | |||
1135 | if (fvp->v_type == VDIR && tvp->v_type != VDIR) { | |||
1136 | error = (ndflag & ND_NFSV20x00000004) ? EISDIR21 : EEXIST17; | |||
1137 | goto out; | |||
1138 | } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) { | |||
1139 | error = (ndflag & ND_NFSV20x00000004) ? ENOTDIR20 : EEXIST17; | |||
1140 | goto out; | |||
1141 | } | |||
1142 | if (tvp->v_type == VDIR && tvp->v_mountedherev_un.vu_mount) { | |||
1143 | error = (ndflag & ND_NFSV20x00000004) ? ENOTEMPTY66 : EXDEV18; | |||
1144 | goto out; | |||
1145 | } | |||
1146 | ||||
1147 | /* | |||
1148 | * A rename to '.' or '..' results in a prematurely | |||
1149 | * unlocked vnode on FreeBSD5, so I'm just going to fail that | |||
1150 | * here. | |||
1151 | */ | |||
1152 | if ((tondp->ni_cnd.cn_namelen == 1 && | |||
1153 | tondp->ni_cnd.cn_nameptr[0] == '.') || | |||
1154 | (tondp->ni_cnd.cn_namelen == 2 && | |||
1155 | tondp->ni_cnd.cn_nameptr[0] == '.' && | |||
1156 | tondp->ni_cnd.cn_nameptr[1] == '.')) { | |||
1157 | error = EINVAL22; | |||
1158 | goto out; | |||
1159 | } | |||
1160 | } | |||
1161 | if (fvp->v_type == VDIR && fvp->v_mountedherev_un.vu_mount) { | |||
1162 | error = (ndflag & ND_NFSV20x00000004) ? ENOTEMPTY66 : EXDEV18; | |||
1163 | goto out; | |||
1164 | } | |||
1165 | if (fvp->v_mount != tdvp->v_mount) { | |||
1166 | error = (ndflag & ND_NFSV20x00000004) ? ENOTEMPTY66 : EXDEV18; | |||
1167 | goto out; | |||
1168 | } | |||
1169 | if (fvp == tdvp) { | |||
1170 | error = (ndflag & ND_NFSV20x00000004) ? ENOTEMPTY66 : EINVAL22; | |||
1171 | goto out; | |||
1172 | } | |||
1173 | if (fvp == tvp) { | |||
1174 | /* | |||
1175 | * If source and destination are the same, there is nothing to | |||
1176 | * do. Set error to -1 to indicate this. | |||
1177 | */ | |||
1178 | error = -1; | |||
1179 | goto out; | |||
1180 | } | |||
1181 | if (ndflag & ND_NFSV40x00000010) { | |||
1182 | if (NFSVOPLOCK(fvp, LK_EXCLUSIVE)_vn_lock((fvp), (0x080000), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1182) == 0) { | |||
1183 | error = nfsrv_checkremove(fvp, 0, p); | |||
1184 | NFSVOPUNLOCK(fvp, 0)VOP_UNLOCK((fvp), (0)); | |||
1185 | } else | |||
1186 | error = EPERM1; | |||
1187 | if (tvp && !error) | |||
1188 | error = nfsrv_checkremove(tvp, 1, p); | |||
1189 | } else { | |||
1190 | /* | |||
1191 | * For NFSv2 and NFSv3, try to get rid of the delegation, so | |||
1192 | * that the NFSv4 client won't be confused by the rename. | |||
1193 | * Since nfsd_recalldelegation() can only be called on an | |||
1194 | * unlocked vnode at this point and fvp is the file that will | |||
1195 | * still exist after the rename, just do fvp. | |||
1196 | */ | |||
1197 | nfsd_recalldelegation(fvp, p); | |||
1198 | } | |||
1199 | out: | |||
1200 | if (!error) { | |||
1201 | error = VOP_RENAME(fromndp->ni_dvp, fromndp->ni_vp, | |||
1202 | &fromndp->ni_cnd, tondp->ni_dvp, tondp->ni_vp, | |||
1203 | &tondp->ni_cnd); | |||
1204 | } else { | |||
1205 | if (tdvp == tvp) | |||
1206 | vrele(tdvp); | |||
1207 | else | |||
1208 | vput(tdvp); | |||
1209 | if (tvp) | |||
1210 | vput(tvp); | |||
1211 | vrele(fromndp->ni_dvp); | |||
1212 | vrele(fvp); | |||
1213 | if (error == -1) | |||
1214 | error = 0; | |||
1215 | } | |||
1216 | vrele(tondp->ni_startdir); | |||
1217 | nfsvno_relpathbuf(tondp); | |||
1218 | out1: | |||
1219 | vrele(fromndp->ni_startdir); | |||
1220 | nfsvno_relpathbuf(fromndp); | |||
1221 | NFSEXITCODE(error); | |||
1222 | return (error); | |||
1223 | } | |||
1224 | ||||
1225 | /* | |||
1226 | * Link vnode op. | |||
1227 | */ | |||
1228 | int | |||
1229 | nfsvno_link(struct nameidata *ndp, struct vnode *vp, struct ucred *cred, | |||
1230 | struct thread *p, struct nfsexstuff *exp) | |||
1231 | { | |||
1232 | struct vnode *xp; | |||
1233 | int error = 0; | |||
1234 | ||||
1235 | xp = ndp->ni_vp; | |||
1236 | if (xp != NULL((void *)0)) { | |||
1237 | error = EEXIST17; | |||
1238 | } else { | |||
1239 | xp = ndp->ni_dvp; | |||
1240 | if (vp->v_mount != xp->v_mount) | |||
1241 | error = EXDEV18; | |||
1242 | } | |||
1243 | if (!error) { | |||
1244 | NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY)_vn_lock((vp), (0x080000 | 0x000400), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1244); | |||
1245 | if ((vp->v_iflag & VI_DOOMED0x0080) == 0) | |||
1246 | error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd); | |||
1247 | else | |||
1248 | error = EPERM1; | |||
1249 | if (ndp->ni_dvp == vp) | |||
1250 | vrele(ndp->ni_dvp); | |||
1251 | else | |||
1252 | vput(ndp->ni_dvp); | |||
1253 | NFSVOPUNLOCK(vp, 0)VOP_UNLOCK((vp), (0)); | |||
1254 | } else { | |||
1255 | if (ndp->ni_dvp == ndp->ni_vp) | |||
1256 | vrele(ndp->ni_dvp); | |||
1257 | else | |||
1258 | vput(ndp->ni_dvp); | |||
1259 | if (ndp->ni_vp) | |||
1260 | vrele(ndp->ni_vp); | |||
1261 | } | |||
1262 | nfsvno_relpathbuf(ndp); | |||
1263 | NFSEXITCODE(error); | |||
1264 | return (error); | |||
1265 | } | |||
1266 | ||||
1267 | /* | |||
1268 | * Do the fsync() appropriate for the commit. | |||
1269 | */ | |||
1270 | int | |||
1271 | nfsvno_fsync(struct vnode *vp, u_int64_t off, int cnt, struct ucred *cred, | |||
1272 | struct thread *td) | |||
1273 | { | |||
1274 | int error = 0; | |||
1275 | ||||
1276 | /* | |||
1277 | * RFC 1813 3.3.21: if count is 0, a flush from offset to the end of | |||
1278 | * file is done. At this time VOP_FSYNC does not accept offset and | |||
1279 | * byte count parameters so call VOP_FSYNC the whole file for now. | |||
1280 | * The same is true for NFSv4: RFC 3530 Sec. 14.2.3. | |||
1281 | * File systems that do not use the buffer cache (as indicated | |||
1282 | * by MNTK_USES_BCACHE not being set) must use VOP_FSYNC(). | |||
1283 | */ | |||
1284 | if (cnt == 0 || cnt > MAX_COMMIT_COUNT(1024 * 1024) || | |||
1285 | (vp->v_mount->mnt_kern_flag & MNTK_USES_BCACHE0x00004000) == 0) { | |||
1286 | /* | |||
1287 | * Give up and do the whole thing | |||
1288 | */ | |||
1289 | if (vp->v_objectv_bufobj.bo_object && | |||
1290 | (vp->v_objectv_bufobj.bo_object->flags & OBJ_MIGHTBEDIRTY0x0100)) { | |||
1291 | VM_OBJECT_WLOCK(vp->v_object)_rw_wlock_cookie(&((&(vp->v_bufobj.bo_object)-> lock))->rw_lock, "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1291); | |||
1292 | vm_object_page_clean(vp->v_objectv_bufobj.bo_object, 0, 0, OBJPC_SYNC0x1); | |||
1293 | VM_OBJECT_WUNLOCK(vp->v_object)_rw_wunlock_cookie(&((&(vp->v_bufobj.bo_object)-> lock))->rw_lock, "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1293); | |||
1294 | } | |||
1295 | error = VOP_FSYNC(vp, MNT_WAIT1, td); | |||
1296 | } else { | |||
1297 | /* | |||
1298 | * Locate and synchronously write any buffers that fall | |||
1299 | * into the requested range. Note: we are assuming that | |||
1300 | * f_iosize is a power of 2. | |||
1301 | */ | |||
1302 | int iosize = vp->v_mount->mnt_stat.f_iosize; | |||
1303 | int iomask = iosize - 1; | |||
1304 | struct bufobj *bo; | |||
1305 | daddr_t lblkno; | |||
1306 | ||||
1307 | /* | |||
1308 | * Align to iosize boundary, super-align to page boundary. | |||
1309 | */ | |||
1310 | if (off & iomask) { | |||
1311 | cnt += off & iomask; | |||
1312 | off &= ~(u_quad_t)iomask; | |||
1313 | } | |||
1314 | if (off & PAGE_MASK((1<<12)-1)) { | |||
1315 | cnt += off & PAGE_MASK((1<<12)-1); | |||
1316 | off &= ~(u_quad_t)PAGE_MASK((1<<12)-1); | |||
1317 | } | |||
1318 | lblkno = off / iosize; | |||
1319 | ||||
1320 | if (vp->v_objectv_bufobj.bo_object && | |||
1321 | (vp->v_objectv_bufobj.bo_object->flags & OBJ_MIGHTBEDIRTY0x0100)) { | |||
1322 | VM_OBJECT_WLOCK(vp->v_object)_rw_wlock_cookie(&((&(vp->v_bufobj.bo_object)-> lock))->rw_lock, "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1322); | |||
1323 | vm_object_page_clean(vp->v_objectv_bufobj.bo_object, off, off + cnt, | |||
1324 | OBJPC_SYNC0x1); | |||
1325 | VM_OBJECT_WUNLOCK(vp->v_object)_rw_wunlock_cookie(&((&(vp->v_bufobj.bo_object)-> lock))->rw_lock, "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1325); | |||
1326 | } | |||
1327 | ||||
1328 | bo = &vp->v_bufobj; | |||
1329 | BO_LOCK(bo)_rw_wlock_cookie(&(((&((bo))->bo_lock)))->rw_lock , "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1329); | |||
1330 | while (cnt > 0) { | |||
1331 | struct buf *bp; | |||
1332 | ||||
1333 | /* | |||
1334 | * If we have a buffer and it is marked B_DELWRI we | |||
1335 | * have to lock and write it. Otherwise the prior | |||
1336 | * write is assumed to have already been committed. | |||
1337 | * | |||
1338 | * gbincore() can return invalid buffers now so we | |||
1339 | * have to check that bit as well (though B_DELWRI | |||
1340 | * should not be set if B_INVAL is set there could be | |||
1341 | * a race here since we haven't locked the buffer). | |||
1342 | */ | |||
1343 | if ((bp = gbincore(&vp->v_bufobj, lblkno)) != NULL((void *)0)) { | |||
1344 | if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL |_lockmgr_args_rw(&(bp)->b_lock, (0x080000 | 0x000800 | 0x000100), ((&(bo)->bo_lock)), (((void *)0)), (0), (0 ), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1345) | |||
1345 | LK_INTERLOCK, BO_LOCKPTR(bo))_lockmgr_args_rw(&(bp)->b_lock, (0x080000 | 0x000800 | 0x000100), ((&(bo)->bo_lock)), (((void *)0)), (0), (0 ), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1345) == ENOLCK77) { | |||
1346 | BO_LOCK(bo)_rw_wlock_cookie(&(((&((bo))->bo_lock)))->rw_lock , "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1346); | |||
1347 | continue; /* retry */ | |||
1348 | } | |||
1349 | if ((bp->b_flags & (B_DELWRI0x00000080|B_INVAL0x00002000)) == | |||
1350 | B_DELWRI0x00000080) { | |||
1351 | bremfree(bp); | |||
1352 | bp->b_flags &= ~B_ASYNC0x00000004; | |||
1353 | bwrite(bp); | |||
1354 | ++nfs_commit_miss; | |||
1355 | } else | |||
1356 | BUF_UNLOCK(bp)do { do { } while (0); (void)_lockmgr_args(&(bp)->b_lock , 0x100000, ((void *)0), (((void *)0)), (0), (0), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1356); } while (0); | |||
1357 | BO_LOCK(bo)_rw_wlock_cookie(&(((&((bo))->bo_lock)))->rw_lock , "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1357); | |||
1358 | } | |||
1359 | ++nfs_commit_blks; | |||
1360 | if (cnt < iosize) | |||
1361 | break; | |||
1362 | cnt -= iosize; | |||
1363 | ++lblkno; | |||
1364 | } | |||
1365 | BO_UNLOCK(bo)_rw_wunlock_cookie(&(((&((bo))->bo_lock)))->rw_lock , "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1365); | |||
1366 | } | |||
1367 | NFSEXITCODE(error); | |||
1368 | return (error); | |||
1369 | } | |||
1370 | ||||
1371 | /* | |||
1372 | * Statfs vnode op. | |||
1373 | */ | |||
1374 | int | |||
1375 | nfsvno_statfs(struct vnode *vp, struct statfs *sf) | |||
1376 | { | |||
1377 | int error; | |||
1378 | ||||
1379 | error = VFS_STATFS(vp->v_mount, sf)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( vp->v_mount); _prev_stops = sigdeferstop((mp__ != ((void * )0) && (mp__->mnt_vfc->vfc_flags & 0x01000000 ) != 0) ? 2 : 0);; _rc = __vfs_statfs((vp->v_mount), (sf)) ; sigallowstop(_prev_stops); } while (0); _rc; }); | |||
1380 | if (error == 0) { | |||
1381 | /* | |||
1382 | * Since NFS handles these values as unsigned on the | |||
1383 | * wire, there is no way to represent negative values, | |||
1384 | * so set them to 0. Without this, they will appear | |||
1385 | * to be very large positive values for clients like | |||
1386 | * Solaris10. | |||
1387 | */ | |||
1388 | if (sf->f_bavail < 0) | |||
1389 | sf->f_bavail = 0; | |||
1390 | if (sf->f_ffree < 0) | |||
1391 | sf->f_ffree = 0; | |||
1392 | } | |||
1393 | NFSEXITCODE(error); | |||
1394 | return (error); | |||
1395 | } | |||
1396 | ||||
1397 | /* | |||
1398 | * Do the vnode op stuff for Open. Similar to nfsvno_createsub(), but | |||
1399 | * must handle nfsrv_opencheck() calls after any other access checks. | |||
1400 | */ | |||
1401 | void | |||
1402 | nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp, | |||
1403 | nfsquad_t clientid, nfsv4stateid_t *stateidp, struct nfsstate *stp, | |||
1404 | int *exclusive_flagp, struct nfsvattr *nvap, int32_t *cverf, int create, | |||
1405 | NFSACL_Tstruct acl *aclp, nfsattrbit_t *attrbitp, struct ucred *cred, struct thread *p, | |||
1406 | struct nfsexstuff *exp, struct vnode **vpp) | |||
1407 | { | |||
1408 | struct vnode *vp = NULL((void *)0); | |||
1409 | u_quad_t tempsize; | |||
1410 | struct nfsexstuff nes; | |||
1411 | ||||
1412 | if (ndp->ni_vp == NULL((void *)0)) | |||
1413 | nd->nd_repstat = nfsrv_opencheck(clientid, | |||
1414 | stateidp, stp, NULL((void *)0), nd, p, nd->nd_repstat); | |||
1415 | if (!nd->nd_repstat) { | |||
1416 | if (ndp->ni_vp == NULL((void *)0)) { | |||
1417 | vrele(ndp->ni_startdir); | |||
1418 | nd->nd_repstat = VOP_CREATE(ndp->ni_dvp, | |||
1419 | &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr); | |||
1420 | vput(ndp->ni_dvp); | |||
1421 | nfsvno_relpathbuf(ndp); | |||
1422 | if (!nd->nd_repstat) { | |||
1423 | if (*exclusive_flagp) { | |||
1424 | *exclusive_flagp = 0; | |||
1425 | NFSVNO_ATTRINIT(nvap)((*(&((nvap)->na_vattr)) = va_null)); | |||
1426 | nvap->na_atimena_vattr.va_atime.tv_sec = cverf[0]; | |||
1427 | nvap->na_atimena_vattr.va_atime.tv_nsec = cverf[1]; | |||
1428 | nd->nd_repstat = VOP_SETATTR(ndp->ni_vp, | |||
1429 | &nvap->na_vattr, cred); | |||
1430 | if (nd->nd_repstat != 0) { | |||
1431 | vput(ndp->ni_vp); | |||
1432 | ndp->ni_vp = NULL((void *)0); | |||
1433 | nd->nd_repstat = NFSERR_NOTSUPP10004; | |||
1434 | } | |||
1435 | } else { | |||
1436 | nfsrv_fixattr(nd, ndp->ni_vp, nvap, | |||
1437 | aclp, p, attrbitp, exp); | |||
1438 | } | |||
1439 | } | |||
1440 | vp = ndp->ni_vp; | |||
1441 | } else { | |||
1442 | if (ndp->ni_startdir) | |||
1443 | vrele(ndp->ni_startdir); | |||
1444 | nfsvno_relpathbuf(ndp); | |||
1445 | vp = ndp->ni_vp; | |||
1446 | if (create == NFSV4OPEN_CREATE1) { | |||
1447 | if (ndp->ni_dvp == vp) | |||
1448 | vrele(ndp->ni_dvp); | |||
1449 | else | |||
1450 | vput(ndp->ni_dvp); | |||
1451 | } | |||
1452 | if (NFSVNO_ISSETSIZE(nvap)((nvap)->na_vattr.va_size != (-1)) && vp->v_type == VREG) { | |||
1453 | if (ndp->ni_cnd.cn_flags & RDONLY0x00000200) | |||
1454 | NFSVNO_SETEXRDONLY(&nes)((&nes)->nes_exflag = (0x0000000000000100ULL|0x0000000000000080ULL )); | |||
1455 | else | |||
1456 | NFSVNO_EXINIT(&nes)((&nes)->nes_exflag = 0); | |||
1457 | nd->nd_repstat = nfsvno_accchk(vp, | |||
1458 | VWRITE000000000200, cred, &nes, p, | |||
1459 | NFSACCCHK_NOOVERRIDE0, | |||
1460 | NFSACCCHK_VPISLOCKED1, NULL((void *)0)); | |||
1461 | nd->nd_repstat = nfsrv_opencheck(clientid, | |||
1462 | stateidp, stp, vp, nd, p, nd->nd_repstat); | |||
1463 | if (!nd->nd_repstat) { | |||
1464 | tempsize = nvap->na_sizena_vattr.va_size; | |||
1465 | NFSVNO_ATTRINIT(nvap)((*(&((nvap)->na_vattr)) = va_null)); | |||
1466 | nvap->na_sizena_vattr.va_size = tempsize; | |||
1467 | nd->nd_repstat = VOP_SETATTR(vp, | |||
1468 | &nvap->na_vattr, cred); | |||
1469 | } | |||
1470 | } else if (vp->v_type == VREG) { | |||
1471 | nd->nd_repstat = nfsrv_opencheck(clientid, | |||
1472 | stateidp, stp, vp, nd, p, nd->nd_repstat); | |||
1473 | } | |||
1474 | } | |||
1475 | } else { | |||
1476 | if (ndp->ni_cnd.cn_flags & HASBUF0x00000400) | |||
1477 | nfsvno_relpathbuf(ndp); | |||
1478 | if (ndp->ni_startdir && create == NFSV4OPEN_CREATE1) { | |||
1479 | vrele(ndp->ni_startdir); | |||
1480 | if (ndp->ni_dvp == ndp->ni_vp) | |||
1481 | vrele(ndp->ni_dvp); | |||
1482 | else | |||
1483 | vput(ndp->ni_dvp); | |||
1484 | if (ndp->ni_vp) | |||
1485 | vput(ndp->ni_vp); | |||
1486 | } | |||
1487 | } | |||
1488 | *vpp = vp; | |||
1489 | ||||
1490 | NFSEXITCODE2(0, nd); | |||
1491 | } | |||
1492 | ||||
1493 | /* | |||
1494 | * Updates the file rev and sets the mtime and ctime | |||
1495 | * to the current clock time, returning the va_filerev and va_Xtime | |||
1496 | * values. | |||
1497 | * Return ESTALE to indicate the vnode is VI_DOOMED. | |||
1498 | */ | |||
1499 | int | |||
1500 | nfsvno_updfilerev(struct vnode *vp, struct nfsvattr *nvap, | |||
1501 | struct ucred *cred, struct thread *p) | |||
1502 | { | |||
1503 | struct vattr va; | |||
1504 | ||||
1505 | VATTR_NULL(&va)(*(&va) = va_null); | |||
1506 | vfs_timestamp(&va.va_mtime); | |||
1507 | if (NFSVOPISLOCKED(vp)VOP_ISLOCKED((vp)) != LK_EXCLUSIVE0x080000) { | |||
1508 | NFSVOPLOCK(vp, LK_UPGRADE | LK_RETRY)_vn_lock((vp), (0x400000 | 0x000400), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 1508); | |||
1509 | if ((vp->v_iflag & VI_DOOMED0x0080) != 0) | |||
1510 | return (ESTALE70); | |||
1511 | } | |||
1512 | (void) VOP_SETATTR(vp, &va, cred); | |||
1513 | (void) nfsvno_getattr(vp, nvap, cred, p, 1); | |||
1514 | return (0); | |||
1515 | } | |||
1516 | ||||
1517 | /* | |||
1518 | * Glue routine to nfsv4_fillattr(). | |||
1519 | */ | |||
1520 | int | |||
1521 | nfsvno_fillattr(struct nfsrv_descript *nd, struct mount *mp, struct vnode *vp, | |||
1522 | struct nfsvattr *nvap, fhandle_t *fhp, int rderror, nfsattrbit_t *attrbitp, | |||
1523 | struct ucred *cred, struct thread *p, int isdgram, int reterr, | |||
1524 | int supports_nfsv4acls, int at_root, uint64_t mounted_on_fileno) | |||
1525 | { | |||
1526 | int error; | |||
1527 | ||||
1528 | error = nfsv4_fillattr(nd, mp, vp, NULL((void *)0), &nvap->na_vattr, fhp, rderror, | |||
1529 | attrbitp, cred, p, isdgram, reterr, supports_nfsv4acls, at_root, | |||
1530 | mounted_on_fileno); | |||
1531 | NFSEXITCODE2(0, nd); | |||
1532 | return (error); | |||
1533 | } | |||
1534 | ||||
1535 | /* Since the Readdir vnode ops vary, put the entire functions in here. */ | |||
1536 | /* | |||
1537 | * nfs readdir service | |||
1538 | * - mallocs what it thinks is enough to read | |||
1539 | * count rounded up to a multiple of DIRBLKSIZ <= NFS_MAXREADDIR | |||
1540 | * - calls VOP_READDIR() | |||
1541 | * - loops around building the reply | |||
1542 | * if the output generated exceeds count break out of loop | |||
1543 | * The NFSM_CLGET macro is used here so that the reply will be packed | |||
1544 | * tightly in mbuf clusters. | |||
1545 | * - it trims out records with d_fileno == 0 | |||
1546 | * this doesn't matter for Unix clients, but they might confuse clients | |||
1547 | * for other os'. | |||
1548 | * - it trims out records with d_type == DT_WHT | |||
1549 | * these cannot be seen through NFS (unless we extend the protocol) | |||
1550 | * The alternate call nfsrvd_readdirplus() does lookups as well. | |||
1551 | * PS: The NFS protocol spec. does not clarify what the "count" byte | |||
1552 | * argument is a count of.. just name strings and file id's or the | |||
1553 | * entire reply rpc or ... | |||
1554 | * I tried just file name and id sizes and it confused the Sun client, | |||
1555 | * so I am using the full rpc size now. The "paranoia.." comment refers | |||
1556 | * to including the status longwords that are not a part of the dir. | |||
1557 | * "entry" structures, but are in the rpc. | |||
1558 | */ | |||
1559 | int | |||
1560 | nfsrvd_readdir(struct nfsrv_descript *nd, int isdgram, | |||
1561 | struct vnode *vp, struct thread *p, struct nfsexstuff *exp) | |||
1562 | { | |||
1563 | struct dirent *dp; | |||
1564 | u_int32_t *tl; | |||
1565 | int dirlen; | |||
1566 | char *cpos, *cend, *rbuf; | |||
1567 | struct nfsvattr at; | |||
1568 | int nlen, error = 0, getret = 1; | |||
1569 | int siz, cnt, fullsiz, eofflag, ncookies; | |||
1570 | u_int64_t off, toff, verf; | |||
1571 | u_long *cookies = NULL((void *)0), *cookiep; | |||
1572 | struct uio io; | |||
1573 | struct iovec iv; | |||
1574 | int is_ufs; | |||
1575 | ||||
1576 | if (nd->nd_repstat) { | |||
1577 | nfsrv_postopattr(nd, getret, &at); | |||
1578 | goto out; | |||
1579 | } | |||
1580 | if (nd->nd_flag & ND_NFSV20x00000004) { | |||
1581 | NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (2 * 4)); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
1582 | off = fxdr_unsigned(u_quad_t, *tl++)((u_quad_t)(__builtin_constant_p((int32_t)(*tl++)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl++))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)(*tl++))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(*tl++))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*tl++))) & 0xffff ))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)(*tl++))) >> 16) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)(*tl++))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(*tl++))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*tl++))) >> 16)))) : __bswap32_var((int32_t)(*tl++)))); | |||
1583 | } else { | |||
1584 | NFSM_DISSECT(tl, u_int32_t *, 5 * NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (5 * 4)); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
1585 | off = fxdr_hyper(tl)((((u_quad_t)(__builtin_constant_p(((u_int32_t *)(tl))[0]) ? ( ((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t) (((u_int32_t *)(tl))[0])) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *) (tl))[0])) >> 16)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[0])) >> 16)))) : __bswap32_var((( u_int32_t *)(tl))[0]))) << 32) | (u_quad_t)((__builtin_constant_p (((u_int32_t *)(tl))[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl ))[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[1])) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(((u_int32_t *)(tl))[1])) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)))) : __bswap32_var (((u_int32_t *)(tl))[1])))); | |||
1586 | tl += 2; | |||
1587 | verf = fxdr_hyper(tl)((((u_quad_t)(__builtin_constant_p(((u_int32_t *)(tl))[0]) ? ( ((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t) (((u_int32_t *)(tl))[0])) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *) (tl))[0])) >> 16)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[0])) >> 16)))) : __bswap32_var((( u_int32_t *)(tl))[0]))) << 32) | (u_quad_t)((__builtin_constant_p (((u_int32_t *)(tl))[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl ))[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[1])) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(((u_int32_t *)(tl))[1])) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)))) : __bswap32_var (((u_int32_t *)(tl))[1])))); | |||
1588 | tl += 2; | |||
1589 | } | |||
1590 | toff = off; | |||
1591 | cnt = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
1592 | if (cnt > NFS_SRVMAXDATA(nd)(((nd)->nd_flag & (0x00000008 | 0x00000010)) ? (128 * 1024 ) : 8192) || cnt < 0) | |||
1593 | cnt = NFS_SRVMAXDATA(nd)(((nd)->nd_flag & (0x00000008 | 0x00000010)) ? (128 * 1024 ) : 8192); | |||
1594 | siz = ((cnt + DIRBLKSIZ(1<<9) - 1) & ~(DIRBLKSIZ(1<<9) - 1)); | |||
1595 | fullsiz = siz; | |||
1596 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
1597 | nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred, | |||
1598 | p, 1); | |||
1599 | #if 0 | |||
1600 | /* | |||
1601 | * va_filerev is not sufficient as a cookie verifier, | |||
1602 | * since it is not supposed to change when entries are | |||
1603 | * removed/added unless that offset cookies returned to | |||
1604 | * the client are no longer valid. | |||
1605 | */ | |||
1606 | if (!nd->nd_repstat && toff && verf != at.na_filerevna_vattr.va_filerev) | |||
1607 | nd->nd_repstat = NFSERR_BAD_COOKIE10003; | |||
1608 | #endif | |||
1609 | } | |||
1610 | if (!nd->nd_repstat && vp->v_type != VDIR) | |||
1611 | nd->nd_repstat = NFSERR_NOTDIR20; | |||
1612 | if (nd->nd_repstat == 0 && cnt == 0) { | |||
1613 | if (nd->nd_flag & ND_NFSV20x00000004) | |||
1614 | /* NFSv2 does not have NFSERR_TOOSMALL */ | |||
1615 | nd->nd_repstat = EPERM1; | |||
1616 | else | |||
1617 | nd->nd_repstat = NFSERR_TOOSMALL10005; | |||
1618 | } | |||
1619 | if (!nd->nd_repstat) | |||
1620 | nd->nd_repstat = nfsvno_accchk(vp, VEXEC000000000100, | |||
1621 | nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE0, | |||
1622 | NFSACCCHK_VPISLOCKED1, NULL((void *)0)); | |||
1623 | if (nd->nd_repstat) { | |||
1624 | vput(vp); | |||
1625 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
1626 | nfsrv_postopattr(nd, getret, &at); | |||
1627 | goto out; | |||
1628 | } | |||
1629 | is_ufs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "ufs") == 0; | |||
1630 | MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK)((rbuf) = (caddr_t)malloc((u_long)(siz), (M_TEMP), (0x0002))); | |||
1631 | again: | |||
1632 | eofflag = 0; | |||
1633 | if (cookies) { | |||
1634 | free((caddr_t)cookies, M_TEMP); | |||
1635 | cookies = NULL((void *)0); | |||
1636 | } | |||
1637 | ||||
1638 | iv.iov_base = rbuf; | |||
1639 | iv.iov_len = siz; | |||
1640 | io.uio_iov = &iv; | |||
1641 | io.uio_iovcnt = 1; | |||
1642 | io.uio_offset = (off_t)off; | |||
1643 | io.uio_resid = siz; | |||
1644 | io.uio_segflg = UIO_SYSSPACE; | |||
1645 | io.uio_rw = UIO_READ; | |||
1646 | io.uio_td = NULL((void *)0); | |||
1647 | nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies, | |||
1648 | &cookies); | |||
1649 | off = (u_int64_t)io.uio_offset; | |||
1650 | if (io.uio_resid) | |||
1651 | siz -= io.uio_resid; | |||
1652 | ||||
1653 | if (!cookies && !nd->nd_repstat) | |||
1654 | nd->nd_repstat = NFSERR_PERM1; | |||
1655 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
1656 | getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1); | |||
1657 | if (!nd->nd_repstat) | |||
1658 | nd->nd_repstat = getret; | |||
1659 | } | |||
1660 | ||||
1661 | /* | |||
1662 | * Handles the failed cases. nd->nd_repstat == 0 past here. | |||
1663 | */ | |||
1664 | if (nd->nd_repstat) { | |||
1665 | vput(vp); | |||
1666 | free((caddr_t)rbuf, M_TEMP); | |||
1667 | if (cookies) | |||
1668 | free((caddr_t)cookies, M_TEMP); | |||
1669 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
1670 | nfsrv_postopattr(nd, getret, &at); | |||
1671 | goto out; | |||
1672 | } | |||
1673 | /* | |||
1674 | * If nothing read, return eof | |||
1675 | * rpc reply | |||
1676 | */ | |||
1677 | if (siz == 0) { | |||
1678 | vput(vp); | |||
1679 | if (nd->nd_flag & ND_NFSV20x00000004) { | |||
1680 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
1681 | } else { | |||
1682 | nfsrv_postopattr(nd, getret, &at); | |||
1683 | NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (4 * 4))); | |||
1684 | txdr_hyper(at.na_filerev, tl)do { ((u_int32_t *)(tl))[0] = (__builtin_constant_p((u_int32_t )((at.na_vattr.va_filerev) >> 32)) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr .va_filerev) >> 32))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff )) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)((at. na_vattr.va_filerev) >> 32))) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) >> 32))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) >> 32))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) >> 32))) >> 16)))) : __bswap32_var ((u_int32_t)((at.na_vattr.va_filerev) >> 32))); ((u_int32_t *)(tl))[1] = (__builtin_constant_p((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff)) ? (((__uint32_t)((__uint16_t)( __builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(( u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) ) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) & 0xffffffff))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) >> 16)))) : __bswap32_var((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff))); } while (0); | |||
1685 | tl += 2; | |||
1686 | } | |||
1687 | *tl++ = newnfs_false; | |||
1688 | *tl = newnfs_true; | |||
1689 | FREE((caddr_t)rbuf, M_TEMP)free(((caddr_t)rbuf), (M_TEMP)); | |||
1690 | FREE((caddr_t)cookies, M_TEMP)free(((caddr_t)cookies), (M_TEMP)); | |||
1691 | goto out; | |||
1692 | } | |||
1693 | ||||
1694 | /* | |||
1695 | * Check for degenerate cases of nothing useful read. | |||
1696 | * If so go try again | |||
1697 | */ | |||
1698 | cpos = rbuf; | |||
1699 | cend = rbuf + siz; | |||
1700 | dp = (struct dirent *)cpos; | |||
1701 | cookiep = cookies; | |||
1702 | ||||
1703 | /* | |||
1704 | * For some reason FreeBSD's ufs_readdir() chooses to back the | |||
1705 | * directory offset up to a block boundary, so it is necessary to | |||
1706 | * skip over the records that precede the requested offset. This | |||
1707 | * requires the assumption that file offset cookies monotonically | |||
1708 | * increase. | |||
1709 | */ | |||
1710 | while (cpos < cend && ncookies > 0 && | |||
1711 | (dp->d_fileno == 0 || dp->d_type == DT_WHT14 || | |||
1712 | (is_ufs == 1 && ((u_quad_t)(*cookiep)) <= toff))) { | |||
1713 | cpos += dp->d_reclen; | |||
1714 | dp = (struct dirent *)cpos; | |||
1715 | cookiep++; | |||
1716 | ncookies--; | |||
1717 | } | |||
1718 | if (cpos >= cend || ncookies == 0) { | |||
1719 | siz = fullsiz; | |||
1720 | toff = off; | |||
1721 | goto again; | |||
1722 | } | |||
1723 | vput(vp); | |||
1724 | ||||
1725 | /* | |||
1726 | * dirlen is the size of the reply, including all XDR and must | |||
1727 | * not exceed cnt. For NFSv2, RFC1094 didn't clearly indicate | |||
1728 | * if the XDR should be included in "count", but to be safe, we do. | |||
1729 | * (Include the two booleans at the end of the reply in dirlen now.) | |||
1730 | */ | |||
1731 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
1732 | nfsrv_postopattr(nd, getret, &at); | |||
1733 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
1734 | txdr_hyper(at.na_filerev, tl)do { ((u_int32_t *)(tl))[0] = (__builtin_constant_p((u_int32_t )((at.na_vattr.va_filerev) >> 32)) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr .va_filerev) >> 32))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff )) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)((at. na_vattr.va_filerev) >> 32))) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) >> 32))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) >> 32))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) >> 32))) >> 16)))) : __bswap32_var ((u_int32_t)((at.na_vattr.va_filerev) >> 32))); ((u_int32_t *)(tl))[1] = (__builtin_constant_p((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff)) ? (((__uint32_t)((__uint16_t)( __builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(( u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) ) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) & 0xffffffff))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) >> 16)))) : __bswap32_var((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff))); } while (0); | |||
1735 | dirlen = NFSX_V3POSTOPATTR(84 + 4) + NFSX_VERF8 + 2 * NFSX_UNSIGNED4; | |||
1736 | } else { | |||
1737 | dirlen = 2 * NFSX_UNSIGNED4; | |||
1738 | } | |||
1739 | ||||
1740 | /* Loop through the records and build reply */ | |||
1741 | while (cpos < cend && ncookies > 0) { | |||
1742 | nlen = dp->d_namlen; | |||
1743 | if (dp->d_fileno != 0 && dp->d_type != DT_WHT14 && | |||
1744 | nlen <= NFS_MAXNAMLEN255) { | |||
1745 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
1746 | dirlen += (6*NFSX_UNSIGNED4 + NFSM_RNDUP(nlen)(((nlen)+3)&(~0x3))); | |||
1747 | else | |||
1748 | dirlen += (4*NFSX_UNSIGNED4 + NFSM_RNDUP(nlen)(((nlen)+3)&(~0x3))); | |||
1749 | if (dirlen > cnt) { | |||
1750 | eofflag = 0; | |||
1751 | break; | |||
1752 | } | |||
1753 | ||||
1754 | /* | |||
1755 | * Build the directory record xdr from | |||
1756 | * the dirent entry. | |||
1757 | */ | |||
1758 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
1759 | NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (3 * 4))); | |||
1760 | *tl++ = newnfs_true; | |||
1761 | *tl++ = 0; | |||
1762 | } else { | |||
1763 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
1764 | *tl++ = newnfs_true; | |||
1765 | } | |||
1766 | *tl = txdr_unsigned(dp->d_fileno)((__builtin_constant_p((int32_t)(dp->d_fileno)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(dp ->d_fileno))) & 0xffff) ? (__uint16_t)(((__uint16_t)(( (__uint32_t)((int32_t)(dp->d_fileno))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(dp->d_fileno))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t )(dp->d_fileno))) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)((int32_t)(dp->d_fileno ))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(( int32_t)(dp->d_fileno))) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(dp->d_fileno))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(dp->d_fileno)) ) >> 16)))) : __bswap32_var((int32_t)(dp->d_fileno)) )); | |||
1767 | (void) nfsm_strtom(nd, dp->d_name, nlen); | |||
1768 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
1769 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
1770 | *tl++ = 0; | |||
1771 | } else | |||
1772 | NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (4))); | |||
1773 | *tl = txdr_unsigned(*cookiep)((__builtin_constant_p((int32_t)(*cookiep)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*cookiep ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*cookiep))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(*cookiep))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*cookiep))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)((int32_t)(*cookiep))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((int32_t)(*cookiep))) >> 16 )) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(*cookiep ))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(( int32_t)(*cookiep))) >> 16)))) : __bswap32_var((int32_t )(*cookiep)))); | |||
1774 | } | |||
1775 | cpos += dp->d_reclen; | |||
1776 | dp = (struct dirent *)cpos; | |||
1777 | cookiep++; | |||
1778 | ncookies--; | |||
1779 | } | |||
1780 | if (cpos < cend) | |||
1781 | eofflag = 0; | |||
1782 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
1783 | *tl++ = newnfs_false; | |||
1784 | if (eofflag) | |||
1785 | *tl = newnfs_true; | |||
1786 | else | |||
1787 | *tl = newnfs_false; | |||
1788 | FREE((caddr_t)rbuf, M_TEMP)free(((caddr_t)rbuf), (M_TEMP)); | |||
1789 | FREE((caddr_t)cookies, M_TEMP)free(((caddr_t)cookies), (M_TEMP)); | |||
1790 | ||||
1791 | out: | |||
1792 | NFSEXITCODE2(0, nd); | |||
1793 | return (0); | |||
1794 | nfsmout: | |||
1795 | vput(vp); | |||
1796 | NFSEXITCODE2(error, nd); | |||
1797 | return (error); | |||
1798 | } | |||
1799 | ||||
1800 | /* | |||
1801 | * Readdirplus for V3 and Readdir for V4. | |||
1802 | */ | |||
1803 | int | |||
1804 | nfsrvd_readdirplus(struct nfsrv_descript *nd, int isdgram, | |||
1805 | struct vnode *vp, struct thread *p, struct nfsexstuff *exp) | |||
1806 | { | |||
1807 | struct dirent *dp; | |||
1808 | u_int32_t *tl; | |||
1809 | int dirlen; | |||
1810 | char *cpos, *cend, *rbuf; | |||
1811 | struct vnode *nvp; | |||
1812 | fhandle_t nfh; | |||
1813 | struct nfsvattr nva, at, *nvap = &nva; | |||
1814 | struct mbuf *mb0, *mb1; | |||
1815 | struct nfsreferral *refp; | |||
1816 | int nlen, r, error = 0, getret = 1, usevget = 1; | |||
1817 | int siz, cnt, fullsiz, eofflag, ncookies, entrycnt; | |||
1818 | caddr_t bpos0, bpos1; | |||
1819 | u_int64_t off, toff, verf; | |||
1820 | u_long *cookies = NULL((void *)0), *cookiep; | |||
1821 | nfsattrbit_t attrbits, rderrbits, savbits; | |||
1822 | struct uio io; | |||
1823 | struct iovec iv; | |||
1824 | struct componentname cn; | |||
1825 | int at_root, is_ufs, is_zfs, needs_unbusy, supports_nfsv4acls; | |||
1826 | struct mount *mp, *new_mp; | |||
1827 | uint64_t mounted_on_fileno; | |||
1828 | ||||
1829 | if (nd->nd_repstat) { | |||
1830 | nfsrv_postopattr(nd, getret, &at); | |||
1831 | goto out; | |||
1832 | } | |||
1833 | NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (6 * 4)); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
1834 | off = fxdr_hyper(tl)((((u_quad_t)(__builtin_constant_p(((u_int32_t *)(tl))[0]) ? ( ((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t) (((u_int32_t *)(tl))[0])) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *) (tl))[0])) >> 16)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[0])) >> 16)))) : __bswap32_var((( u_int32_t *)(tl))[0]))) << 32) | (u_quad_t)((__builtin_constant_p (((u_int32_t *)(tl))[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl ))[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[1])) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(((u_int32_t *)(tl))[1])) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)))) : __bswap32_var (((u_int32_t *)(tl))[1])))); | |||
1835 | toff = off; | |||
1836 | tl += 2; | |||
1837 | verf = fxdr_hyper(tl)((((u_quad_t)(__builtin_constant_p(((u_int32_t *)(tl))[0]) ? ( ((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t) (((u_int32_t *)(tl))[0])) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *) (tl))[0])) >> 16)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[0])) >> 16)))) : __bswap32_var((( u_int32_t *)(tl))[0]))) << 32) | (u_quad_t)((__builtin_constant_p (((u_int32_t *)(tl))[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl ))[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[1])) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(((u_int32_t *)(tl))[1])) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)))) : __bswap32_var (((u_int32_t *)(tl))[1])))); | |||
1838 | tl += 2; | |||
1839 | siz = fxdr_unsigned(int, *tl++)((int)(__builtin_constant_p((int32_t)(*tl++)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl++))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)(*tl++))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(*tl++))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*tl++))) & 0xffff ))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)(*tl++))) >> 16) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)(*tl++))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(*tl++))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*tl++))) >> 16)))) : __bswap32_var((int32_t)(*tl++)))); | |||
1840 | cnt = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
1841 | ||||
1842 | /* | |||
1843 | * Use the server's maximum data transfer size as the upper bound | |||
1844 | * on reply datalen. | |||
1845 | */ | |||
1846 | if (cnt > NFS_SRVMAXDATA(nd)(((nd)->nd_flag & (0x00000008 | 0x00000010)) ? (128 * 1024 ) : 8192) || cnt < 0) | |||
1847 | cnt = NFS_SRVMAXDATA(nd)(((nd)->nd_flag & (0x00000008 | 0x00000010)) ? (128 * 1024 ) : 8192); | |||
1848 | ||||
1849 | /* | |||
1850 | * siz is a "hint" of how much directory information (name, fileid, | |||
1851 | * cookie) should be in the reply. At least one client "hints" 0, | |||
1852 | * so I set it to cnt for that case. I also round it up to the | |||
1853 | * next multiple of DIRBLKSIZ. | |||
1854 | */ | |||
1855 | if (siz <= 0) | |||
1856 | siz = cnt; | |||
1857 | siz = ((siz + DIRBLKSIZ(1<<9) - 1) & ~(DIRBLKSIZ(1<<9) - 1)); | |||
1858 | ||||
1859 | if (nd->nd_flag & ND_NFSV40x00000010) { | |||
1860 | error = nfsrv_getattrbits(nd, &attrbits, NULL((void *)0), NULL((void *)0)); | |||
1861 | if (error) | |||
1862 | goto nfsmout; | |||
1863 | NFSSET_ATTRBIT(&savbits, &attrbits)do { (&savbits)->bits[0] = (&attrbits)->bits[0] ; (&savbits)->bits[1] = (&attrbits)->bits[1]; ( &savbits)->bits[2] = (&attrbits)->bits[2]; } while (0); | |||
1864 | NFSCLRNOTFILLABLE_ATTRBIT(&attrbits)do { (&attrbits)->bits[0] &= (0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000080 | 0x00000100 | 0x00000200 | 0x00000400 | 0x00000800 | 0x00001000 | 0x00002000 | 0x00008000 | 0x00010000 | 0x00020000 | 0x00040000 | 0x00080000 | 0x00100000 | 0x00200000 | 0x00400000 | 0x00800000 | 0x01000000 | 0x04000000 | 0x08000000 | 0x10000000 | 0x20000000 | 0x40000000 | 0x80000000); (&attrbits)-> bits[1] &= (0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000200 | 0x00000400 | 0x00000800 | 0x00001000 | 0x00002000 | 0x00008000 | 0x00080000 | 0x00100000 | 0x00200000 | 0x00800000 | 0x00000040 | 0x00000080 | 0x00000100); (& attrbits)->bits[2] &= 0x00000800; } while (0); | |||
1865 | NFSZERO_ATTRBIT(&rderrbits)do { (&rderrbits)->bits[0] = 0; (&rderrbits)->bits [1] = 0; (&rderrbits)->bits[2] = 0; } while (0); | |||
1866 | NFSSETBIT_ATTRBIT(&rderrbits, NFSATTRBIT_RDATTRERROR)((&rderrbits)->bits[(11) / 32] |= (1 << ((11) % 32 ))); | |||
1867 | } else { | |||
1868 | NFSZERO_ATTRBIT(&attrbits)do { (&attrbits)->bits[0] = 0; (&attrbits)->bits [1] = 0; (&attrbits)->bits[2] = 0; } while (0); | |||
1869 | } | |||
1870 | fullsiz = siz; | |||
1871 | nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1); | |||
1872 | if (!nd->nd_repstat) { | |||
1873 | if (off && verf != at.na_filerevna_vattr.va_filerev) { | |||
1874 | /* | |||
1875 | * va_filerev is not sufficient as a cookie verifier, | |||
1876 | * since it is not supposed to change when entries are | |||
1877 | * removed/added unless that offset cookies returned to | |||
1878 | * the client are no longer valid. | |||
1879 | */ | |||
1880 | #if 0 | |||
1881 | if (nd->nd_flag & ND_NFSV40x00000010) { | |||
1882 | nd->nd_repstat = NFSERR_NOTSAME10027; | |||
1883 | } else { | |||
1884 | nd->nd_repstat = NFSERR_BAD_COOKIE10003; | |||
1885 | } | |||
1886 | #endif | |||
1887 | } else if ((nd->nd_flag & ND_NFSV40x00000010) && off == 0 && verf != 0) { | |||
1888 | nd->nd_repstat = NFSERR_BAD_COOKIE10003; | |||
1889 | } | |||
1890 | } | |||
1891 | if (!nd->nd_repstat && vp->v_type != VDIR) | |||
1892 | nd->nd_repstat = NFSERR_NOTDIR20; | |||
1893 | if (!nd->nd_repstat && cnt == 0) | |||
1894 | nd->nd_repstat = NFSERR_TOOSMALL10005; | |||
1895 | if (!nd->nd_repstat) | |||
1896 | nd->nd_repstat = nfsvno_accchk(vp, VEXEC000000000100, | |||
1897 | nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE0, | |||
1898 | NFSACCCHK_VPISLOCKED1, NULL((void *)0)); | |||
1899 | if (nd->nd_repstat) { | |||
1900 | vput(vp); | |||
1901 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
1902 | nfsrv_postopattr(nd, getret, &at); | |||
1903 | goto out; | |||
1904 | } | |||
1905 | is_ufs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "ufs") == 0; | |||
1906 | is_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs") == 0; | |||
1907 | ||||
1908 | MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK)((rbuf) = (caddr_t)malloc((u_long)(siz), (M_TEMP), (0x0002))); | |||
1909 | again: | |||
1910 | eofflag = 0; | |||
1911 | if (cookies) { | |||
1912 | free((caddr_t)cookies, M_TEMP); | |||
1913 | cookies = NULL((void *)0); | |||
1914 | } | |||
1915 | ||||
1916 | iv.iov_base = rbuf; | |||
1917 | iv.iov_len = siz; | |||
1918 | io.uio_iov = &iv; | |||
1919 | io.uio_iovcnt = 1; | |||
1920 | io.uio_offset = (off_t)off; | |||
1921 | io.uio_resid = siz; | |||
1922 | io.uio_segflg = UIO_SYSSPACE; | |||
1923 | io.uio_rw = UIO_READ; | |||
1924 | io.uio_td = NULL((void *)0); | |||
1925 | nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies, | |||
1926 | &cookies); | |||
1927 | off = (u_int64_t)io.uio_offset; | |||
1928 | if (io.uio_resid) | |||
1929 | siz -= io.uio_resid; | |||
1930 | ||||
1931 | getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1); | |||
1932 | ||||
1933 | if (!cookies && !nd->nd_repstat) | |||
1934 | nd->nd_repstat = NFSERR_PERM1; | |||
1935 | if (!nd->nd_repstat) | |||
1936 | nd->nd_repstat = getret; | |||
1937 | if (nd->nd_repstat) { | |||
1938 | vput(vp); | |||
1939 | if (cookies) | |||
1940 | free((caddr_t)cookies, M_TEMP); | |||
1941 | free((caddr_t)rbuf, M_TEMP); | |||
1942 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
1943 | nfsrv_postopattr(nd, getret, &at); | |||
1944 | goto out; | |||
1945 | } | |||
1946 | /* | |||
1947 | * If nothing read, return eof | |||
1948 | * rpc reply | |||
1949 | */ | |||
1950 | if (siz == 0) { | |||
1951 | vput(vp); | |||
1952 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
1953 | nfsrv_postopattr(nd, getret, &at); | |||
1954 | NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (4 * 4))); | |||
1955 | txdr_hyper(at.na_filerev, tl)do { ((u_int32_t *)(tl))[0] = (__builtin_constant_p((u_int32_t )((at.na_vattr.va_filerev) >> 32)) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr .va_filerev) >> 32))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff )) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)((at. na_vattr.va_filerev) >> 32))) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) >> 32))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) >> 32))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) >> 32))) >> 16)))) : __bswap32_var ((u_int32_t)((at.na_vattr.va_filerev) >> 32))); ((u_int32_t *)(tl))[1] = (__builtin_constant_p((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff)) ? (((__uint32_t)((__uint16_t)( __builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(( u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) ) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) & 0xffffffff))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) >> 16)))) : __bswap32_var((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff))); } while (0); | |||
1956 | tl += 2; | |||
1957 | *tl++ = newnfs_false; | |||
1958 | *tl = newnfs_true; | |||
1959 | free((caddr_t)cookies, M_TEMP); | |||
1960 | free((caddr_t)rbuf, M_TEMP); | |||
1961 | goto out; | |||
1962 | } | |||
1963 | ||||
1964 | /* | |||
1965 | * Check for degenerate cases of nothing useful read. | |||
1966 | * If so go try again | |||
1967 | */ | |||
1968 | cpos = rbuf; | |||
1969 | cend = rbuf + siz; | |||
1970 | dp = (struct dirent *)cpos; | |||
1971 | cookiep = cookies; | |||
1972 | ||||
1973 | /* | |||
1974 | * For some reason FreeBSD's ufs_readdir() chooses to back the | |||
1975 | * directory offset up to a block boundary, so it is necessary to | |||
1976 | * skip over the records that precede the requested offset. This | |||
1977 | * requires the assumption that file offset cookies monotonically | |||
1978 | * increase. | |||
1979 | */ | |||
1980 | while (cpos < cend && ncookies > 0 && | |||
1981 | (dp->d_fileno == 0 || dp->d_type == DT_WHT14 || | |||
1982 | (is_ufs == 1 && ((u_quad_t)(*cookiep)) <= toff) || | |||
1983 | ((nd->nd_flag & ND_NFSV40x00000010) && | |||
1984 | ((dp->d_namlen == 1 && dp->d_name[0] == '.') || | |||
1985 | (dp->d_namlen==2 && dp->d_name[0]=='.' && dp->d_name[1]=='.'))))) { | |||
1986 | cpos += dp->d_reclen; | |||
1987 | dp = (struct dirent *)cpos; | |||
1988 | cookiep++; | |||
1989 | ncookies--; | |||
1990 | } | |||
1991 | if (cpos >= cend || ncookies == 0) { | |||
1992 | siz = fullsiz; | |||
1993 | toff = off; | |||
1994 | goto again; | |||
1995 | } | |||
1996 | ||||
1997 | /* | |||
1998 | * Busy the file system so that the mount point won't go away | |||
1999 | * and, as such, VFS_VGET() can be used safely. | |||
2000 | */ | |||
2001 | mp = vp->v_mount; | |||
2002 | vfs_ref(mp); | |||
2003 | NFSVOPUNLOCK(vp, 0)VOP_UNLOCK((vp), (0)); | |||
2004 | nd->nd_repstat = vfs_busy(mp, 0); | |||
2005 | vfs_rel(mp); | |||
2006 | if (nd->nd_repstat != 0) { | |||
2007 | vrele(vp); | |||
2008 | free(cookies, M_TEMP); | |||
2009 | free(rbuf, M_TEMP); | |||
2010 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
2011 | nfsrv_postopattr(nd, getret, &at); | |||
2012 | goto out; | |||
2013 | } | |||
2014 | ||||
2015 | /* | |||
2016 | * Check to see if entries in this directory can be safely acquired | |||
2017 | * via VFS_VGET() or if a switch to VOP_LOOKUP() is required. | |||
2018 | * ZFS snapshot directories need VOP_LOOKUP(), so that any | |||
2019 | * automount of the snapshot directory that is required will | |||
2020 | * be done. | |||
2021 | * This needs to be done here for NFSv4, since NFSv4 never does | |||
2022 | * a VFS_VGET() for "." or "..". | |||
2023 | */ | |||
2024 | if (is_zfs == 1) { | |||
2025 | r = VFS_VGET(mp, at.na_fileid, LK_SHARED, &nvp)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_vget)(mp, at.na_vattr.va_fileid , 0x200000, &nvp); sigallowstop(_prev_stops); } while (0) ; _rc; }); | |||
2026 | if (r == EOPNOTSUPP45) { | |||
2027 | usevget = 0; | |||
2028 | cn.cn_nameiop = LOOKUP0; | |||
2029 | cn.cn_lkflags = LK_SHARED0x200000 | LK_RETRY0x000400; | |||
2030 | cn.cn_cred = nd->nd_cred; | |||
2031 | cn.cn_thread = p; | |||
2032 | } else if (r == 0) | |||
2033 | vput(nvp); | |||
2034 | } | |||
2035 | ||||
2036 | /* | |||
2037 | * Save this position, in case there is an error before one entry | |||
2038 | * is created. | |||
2039 | */ | |||
2040 | mb0 = nd->nd_mb; | |||
2041 | bpos0 = nd->nd_bpos; | |||
2042 | ||||
2043 | /* | |||
2044 | * Fill in the first part of the reply. | |||
2045 | * dirlen is the reply length in bytes and cannot exceed cnt. | |||
2046 | * (Include the two booleans at the end of the reply in dirlen now, | |||
2047 | * so we recognize when we have exceeded cnt.) | |||
2048 | */ | |||
2049 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
2050 | dirlen = NFSX_V3POSTOPATTR(84 + 4) + NFSX_VERF8 + 2 * NFSX_UNSIGNED4; | |||
2051 | nfsrv_postopattr(nd, getret, &at); | |||
2052 | } else { | |||
2053 | dirlen = NFSX_VERF8 + 2 * NFSX_UNSIGNED4; | |||
2054 | } | |||
2055 | NFSM_BUILD(tl, u_int32_t *, NFSX_VERF)((tl) = (u_int32_t *)nfsm_build(nd, (8))); | |||
2056 | txdr_hyper(at.na_filerev, tl)do { ((u_int32_t *)(tl))[0] = (__builtin_constant_p((u_int32_t )((at.na_vattr.va_filerev) >> 32)) ? (((__uint32_t)((__uint16_t )(__builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr .va_filerev) >> 32))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) & 0xffff )) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)((at. na_vattr.va_filerev) >> 32))) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) >> 32))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) >> 32))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) >> 32))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) >> 32))) >> 16)))) : __bswap32_var ((u_int32_t)((at.na_vattr.va_filerev) >> 32))); ((u_int32_t *)(tl))[1] = (__builtin_constant_p((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff)) ? (((__uint32_t)((__uint16_t)( __builtin_constant_p(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(( u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((u_int32_t )((at.na_vattr.va_filerev) & 0xffffffff))) & 0xffff)) ) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((u_int32_t)(( at.na_vattr.va_filerev) & 0xffffffff))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev ) & 0xffffffff))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((u_int32_t)((at.na_vattr.va_filerev) & 0xffffffff ))) >> 16)))) : __bswap32_var((u_int32_t)((at.na_vattr. va_filerev) & 0xffffffff))); } while (0); | |||
2057 | ||||
2058 | /* | |||
2059 | * Save this position, in case there is an empty reply needed. | |||
2060 | */ | |||
2061 | mb1 = nd->nd_mb; | |||
2062 | bpos1 = nd->nd_bpos; | |||
2063 | ||||
2064 | /* Loop through the records and build reply */ | |||
2065 | entrycnt = 0; | |||
2066 | while (cpos < cend && ncookies > 0 && dirlen < cnt) { | |||
2067 | nlen = dp->d_namlen; | |||
2068 | if (dp->d_fileno != 0 && dp->d_type != DT_WHT14 && | |||
2069 | nlen <= NFS_MAXNAMLEN255 && | |||
2070 | ((nd->nd_flag & ND_NFSV30x00000008) || nlen > 2 || | |||
2071 | (nlen==2 && (dp->d_name[0]!='.' || dp->d_name[1]!='.')) | |||
2072 | || (nlen == 1 && dp->d_name[0] != '.'))) { | |||
2073 | /* | |||
2074 | * Save the current position in the reply, in case | |||
2075 | * this entry exceeds cnt. | |||
2076 | */ | |||
2077 | mb1 = nd->nd_mb; | |||
2078 | bpos1 = nd->nd_bpos; | |||
2079 | ||||
2080 | /* | |||
2081 | * For readdir_and_lookup get the vnode using | |||
2082 | * the file number. | |||
2083 | */ | |||
2084 | nvp = NULL((void *)0); | |||
2085 | refp = NULL((void *)0); | |||
2086 | r = 0; | |||
2087 | at_root = 0; | |||
2088 | needs_unbusy = 0; | |||
2089 | new_mp = mp; | |||
2090 | mounted_on_fileno = (uint64_t)dp->d_fileno; | |||
2091 | if ((nd->nd_flag & ND_NFSV30x00000008) || | |||
2092 | NFSNONZERO_ATTRBIT(&savbits)((&savbits)->bits[0] || (&savbits)->bits[1] || ( &savbits)->bits[2])) { | |||
2093 | if (nd->nd_flag & ND_NFSV40x00000010) | |||
2094 | refp = nfsv4root_getreferral(NULL((void *)0), | |||
2095 | vp, dp->d_fileno); | |||
2096 | if (refp == NULL((void *)0)) { | |||
2097 | if (usevget) | |||
2098 | r = VFS_VGET(mp, dp->d_fileno,({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_vget)(mp, dp->d_fileno , 0x200000, &nvp); sigallowstop(_prev_stops); } while (0) ; _rc; }) | |||
2099 | LK_SHARED, &nvp)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_vget)(mp, dp->d_fileno , 0x200000, &nvp); sigallowstop(_prev_stops); } while (0) ; _rc; }); | |||
2100 | else | |||
2101 | r = EOPNOTSUPP45; | |||
2102 | if (r == EOPNOTSUPP45) { | |||
2103 | if (usevget) { | |||
2104 | usevget = 0; | |||
2105 | cn.cn_nameiop = LOOKUP0; | |||
2106 | cn.cn_lkflags = | |||
2107 | LK_SHARED0x200000 | | |||
2108 | LK_RETRY0x000400; | |||
2109 | cn.cn_cred = | |||
2110 | nd->nd_cred; | |||
2111 | cn.cn_thread = p; | |||
2112 | } | |||
2113 | cn.cn_nameptr = dp->d_name; | |||
2114 | cn.cn_namelen = nlen; | |||
2115 | cn.cn_flags = ISLASTCN0x00008000 | | |||
2116 | NOFOLLOW0x0000 | LOCKLEAF0x0004; | |||
2117 | if (nlen == 2 && | |||
2118 | dp->d_name[0] == '.' && | |||
2119 | dp->d_name[1] == '.') | |||
2120 | cn.cn_flags |= | |||
2121 | ISDOTDOT0x00002000; | |||
2122 | if (NFSVOPLOCK(vp, LK_SHARED)_vn_lock((vp), (0x200000), "/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" , 2122) | |||
2123 | != 0) { | |||
2124 | nd->nd_repstat = EPERM1; | |||
2125 | break; | |||
2126 | } | |||
2127 | if ((vp->v_vflag & VV_ROOT0x0001) != 0 | |||
2128 | && (cn.cn_flags & ISDOTDOT0x00002000) | |||
2129 | != 0) { | |||
2130 | vref(vp); | |||
2131 | nvp = vp; | |||
2132 | r = 0; | |||
2133 | } else { | |||
2134 | r = VOP_LOOKUP(vp, &nvp, | |||
2135 | &cn); | |||
2136 | if (vp != nvp) | |||
2137 | NFSVOPUNLOCK(vp,VOP_UNLOCK((vp), (0)) | |||
2138 | 0)VOP_UNLOCK((vp), (0)); | |||
2139 | } | |||
2140 | } | |||
2141 | ||||
2142 | /* | |||
2143 | * For NFSv4, check to see if nvp is | |||
2144 | * a mount point and get the mount | |||
2145 | * point vnode, as required. | |||
2146 | */ | |||
2147 | if (r == 0 && | |||
2148 | nfsrv_enable_crossmntpt != 0 && | |||
2149 | (nd->nd_flag & ND_NFSV40x00000010) != 0 && | |||
2150 | nvp->v_type == VDIR && | |||
2151 | nvp->v_mountedherev_un.vu_mount != NULL((void *)0)) { | |||
2152 | new_mp = nvp->v_mountedherev_un.vu_mount; | |||
2153 | r = vfs_busy(new_mp, 0); | |||
2154 | vput(nvp); | |||
2155 | nvp = NULL((void *)0); | |||
2156 | if (r == 0) { | |||
2157 | r = VFS_ROOT(new_mp,({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( new_mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(new_mp)->mnt_op->vfs_root)(new_mp, 0x200000 , &nvp); sigallowstop(_prev_stops); } while (0); _rc; }) | |||
2158 | LK_SHARED, &nvp)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( new_mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(new_mp)->mnt_op->vfs_root)(new_mp, 0x200000 , &nvp); sigallowstop(_prev_stops); } while (0); _rc; }); | |||
2159 | needs_unbusy = 1; | |||
2160 | if (r == 0) | |||
2161 | at_root = 1; | |||
2162 | } | |||
2163 | } | |||
2164 | } | |||
2165 | if (!r) { | |||
2166 | if (refp == NULL((void *)0) && | |||
2167 | ((nd->nd_flag & ND_NFSV30x00000008) || | |||
2168 | NFSNONZERO_ATTRBIT(&attrbits)((&attrbits)->bits[0] || (&attrbits)->bits[1] || (&attrbits)->bits[2]))) { | |||
2169 | r = nfsvno_getfh(nvp, &nfh, p); | |||
2170 | if (!r) | |||
2171 | r = nfsvno_getattr(nvp, nvap, | |||
2172 | nd->nd_cred, p, 1); | |||
2173 | if (r == 0 && is_zfs == 1 && | |||
2174 | nfsrv_enable_crossmntpt != 0 && | |||
2175 | (nd->nd_flag & ND_NFSV40x00000010) != 0 && | |||
2176 | nvp->v_type == VDIR && | |||
2177 | vp->v_mount != nvp->v_mount) { | |||
2178 | /* | |||
2179 | * For a ZFS snapshot, there is a | |||
2180 | * pseudo mount that does not set | |||
2181 | * v_mountedhere, so it needs to | |||
2182 | * be detected via a different | |||
2183 | * mount structure. | |||
2184 | */ | |||
2185 | at_root = 1; | |||
2186 | if (new_mp == mp) | |||
2187 | new_mp = nvp->v_mount; | |||
2188 | } | |||
2189 | } | |||
2190 | } else { | |||
2191 | nvp = NULL((void *)0); | |||
2192 | } | |||
2193 | if (r) { | |||
2194 | if (!NFSISSET_ATTRBIT(&attrbits,((&attrbits)->bits[(11) / 32] & (1 << ((11) % 32))) | |||
2195 | NFSATTRBIT_RDATTRERROR)((&attrbits)->bits[(11) / 32] & (1 << ((11) % 32)))) { | |||
2196 | if (nvp != NULL((void *)0)) | |||
2197 | vput(nvp); | |||
2198 | if (needs_unbusy != 0) | |||
2199 | vfs_unbusy(new_mp); | |||
2200 | nd->nd_repstat = r; | |||
2201 | break; | |||
2202 | } | |||
2203 | } | |||
2204 | } | |||
2205 | ||||
2206 | /* | |||
2207 | * Build the directory record xdr | |||
2208 | */ | |||
2209 | if (nd->nd_flag & ND_NFSV30x00000008) { | |||
2210 | NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (3 * 4))); | |||
2211 | *tl++ = newnfs_true; | |||
2212 | *tl++ = 0; | |||
2213 | *tl = txdr_unsigned(dp->d_fileno)((__builtin_constant_p((int32_t)(dp->d_fileno)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(dp ->d_fileno))) & 0xffff) ? (__uint16_t)(((__uint16_t)(( (__uint32_t)((int32_t)(dp->d_fileno))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(dp->d_fileno))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t )(dp->d_fileno))) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)((int32_t)(dp->d_fileno ))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(( int32_t)(dp->d_fileno))) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(dp->d_fileno))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(dp->d_fileno)) ) >> 16)))) : __bswap32_var((int32_t)(dp->d_fileno)) )); | |||
2214 | dirlen += nfsm_strtom(nd, dp->d_name, nlen); | |||
2215 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
2216 | *tl++ = 0; | |||
2217 | *tl = txdr_unsigned(*cookiep)((__builtin_constant_p((int32_t)(*cookiep)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*cookiep ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*cookiep))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(*cookiep))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*cookiep))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)((int32_t)(*cookiep))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((int32_t)(*cookiep))) >> 16 )) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(*cookiep ))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(( int32_t)(*cookiep))) >> 16)))) : __bswap32_var((int32_t )(*cookiep)))); | |||
2218 | nfsrv_postopattr(nd, 0, nvap); | |||
2219 | dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1); | |||
2220 | dirlen += (5*NFSX_UNSIGNED4+NFSX_V3POSTOPATTR(84 + 4)); | |||
2221 | if (nvp != NULL((void *)0)) | |||
2222 | vput(nvp); | |||
2223 | } else { | |||
2224 | NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (3 * 4))); | |||
2225 | *tl++ = newnfs_true; | |||
2226 | *tl++ = 0; | |||
2227 | *tl = txdr_unsigned(*cookiep)((__builtin_constant_p((int32_t)(*cookiep)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*cookiep ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*cookiep))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(*cookiep))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(*cookiep))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)((int32_t)(*cookiep))) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((int32_t)(*cookiep))) >> 16 )) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(*cookiep ))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(( int32_t)(*cookiep))) >> 16)))) : __bswap32_var((int32_t )(*cookiep)))); | |||
2228 | dirlen += nfsm_strtom(nd, dp->d_name, nlen); | |||
2229 | if (nvp != NULL((void *)0)) { | |||
2230 | supports_nfsv4acls = | |||
2231 | nfs_supportsnfsv4acls(nvp); | |||
2232 | NFSVOPUNLOCK(nvp, 0)VOP_UNLOCK((nvp), (0)); | |||
2233 | } else | |||
2234 | supports_nfsv4acls = 0; | |||
2235 | if (refp != NULL((void *)0)) { | |||
2236 | dirlen += nfsrv_putreferralattr(nd, | |||
2237 | &savbits, refp, 0, | |||
2238 | &nd->nd_repstat); | |||
2239 | if (nd->nd_repstat) { | |||
2240 | if (nvp != NULL((void *)0)) | |||
2241 | vrele(nvp); | |||
2242 | if (needs_unbusy != 0) | |||
2243 | vfs_unbusy(new_mp); | |||
2244 | break; | |||
2245 | } | |||
2246 | } else if (r) { | |||
2247 | dirlen += nfsvno_fillattr(nd, new_mp, | |||
2248 | nvp, nvap, &nfh, r, &rderrbits, | |||
2249 | nd->nd_cred, p, isdgram, 0, | |||
2250 | supports_nfsv4acls, at_root, | |||
2251 | mounted_on_fileno); | |||
2252 | } else { | |||
2253 | dirlen += nfsvno_fillattr(nd, new_mp, | |||
2254 | nvp, nvap, &nfh, r, &attrbits, | |||
2255 | nd->nd_cred, p, isdgram, 0, | |||
2256 | supports_nfsv4acls, at_root, | |||
2257 | mounted_on_fileno); | |||
2258 | } | |||
2259 | if (nvp != NULL((void *)0)) | |||
2260 | vrele(nvp); | |||
2261 | dirlen += (3 * NFSX_UNSIGNED4); | |||
2262 | } | |||
2263 | if (needs_unbusy != 0) | |||
2264 | vfs_unbusy(new_mp); | |||
2265 | if (dirlen <= cnt) | |||
2266 | entrycnt++; | |||
2267 | } | |||
2268 | cpos += dp->d_reclen; | |||
2269 | dp = (struct dirent *)cpos; | |||
2270 | cookiep++; | |||
2271 | ncookies--; | |||
2272 | } | |||
2273 | vrele(vp); | |||
2274 | vfs_unbusy(mp); | |||
2275 | ||||
2276 | /* | |||
2277 | * If dirlen > cnt, we must strip off the last entry. If that | |||
2278 | * results in an empty reply, report NFSERR_TOOSMALL. | |||
2279 | */ | |||
2280 | if (dirlen > cnt || nd->nd_repstat) { | |||
2281 | if (!nd->nd_repstat && entrycnt == 0) | |||
2282 | nd->nd_repstat = NFSERR_TOOSMALL10005; | |||
2283 | if (nd->nd_repstat) { | |||
2284 | newnfs_trimtrailing(nd, mb0, bpos0); | |||
2285 | if (nd->nd_flag & ND_NFSV30x00000008) | |||
2286 | nfsrv_postopattr(nd, getret, &at); | |||
2287 | } else | |||
2288 | newnfs_trimtrailing(nd, mb1, bpos1); | |||
2289 | eofflag = 0; | |||
2290 | } else if (cpos < cend) | |||
2291 | eofflag = 0; | |||
2292 | if (!nd->nd_repstat) { | |||
2293 | NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED)((tl) = (u_int32_t *)nfsm_build(nd, (2 * 4))); | |||
2294 | *tl++ = newnfs_false; | |||
2295 | if (eofflag) | |||
2296 | *tl = newnfs_true; | |||
2297 | else | |||
2298 | *tl = newnfs_false; | |||
2299 | } | |||
2300 | FREE((caddr_t)cookies, M_TEMP)free(((caddr_t)cookies), (M_TEMP)); | |||
2301 | FREE((caddr_t)rbuf, M_TEMP)free(((caddr_t)rbuf), (M_TEMP)); | |||
2302 | ||||
2303 | out: | |||
2304 | NFSEXITCODE2(0, nd); | |||
2305 | return (0); | |||
2306 | nfsmout: | |||
2307 | vput(vp); | |||
2308 | NFSEXITCODE2(error, nd); | |||
2309 | return (error); | |||
2310 | } | |||
2311 | ||||
2312 | /* | |||
2313 | * Get the settable attributes out of the mbuf list. | |||
2314 | * (Return 0 or EBADRPC) | |||
2315 | */ | |||
2316 | int | |||
2317 | nfsrv_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap, | |||
2318 | nfsattrbit_t *attrbitp, NFSACL_Tstruct acl *aclp, struct thread *p) | |||
2319 | { | |||
2320 | u_int32_t *tl; | |||
2321 | struct nfsv2_sattr *sp; | |||
2322 | int error = 0, toclient = 0; | |||
2323 | ||||
2324 | switch (nd->nd_flag & (ND_NFSV20x00000004 | ND_NFSV30x00000008 | ND_NFSV40x00000010)) { | |||
2325 | case ND_NFSV20x00000004: | |||
2326 | NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR)do { (sp) = (struct nfsv2_sattr *)nfsm_dissect(nd, (32)); if ( (sp) == ((void *)0)) { error = 72; goto nfsmout; } } while (0 ); | |||
2327 | /* | |||
2328 | * Some old clients didn't fill in the high order 16bits. | |||
2329 | * --> check the low order 2 bytes for 0xffff | |||
2330 | */ | |||
2331 | if ((fxdr_unsigned(int, sp->sa_mode)((int)(__builtin_constant_p((int32_t)(sp->sa_mode)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(sp ->sa_mode))) & 0xffff) ? (__uint16_t)(((__uint16_t)((( __uint32_t)((int32_t)(sp->sa_mode))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(sp->sa_mode))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t) (sp->sa_mode))) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)((int32_t)(sp->sa_mode ))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(( int32_t)(sp->sa_mode))) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(sp->sa_mode))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp->sa_mode))) >> 16)))) : __bswap32_var((int32_t)(sp->sa_mode)))) & 0xffff) != 0xffff) | |||
2332 | nvap->na_modena_vattr.va_mode = nfstov_mode(sp->sa_mode)(((u_int16_t)(__builtin_constant_p((int32_t)((sp->sa_mode) )) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)((sp->sa_mode)))) & 0xffff) ? (__uint16_t)( ((__uint16_t)(((__uint32_t)((int32_t)((sp->sa_mode)))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)( (sp->sa_mode)))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)((sp->sa_mode)))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t )((sp->sa_mode)))) >> 16) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)((sp->sa_mode)))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)((sp->sa_mode))) ) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t )((sp->sa_mode)))) >> 16)))) : __bswap32_var((int32_t )((sp->sa_mode)))))&07777); | |||
2333 | if (sp->sa_uid != newnfs_xdrneg1) | |||
2334 | nvap->na_uidna_vattr.va_uid = fxdr_unsigned(uid_t, sp->sa_uid)((uid_t)(__builtin_constant_p((int32_t)(sp->sa_uid)) ? ((( __uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t)(( int32_t)(sp->sa_uid))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)(sp->sa_uid))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(sp->sa_uid))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t) (sp->sa_uid))) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)((int32_t)(sp->sa_uid) )) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((int32_t )(sp->sa_uid))) >> 16)) << 8 | ((__uint16_t)(( (__uint32_t)((int32_t)(sp->sa_uid))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp->sa_uid))) >> 16)))) : __bswap32_var((int32_t)(sp->sa_uid)))); | |||
2335 | if (sp->sa_gid != newnfs_xdrneg1) | |||
2336 | nvap->na_gidna_vattr.va_gid = fxdr_unsigned(gid_t, sp->sa_gid)((gid_t)(__builtin_constant_p((int32_t)(sp->sa_gid)) ? ((( __uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t)(( int32_t)(sp->sa_gid))) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)(sp->sa_gid))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(sp->sa_gid))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t) (sp->sa_gid))) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)((int32_t)(sp->sa_gid) )) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((int32_t )(sp->sa_gid))) >> 16)) << 8 | ((__uint16_t)(( (__uint32_t)((int32_t)(sp->sa_gid))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp->sa_gid))) >> 16)))) : __bswap32_var((int32_t)(sp->sa_gid)))); | |||
2337 | if (sp->sa_size != newnfs_xdrneg1) | |||
2338 | nvap->na_sizena_vattr.va_size = fxdr_unsigned(u_quad_t, sp->sa_size)((u_quad_t)(__builtin_constant_p((int32_t)(sp->sa_size)) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)(sp->sa_size))) & 0xffff) ? (__uint16_t)((( __uint16_t)(((__uint32_t)((int32_t)(sp->sa_size))) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)(sp-> sa_size))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )((int32_t)(sp->sa_size))) & 0xffff))) << 16) | ( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(sp-> sa_size))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)(sp->sa_size))) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(sp->sa_size))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp->sa_size))) >> 16)))) : __bswap32_var((int32_t)(sp->sa_size)))); | |||
2339 | if (sp->sa_atime.nfsv2_sec != newnfs_xdrneg1) { | |||
2340 | #ifdef notyet | |||
2341 | fxdr_nfsv2time(&sp->sa_atime, &nvap->na_atime)do { (&nvap->na_vattr.va_atime)->tv_sec = (__builtin_constant_p (((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec )) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(( (struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec)) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv2_time *)(& sp->sa_atime))->nfsv2_sec)) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(& sp->sa_atime))->nfsv2_sec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv2_time *)(&sp-> sa_atime))->nfsv2_sec)) >> 16)))) : __bswap32_var((( struct nfsv2_time *)(&sp->sa_atime))->nfsv2_sec)); if (((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_usec != 0xffffffff) (&nvap->na_vattr.va_atime)->tv_nsec = 1000 * (__builtin_constant_p(((struct nfsv2_time *)(&sp ->sa_atime))->nfsv2_usec) ? (((__uint32_t)((__uint16_t) (__builtin_constant_p(((__uint32_t)(((struct nfsv2_time *)(& sp->sa_atime))->nfsv2_usec)) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp-> sa_atime))->nfsv2_usec)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime)) ->nfsv2_usec)) & 0xffff)) >> 8) : __bswap16_var( ((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))-> nfsv2_usec)) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))-> nfsv2_usec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t )(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_usec )) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_usec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_atime))->nfsv2_usec)) >> 16)))) : __bswap32_var(((struct nfsv2_time *)(&sp->sa_atime))-> nfsv2_usec)); else (&nvap->na_vattr.va_atime)->tv_nsec = 0; } while (0); | |||
2342 | #else | |||
2343 | nvap->na_atimena_vattr.va_atime.tv_sec = | |||
2344 | fxdr_unsigned(u_int32_t,sp->sa_atime.nfsv2_sec)((u_int32_t)(__builtin_constant_p((int32_t)(sp->sa_atime.nfsv2_sec )) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)(sp->sa_atime.nfsv2_sec))) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)((int32_t)(sp->sa_atime.nfsv2_sec ))) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(( int32_t)(sp->sa_atime.nfsv2_sec))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp->sa_atime.nfsv2_sec ))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)((int32_t)(sp->sa_atime.nfsv2_sec))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)((int32_t)(sp-> sa_atime.nfsv2_sec))) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)(sp->sa_atime.nfsv2_sec))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)(sp-> sa_atime.nfsv2_sec))) >> 16)))) : __bswap32_var((int32_t )(sp->sa_atime.nfsv2_sec)))); | |||
2345 | nvap->na_atimena_vattr.va_atime.tv_nsec = 0; | |||
2346 | #endif | |||
2347 | } | |||
2348 | if (sp->sa_mtime.nfsv2_sec != newnfs_xdrneg1) | |||
2349 | fxdr_nfsv2time(&sp->sa_mtime, &nvap->na_mtime)do { (&nvap->na_vattr.va_mtime)->tv_sec = (__builtin_constant_p (((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t )(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec )) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(( (struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec)) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv2_time *)(& sp->sa_mtime))->nfsv2_sec)) & 0xffff))) << 16 ) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(& sp->sa_mtime))->nfsv2_sec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv2_time *)(&sp-> sa_mtime))->nfsv2_sec)) >> 16)))) : __bswap32_var((( struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_sec)); if (((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_usec != 0xffffffff) (&nvap->na_vattr.va_mtime)->tv_nsec = 1000 * (__builtin_constant_p(((struct nfsv2_time *)(&sp ->sa_mtime))->nfsv2_usec) ? (((__uint32_t)((__uint16_t) (__builtin_constant_p(((__uint32_t)(((struct nfsv2_time *)(& sp->sa_mtime))->nfsv2_usec)) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp-> sa_mtime))->nfsv2_usec)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime)) ->nfsv2_usec)) & 0xffff)) >> 8) : __bswap16_var( ((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))-> nfsv2_usec)) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))-> nfsv2_usec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t )(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_usec )) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_usec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv2_time *)(&sp->sa_mtime))->nfsv2_usec)) >> 16)))) : __bswap32_var(((struct nfsv2_time *)(&sp->sa_mtime))-> nfsv2_usec)); else (&nvap->na_vattr.va_mtime)->tv_nsec = 0; } while (0); | |||
2350 | break; | |||
2351 | case ND_NFSV30x00000008: | |||
2352 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2353 | if (*tl == newnfs_true) { | |||
2354 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2355 | nvap->na_modena_vattr.va_mode = nfstov_mode(*tl)(((u_int16_t)(__builtin_constant_p((int32_t)((*tl))) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(( *tl)))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)((*tl)))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)((*tl)))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)((*tl)))) & 0xffff ))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)((*tl)))) >> 16) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)((*tl)))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)((*tl)))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)((*tl)))) >> 16)))) : __bswap32_var((int32_t)((*tl)))))&07777 ); | |||
2356 | } | |||
2357 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2358 | if (*tl == newnfs_true) { | |||
2359 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2360 | nvap->na_uidna_vattr.va_uid = fxdr_unsigned(uid_t, *tl)((uid_t)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)( ((__uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
2361 | } | |||
2362 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2363 | if (*tl == newnfs_true) { | |||
2364 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2365 | nvap->na_gidna_vattr.va_gid = fxdr_unsigned(gid_t, *tl)((gid_t)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)( ((__uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
2366 | } | |||
2367 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2368 | if (*tl == newnfs_true) { | |||
2369 | NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (2 * 4)); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2370 | nvap->na_sizena_vattr.va_size = fxdr_hyper(tl)((((u_quad_t)(__builtin_constant_p(((u_int32_t *)(tl))[0]) ? ( ((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t) (((u_int32_t *)(tl))[0])) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *) (tl))[0])) >> 16)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[0])) >> 16)))) : __bswap32_var((( u_int32_t *)(tl))[0]))) << 32) | (u_quad_t)((__builtin_constant_p (((u_int32_t *)(tl))[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl ))[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[1])) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(((u_int32_t *)(tl))[1])) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)))) : __bswap32_var (((u_int32_t *)(tl))[1])))); | |||
2371 | } | |||
2372 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2373 | switch (fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl))))) { | |||
2374 | case NFSV3SATTRTIME_TOCLIENT2: | |||
2375 | NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (2 * 4)); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2376 | fxdr_nfsv3time(tl, &nvap->na_atime)do { (&nvap->na_vattr.va_atime)->tv_sec = (__builtin_constant_p (((struct nfsv3_time *)(tl))->nfsv3_sec) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16)))) : __bswap32_var(((struct nfsv3_time *)(tl))->nfsv3_sec)); (&nvap->na_vattr. va_atime)->tv_nsec = (__builtin_constant_p(((struct nfsv3_time *)(tl))->nfsv3_nsec) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((struct nfsv3_time *)(tl ))->nfsv3_nsec)) >> 16) ? (__uint16_t)(((__uint16_t) (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) >> 16)))) : __bswap32_var(((struct nfsv3_time *)(tl))->nfsv3_nsec )); } while (0); | |||
2377 | toclient = 1; | |||
2378 | break; | |||
2379 | case NFSV3SATTRTIME_TOSERVER1: | |||
2380 | vfs_timestamp(&nvap->na_atimena_vattr.va_atime); | |||
2381 | nvap->na_vaflagsna_vattr.va_vaflags |= VA_UTIMES_NULL0x01; | |||
2382 | break; | |||
2383 | } | |||
2384 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2385 | switch (fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl))))) { | |||
2386 | case NFSV3SATTRTIME_TOCLIENT2: | |||
2387 | NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (2 * 4)); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2388 | fxdr_nfsv3time(tl, &nvap->na_mtime)do { (&nvap->na_vattr.va_mtime)->tv_sec = (__builtin_constant_p (((struct nfsv3_time *)(tl))->nfsv3_sec) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_sec)) >> 16)))) : __bswap32_var(((struct nfsv3_time *)(tl))->nfsv3_sec)); (&nvap->na_vattr. va_mtime)->tv_nsec = (__builtin_constant_p(((struct nfsv3_time *)(tl))->nfsv3_nsec) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((struct nfsv3_time *)(tl ))->nfsv3_nsec)) >> 16) ? (__uint16_t)(((__uint16_t) (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv3_time *)(tl))->nfsv3_nsec)) >> 16)))) : __bswap32_var(((struct nfsv3_time *)(tl))->nfsv3_nsec )); } while (0); | |||
2389 | nvap->na_vaflagsna_vattr.va_vaflags &= ~VA_UTIMES_NULL0x01; | |||
2390 | break; | |||
2391 | case NFSV3SATTRTIME_TOSERVER1: | |||
2392 | vfs_timestamp(&nvap->na_mtimena_vattr.va_mtime); | |||
2393 | if (!toclient) | |||
2394 | nvap->na_vaflagsna_vattr.va_vaflags |= VA_UTIMES_NULL0x01; | |||
2395 | break; | |||
2396 | } | |||
2397 | break; | |||
2398 | case ND_NFSV40x00000010: | |||
2399 | error = nfsv4_sattr(nd, vp, nvap, attrbitp, aclp, p); | |||
2400 | } | |||
2401 | nfsmout: | |||
2402 | NFSEXITCODE2(error, nd); | |||
2403 | return (error); | |||
2404 | } | |||
2405 | ||||
2406 | /* | |||
2407 | * Handle the setable attributes for V4. | |||
2408 | * Returns NFSERR_BADXDR if it can't be parsed, 0 otherwise. | |||
2409 | */ | |||
2410 | int | |||
2411 | nfsv4_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap, | |||
2412 | nfsattrbit_t *attrbitp, NFSACL_Tstruct acl *aclp, struct thread *p) | |||
2413 | { | |||
2414 | u_int32_t *tl; | |||
2415 | int attrsum = 0; | |||
2416 | int i, j; | |||
2417 | int error, attrsize, bitpos, aclsize, aceerr, retnotsup = 0; | |||
2418 | int toclient = 0; | |||
2419 | u_char *cp, namestr[NFSV4_SMALLSTR50 + 1]; | |||
2420 | uid_t uid; | |||
2421 | gid_t gid; | |||
2422 | ||||
2423 | error = nfsrv_getattrbits(nd, attrbitp, NULL((void *)0), &retnotsup); | |||
2424 | if (error) | |||
2425 | goto nfsmout; | |||
2426 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2427 | attrsize = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
2428 | ||||
2429 | /* | |||
2430 | * Loop around getting the setable attributes. If an unsupported | |||
2431 | * one is found, set nd_repstat == NFSERR_ATTRNOTSUPP and return. | |||
2432 | */ | |||
2433 | if (retnotsup) { | |||
2434 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2435 | bitpos = NFSATTRBIT_MAX77; | |||
2436 | } else { | |||
2437 | bitpos = 0; | |||
2438 | } | |||
2439 | for (; bitpos < NFSATTRBIT_MAX77; bitpos++) { | |||
2440 | if (attrsum > attrsize) { | |||
2441 | error = NFSERR_BADXDR10036; | |||
2442 | goto nfsmout; | |||
2443 | } | |||
2444 | if (NFSISSET_ATTRBIT(attrbitp, bitpos)((attrbitp)->bits[(bitpos) / 32] & (1 << ((bitpos ) % 32)))) | |||
2445 | switch (bitpos) { | |||
2446 | case NFSATTRBIT_SIZE4: | |||
2447 | NFSM_DISSECT(tl, u_int32_t *, NFSX_HYPER)do { (tl) = (u_int32_t *)nfsm_dissect(nd, ((2 * 4))); if ((tl ) == ((void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2448 | if (vp != NULL((void *)0) && vp->v_type != VREG) { | |||
2449 | error = (vp->v_type == VDIR) ? NFSERR_ISDIR21 : | |||
2450 | NFSERR_INVAL22; | |||
2451 | goto nfsmout; | |||
2452 | } | |||
2453 | nvap->na_sizena_vattr.va_size = fxdr_hyper(tl)((((u_quad_t)(__builtin_constant_p(((u_int32_t *)(tl))[0]) ? ( ((__uint32_t)((__uint16_t)(__builtin_constant_p(((__uint32_t) (((u_int32_t *)(tl))[0])) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((u_int32_t *)(tl))[0])) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[0])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *) (tl))[0])) >> 16)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[0])) >> 16)))) : __bswap32_var((( u_int32_t *)(tl))[0]))) << 32) | (u_quad_t)((__builtin_constant_p (((u_int32_t *)(tl))[1]) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff) ? (__uint16_t )(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) & 0xffff )) << 8 | ((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl ))[1])) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t )(((u_int32_t *)(tl))[1])) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)) << 8 | ((__uint16_t)(((__uint32_t )(((u_int32_t *)(tl))[1])) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((u_int32_t *)(tl))[1])) >> 16)))) : __bswap32_var (((u_int32_t *)(tl))[1])))); | |||
2454 | attrsum += NFSX_HYPER(2 * 4); | |||
2455 | break; | |||
2456 | case NFSATTRBIT_ACL12: | |||
2457 | error = nfsrv_dissectacl(nd, aclp, &aceerr, &aclsize, | |||
2458 | p); | |||
2459 | if (error) | |||
2460 | goto nfsmout; | |||
2461 | if (aceerr && !nd->nd_repstat) | |||
2462 | nd->nd_repstat = aceerr; | |||
2463 | attrsum += aclsize; | |||
2464 | break; | |||
2465 | case NFSATTRBIT_ARCHIVE14: | |||
2466 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2467 | if (!nd->nd_repstat) | |||
2468 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2469 | attrsum += NFSX_UNSIGNED4; | |||
2470 | break; | |||
2471 | case NFSATTRBIT_HIDDEN25: | |||
2472 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2473 | if (!nd->nd_repstat) | |||
2474 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2475 | attrsum += NFSX_UNSIGNED4; | |||
2476 | break; | |||
2477 | case NFSATTRBIT_MIMETYPE32: | |||
2478 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2479 | i = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
2480 | error = nfsm_advance(nd, NFSM_RNDUP(i)(((i)+3)&(~0x3)), -1); | |||
2481 | if (error) | |||
2482 | goto nfsmout; | |||
2483 | if (!nd->nd_repstat) | |||
2484 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2485 | attrsum += (NFSX_UNSIGNED4 + NFSM_RNDUP(i)(((i)+3)&(~0x3))); | |||
2486 | break; | |||
2487 | case NFSATTRBIT_MODE33: | |||
2488 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2489 | nvap->na_modena_vattr.va_mode = nfstov_mode(*tl)(((u_int16_t)(__builtin_constant_p((int32_t)((*tl))) ? (((__uint32_t )((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(( *tl)))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t )((int32_t)((*tl)))) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)((int32_t)((*tl)))) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)((*tl)))) & 0xffff ))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t )((int32_t)((*tl)))) >> 16) ? (__uint16_t)(((__uint16_t )(((__uint32_t)((int32_t)((*tl)))) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)((int32_t)((*tl)))) >> 16)) >> 8) : __bswap16_var(((__uint32_t)((int32_t)((*tl)))) >> 16)))) : __bswap32_var((int32_t)((*tl)))))&07777 ); | |||
2490 | attrsum += NFSX_UNSIGNED4; | |||
2491 | break; | |||
2492 | case NFSATTRBIT_OWNER36: | |||
2493 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2494 | j = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
2495 | if (j < 0) { | |||
2496 | error = NFSERR_BADXDR10036; | |||
2497 | goto nfsmout; | |||
2498 | } | |||
2499 | if (j > NFSV4_SMALLSTR50) | |||
2500 | cp = malloc(j + 1, M_NFSSTRINGM_NEWNFSSTRING, M_WAITOK0x0002); | |||
2501 | else | |||
2502 | cp = namestr; | |||
2503 | error = nfsrv_mtostr(nd, cp, j); | |||
2504 | if (error) { | |||
2505 | if (j > NFSV4_SMALLSTR50) | |||
2506 | free(cp, M_NFSSTRINGM_NEWNFSSTRING); | |||
2507 | goto nfsmout; | |||
2508 | } | |||
2509 | if (!nd->nd_repstat) { | |||
2510 | nd->nd_repstat = nfsv4_strtouid(nd, cp, j, &uid, | |||
2511 | p); | |||
2512 | if (!nd->nd_repstat) | |||
2513 | nvap->na_uidna_vattr.va_uid = uid; | |||
2514 | } | |||
2515 | if (j > NFSV4_SMALLSTR50) | |||
2516 | free(cp, M_NFSSTRINGM_NEWNFSSTRING); | |||
2517 | attrsum += (NFSX_UNSIGNED4 + NFSM_RNDUP(j)(((j)+3)&(~0x3))); | |||
2518 | break; | |||
2519 | case NFSATTRBIT_OWNERGROUP37: | |||
2520 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2521 | j = fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl)))); | |||
2522 | if (j < 0) { | |||
2523 | error = NFSERR_BADXDR10036; | |||
2524 | goto nfsmout; | |||
2525 | } | |||
2526 | if (j > NFSV4_SMALLSTR50) | |||
2527 | cp = malloc(j + 1, M_NFSSTRINGM_NEWNFSSTRING, M_WAITOK0x0002); | |||
2528 | else | |||
2529 | cp = namestr; | |||
2530 | error = nfsrv_mtostr(nd, cp, j); | |||
2531 | if (error) { | |||
2532 | if (j > NFSV4_SMALLSTR50) | |||
2533 | free(cp, M_NFSSTRINGM_NEWNFSSTRING); | |||
2534 | goto nfsmout; | |||
2535 | } | |||
2536 | if (!nd->nd_repstat) { | |||
2537 | nd->nd_repstat = nfsv4_strtogid(nd, cp, j, &gid, | |||
2538 | p); | |||
2539 | if (!nd->nd_repstat) | |||
2540 | nvap->na_gidna_vattr.va_gid = gid; | |||
2541 | } | |||
2542 | if (j > NFSV4_SMALLSTR50) | |||
2543 | free(cp, M_NFSSTRINGM_NEWNFSSTRING); | |||
2544 | attrsum += (NFSX_UNSIGNED4 + NFSM_RNDUP(j)(((j)+3)&(~0x3))); | |||
2545 | break; | |||
2546 | case NFSATTRBIT_SYSTEM46: | |||
2547 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2548 | if (!nd->nd_repstat) | |||
2549 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2550 | attrsum += NFSX_UNSIGNED4; | |||
2551 | break; | |||
2552 | case NFSATTRBIT_TIMEACCESSSET48: | |||
2553 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2554 | attrsum += NFSX_UNSIGNED4; | |||
2555 | if (fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl))))==NFSV4SATTRTIME_TOCLIENT1) { | |||
2556 | NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (((2 * 4) + 4))); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while ( 0); | |||
2557 | fxdr_nfsv4time(tl, &nvap->na_atime)do { (&nvap->na_vattr.va_atime)->tv_sec = (__builtin_constant_p (((struct nfsv4_time *)(tl))->nfsv4_sec) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16)))) : __bswap32_var(((struct nfsv4_time *)(tl))->nfsv4_sec)); (&nvap->na_vattr. va_atime)->tv_nsec = ((__builtin_constant_p(((struct nfsv4_time *)(tl))->nfsv4_nsec) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((struct nfsv4_time *)(tl ))->nfsv4_nsec)) >> 16) ? (__uint16_t)(((__uint16_t) (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) >> 16)))) : __bswap32_var(((struct nfsv4_time *)(tl))->nfsv4_nsec )) % 1000000000); } while (0); | |||
2558 | toclient = 1; | |||
2559 | attrsum += NFSX_V4TIME((2 * 4) + 4); | |||
2560 | } else { | |||
2561 | vfs_timestamp(&nvap->na_atimena_vattr.va_atime); | |||
2562 | nvap->na_vaflagsna_vattr.va_vaflags |= VA_UTIMES_NULL0x01; | |||
2563 | } | |||
2564 | break; | |||
2565 | case NFSATTRBIT_TIMEBACKUP49: | |||
2566 | NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (((2 * 4) + 4))); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while ( 0); | |||
2567 | if (!nd->nd_repstat) | |||
2568 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2569 | attrsum += NFSX_V4TIME((2 * 4) + 4); | |||
2570 | break; | |||
2571 | case NFSATTRBIT_TIMECREATE50: | |||
2572 | NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (((2 * 4) + 4))); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while ( 0); | |||
2573 | if (!nd->nd_repstat) | |||
2574 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2575 | attrsum += NFSX_V4TIME((2 * 4) + 4); | |||
2576 | break; | |||
2577 | case NFSATTRBIT_TIMEMODIFYSET54: | |||
2578 | NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (4)); if ((tl) == ( (void *)0)) { error = 72; goto nfsmout; } } while (0); | |||
2579 | attrsum += NFSX_UNSIGNED4; | |||
2580 | if (fxdr_unsigned(int, *tl)((int)(__builtin_constant_p((int32_t)(*tl)) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(*tl ))) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)( (int32_t)(*tl))) & 0xffff)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p(((__uint32_t)((int32_t)(* tl))) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t) ((int32_t)(*tl))) >> 16)) << 8 | ((__uint16_t)((( __uint32_t)((int32_t)(*tl))) >> 16)) >> 8) : __bswap16_var (((__uint32_t)((int32_t)(*tl))) >> 16)))) : __bswap32_var ((int32_t)(*tl))))==NFSV4SATTRTIME_TOCLIENT1) { | |||
2581 | NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME)do { (tl) = (u_int32_t *)nfsm_dissect(nd, (((2 * 4) + 4))); if ((tl) == ((void *)0)) { error = 72; goto nfsmout; } } while ( 0); | |||
2582 | fxdr_nfsv4time(tl, &nvap->na_mtime)do { (&nvap->na_vattr.va_mtime)->tv_sec = (__builtin_constant_p (((struct nfsv4_time *)(tl))->nfsv4_sec) ? (((__uint32_t)( (__uint16_t)(__builtin_constant_p(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff) ? (__uint16_t)(((__uint16_t )(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) & 0xffff))) << 16) | ((__uint16_t)(__builtin_constant_p( ((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_sec)) >> 16)))) : __bswap32_var(((struct nfsv4_time *)(tl))->nfsv4_sec)); (&nvap->na_vattr. va_mtime)->tv_nsec = ((__builtin_constant_p(((struct nfsv4_time *)(tl))->nfsv4_nsec) ? (((__uint32_t)((__uint16_t)(__builtin_constant_p (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff) ? (__uint16_t)(((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff)) << 8 | ((__uint16_t )(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff)) >> 8) : __bswap16_var(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) & 0xffff))) << 16) | ((__uint16_t )(__builtin_constant_p(((__uint32_t)(((struct nfsv4_time *)(tl ))->nfsv4_nsec)) >> 16) ? (__uint16_t)(((__uint16_t) (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) >> 16)) << 8 | ((__uint16_t)(((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) >> 16)) >> 8) : __bswap16_var (((__uint32_t)(((struct nfsv4_time *)(tl))->nfsv4_nsec)) >> 16)))) : __bswap32_var(((struct nfsv4_time *)(tl))->nfsv4_nsec )) % 1000000000); } while (0); | |||
2583 | nvap->na_vaflagsna_vattr.va_vaflags &= ~VA_UTIMES_NULL0x01; | |||
2584 | attrsum += NFSX_V4TIME((2 * 4) + 4); | |||
2585 | } else { | |||
2586 | vfs_timestamp(&nvap->na_mtimena_vattr.va_mtime); | |||
2587 | if (!toclient) | |||
2588 | nvap->na_vaflagsna_vattr.va_vaflags |= VA_UTIMES_NULL0x01; | |||
2589 | } | |||
2590 | break; | |||
2591 | default: | |||
2592 | nd->nd_repstat = NFSERR_ATTRNOTSUPP10032; | |||
2593 | /* | |||
2594 | * set bitpos so we drop out of the loop. | |||
2595 | */ | |||
2596 | bitpos = NFSATTRBIT_MAX77; | |||
2597 | break; | |||
2598 | } | |||
2599 | } | |||
2600 | ||||
2601 | /* | |||
2602 | * some clients pad the attrlist, so we need to skip over the | |||
2603 | * padding. | |||
2604 | */ | |||
2605 | if (attrsum > attrsize) { | |||
2606 | error = NFSERR_BADXDR10036; | |||
2607 | } else { | |||
2608 | attrsize = NFSM_RNDUP(attrsize)(((attrsize)+3)&(~0x3)); | |||
2609 | if (attrsum < attrsize) | |||
2610 | error = nfsm_advance(nd, attrsize - attrsum, -1); | |||
2611 | } | |||
2612 | nfsmout: | |||
2613 | NFSEXITCODE2(error, nd); | |||
2614 | return (error); | |||
2615 | } | |||
2616 | ||||
2617 | /* | |||
2618 | * Check/setup export credentials. | |||
2619 | */ | |||
2620 | int | |||
2621 | nfsd_excred(struct nfsrv_descript *nd, struct nfsexstuff *exp, | |||
2622 | struct ucred *credanon) | |||
2623 | { | |||
2624 | int error = 0; | |||
2625 | ||||
2626 | /* | |||
2627 | * Check/setup credentials. | |||
2628 | */ | |||
2629 | if (nd->nd_flag & ND_GSS(0x00000020)) | |||
2630 | exp->nes_exflag &= ~MNT_EXPORTANON0x0000000000000400ULL; | |||
2631 | ||||
2632 | /* | |||
2633 | * Check to see if the operation is allowed for this security flavor. | |||
2634 | * RFC2623 suggests that the NFSv3 Fsinfo RPC be allowed to | |||
2635 | * AUTH_NONE or AUTH_SYS for file systems requiring RPCSEC_GSS. | |||
2636 | * Also, allow Secinfo, so that it can acquire the correct flavor(s). | |||
2637 | */ | |||
2638 | if (nfsvno_testexp(nd, exp) && | |||
2639 | nd->nd_procnum != NFSV4OP_SECINFO33 && | |||
2640 | nd->nd_procnum != NFSPROC_FSINFO19) { | |||
2641 | if (nd->nd_flag & ND_NFSV40x00000010) | |||
2642 | error = NFSERR_WRONGSEC10016; | |||
2643 | else | |||
2644 | error = (NFSERR_AUTHERR0x80000000 | AUTH_TOOWEAK5); | |||
2645 | goto out; | |||
2646 | } | |||
2647 | ||||
2648 | /* | |||
2649 | * Check to see if the file system is exported V4 only. | |||
2650 | */ | |||
2651 | if (NFSVNO_EXV4ONLY(exp)((exp)->nes_exflag & 0x0) && !(nd->nd_flag & ND_NFSV40x00000010)) { | |||
2652 | error = NFSERR_PROGNOTV4(0x40000000 | 0xffff); | |||
2653 | goto out; | |||
2654 | } | |||
2655 | ||||
2656 | /* | |||
2657 | * Now, map the user credentials. | |||
2658 | * (Note that ND_AUTHNONE will only be set for an NFSv3 | |||
2659 | * Fsinfo RPC. If set for anything else, this code might need | |||
2660 | * to change.) | |||
2661 | */ | |||
2662 | if (NFSVNO_EXPORTED(exp)((exp)->nes_exflag & 0x0000000000000100ULL)) { | |||
2663 | if (((nd->nd_flag & ND_GSS(0x00000020)) == 0 && nd->nd_cred->cr_uid == 0) || | |||
2664 | NFSVNO_EXPORTANON(exp)((exp)->nes_exflag & 0x0000000000000400ULL) || | |||
2665 | (nd->nd_flag & ND_AUTHNONE0x00040000) != 0) { | |||
2666 | nd->nd_cred->cr_uid = credanon->cr_uid; | |||
2667 | nd->nd_cred->cr_gidcr_groups[0] = credanon->cr_gidcr_groups[0]; | |||
2668 | crsetgroups(nd->nd_cred, credanon->cr_ngroups, | |||
2669 | credanon->cr_groups); | |||
2670 | } else if ((nd->nd_flag & ND_GSS(0x00000020)) == 0) { | |||
2671 | /* | |||
2672 | * If using AUTH_SYS, call nfsrv_getgrpscred() to see | |||
2673 | * if there is a replacement credential with a group | |||
2674 | * list set up by "nfsuserd -manage-gids". | |||
2675 | * If there is no replacement, nfsrv_getgrpscred() | |||
2676 | * simply returns its argument. | |||
2677 | */ | |||
2678 | nd->nd_cred = nfsrv_getgrpscred(nd->nd_cred); | |||
2679 | } | |||
2680 | } | |||
2681 | ||||
2682 | out: | |||
2683 | NFSEXITCODE2(error, nd); | |||
2684 | return (error); | |||
2685 | } | |||
2686 | ||||
2687 | /* | |||
2688 | * Check exports. | |||
2689 | */ | |||
2690 | int | |||
2691 | nfsvno_checkexp(struct mount *mp, struct sockaddr *nam, struct nfsexstuff *exp, | |||
2692 | struct ucred **credp) | |||
2693 | { | |||
2694 | int i, error, *secflavors; | |||
2695 | ||||
2696 | error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_checkexp)(mp, nam, & exp->nes_exflag, credp, &exp->nes_numsecflavor, & secflavors); sigallowstop(_prev_stops); } while (0); _rc; }) | |||
2697 | &exp->nes_numsecflavor, &secflavors)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_checkexp)(mp, nam, & exp->nes_exflag, credp, &exp->nes_numsecflavor, & secflavors); sigallowstop(_prev_stops); } while (0); _rc; }); | |||
2698 | if (error) { | |||
2699 | if (nfs_rootfhset) { | |||
2700 | exp->nes_exflag = 0; | |||
2701 | exp->nes_numsecflavor = 0; | |||
2702 | error = 0; | |||
2703 | } | |||
2704 | } else { | |||
2705 | /* Copy the security flavors. */ | |||
2706 | for (i = 0; i < exp->nes_numsecflavor; i++) | |||
2707 | exp->nes_secflavors[i] = secflavors[i]; | |||
2708 | } | |||
2709 | NFSEXITCODE(error); | |||
2710 | return (error); | |||
2711 | } | |||
2712 | ||||
2713 | /* | |||
2714 | * Get a vnode for a file handle and export stuff. | |||
2715 | */ | |||
2716 | int | |||
2717 | nfsvno_fhtovp(struct mount *mp, fhandle_t *fhp, struct sockaddr *nam, | |||
2718 | int lktype, struct vnode **vpp, struct nfsexstuff *exp, | |||
2719 | struct ucred **credp) | |||
2720 | { | |||
2721 | int i, error, *secflavors; | |||
2722 | ||||
2723 | *credp = NULL((void *)0); | |||
2724 | exp->nes_numsecflavor = 0; | |||
2725 | error = VFS_FHTOVP(mp, &fhp->fh_fid, lktype, vpp)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_fhtovp)(mp, &fhp-> fh_fid, lktype, vpp); sigallowstop(_prev_stops); } while (0); _rc; }); | |||
2726 | if (error != 0) | |||
2727 | /* Make sure the server replies ESTALE to the client. */ | |||
2728 | error = ESTALE70; | |||
2729 | if (nam && !error) { | |||
2730 | error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_checkexp)(mp, nam, & exp->nes_exflag, credp, &exp->nes_numsecflavor, & secflavors); sigallowstop(_prev_stops); } while (0); _rc; }) | |||
2731 | &exp->nes_numsecflavor, &secflavors)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_checkexp)(mp, nam, & exp->nes_exflag, credp, &exp->nes_numsecflavor, & secflavors); sigallowstop(_prev_stops); } while (0); _rc; }); | |||
2732 | if (error) { | |||
2733 | if (nfs_rootfhset) { | |||
2734 | exp->nes_exflag = 0; | |||
2735 | exp->nes_numsecflavor = 0; | |||
2736 | error = 0; | |||
2737 | } else { | |||
2738 | vput(*vpp); | |||
2739 | } | |||
2740 | } else { | |||
2741 | /* Copy the security flavors. */ | |||
2742 | for (i = 0; i < exp->nes_numsecflavor; i++) | |||
2743 | exp->nes_secflavors[i] = secflavors[i]; | |||
2744 | } | |||
2745 | } | |||
2746 | NFSEXITCODE(error); | |||
2747 | return (error); | |||
2748 | } | |||
2749 | ||||
2750 | /* | |||
2751 | * nfsd_fhtovp() - convert a fh to a vnode ptr | |||
2752 | * - look up fsid in mount list (if not found ret error) | |||
2753 | * - get vp and export rights by calling nfsvno_fhtovp() | |||
2754 | * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon | |||
2755 | * for AUTH_SYS | |||
2756 | * - if mpp != NULL, return the mount point so that it can | |||
2757 | * be used for vn_finished_write() by the caller | |||
2758 | */ | |||
2759 | void | |||
2760 | nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, int lktype, | |||
2761 | struct vnode **vpp, struct nfsexstuff *exp, | |||
2762 | struct mount **mpp, int startwrite, struct thread *p) | |||
2763 | { | |||
2764 | struct mount *mp; | |||
2765 | struct ucred *credanon; | |||
2766 | fhandle_t *fhp; | |||
2767 | ||||
2768 | fhp = (fhandle_t *)nfp->nfsrvfh_data; | |||
2769 | /* | |||
2770 | * Check for the special case of the nfsv4root_fh. | |||
2771 | */ | |||
2772 | mp = vfs_busyfs(&fhp->fh_fsid); | |||
2773 | if (mpp != NULL((void *)0)) | |||
2774 | *mpp = mp; | |||
2775 | if (mp == NULL((void *)0)) { | |||
2776 | *vpp = NULL((void *)0); | |||
2777 | nd->nd_repstat = ESTALE70; | |||
2778 | goto out; | |||
2779 | } | |||
2780 | ||||
2781 | if (startwrite) { | |||
2782 | vn_start_write(NULL((void *)0), mpp, V_WAIT0x0001); | |||
2783 | if (lktype == LK_SHARED0x200000 && !(MNT_SHARED_WRITES(mp))) | |||
2784 | lktype = LK_EXCLUSIVE0x080000; | |||
2785 | } | |||
2786 | nd->nd_repstat = nfsvno_fhtovp(mp, fhp, nd->nd_nam, lktype, vpp, exp, | |||
2787 | &credanon); | |||
2788 | vfs_unbusy(mp); | |||
2789 | ||||
2790 | /* | |||
2791 | * For NFSv4 without a pseudo root fs, unexported file handles | |||
2792 | * can be returned, so that Lookup works everywhere. | |||
2793 | */ | |||
2794 | if (!nd->nd_repstat && exp->nes_exflag == 0 && | |||
2795 | !(nd->nd_flag & ND_NFSV40x00000010)) { | |||
2796 | vput(*vpp); | |||
2797 | nd->nd_repstat = EACCES13; | |||
2798 | } | |||
2799 | ||||
2800 | /* | |||
2801 | * Personally, I've never seen any point in requiring a | |||
2802 | * reserved port#, since only in the rare case where the | |||
2803 | * clients are all boxes with secure system privileges, | |||
2804 | * does it provide any enhanced security, but... some people | |||
2805 | * believe it to be useful and keep putting this code back in. | |||
2806 | * (There is also some "security checker" out there that | |||
2807 | * complains if the nfs server doesn't enforce this.) | |||
2808 | * However, note the following: | |||
2809 | * RFC3530 (NFSv4) specifies that a reserved port# not be | |||
2810 | * required. | |||
2811 | * RFC2623 recommends that, if a reserved port# is checked for, | |||
2812 | * that there be a way to turn that off--> ifdef'd. | |||
2813 | */ | |||
2814 | #ifdef NFS_REQRSVPORT | |||
2815 | if (!nd->nd_repstat) { | |||
2816 | struct sockaddr_in *saddr; | |||
2817 | struct sockaddr_in6 *saddr6; | |||
2818 | ||||
2819 | saddr = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *)((struct sockaddr_in *)(nd->nd_nam)); | |||
2820 | saddr6 = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in6 *)((struct sockaddr_in6 *)(nd->nd_nam)); | |||
2821 | if (!(nd->nd_flag & ND_NFSV40x00000010) && | |||
2822 | ((saddr->sin_family == AF_INET2 && | |||
2823 | ntohs(saddr->sin_port)((__uint16_t)(__builtin_constant_p(saddr->sin_port) ? (__uint16_t )(((__uint16_t)(saddr->sin_port)) << 8 | ((__uint16_t )(saddr->sin_port)) >> 8) : __bswap16_var(saddr-> sin_port))) >= IPPORT_RESERVED1024) || | |||
2824 | (saddr6->sin6_family == AF_INET628 && | |||
2825 | ntohs(saddr6->sin6_port)((__uint16_t)(__builtin_constant_p(saddr6->sin6_port) ? (__uint16_t )(((__uint16_t)(saddr6->sin6_port)) << 8 | ((__uint16_t )(saddr6->sin6_port)) >> 8) : __bswap16_var(saddr6-> sin6_port))) >= IPPORT_RESERVED1024))) { | |||
2826 | vput(*vpp); | |||
2827 | nd->nd_repstat = (NFSERR_AUTHERR0x80000000 | AUTH_TOOWEAK5); | |||
2828 | } | |||
2829 | } | |||
2830 | #endif /* NFS_REQRSVPORT */ | |||
2831 | ||||
2832 | /* | |||
2833 | * Check/setup credentials. | |||
2834 | */ | |||
2835 | if (!nd->nd_repstat) { | |||
2836 | nd->nd_saveduid = nd->nd_cred->cr_uid; | |||
2837 | nd->nd_repstat = nfsd_excred(nd, exp, credanon); | |||
2838 | if (nd->nd_repstat) | |||
2839 | vput(*vpp); | |||
2840 | } | |||
2841 | if (credanon != NULL((void *)0)) | |||
2842 | crfree(credanon); | |||
2843 | if (nd->nd_repstat) { | |||
2844 | if (startwrite) | |||
2845 | vn_finished_write(mp); | |||
2846 | *vpp = NULL((void *)0); | |||
2847 | if (mpp != NULL((void *)0)) | |||
2848 | *mpp = NULL((void *)0); | |||
2849 | } | |||
2850 | ||||
2851 | out: | |||
2852 | NFSEXITCODE2(0, nd); | |||
2853 | } | |||
2854 | ||||
2855 | /* | |||
2856 | * glue for fp. | |||
2857 | */ | |||
2858 | static int | |||
2859 | fp_getfvp(struct thread *p, int fd, struct file **fpp, struct vnode **vpp) | |||
2860 | { | |||
2861 | struct filedesc *fdp; | |||
2862 | struct file *fp; | |||
2863 | int error = 0; | |||
2864 | ||||
2865 | fdp = p->td_proc->p_fd; | |||
2866 | if (fd < 0 || fd >= fdp->fd_nfilesfd_files->fdt_nfiles || | |||
2867 | (fp = fdp->fd_ofilesfd_files->fdt_ofiles[fd].fde_file) == NULL((void *)0)) { | |||
2868 | error = EBADF9; | |||
2869 | goto out; | |||
2870 | } | |||
2871 | *fpp = fp; | |||
2872 | ||||
2873 | out: | |||
2874 | NFSEXITCODE(error); | |||
2875 | return (error); | |||
2876 | } | |||
2877 | ||||
2878 | /* | |||
2879 | * Called from nfssvc() to update the exports list. Just call | |||
2880 | * vfs_export(). This has to be done, since the v4 root fake fs isn't | |||
2881 | * in the mount list. | |||
2882 | */ | |||
2883 | int | |||
2884 | nfsrv_v4rootexport(void *argp, struct ucred *cred, struct thread *p) | |||
2885 | { | |||
2886 | struct nfsex_args *nfsexargp = (struct nfsex_args *)argp; | |||
2887 | int error = 0; | |||
2888 | struct nameidata nd; | |||
2889 | fhandle_t fh; | |||
2890 | ||||
2891 | error = vfs_export(&nfsv4root_mnt, &nfsexargp->export); | |||
2892 | if ((nfsexargp->export.ex_flags & MNT_DELEXPORT0x0000000000020000ULL) != 0) | |||
2893 | nfs_rootfhset = 0; | |||
2894 | else if (error == 0) { | |||
2895 | if (nfsexargp->fspec == NULL((void *)0)) { | |||
2896 | error = EPERM1; | |||
2897 | goto out; | |||
2898 | } | |||
2899 | /* | |||
2900 | * If fspec != NULL, this is the v4root path. | |||
2901 | */ | |||
2902 | NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,NDINIT_ALL(&nd, 0, 0x0040, UIO_USERSPACE, nfsexargp->fspec , -100, ((void *)0), 0, p) | |||
2903 | nfsexargp->fspec, p)NDINIT_ALL(&nd, 0, 0x0040, UIO_USERSPACE, nfsexargp->fspec , -100, ((void *)0), 0, p); | |||
2904 | if ((error = namei(&nd)) != 0) | |||
2905 | goto out; | |||
2906 | error = nfsvno_getfh(nd.ni_vp, &fh, p); | |||
2907 | vrele(nd.ni_vp); | |||
2908 | if (!error) { | |||
2909 | nfs_rootfh.nfsrvfh_len = NFSX_MYFH(sizeof (fhandle_t)); | |||
2910 | NFSBCOPY((caddr_t)&fh,bcopy(((caddr_t)&fh), (nfs_rootfh.nfsrvfh_data), (sizeof ( fhandle_t))) | |||
2911 | nfs_rootfh.nfsrvfh_data,bcopy(((caddr_t)&fh), (nfs_rootfh.nfsrvfh_data), (sizeof ( fhandle_t))) | |||
2912 | sizeof (fhandle_t))bcopy(((caddr_t)&fh), (nfs_rootfh.nfsrvfh_data), (sizeof ( fhandle_t))); | |||
2913 | nfs_rootfhset = 1; | |||
2914 | } | |||
2915 | } | |||
2916 | ||||
2917 | out: | |||
2918 | NFSEXITCODE(error); | |||
2919 | return (error); | |||
2920 | } | |||
2921 | ||||
2922 | /* | |||
2923 | * This function needs to test to see if the system is near its limit | |||
2924 | * for memory allocation via malloc() or mget() and return True iff | |||
2925 | * either of these resources are near their limit. | |||
2926 | * XXX (For now, this is just a stub.) | |||
2927 | */ | |||
2928 | int nfsrv_testmalloclimit = 0; | |||
2929 | int | |||
2930 | nfsrv_mallocmget_limit(void) | |||
2931 | { | |||
2932 | static int printmesg = 0; | |||
2933 | static int testval = 1; | |||
2934 | ||||
2935 | if (nfsrv_testmalloclimit && (testval++ % 1000) == 0) { | |||
2936 | if ((printmesg++ % 100) == 0) | |||
2937 | printf("nfsd: malloc/mget near limit\n"); | |||
2938 | return (1); | |||
2939 | } | |||
2940 | return (0); | |||
2941 | } | |||
2942 | ||||
2943 | /* | |||
2944 | * BSD specific initialization of a mount point. | |||
2945 | */ | |||
2946 | void | |||
2947 | nfsd_mntinit(void) | |||
2948 | { | |||
2949 | static int inited = 0; | |||
2950 | ||||
2951 | if (inited) | |||
2952 | return; | |||
2953 | inited = 1; | |||
2954 | nfsv4root_mnt.mnt_flag = (MNT_RDONLY0x0000000000000001ULL | MNT_EXPORTED0x0000000000000100ULL); | |||
2955 | TAILQ_INIT(&nfsv4root_mnt.mnt_nvnodelist)do { (((&nfsv4root_mnt.mnt_nvnodelist))->tqh_first) = ( (void *)0); (&nfsv4root_mnt.mnt_nvnodelist)->tqh_last = &(((&nfsv4root_mnt.mnt_nvnodelist))->tqh_first); ; } while (0); | |||
2956 | TAILQ_INIT(&nfsv4root_mnt.mnt_activevnodelist)do { (((&nfsv4root_mnt.mnt_activevnodelist))->tqh_first ) = ((void *)0); (&nfsv4root_mnt.mnt_activevnodelist)-> tqh_last = &(((&nfsv4root_mnt.mnt_activevnodelist))-> tqh_first); ; } while (0); | |||
2957 | nfsv4root_mnt.mnt_export = NULL((void *)0); | |||
2958 | TAILQ_INIT(&nfsv4root_opt)do { (((&nfsv4root_opt))->tqh_first) = ((void *)0); (& nfsv4root_opt)->tqh_last = &(((&nfsv4root_opt))-> tqh_first); ; } while (0); | |||
2959 | TAILQ_INIT(&nfsv4root_newopt)do { (((&nfsv4root_newopt))->tqh_first) = ((void *)0); (&nfsv4root_newopt)->tqh_last = &(((&nfsv4root_newopt ))->tqh_first); ; } while (0); | |||
2960 | nfsv4root_mnt.mnt_opt = &nfsv4root_opt; | |||
2961 | nfsv4root_mnt.mnt_optnew = &nfsv4root_newopt; | |||
2962 | nfsv4root_mnt.mnt_nvnodelistsize = 0; | |||
2963 | nfsv4root_mnt.mnt_activevnodelistsize = 0; | |||
2964 | } | |||
2965 | ||||
2966 | /* | |||
2967 | * Get a vnode for a file handle, without checking exports, etc. | |||
2968 | */ | |||
2969 | struct vnode * | |||
2970 | nfsvno_getvp(fhandle_t *fhp) | |||
2971 | { | |||
2972 | struct mount *mp; | |||
2973 | struct vnode *vp; | |||
2974 | int error; | |||
2975 | ||||
2976 | mp = vfs_busyfs(&fhp->fh_fsid); | |||
2977 | if (mp == NULL((void *)0)) | |||
2978 | return (NULL((void *)0)); | |||
2979 | error = VFS_FHTOVP(mp, &fhp->fh_fid, LK_EXCLUSIVE, &vp)({ int _rc; do { struct mount *mp__; int _prev_stops; mp__ = ( mp); _prev_stops = sigdeferstop((mp__ != ((void *)0) && (mp__->mnt_vfc->vfc_flags & 0x01000000) != 0) ? 2 : 0);; _rc = (*(mp)->mnt_op->vfs_fhtovp)(mp, &fhp-> fh_fid, 0x080000, &vp); sigallowstop(_prev_stops); } while (0); _rc; }); | |||
2980 | vfs_unbusy(mp); | |||
2981 | if (error) | |||
2982 | return (NULL((void *)0)); | |||
2983 | return (vp); | |||
2984 | } | |||
2985 | ||||
2986 | /* | |||
2987 | * Do a local VOP_ADVLOCK(). | |||
2988 | */ | |||
2989 | int | |||
2990 | nfsvno_advlock(struct vnode *vp, int ftype, u_int64_t first, | |||
2991 | u_int64_t end, struct thread *td) | |||
2992 | { | |||
2993 | int error = 0; | |||
2994 | struct flock fl; | |||
2995 | u_int64_t tlen; | |||
2996 | ||||
2997 | if (nfsrv_dolocallocks == 0) | |||
2998 | goto out; | |||
2999 | ASSERT_VOP_UNLOCKED(vp, "nfsvno_advlock: vp locked")((void)0); | |||
3000 | ||||
3001 | fl.l_whence = SEEK_SET0; | |||
3002 | fl.l_type = ftype; | |||
3003 | fl.l_start = (off_t)first; | |||
3004 | if (end == NFS64BITSSET0xffffffffffffffffull) { | |||
3005 | fl.l_len = 0; | |||
3006 | } else { | |||
3007 | tlen = end - first; | |||
3008 | fl.l_len = (off_t)tlen; | |||
3009 | } | |||
3010 | /* | |||
3011 | * For FreeBSD8, the l_pid and l_sysid must be set to the same | |||
3012 | * values for all calls, so that all locks will be held by the | |||
3013 | * nfsd server. (The nfsd server handles conflicts between the | |||
3014 | * various clients.) | |||
3015 | * Since an NFSv4 lockowner is a ClientID plus an array of up to 1024 | |||
3016 | * bytes, so it can't be put in l_sysid. | |||
3017 | */ | |||
3018 | if (nfsv4_sysid == 0) | |||
3019 | nfsv4_sysid = nlm_acquire_next_sysid(); | |||
3020 | fl.l_pid = (pid_t)0; | |||
3021 | fl.l_sysid = (int)nfsv4_sysid; | |||
3022 | ||||
3023 | if (ftype == F_UNLCK2) | |||
3024 | error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_UNLCK2, &fl, | |||
3025 | (F_POSIX0x040 | F_REMOTE0x080)); | |||
3026 | else | |||
3027 | error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_SETLK12, &fl, | |||
3028 | (F_POSIX0x040 | F_REMOTE0x080)); | |||
3029 | ||||
3030 | out: | |||
3031 | NFSEXITCODE(error); | |||
3032 | return (error); | |||
3033 | } | |||
3034 | ||||
3035 | /* | |||
3036 | * Check the nfsv4 root exports. | |||
3037 | */ | |||
3038 | int | |||
3039 | nfsvno_v4rootexport(struct nfsrv_descript *nd) | |||
3040 | { | |||
3041 | struct ucred *credanon; | |||
3042 | int exflags, error = 0, numsecflavor, *secflavors, i; | |||
3043 | ||||
3044 | error = vfs_stdcheckexp(&nfsv4root_mnt, nd->nd_nam, &exflags, | |||
3045 | &credanon, &numsecflavor, &secflavors); | |||
3046 | if (error) { | |||
3047 | error = NFSERR_PROGUNAVAIL(0x40000000 | 1); | |||
3048 | goto out; | |||
3049 | } | |||
3050 | if (credanon != NULL((void *)0)) | |||
3051 | crfree(credanon); | |||
3052 | for (i = 0; i < numsecflavor; i++) { | |||
3053 | if (secflavors[i] == AUTH_SYS1) | |||
3054 | nd->nd_flag |= ND_EXAUTHSYS0x00080000; | |||
3055 | else if (secflavors[i] == RPCSEC_GSS_KRB5390003) | |||
3056 | nd->nd_flag |= ND_EXGSS0x00100000; | |||
3057 | else if (secflavors[i] == RPCSEC_GSS_KRB5I390004) | |||
3058 | nd->nd_flag |= ND_EXGSSINTEGRITY0x00200000; | |||
3059 | else if (secflavors[i] == RPCSEC_GSS_KRB5P390005) | |||
3060 | nd->nd_flag |= ND_EXGSSPRIVACY0x00400000; | |||
3061 | } | |||
3062 | ||||
3063 | out: | |||
3064 | NFSEXITCODE(error); | |||
3065 | return (error); | |||
3066 | } | |||
3067 | ||||
3068 | /* | |||
3069 | * Nfs server pseudo system call for the nfsd's | |||
3070 | */ | |||
3071 | /* | |||
3072 | * MPSAFE | |||
3073 | */ | |||
3074 | static int | |||
3075 | nfssvc_nfsd(struct thread *td, struct nfssvc_args *uap) | |||
3076 | { | |||
3077 | struct file *fp; | |||
3078 | struct nfsd_addsock_args sockarg; | |||
3079 | struct nfsd_nfsd_args nfsdarg; | |||
3080 | cap_rights_t rights; | |||
3081 | int error; | |||
3082 | ||||
3083 | if (uap->flag & NFSSVC_NFSDADDSOCK0x00000100) { | |||
3084 | error = copyin(uap->argp, (caddr_t)&sockarg, sizeof (sockarg)); | |||
3085 | if (error) | |||
3086 | goto out; | |||
3087 | /* | |||
3088 | * Since we don't know what rights might be required, | |||
3089 | * pretend that we need them all. It is better to be too | |||
3090 | * careful than too reckless. | |||
3091 | */ | |||
3092 | error = fget(td, sockarg.sock, | |||
3093 | cap_rights_init(&rights, CAP_SOCK_SERVER)__cap_rights_init(0, &rights, (((1ULL << (57 + (0)) ) | (0x0000000020000000ULL)) | ((1ULL << (57 + (0))) | ( 0x0000000040000000ULL)) | ((1ULL << (57 + (0))) | (0x0000000100000000ULL )) | ((1ULL << (57 + (0))) | (0x0000000200000000ULL)) | ((1ULL << (57 + (0))) | (0x0000000400000000ULL)) | ((1ULL << (57 + (0))) | (0x0000000800000000ULL)) | ((1ULL << (57 + (0))) | (0x0000001000000000ULL)) | ((1ULL << (57 + (0))) | (0x0000000000000001ULL)) | ((1ULL << (57 + ( 0))) | (0x0000000000000002ULL)) | ((1ULL << (57 + (0))) | (0x0000002000000000ULL)) | ((1ULL << (57 + (0))) | ( 0x0000004000000000ULL))), 0ULL), &fp); | |||
3094 | if (error != 0) | |||
3095 | goto out; | |||
3096 | if (fp->f_type != DTYPE_SOCKET2) { | |||
3097 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
3098 | error = EPERM1; | |||
3099 | goto out; | |||
3100 | } | |||
3101 | error = nfsrvd_addsock(fp); | |||
3102 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
3103 | } else if (uap->flag & NFSSVC_NFSDNFSD0x00000080) { | |||
3104 | if (uap->argp == NULL((void *)0)) { | |||
3105 | error = EINVAL22; | |||
3106 | goto out; | |||
3107 | } | |||
3108 | error = copyin(uap->argp, (caddr_t)&nfsdarg, | |||
3109 | sizeof (nfsdarg)); | |||
3110 | if (error) | |||
3111 | goto out; | |||
3112 | error = nfsrvd_nfsd(td, &nfsdarg); | |||
3113 | } else { | |||
3114 | error = nfssvc_srvcall(td, uap, td->td_ucred); | |||
3115 | } | |||
3116 | ||||
3117 | out: | |||
3118 | NFSEXITCODE(error); | |||
3119 | return (error); | |||
3120 | } | |||
3121 | ||||
3122 | static int | |||
3123 | nfssvc_srvcall(struct thread *p, struct nfssvc_args *uap, struct ucred *cred) | |||
3124 | { | |||
3125 | struct nfsex_args export; | |||
3126 | struct file *fp = NULL((void *)0); | |||
3127 | int stablefd, len; | |||
3128 | struct nfsd_clid adminrevoke; | |||
3129 | struct nfsd_dumplist dumplist; | |||
3130 | struct nfsd_dumpclients *dumpclients; | |||
3131 | struct nfsd_dumplocklist dumplocklist; | |||
3132 | struct nfsd_dumplocks *dumplocks; | |||
3133 | struct nameidata nd; | |||
3134 | vnode_t vp; | |||
3135 | int error = EINVAL22, igotlock; | |||
3136 | struct proc *procp; | |||
3137 | static int suspend_nfsd = 0; | |||
3138 | ||||
3139 | if (uap->flag & NFSSVC_PUBLICFH0x00080000) { | |||
| ||||
3140 | NFSBZERO((caddr_t)&nfs_pubfh.nfsrvfh_data,bzero(((caddr_t)&nfs_pubfh.nfsrvfh_data), (sizeof (fhandle_t ))) | |||
3141 | sizeof (fhandle_t))bzero(((caddr_t)&nfs_pubfh.nfsrvfh_data), (sizeof (fhandle_t ))); | |||
3142 | error = copyin(uap->argp, | |||
3143 | &nfs_pubfh.nfsrvfh_data, sizeof (fhandle_t)); | |||
3144 | if (!error) | |||
3145 | nfs_pubfhset = 1; | |||
3146 | } else if (uap->flag & NFSSVC_V4ROOTEXPORT0x00004000) { | |||
3147 | error = copyin(uap->argp,(caddr_t)&export, | |||
3148 | sizeof (struct nfsex_args)); | |||
3149 | if (!error) | |||
3150 | error = nfsrv_v4rootexport(&export, cred, p); | |||
3151 | } else if (uap->flag & NFSSVC_NOPUBLICFH0x00000020) { | |||
3152 | nfs_pubfhset = 0; | |||
3153 | error = 0; | |||
3154 | } else if (uap->flag & NFSSVC_STABLERESTART0x00000040) { | |||
3155 | error = copyin(uap->argp, (caddr_t)&stablefd, | |||
3156 | sizeof (int)); | |||
3157 | if (!error) | |||
3158 | error = fp_getfvp(p, stablefd, &fp, &vp); | |||
3159 | if (!error && (NFSFPFLAG(fp)((fp)->f_flag) & (FREAD0x0001 | FWRITE0x0002)) != (FREAD0x0001 | FWRITE0x0002)) | |||
3160 | error = EBADF9; | |||
3161 | if (!error && newnfs_numnfsd != 0) | |||
3162 | error = EPERM1; | |||
3163 | if (!error) { | |||
3164 | nfsrv_stablefirst.nsf_fp = fp; | |||
3165 | nfsrv_setupstable(p); | |||
3166 | } | |||
3167 | } else if (uap->flag & NFSSVC_ADMINREVOKE0x00008000) { | |||
3168 | error = copyin(uap->argp, (caddr_t)&adminrevoke, | |||
3169 | sizeof (struct nfsd_clid)); | |||
3170 | if (!error) | |||
3171 | error = nfsrv_adminrevoke(&adminrevoke, p); | |||
3172 | } else if (uap->flag & NFSSVC_DUMPCLIENTS0x00010000) { | |||
3173 | error = copyin(uap->argp, (caddr_t)&dumplist, | |||
3174 | sizeof (struct nfsd_dumplist)); | |||
3175 | if (!error && (dumplist.ndl_size < 1 || | |||
3176 | dumplist.ndl_size > NFSRV_MAXDUMPLIST10000)) | |||
3177 | error = EPERM1; | |||
3178 | if (!error) { | |||
3179 | len = sizeof (struct nfsd_dumpclients) * dumplist.ndl_size; | |||
3180 | dumpclients = (struct nfsd_dumpclients *)malloc(len, | |||
3181 | M_TEMP, M_WAITOK0x0002); | |||
3182 | nfsrv_dumpclients(dumpclients, dumplist.ndl_size); | |||
3183 | error = copyout(dumpclients, | |||
| ||||
3184 | CAST_USER_ADDR_T(dumplist.ndl_list)(dumplist.ndl_list), len); | |||
3185 | free((caddr_t)dumpclients, M_TEMP); | |||
3186 | } | |||
3187 | } else if (uap->flag & NFSSVC_DUMPLOCKS0x00020000) { | |||
3188 | error = copyin(uap->argp, (caddr_t)&dumplocklist, | |||
3189 | sizeof (struct nfsd_dumplocklist)); | |||
3190 | if (!error && (dumplocklist.ndllck_size < 1 || | |||
3191 | dumplocklist.ndllck_size > NFSRV_MAXDUMPLIST10000)) | |||
3192 | error = EPERM1; | |||
3193 | if (!error) | |||
3194 | error = nfsrv_lookupfilename(&nd, | |||
3195 | dumplocklist.ndllck_fname, p); | |||
3196 | if (!error) { | |||
3197 | len = sizeof (struct nfsd_dumplocks) * | |||
3198 | dumplocklist.ndllck_size; | |||
3199 | dumplocks = (struct nfsd_dumplocks *)malloc(len, | |||
3200 | M_TEMP, M_WAITOK0x0002); | |||
3201 | nfsrv_dumplocks(nd.ni_vp, dumplocks, | |||
3202 | dumplocklist.ndllck_size, p); | |||
3203 | vput(nd.ni_vp); | |||
3204 | error = copyout(dumplocks, | |||
3205 | CAST_USER_ADDR_T(dumplocklist.ndllck_list)(dumplocklist.ndllck_list), len); | |||
3206 | free((caddr_t)dumplocks, M_TEMP); | |||
3207 | } | |||
3208 | } else if (uap->flag & NFSSVC_BACKUPSTABLE0x00800000) { | |||
3209 | procp = p->td_proc; | |||
3210 | PROC_LOCK(procp)__mtx_lock_flags(&((((&(procp)->p_mtx))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3210)); | |||
3211 | nfsd_master_pid = procp->p_pid; | |||
3212 | bcopy(procp->p_comm, nfsd_master_comm, MAXCOMLEN19 + 1); | |||
3213 | nfsd_master_start = procp->p_stats->p_start; | |||
3214 | nfsd_master_proc = procp; | |||
3215 | PROC_UNLOCK(procp)__mtx_unlock_flags(&((((&(procp)->p_mtx))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3215)); | |||
3216 | } else if ((uap->flag & NFSSVC_SUSPENDNFSD0x04000000) != 0) { | |||
3217 | NFSLOCKV4ROOTMUTEX()__mtx_lock_flags(&((((&nfs_v4root_mutex))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3217)); | |||
3218 | if (suspend_nfsd == 0) { | |||
3219 | /* Lock out all nfsd threads */ | |||
3220 | do { | |||
3221 | igotlock = nfsv4_lock(&nfsd_suspend_lock, 1, | |||
3222 | NULL((void *)0), NFSV4ROOTLOCKMUTEXPTR(&nfs_v4root_mutex), NULL((void *)0)); | |||
3223 | } while (igotlock == 0 && suspend_nfsd == 0); | |||
3224 | suspend_nfsd = 1; | |||
3225 | } | |||
3226 | NFSUNLOCKV4ROOTMUTEX()__mtx_unlock_flags(&((((&nfs_v4root_mutex))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3226)); | |||
3227 | error = 0; | |||
3228 | } else if ((uap->flag & NFSSVC_RESUMENFSD0x08000000) != 0) { | |||
3229 | NFSLOCKV4ROOTMUTEX()__mtx_lock_flags(&((((&nfs_v4root_mutex))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3229)); | |||
3230 | if (suspend_nfsd != 0) { | |||
3231 | nfsv4_unlock(&nfsd_suspend_lock, 0); | |||
3232 | suspend_nfsd = 0; | |||
3233 | } | |||
3234 | NFSUNLOCKV4ROOTMUTEX()__mtx_unlock_flags(&((((&nfs_v4root_mutex))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3234)); | |||
3235 | error = 0; | |||
3236 | } | |||
3237 | ||||
3238 | NFSEXITCODE(error); | |||
3239 | return (error); | |||
3240 | } | |||
3241 | ||||
3242 | /* | |||
3243 | * Check exports. | |||
3244 | * Returns 0 if ok, 1 otherwise. | |||
3245 | */ | |||
3246 | int | |||
3247 | nfsvno_testexp(struct nfsrv_descript *nd, struct nfsexstuff *exp) | |||
3248 | { | |||
3249 | int i; | |||
3250 | ||||
3251 | /* | |||
3252 | * This seems odd, but allow the case where the security flavor | |||
3253 | * list is empty. This happens when NFSv4 is traversing non-exported | |||
3254 | * file systems. Exported file systems should always have a non-empty | |||
3255 | * security flavor list. | |||
3256 | */ | |||
3257 | if (exp->nes_numsecflavor == 0) | |||
3258 | return (0); | |||
3259 | ||||
3260 | for (i = 0; i < exp->nes_numsecflavor; i++) { | |||
3261 | /* | |||
3262 | * The tests for privacy and integrity must be first, | |||
3263 | * since ND_GSS is set for everything but AUTH_SYS. | |||
3264 | */ | |||
3265 | if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5P390005 && | |||
3266 | (nd->nd_flag & ND_GSSPRIVACY0x00000080)) | |||
3267 | return (0); | |||
3268 | if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5I390004 && | |||
3269 | (nd->nd_flag & ND_GSSINTEGRITY0x00000040)) | |||
3270 | return (0); | |||
3271 | if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5390003 && | |||
3272 | (nd->nd_flag & ND_GSS(0x00000020))) | |||
3273 | return (0); | |||
3274 | if (exp->nes_secflavors[i] == AUTH_SYS1 && | |||
3275 | (nd->nd_flag & ND_GSS(0x00000020)) == 0) | |||
3276 | return (0); | |||
3277 | } | |||
3278 | return (1); | |||
3279 | } | |||
3280 | ||||
3281 | /* | |||
3282 | * Calculate a hash value for the fid in a file handle. | |||
3283 | */ | |||
3284 | uint32_t | |||
3285 | nfsrv_hashfh(fhandle_t *fhp) | |||
3286 | { | |||
3287 | uint32_t hashval; | |||
3288 | ||||
3289 | hashval = hash32_buf(&fhp->fh_fid, sizeof(struct fid), 0); | |||
3290 | return (hashval); | |||
3291 | } | |||
3292 | ||||
3293 | /* | |||
3294 | * Calculate a hash value for the sessionid. | |||
3295 | */ | |||
3296 | uint32_t | |||
3297 | nfsrv_hashsessionid(uint8_t *sessionid) | |||
3298 | { | |||
3299 | uint32_t hashval; | |||
3300 | ||||
3301 | hashval = hash32_buf(sessionid, NFSX_V4SESSIONID16, 0); | |||
3302 | return (hashval); | |||
3303 | } | |||
3304 | ||||
3305 | /* | |||
3306 | * Signal the userland master nfsd to backup the stable restart file. | |||
3307 | */ | |||
3308 | void | |||
3309 | nfsrv_backupstable(void) | |||
3310 | { | |||
3311 | struct proc *procp; | |||
3312 | ||||
3313 | if (nfsd_master_proc != NULL((void *)0)) { | |||
3314 | procp = pfind(nfsd_master_pid); | |||
3315 | /* Try to make sure it is the correct process. */ | |||
3316 | if (procp == nfsd_master_proc && | |||
3317 | procp->p_stats->p_start.tv_sec == | |||
3318 | nfsd_master_start.tv_sec && | |||
3319 | procp->p_stats->p_start.tv_usec == | |||
3320 | nfsd_master_start.tv_usec && | |||
3321 | strcmp(procp->p_comm, nfsd_master_comm) == 0) | |||
3322 | kern_psignal(procp, SIGUSR231); | |||
3323 | else | |||
3324 | nfsd_master_proc = NULL((void *)0); | |||
3325 | ||||
3326 | if (procp != NULL((void *)0)) | |||
3327 | PROC_UNLOCK(procp)__mtx_unlock_flags(&((((&(procp)->p_mtx))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3327)); | |||
3328 | } | |||
3329 | } | |||
3330 | ||||
3331 | extern int (*nfsd_call_nfsd)(struct thread *, struct nfssvc_args *); | |||
3332 | ||||
3333 | /* | |||
3334 | * Called once to initialize data structures... | |||
3335 | */ | |||
3336 | static int | |||
3337 | nfsd_modevent(module_t mod, int type, void *data) | |||
3338 | { | |||
3339 | int error = 0, i; | |||
3340 | static int loaded = 0; | |||
3341 | ||||
3342 | switch (type) { | |||
3343 | case MOD_LOAD: | |||
3344 | if (loaded) | |||
3345 | goto out; | |||
3346 | newnfs_portinit(); | |||
3347 | for (i = 0; i < NFSRVCACHE_HASHSIZE500; i++) { | |||
3348 | mtx_init(&nfsrchash_table[i].mtx, "nfsrtc", NULL,_mtx_init(&(&nfsrchash_table[i].mtx)->mtx_lock, "nfsrtc" , ((void *)0), 0x00000000) | |||
3349 | MTX_DEF)_mtx_init(&(&nfsrchash_table[i].mtx)->mtx_lock, "nfsrtc" , ((void *)0), 0x00000000); | |||
3350 | mtx_init(&nfsrcahash_table[i].mtx, "nfsrtca", NULL,_mtx_init(&(&nfsrcahash_table[i].mtx)->mtx_lock, "nfsrtca" , ((void *)0), 0x00000000) | |||
3351 | MTX_DEF)_mtx_init(&(&nfsrcahash_table[i].mtx)->mtx_lock, "nfsrtca" , ((void *)0), 0x00000000); | |||
3352 | } | |||
3353 | mtx_init(&nfsrc_udpmtx, "nfsuc", NULL, MTX_DEF)_mtx_init(&(&nfsrc_udpmtx)->mtx_lock, "nfsuc", ((void *)0), 0x00000000); | |||
3354 | mtx_init(&nfs_v4root_mutex, "nfs4rt", NULL, MTX_DEF)_mtx_init(&(&nfs_v4root_mutex)->mtx_lock, "nfs4rt" , ((void *)0), 0x00000000); | |||
3355 | mtx_init(&nfsv4root_mnt.mnt_mtx, "nfs4mnt", NULL, MTX_DEF)_mtx_init(&(&nfsv4root_mnt.mnt_mtx)->mtx_lock, "nfs4mnt" , ((void *)0), 0x00000000); | |||
3356 | lockinit(&nfsv4root_mnt.mnt_explock, PVFS((80) + 16), "explock", 0, 0); | |||
3357 | nfsrvd_initcache(); | |||
3358 | nfsd_init(); | |||
3359 | NFSD_LOCK()__mtx_lock_flags(&((((&newnfsd_mtx))))->mtx_lock, ( (0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3359)); | |||
3360 | nfsrvd_init(0); | |||
3361 | NFSD_UNLOCK()__mtx_unlock_flags(&((((&newnfsd_mtx))))->mtx_lock , ((0)), ("/usr/src/sys/modules/nfsd/../../fs/nfsserver/nfs_nfsdport.c" ), (3361)); | |||
3362 | nfsd_mntinit(); | |||
3363 | #ifdef VV_DISABLEDELEG | |||
3364 | vn_deleg_ops.vndeleg_recall = nfsd_recalldelegation; | |||
3365 | vn_deleg_ops.vndeleg_disable = nfsd_disabledelegation; | |||
3366 | #endif | |||
3367 | nfsd_call_servertimer = nfsrv_servertimer; | |||
3368 | nfsd_call_nfsd = nfssvc_nfsd; | |||
3369 | loaded = 1; | |||
3370 | break; | |||
3371 | ||||
3372 | case MOD_UNLOAD: | |||
3373 | if (newnfs_numnfsd != 0) { | |||
3374 | error = EBUSY16; | |||
3375 | break; | |||
3376 | } | |||
3377 | ||||
3378 | #ifdef VV_DISABLEDELEG | |||
3379 | vn_deleg_ops.vndeleg_recall = NULL((void *)0); | |||
3380 | vn_deleg_ops.vndeleg_disable = NULL((void *)0); | |||
3381 | #endif | |||
3382 | nfsd_call_servertimer = NULL((void *)0); | |||
3383 | nfsd_call_nfsd = NULL((void *)0); | |||
3384 | ||||
3385 | /* Clean out all NFSv4 state. */ | |||
3386 | nfsrv_throwawayallstate(curthread(__curthread())); | |||
3387 | ||||
3388 | /* Clean the NFS server reply cache */ | |||
3389 | nfsrvd_cleancache(); | |||
3390 | ||||
3391 | /* Free up the krpc server pool. */ | |||
3392 | if (nfsrvd_pool != NULL((void *)0)) | |||
3393 | svcpool_destroy(nfsrvd_pool); | |||
3394 | ||||
3395 | /* and get rid of the locks */ | |||
3396 | for (i = 0; i < NFSRVCACHE_HASHSIZE500; i++) { | |||
3397 | mtx_destroy(&nfsrchash_table[i].mtx)_mtx_destroy(&(&nfsrchash_table[i].mtx)->mtx_lock); | |||
3398 | mtx_destroy(&nfsrcahash_table[i].mtx)_mtx_destroy(&(&nfsrcahash_table[i].mtx)->mtx_lock ); | |||
3399 | } | |||
3400 | mtx_destroy(&nfsrc_udpmtx)_mtx_destroy(&(&nfsrc_udpmtx)->mtx_lock); | |||
3401 | mtx_destroy(&nfs_v4root_mutex)_mtx_destroy(&(&nfs_v4root_mutex)->mtx_lock); | |||
3402 | mtx_destroy(&nfsv4root_mnt.mnt_mtx)_mtx_destroy(&(&nfsv4root_mnt.mnt_mtx)->mtx_lock); | |||
3403 | for (i = 0; i < nfsrv_sessionhashsize; i++) | |||
3404 | mtx_destroy(&nfssessionhash[i].mtx)_mtx_destroy(&(&nfssessionhash[i].mtx)->mtx_lock); | |||
3405 | lockdestroy(&nfsv4root_mnt.mnt_explock); | |||
3406 | free(nfsclienthash, M_NFSDCLIENTM_NEWNFSDCLIENT); | |||
3407 | free(nfslockhash, M_NFSDLOCKFILEM_NEWNFSDLOCKFILE); | |||
3408 | free(nfssessionhash, M_NFSDSESSIONM_NEWNFSDSESSION); | |||
3409 | loaded = 0; | |||
3410 | break; | |||
3411 | default: | |||
3412 | error = EOPNOTSUPP45; | |||
3413 | break; | |||
3414 | } | |||
3415 | ||||
3416 | out: | |||
3417 | NFSEXITCODE(error); | |||
3418 | return (error); | |||
3419 | } | |||
3420 | static moduledata_t nfsd_mod = { | |||
3421 | "nfsd", | |||
3422 | nfsd_modevent, | |||
3423 | NULL((void *)0), | |||
3424 | }; | |||
3425 | DECLARE_MODULE(nfsd, nfsd_mod, SI_SUB_VFS, SI_ORDER_ANY)static struct mod_depend _nfsd_depend_on_kernel __attribute__ ((__section__(".data"))) = { 1100122, 1100122, (((((1100122)+ ((100000)-1))/(100000))*(100000)) - 1) }; static struct mod_metadata _mod_metadata_md_nfsd_on_kernel = { 1, 1, &_nfsd_depend_on_kernel , "kernel" }; __asm__(".globl " "__start_set_modmetadata_set" ); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd_on_kernel __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd_on_kernel); static struct mod_metadata _mod_metadata_md_nfsd = { 1, 2, &nfsd_mod , "nfsd" }; __asm__(".globl " "__start_set_modmetadata_set"); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd); static struct sysinit nfsdmodule_sys_init = { SI_SUB_VFS, SI_ORDER_ANY, (sysinit_cfunc_t )(sysinit_nfunc_t)module_register_init, ((void *)(&nfsd_mod )) }; __asm__(".globl " "__start_set_sysinit_set"); __asm__(".globl " "__stop_set_sysinit_set"); static void const * const __set_sysinit_set_sym_nfsdmodule_sys_init __attribute__((__section__("set_" "sysinit_set"))) __attribute__ ((__used__)) = &(nfsdmodule_sys_init); struct __hack; | |||
3426 | ||||
3427 | /* So that loader and kldload(2) can find us, wherever we are.. */ | |||
3428 | MODULE_VERSION(nfsd, 1)static struct mod_version _nfsd_version __attribute__((__section__ (".data"))) = { 1 }; static struct mod_metadata _mod_metadata_nfsd_version = { 1, 3, &_nfsd_version, "nfsd" }; __asm__(".globl " "__start_set_modmetadata_set" ); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_nfsd_version __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_nfsd_version); | |||
3429 | MODULE_DEPEND(nfsd, nfscommon, 1, 1, 1)static struct mod_depend _nfsd_depend_on_nfscommon __attribute__ ((__section__(".data"))) = { 1, 1, 1 }; static struct mod_metadata _mod_metadata_md_nfsd_on_nfscommon = { 1, 1, &_nfsd_depend_on_nfscommon , "nfscommon" }; __asm__(".globl " "__start_set_modmetadata_set" ); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd_on_nfscommon __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd_on_nfscommon); | |||
3430 | MODULE_DEPEND(nfsd, nfslock, 1, 1, 1)static struct mod_depend _nfsd_depend_on_nfslock __attribute__ ((__section__(".data"))) = { 1, 1, 1 }; static struct mod_metadata _mod_metadata_md_nfsd_on_nfslock = { 1, 1, &_nfsd_depend_on_nfslock , "nfslock" }; __asm__(".globl " "__start_set_modmetadata_set" ); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd_on_nfslock __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd_on_nfslock); | |||
3431 | MODULE_DEPEND(nfsd, nfslockd, 1, 1, 1)static struct mod_depend _nfsd_depend_on_nfslockd __attribute__ ((__section__(".data"))) = { 1, 1, 1 }; static struct mod_metadata _mod_metadata_md_nfsd_on_nfslockd = { 1, 1, &_nfsd_depend_on_nfslockd , "nfslockd" }; __asm__(".globl " "__start_set_modmetadata_set" ); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd_on_nfslockd __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd_on_nfslockd); | |||
3432 | MODULE_DEPEND(nfsd, krpc, 1, 1, 1)static struct mod_depend _nfsd_depend_on_krpc __attribute__(( __section__(".data"))) = { 1, 1, 1 }; static struct mod_metadata _mod_metadata_md_nfsd_on_krpc = { 1, 1, &_nfsd_depend_on_krpc , "krpc" }; __asm__(".globl " "__start_set_modmetadata_set"); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd_on_krpc __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd_on_krpc); | |||
3433 | MODULE_DEPEND(nfsd, nfssvc, 1, 1, 1)static struct mod_depend _nfsd_depend_on_nfssvc __attribute__ ((__section__(".data"))) = { 1, 1, 1 }; static struct mod_metadata _mod_metadata_md_nfsd_on_nfssvc = { 1, 1, &_nfsd_depend_on_nfssvc , "nfssvc" }; __asm__(".globl " "__start_set_modmetadata_set" ); __asm__(".globl " "__stop_set_modmetadata_set"); static void const * const __set_modmetadata_set_sym__mod_metadata_md_nfsd_on_nfssvc __attribute__((__section__("set_" "modmetadata_set"))) __attribute__ ((__used__)) = &(_mod_metadata_md_nfsd_on_nfssvc); | |||
3434 |