| 1 | // SPDX-License-Identifier: GPL-2.0 | 
|---|---|
| 2 | /* | 
| 3 | * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. | 
| 4 | * Written by David Howells (dhowells@redhat.com) | 
| 5 | */ | 
| 6 | |
| 7 | #include <linux/nfs_fs.h> | 
| 8 | #include "nfs4_fs.h" | 
| 9 | #include "internal.h" | 
| 10 | |
| 11 | #define NFSDBG_FACILITY NFSDBG_CLIENT | 
| 12 | |
| 13 | int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe) | 
| 14 | { | 
| 15 | struct nfs_fattr *fattr = nfs_alloc_fattr(); | 
| 16 | int ret = -ENOMEM; | 
| 17 | |
| 18 | if (fattr == NULL) | 
| 19 | goto out; | 
| 20 | |
| 21 | /* Start by getting the root filehandle from the server */ | 
| 22 | ret = nfs4_proc_get_rootfh(server, mntfh, fattr, auth_probe); | 
| 23 | if (ret < 0) { | 
| 24 | dprintk( "nfs4_get_rootfh: getroot error = %d\n", -ret); | 
| 25 | goto out; | 
| 26 | } | 
| 27 | |
| 28 | if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) || !S_ISDIR(fattr->mode)) { | 
| 29 | printk(KERN_ERR "nfs4_get_rootfh:" | 
| 30 | " getroot encountered non-directory\n"); | 
| 31 | ret = -ENOTDIR; | 
| 32 | goto out; | 
| 33 | } | 
| 34 | |
| 35 | memcpy(to: &server->fsid, from: &fattr->fsid, len: sizeof(server->fsid)); | 
| 36 | out: | 
| 37 | nfs_free_fattr(fattr); | 
| 38 | return ret; | 
| 39 | } | 
| 40 | 
