[PATCH 09/14] Add ngnfs_dir_get_handle() for using files/dirs

Valerie Aurora val at versity.com
Thu Feb 27 06:16:18 PST 2025


ngnfs_dir_get_handle() returns a handle that can be used to do
operations on files and directories.

Signed-off-by: Valerie Aurora <val at versity.com>
---
 shared/dir.c | 30 ++++++++++++++++++++++++++++++
 shared/dir.h | 16 +++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/shared/dir.c b/shared/dir.c
index 4b95835..5e825a4 100644
--- a/shared/dir.c
+++ b/shared/dir.c
@@ -573,3 +573,33 @@ int ngnfs_dir_get_dirent(struct ngnfs_fs_info *nfi, u64 dir_ino, char *name, siz
 out:
 	return ret;
 }
+
+int ngnfs_dir_get_handle(struct ngnfs_fs_info *nfi, u64 dir_ino, char *name, size_t name_len,
+			 struct ngnfs_dir_handle *hdl)
+{
+	struct dirent_args *da;
+	int ret;
+
+	if (name_len > NGNFS_NAME_MAX) {
+		ret = -ENAMETOOLONG;
+		goto out;
+	}
+
+	da = kmalloc(sizeof(struct dirent_args), GFP_NOFS);
+	if (!da) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	ret = do_lookup(nfi, dir_ino, name, name_len, da);
+
+	if (ret == 0) {
+		hdl->ino = le64_to_cpu(da->dent.ino);
+		hdl->version = le64_to_cpu(da->dent.version);
+		hdl->dtype = ngnfs_type_to_dtype(da->dent.type);
+	}
+
+	kfree(da);
+out:
+	return ret;
+}
diff --git a/shared/dir.h b/shared/dir.h
index 714ee1a..e15ab5f 100644
--- a/shared/dir.h
+++ b/shared/dir.h
@@ -8,7 +8,21 @@ int ngnfs_dir_create(struct ngnfs_fs_info *nfi, u64 dir_ino, umode_t mode, char
 		     size_t name_len);
 
 /*
- * Readddr fills the buffer with entries.  The start of the buffer must
+ * ngnfs_dir_get_handle() returns a thing that lets userspace clients do
+ * file/directory operations without the complexities of open().
+ */
+
+struct ngnfs_dir_handle {
+	u64 ino;
+	u64 version;
+	u8 dtype;
+};
+
+int ngnfs_dir_get_handle(struct ngnfs_fs_info *nfi, u64 dir_ino, char *name, size_t name_len,
+			 struct ngnfs_dir_handle *hdl);
+
+/*
+ * Readdir fills the buffer with entries.  The start of the buffer must
  * be at least as aligned as the entry.  Entries are padded for
  * alignment.  Use next_off to iterate through them instead of trying to
  * skip name length bytes past the end of the struct.
-- 
2.48.1




More information about the ngnfs-devel mailing list