BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 2d05318728e0aa3fca502a2aeb1738773fffc98b / vfs / file.c

// Related

Nucleus

Barry Directory listing in VFS 2d05318 (3 years, 2 months ago)
diff --git a/vfs/file.c b/vfs/file.c
index bca19dc..8d7e7cc 100644
--- a/vfs/file.c
+++ b/vfs/file.c
@@ -63,7 +63,6 @@ size_t
 file_read(File *file, char *buf, size_t size)
 {
 	size_t count = 0;
-	lock(file);
 	/* Irregular files cannot be cached */
 	if (!S_ISREG(file->inode->mode)) {
 		if (file->ops && file->ops->read)
@@ -98,6 +97,7 @@ file_read(File *file, char *buf, size_t size)
 		count += min;
 	}
 end:
+	lock(file);
 	file->pos += count;
 	unlock(file);
 	return count;
@@ -108,7 +108,6 @@ size_t
 file_write(File *file, char *buf, size_t size)
 {
 	size_t count = 0;
-	lock(file);
 	/* Irregular files cannot be cached */
 	if (!S_ISREG(file->inode->mode)) {
 		if (file->ops && file->ops->write)
@@ -141,6 +140,7 @@ file_write(File *file, char *buf, size_t size)
 		count += min;
 	}
 end:
+	lock(file);
 	file->pos += count;
 	unlock(file);
 	return count;
@@ -157,6 +157,15 @@ file_ioctl(File *file, unsigned long request, uintptr_t argp)
 	return file->ops->ioctl(file, request, argp);
 }
 
+/* Read a directory entry from a directory */
+int
+file_readdir(File *file, struct dirent *dent, off_t index)
+{
+	if (!file->ops || !file->ops->readdir)
+		return -EINVAL;
+	return file->ops->readdir(file, dent, index);
+}
+
 /* Map a file into memory */
 void
 file_mmap(File *file, void *addr, size_t len, off_t offset)