nfs4getroot.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include "internal.h"
  8. #define NFSDBG_FACILITY NFSDBG_CLIENT
  9. int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh)
  10. {
  11. struct nfs_fsinfo fsinfo;
  12. int ret = -ENOMEM;
  13. dprintk("--> nfs4_get_rootfh()\n");
  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);
  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. if (fsinfo.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
  31. printk(KERN_ERR "nfs4_get_rootfh:"
  32. " getroot obtained referral\n");
  33. ret = -EREMOTE;
  34. goto out;
  35. }
  36. memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
  37. out:
  38. nfs_free_fattr(fsinfo.fattr);
  39. dprintk("<-- nfs4_get_rootfh() = %d\n", ret);
  40. return ret;
  41. }