retooled patch for 2.1.45 fs/exec.c

Bill Hawes (whawes@star.net)
Fri, 18 Jul 1997 20:46:23 -0400


This is a multi-part message in MIME format.
--------------DF69BAF4C7AC56D269A1DBAE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I've reworked a patch to fix a small problen in fs/exec.c that causes
files to be read with trash values for the read-ahead parameters. Under
some conditions this could cause read-ahead to perform poorly, though
it's difficult to analyze the effects of trash values from the stack.

The patch defines a small function to clear and initialize a private
file structure, and replaces nearly identical sections of code in
fs/exec.c, fs/binfmt_elf.c, and fs/binfmt_aout.c with a function call.

Regards,
Bill
--------------DF69BAF4C7AC56D269A1DBAE
Content-Type: text/plain; charset=us-ascii; name="exec_46-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="exec_46-patch"

--- linux-2.1.45/fs/exec.c.old Thu Jul 17 06:36:48 1997
+++ linux-2.1.45/fs/exec.c Thu Jul 17 12:59:12 1997
@@ -339,6 +339,24 @@
}

/*
+ * Clears and initializes a (private) struct file for the given dentry,
+ * and calls the open function (if any). The caller must verify that
+ * inode->i_op and inode->i_op->default_file_ops are not NULL.
+ */
+int init_private_file(struct file *filp, struct dentry *dentry, int mode)
+{
+ memset(filp, 0, sizeof(*filp));
+ filp->f_mode = mode;
+ filp->f_count = 1;
+ filp->f_dentry = dentry;
+ filp->f_op = dentry->d_inode->i_op->default_file_ops;
+ if (filp->f_op->open)
+ return filp->f_op->open(dentry->d_inode, filp);
+ else
+ return 0;
+}
+
+/*
* Read in the complete executable. This is used for "-N" files
* that aren't on a block boundary, and for files on filesystems
* without bmap support.
@@ -352,17 +370,9 @@

if (!inode->i_op || !inode->i_op->default_file_ops)
goto end_readexec;
- file.f_mode = 1;
- file.f_flags = 0;
- file.f_count = 1;
- file.f_dentry = dentry;
- file.f_pos = 0;
- file.f_reada = 0;
- file.f_op = inode->i_op->default_file_ops;
- if (file.f_op->open)
- if (file.f_op->open(inode,&file))
- goto end_readexec;
- if (!file.f_op || !file.f_op->read)
+ if (init_private_file(&file, dentry, 1))
+ goto end_readexec;
+ if (!file.f_op->read)
goto close_readexec;
if (file.f_op->llseek) {
if (file.f_op->llseek(inode,&file,offset,0) != offset)
--- linux-2.1.45/fs/binfmt_elf.c.old Thu Jul 17 06:36:48 1997
+++ linux-2.1.45/fs/binfmt_elf.c Thu Jul 17 13:12:02 1997
@@ -42,6 +42,7 @@
static int load_elf_library(int fd);
extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
extern void dump_thread(struct pt_regs *, struct user *);
+extern int init_private_file(struct file *, struct dentry *, int);

#ifdef __sparc__
extern unsigned long get_unmapped_area(unsigned long addr, unsigned long len);
@@ -1091,16 +1092,8 @@
goto end_coredump;
if (!inode->i_op || !inode->i_op->default_file_ops)
goto end_coredump;
- file.f_mode = 3;
- file.f_flags = 0;
- file.f_count = 1;
- file.f_dentry = dentry;
- file.f_pos = 0;
- file.f_reada = 0;
- file.f_op = inode->i_op->default_file_ops;
- if (file.f_op->open)
- if (file.f_op->open(inode,&file))
- goto end_coredump;
+ if (init_private_file(&file, dentry, 3))
+ goto end_coredump;
if (!file.f_op->write)
goto close_coredump;
has_dumped = 1;
--- linux-2.1.45/fs/binfmt_aout.c.old Thu Jul 17 06:36:48 1997
+++ linux-2.1.45/fs/binfmt_aout.c Thu Jul 17 13:11:44 1997
@@ -33,6 +33,7 @@
static int aout_core_dump(long signr, struct pt_regs * regs);

extern void dump_thread(struct pt_regs *, struct user *);
+extern int init_private_file(struct file *, struct dentry *, int);

static struct linux_binfmt aout_format = {
#ifndef MODULE
@@ -127,16 +128,8 @@
goto end_coredump;
if (get_write_access(inode))
goto end_coredump;
- file.f_mode = 3;
- file.f_flags = 0;
- file.f_count = 1;
- file.f_dentry = dentry;
- file.f_pos = 0;
- file.f_reada = 0;
- file.f_op = inode->i_op->default_file_ops;
- if (file.f_op->open)
- if (file.f_op->open(inode,&file))
- goto done_coredump;
+ if (init_private_file(&file, dentry, 3))
+ goto end_coredump;
if (!file.f_op->write)
goto close_coredump;
has_dumped = 1;

--------------DF69BAF4C7AC56D269A1DBAE--