Skip to contentSkip to conversation

fdmap v2 - add a new O_NONSEQFD flag to sys_open

PATCH In review Davide Libenzi 1 participant 1 message Jun 6, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/8 fdmap v2 - add a new O_NONSEQFD flag to sys_open

This patch introduces a new O_NONSEQFD flag for the sys_open() system call. Using such flag, the caller can ask the kernel to allocate the file descriptor inside the non-sequential area.

- Davide

fs/open.c +18 -1
Index: linux-2.6.mod/fs/open.c
===================================================================
@@ -978,6 +978,23 @@
 	return FDMAP_NONSEQ_BASE + (rndb & ((1U << FDMAP_RANDOM_BITS) - 1));
 }
 
+/**
+ * allocate_fd - Allocates a new file descriptor
+ *
+ * @flags:  [in] Flags to control the allocation type and the new descriptor
+ *               characteristics
+ *
+ * Returns the newly allocated file descriptor, or a negative value in
+ * case of error.
+ */
+int allocate_fd(unsigned long flags)
+{
+	if (flags & O_NONSEQFD)
+		return alloc_nonseq_fd(current->files, flags);
+	else
+		return  get_unused_fd();
+}
+
 /*
  * Install a file pointer in the fd array.
  *
@@ -1011,7 +1028,7 @@
 	int fd = PTR_ERR(tmp);
 
 	if (!IS_ERR(tmp)) {
-		fd = get_unused_fd();
+		fd = allocate_fd((unsigned int) flags);
 		if (fd >= 0) {
 			struct file *f = do_filp_open(dfd, tmp, flags, mode);
 			if (IS_ERR(f)) {
include/asm-generic/fcntl.h +3 -0
Index: linux-2.6.mod/include/asm-generic/fcntl.h
===================================================================
@@ -48,6 +48,9 @@
 #ifndef O_NOATIME
 #define O_NOATIME	01000000
 #endif
+#ifndef O_NONSEQFD
+#define O_NONSEQFD	02000000
+#endif
 #ifndef O_NDELAY
 #define O_NDELAY	O_NONBLOCK
 #endif
include/linux/file.h +1 -0
Index: linux-2.6.mod/include/linux/file.h
===================================================================
@@ -85,6 +85,7 @@
 extern int __alloc_nonseq_fd(struct files_struct *files, unsigned long flags);
 extern int alloc_nonseq_fd(struct files_struct *files, unsigned long flags);
 extern unsigned int gen_nonseqfd_base(void);
+extern int allocate_fd(unsigned long flags);
 
 /**
  * nonseq_files_fdmap - Must be called with @files->file_lock held. It forces