nfs4getroot.c 955 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include <linux/nfs_fs.h>
  7. #include "nfs4_fs.h"
  8. #include "internal.h"
  9. #define NFSDBG_FACILITY NFSDBG_CLIENT
  10. int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
  11. {
  12. struct nfs_fattr *fattr = nfs_alloc_fattr();
  13. int ret = -ENOMEM;
  14. if (fattr == NULL)
  15. goto out;
  16. /* Start by getting the root filehandle from the server */
  17. ret = nfs4_proc_get_rootfh(server, mntfh, fattr, auth_probe);
  18. if (ret < 0) {
  19. dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
  20. goto out;
  21. }
  22. if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) || !S_ISDIR(fattr->mode)) {
  23. printk(KERN_ERR "nfs4_get_rootfh:"
  24. " getroot encountered non-directory\n");
  25. ret = -ENOTDIR;
  26. goto out;
  27. }
  28. memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
  29. out:
  30. nfs_free_fattr(fattr);
  31. return ret;
  32. }