Re: [patch-2.3.99-pre10-3] BUGFIX /proc/sys/fs/file-nr is wrong.

From: Bill Wendling (wendling@ganymede.isdn.uiuc.edu)
Date: Thu May 25 2000 - 10:56:28 EST


Also sprach Tigran Aivazian:
} Hi Linus,
}
} The assumption that C code:
}
} int x;
} int y;
} int z;
}
} allocates x,y,z at consecutive virtual addresses is wrong. Yet it is
} assumed when passing &nr_files in kernel/sysctl.c and saying "give me, I
} pray thee, 3 sizeof(int)". This results in garbage displayed in
} /proc/sys/fs/file-nr.
}
} To fix this, I followed (almost) the same technique as inodes_stat in
} fs/inode.c, i.e. gathered variables in a structure called files_stat.
}
[snip]
} --- linux/include/linux/fs.h Thu May 25 09:08:31 2000
} +++ filenr/include/linux/fs.h Thu May 25 09:30:25 2000
} @@ -47,7 +47,12 @@
} #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
}
} /* And dynamically-tunable limits and defaults: */
} -extern int max_files, nr_files, nr_free_files;
} +struct files_stat_struct {
} + int nr_files; /* read only */
} + int nr_free_files; /* read only */
} + int max_files; /* tunable */
} +};
} +extern struct files_stat_struct files_stat;
} extern int max_super_blocks, nr_super_blocks;
}
} #define NR_FILE 8192 /* this can well be larger on a larger system */
[snip]
} - {FS_NRFILE, "file-nr", &nr_files, 3*sizeof(int),
} + {FS_NRFILE, "file-nr", &files_stat, 3*sizeof(int),
} 0444, NULL, &proc_dointvec},
} - {FS_MAXFILE, "file-max", &max_files, sizeof(int),
} + {FS_MAXFILE, "file-max", &files_stat.max_files, sizeof(int),
} 0644, NULL, &proc_dointvec},

This might not be "absolutely" correct either. C doesn't guarantee that a
structure's size is the size of all its elements added together. There's
byte padding and junk. Couldn't one just use sizeof(struct files_stat_struct)?

(Note: I don't know about this code...This is just a C nit-pick.)

-- 
|| Bill Wendling			wendling@ganymede.isdn.uiuc.edu

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed May 31 2000 - 21:00:14 EST