BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / d3f787c50eda2dadb77ae216aef1f0bd0a686ae3 / vfs / files.c

// Related

Nucleus

Barry More VFS functions and structure d3f787c (3 years, 2 months ago)
diff --git a/vfs/files.c b/vfs/files.c
index fffbc42..b830e40 100644
--- a/vfs/files.c
+++ b/vfs/files.c
@@ -101,6 +101,8 @@ close(int fd)
 int
 read(int fd, void *buf, size_t count)
 {
+	if (!buf)
+		return -EFAULT;
 	if (!verify_access(buf, count, PROT_WRITE))
 		return -EFAULT;
 
@@ -121,6 +123,8 @@ read(int fd, void *buf, size_t count)
 int
 write(int fd, void *buf, size_t count)
 {
+	if (!buf)
+		return -EFAULT;
 	if (!verify_access(buf, count, PROT_READ))
 		return -EFAULT;
 
@@ -163,3 +167,22 @@ lseek(int fd, off_t offset, int whence)
 	unlock(file);
 	return file->pos;
 }
+
+/* Perform I/O control on a file */
+int
+ioctl(int fd, unsigned long request, ...)
+{
+	File *file = get_file_by_fd(fd);
+	if (!file)
+		return -EBADF;
+
+	va_list args;
+	va_start(args, request);
+	uintptr_t argp = va_arg(args, uintptr_t);
+	va_end(args);
+
+	lock(file);
+	int ret = file_ioctl(file, request, argp);
+	unlock(file);
+	return ret;
+}