diff --git a/fs/vfs/vfs_syscalls.cc b/fs/vfs/vfs_syscalls.cc
index c13148c812a4b5deb10d90dc263501338fdb8c6c..c19b8877d336227ebf681a5a0354c81084e96729 100644
--- a/fs/vfs/vfs_syscalls.cc
+++ b/fs/vfs/vfs_syscalls.cc
@@ -124,6 +124,12 @@ sys_open(char *path, int flags, mode_t mode, struct file **fpp)
 			if (vp->v_type == VDIR)
 				goto out_drele;
 		}
+		if (flags & O_DIRECTORY) {
+		    if (vp->v_type != VDIR) {
+		        error = ENOTDIR;
+		        goto out_drele;
+		    }
+		}
 	}
 
 	vn_lock(vp);