nfs4getroot.c 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_fsinfo fsinfo;
  13. int ret = -ENOMEM;
  14. fsinfo.fattr = nfs_alloc_fattr();
  15. if (fsinfo.fattr == NULL)
  16. goto out;
  17. /* Start by getting the root filehandle from the server */
  18. ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo, auth_probe);
  19. if (ret < 0) {
  20. dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
  21. goto out;
  22. }
  23. if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
  24. || !S_ISDIR(fsinfo.fattr->mode)) {
  25. printk(KERN_ERR "nfs4_get_rootfh:"
  26. " getroot encountered non-directory\n");
  27. ret = -ENOTDIR;
  28. goto out;
  29. }
  30. memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
  31. out:
  32. nfs_free_fattr(fsinfo.fattr);
  33. return ret;
  34. }