nfs4getroot.c 1.2 KB

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