Linux-Development-Sys Digest #670, Volume #8 Wed, 25 Apr 01 18:13:07 EDT
Contents:
Re: File access within a kernel mod (Kasper Dupont)
Re: ide vs. scsi why so much slower
Re: File access within a kernel mod ("Peter T. Breuer")
Re: Make error
Re: [Help:] msgfmt (Kaelin Colclasure)
problem compiling kernel 2.4.3 (Robert Hamilton)
Re: problem compiling kernel 2.4.3 (Paul Kimoto)
Re: [Help:] msgfmt (Paul Kimoto)
How do I get a display patch added to the kernel dist? (Brian Kendig)
----------------------------------------------------------------------------
From: Kasper Dupont <[EMAIL PROTECTED]>
Subject: Re: File access within a kernel mod
Date: Wed, 25 Apr 2001 12:40:19 +0000
This is a multi-part message in MIME format.
==============69C26635678355465092E5DB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Kasper Dupont wrote:
>
> Wayne wrote:
> >
> > I'm still getting use to this kernel mod stuff and am curious if there is an
> > easy way
> > to access a file on the harddrive.
>
> There is no easy way, you have to do it the hard way.
> Pehaps you can do something smarter, where you don't
> have to access a file from your module. Also try
> reading older postings on this newsgroup, there are
> lots of postings on the subject.
>
> --
> Kasper Dupont
This question has been asked so often that
I finally tried writing some code which
more or less does the trick. This is a
kernel module that will copy a file, it is
tested on kernel 2.2.16.
Comments are wellcomme, have I forgotten
something, can it be done simpler?
--
Kasper Dupont
==============69C26635678355465092E5DB
Content-Type: text/plain; charset=us-ascii; name="kcp.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="kcp.c"
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
#include <linux/malloc.h>
#include <asm/uaccess.h>
char *src = NULL;
char *dst = NULL;
MODULE_PARM(src,"s");
MODULE_PARM(dst,"s");
/* This is a kernel module, I must be very
* carefull to clean up everything myself,
* there is nobody who can do it for me.
*/
int init_module(void)
{
struct file *srcf,*dstf;
int retval,orgfsuid,orgfsgid;
mm_segment_t orgfs;
char *buffer;
unsigned long page;
/* Save uid and gid used for filesystem access.
* Set user and group to 0 (root)
*/
orgfsuid=current->fsuid;
orgfsgid=current->fsgid;
current->fsuid=current->fsgid=0;
/* save FS register and set FS register to kernel
* space, needed for read and write to accept
* buffer in kernel space.
*/
orgfs=get_fs();
set_fs(KERNEL_DS);
if (src&&dst&&*src&&*dst) {
printk("Copying %s to %s\n",src,dst);
/* Allocate one page for buffer */
page = __get_free_page(GFP_KERNEL);
if (page) {
buffer=(char*)page;
srcf = filp_open(src, O_RDONLY, 0);
if (IS_ERR(srcf)) {
printk("kcp: Error %ld opening %s\n",-PTR_ERR(srcf),src);
} else {
/* The object must have a read method */
if (srcf->f_op&&srcf->f_op->read) {
dstf = filp_open(dst, O_WRONLY|O_TRUNC|O_CREAT , 0644);
if (IS_ERR(dstf)) {
printk("kcp: Error %ld opening %s\n",-PTR_ERR(dstf),dst);
} else {
/* The object must have a write method */
if (dstf->f_op&&dstf->f_op->write) {
do {
/* Read as much as posible into the buffer,
* at most one page.
*/
retval=srcf->f_op->read(srcf,buffer,PAGE_SIZE,&srcf->f_pos);
if (retval<0) printk("kcp: Read error %d\n",-retval);
if (retval>0) {
int index=0,bufsize=retval;
/* Continue writing until error or everything
* written.
*/
while ((index<bufsize)&&
((retval=dstf->f_op->write
(dstf,buffer+index,bufsize-index,&dstf->f_pos))>0)
) index+=retval;
if (index<bufsize) printk("kcp: Write error %d\n",-retval);
}
/* Copy loop continues until EOF or error.
*/
} while (retval>0);
/* Now clean up everything that was actually allocated
*/
} else {
printk("kcp: %s does not have a write method\n",dst);
}
retval=filp_close(dstf,NULL);
if (retval) printk("kcp: Error %d closing %s\n",-retval,dst);
}
} else {
printk("kcp: %s does not have a read method\n",src);
}
retval=filp_close(srcf,NULL);
if (retval) printk("kcp: Error %d closing %s\n",-retval,src);
}
free_page(page);
} else {
printk("kcp: Out of memory\n");
}
} else printk("kcp: Both src= and dst= must be specified\n");
set_fs(orgfs);
current->fsuid=orgfsuid;
current->fsgid=orgfsgid;
/* End of demo, returning an error code
* makes insmod/modprobe remove the module
* from memory.
*/
return 1;
}
==============69C26635678355465092E5DB==
------------------------------
From: [EMAIL PROTECTED] ()
Subject: Re: ide vs. scsi why so much slower
Date: Wed, 25 Apr 2001 14:25:37 GMT
On Mon, 23 Apr 2001 22:32:18 -0700, J. E. Garrott, Sr <[EMAIL PROTECTED]> wrote:
>
>I did this and played with it a bit more. The line that works is:
>hdparm -X66 -d1 -u1 -m16 -c3 /dev/hdb
>
>Without the -X66 it corrupts the / partition, unless I drop
>both the -d1 and -u1, then it only gives a 2X improvement.
>As given, it picks up to 20.5 MHz/sec from 3.9. The cache
>transfer rate remains fairly steady around 145 Mhz/sec.
My plextor 12/10/32 cdrw drive still chokes my system even with
dma enabled via:
>sudo hdparm -c1 -d1 -X34 /dev/hdc
The hard drives are 10KRPM ultra2 scsi drives.
------------------------------
From: "Peter T. Breuer" <[EMAIL PROTECTED]>
Subject: Re: File access within a kernel mod
Date: Wed, 25 Apr 2001 16:25:18 +0200
Kasper Dupont <[EMAIL PROTECTED]> wrote:
> This is a multi-part message in MIME format.
> Comments are wellcomme, have I forgotten
> something, can it be done simpler?
It's not really comprehensible as it is written. Split it up into
4 or 5 line subroutines whose names express what they are trying to do,
and I might be able to comment. Also don't do:
if(blah) {
long stuff
} else {
one liner
}
And don't nest if's! Them thar's novice programming mistakes.
> #include <linux/module.h>
> #include <linux/malloc.h>
> #include <asm/uaccess.h>
> char *src = NULL;
> char *dst = NULL;
> MODULE_PARM(src,"s");
> MODULE_PARM(dst,"s");
These are file names, of course?
> /* This is a kernel module, I must be very
> * carefull to clean up everything myself,
> * there is nobody who can do it for me.
> */
> int init_module(void)
> {
You do ALL the work in init_module! Arghh. Go away. At least call a
subroutine that says "I do all the work".
> struct file *srcf,*dstf;
> int retval,orgfsuid,orgfsgid;
> mm_segment_t orgfs;
> char *buffer;
> unsigned long page;
write a struct to hold the data you save. Add a method savedata():
mystruct.savedata();
> /* Save uid and gid used for filesystem access.
> * Set user and group to 0 (root)
> */
> orgfsuid=current->fsuid;
> orgfsgid=current->fsgid;
> current->fsuid=current->fsgid=0;
> /* save FS register and set FS register to kernel
> * space, needed for read and write to accept
> * buffer in kernel space.
> */
> orgfs=get_fs();
> set_fs(KERNEL_DS);
> if (src&&dst&&*src&&*dst) {
programming style error! That's
if (!src)
return -EOUCH;
if (!dst)
return -EOUCH;
if (! src[0])
return -EINVAL;
if (! dst[0])
return -EINVAL;
> printk("Copying %s to %s\n",src,dst);
> /* Allocate one page for buffer */
> page = __get_free_page(GFP_KERNEL);
should loop with retry's, then return -ENOMEM if unsuccessful.
> if (page) {
Your standard programming mistake. The exceptional case should be
discarded first.
> buffer=(char*)page;
> srcf = filp_open(src, O_RDONLY, 0);
> if (IS_ERR(srcf)) {
> printk("kcp: Error %ld opening %s\n",-PTR_ERR(srcf),src);
and return -EBADF; after discarding the page you got? Memory leak?
> } else {
> /* The object must have a read method */
> if (srcf->f_op&&srcf->f_op->read) {
> dstf = filp_open(dst, O_WRONLY|O_TRUNC|O_CREAT , 0644);
> if (IS_ERR(dstf)) {
> printk("kcp: Error %ld opening %s\n",-PTR_ERR(dstf),dst);
more errors of the same kind.
> } else {
> /* The object must have a write method */
> if (dstf->f_op&&dstf->f_op->write) {
> do {
> /* Read as much as posible into the buffer,
> * at most one page.
> */
> retval=srcf->f_op->read(srcf,buffer,PAGE_SIZE,&srcf->f_pos);
you should be in a loop here, and it should be a function
readfile(filp, buffer)
but I'm not sure this will work anyway. But maybe.
> if (retval<0) printk("kcp: Read error %d\n",-retval);
incorrect error treatment.
> if (retval>0) {
> int index=0,bufsize=retval;
> /* Continue writing until error or everything
> * written.
> */
> while ((index<bufsize)&&
> ((retval=dstf->f_op->write
> (dstf,buffer+index,bufsize-index,&dstf->f_pos))>0)
> ) index+=retval;
> if (index<bufsize) printk("kcp: Write error %d\n",-retval);
Impossible to read. Use counters
unsigned long offset = 0;
unsigned long remaining = blah_size();
and are you seriously going to keep BOTH files open? Surely you have to
read them a bit at a time? And what if they're over 2GB in size?
> }
> /* Copy loop continues until EOF or error.
> */
> } while (retval>0);
> /* Now clean up everything that was actually allocated
> */
ecch.
> } else {
> printk("kcp: %s does not have a write method\n",dst);
wrong place. Discard errors first.
> }
> retval=filp_close(dstf,NULL);
> if (retval) printk("kcp: Error %d closing %s\n",-retval,dst);
> }
> } else {
> printk("kcp: %s does not have a read method\n",src);
> }
> retval=filp_close(srcf,NULL);
> if (retval) printk("kcp: Error %d closing %s\n",-retval,src);
> }
> free_page(page);
> } else {
> printk("kcp: Out of memory\n");
> }
> } else printk("kcp: Both src= and dst= must be specified\n");
> set_fs(orgfs);
> current->fsuid=orgfsuid;
> current->fsgid=orgfsgid;
> /* End of demo, returning an error code
> * makes insmod/modprobe remove the module
> * from memory.
> */
> return 1;
> }
Well, it could work under some circumstances! Please clean up your
code.
Peter
------------------------------
From: [EMAIL PROTECTED] ()
Subject: Re: Make error
Date: Wed, 25 Apr 2001 16:38:13 -0000
In article <[EMAIL PROTECTED]>,
cui bin <[EMAIL PROTECTED]> wrote:
> When I complie C++ program, the system reported an error "collect2: ld
>terminated with signal 11 [Segmentation fault] core dumped". Can someone
>tell what's the error?
It can be a lot of things. Have you tried compiling a kernel? If so, did
it work? If a kernel compile fails the same way, you probably have a
hardware problem. Are you over clocking?
--
http://www.spinics.net/linux/
------------------------------
From: Kaelin Colclasure <[EMAIL PROTECTED]>
Subject: Re: [Help:] msgfmt
Date: 25 Apr 2001 11:00:00 -0700
"J. Liu" <[EMAIL PROTECTED]> writes:
> Hello,
>
> what is msgfmt ? where can I get it and how to install it ?
>
> Thanks.
Are you perhaps thinking of fmtmsg? fmtmsg is a System-V-ism. Although
I've never seen it used or used it myself, glibc does seem to support
it -- which means Linux has it too. See </usr/include/fmtmsg.h>.
-- Kaelin
------------------------------
From: Robert Hamilton <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
Subject: problem compiling kernel 2.4.3
Date: Wed, 25 Apr 2001 19:11:19 GMT
Hi all.
I haven't found any mention of this problem in the Changes, kernel
list archives, or on this group -- apologies if it really is a FAQ
and I just missed it....
I just upgraded ggc to 2.95.3, and binutils to 2.11.90.0.5 (with
BFD 2.11.90.0.5), prior to compiling kernel 2.4.3.
I realize the Changes warned that gcc later than 2.91.66 have not been
tested, but this looks too wierd to be a minor revision problem:
gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2
-fomit-frame-pointer -fno-strict-aliasing -pipe
-mpreferred-stack-boundary=2 -march=i586 -c -o i387.o i387.c
{standard input}: Assembler messages:
{standard input}:30: Error: no such 386 instruction: `ldmxcsr'
{standard input}:52: Error: no such 386 instruction: `fxsave'
{standard input}:87: Error: no such 386 instruction: `fxsave'
{standard input}:115: Error: no such 386 instruction: `fxrstor'
make[1]: *** [i387.o] Error 1
make[1]: Leaving directory `/usr/src/linux/arch/i386/kernel'
make: *** [_dir_arch/i386/kernel] Error 2
.config :
#
# Automatically generated by make menuconfig: don't edit
#
CONFIG_X86=y
CONFIG_ISA=y
# CONFIG_SBUS is not set
CONFIG_UID16=y
#
# Code maturity level options
#
CONFIG_EXPERIMENTAL=y
#
# Loadable module support
#
CONFIG_MODULES=y
CONFIG_MODVERSIONS=y
CONFIG_KMOD=y
#
# Processor type and features
#
# Loadable module support
#
CONFIG_MODULES=y
CONFIG_MODVERSIONS=y
CONFIG_KMOD=y
#
# Processor type and features
#
# CONFIG_M386 is not set
# CONFIG_M486 is not set
# CONFIG_M586 is not set
# CONFIG_M586TSC is not set
# CONFIG_M586MMX is not set
# CONFIG_M686 is not set
# CONFIG_MPENTIUMIII is not set
# CONFIG_MPENTIUM4 is not set
CONFIG_MK6=y
# CONFIG_MK7 is not set
# CONFIG_MCRUSOE is not set
# CONFIG_MWINCHIPC6 is not set
# CONFIG_MWINCHIP2 is not set
# CONFIG_MWINCHIP3D is not set
------------------------------
From: [EMAIL PROTECTED] (Paul Kimoto)
Subject: Re: problem compiling kernel 2.4.3
Date: 25 Apr 2001 16:39:10 -0500
Reply-To: [EMAIL PROTECTED]
In article
<[EMAIL PROTECTED]>,
Robert Hamilton wrote:
> I just upgraded ggc to 2.95.3, and binutils to 2.11.90.0.5 (with
> BFD 2.11.90.0.5), prior to compiling kernel 2.4.3.
> I realize the Changes warned that gcc later than 2.91.66 have not been
> tested, but this looks too wierd to be a minor revision problem:
>
> gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2
> -fomit-frame-pointer -fno-strict-aliasing -pipe
> -mpreferred-stack-boundary=2 -march=i586 -c -o i387.o i387.c
> {standard input}: Assembler messages:
> {standard input}:30: Error: no such 386 instruction: `ldmxcsr'
> {standard input}:52: Error: no such 386 instruction: `fxsave'
> {standard input}:87: Error: no such 386 instruction: `fxsave'
> {standard input}:115: Error: no such 386 instruction: `fxrstor'
> make[1]: *** [i387.o] Error 1
> make[1]: Leaving directory `/usr/src/linux/arch/i386/kernel'
> make: *** [_dir_arch/i386/kernel] Error 2
It looks like your binutils (namely, the assembler) was not built with
knowledge of these instructions.
$ strings /usr/bin/as | egrep 'ldmxcsr|fxsave|fxrstor'
ldmxcsr
fxrstor
fxsave
$ cat /proc/version
Linux version 2.4.3 (root@autolycus) (gcc version 2.95.3 20010315
(release)) #1 Fri Mar 30 12:36:11 EST 2001
--
Paul Kimoto
This message was originally posted on Usenet in plain text. Any images,
hyperlinks, or the like shown here have been added without my consent,
and may be a violation of international copyright law.
------------------------------
From: [EMAIL PROTECTED] (Paul Kimoto)
Subject: Re: [Help:] msgfmt
Date: 25 Apr 2001 16:40:40 -0500
Reply-To: [EMAIL PROTECTED]
In article <[EMAIL PROTECTED]>, J. Liu wrote:
> what is msgfmt ? where can I get it and how to install it ?
It's from GNU, in gettext.
What does this have to do with the Linux kernel?
--
Paul Kimoto
This message was originally posted on Usenet in plain text. Any images,
hyperlinks, or the like shown here have been added without my consent,
and may be a violation of international copyright law.
------------------------------
Crossposted-To: comp.os.linux.powerpc
From: [EMAIL PROTECTED] (Brian Kendig)
Subject: How do I get a display patch added to the kernel dist?
Date: Wed, 25 Apr 2001 21:41:10 GMT
The short of it: There's a simple patch I need applied to the Linux kernel
in order to use Linux on my computer. I found the patch online, and I've
been told it was submitted to the development tree several months ago, but
for some reason it was never accepted. I want to see the patch added to the
default kernel distributions so that I (and anyone else with the same
monitor as I have) can download kernel binaries instead of having to patch
the source and re-build it myself every time I upgrade. How do I re-submit
a patch, or find out why it wasn't accepted into the tree?
The long of it: My computer is a Power Mac G4 with a Cinema Display (22"
LCD, 1600x1024). The Linux kernel needs the following patch applied to it
in order to be able to use this display (otherwise it fails to sync and the
monitor goes into sleep mode):
diff -urN linux-2.4.0-ac4/drivers/video/macmodes.c
linux-2.4.0-ac4-ppc/drivers/video/macmodes.c
--- linux-2.4.0-ac4/drivers/video/macmodes.c Tue Nov 28 02:11:26 2000
+++ linux-2.4.0-ac4-ppc/drivers/video/macmodes.c Mon Jan 8 10:44:29 2001
@@ -91,7 +91,11 @@
/* 1280x1024, 75 Hz, Non-Interlaced (135.00 MHz dotclock) */
"mac20", 75, 1280, 1024, 7408, 232, 64, 38, 1, 112, 3,
FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
- },
+ }, {
+ /* 1600x1024, 60 Hz, Non-Interlaced (112.27 MHz dotclock) */
+ "mac22", 75, 1600, 1024, 8908, 88, 104, 1, 10, 16, 1,
+ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
+ }
#if 0
/* Anyone who has timings for these? */
@@ -157,6 +161,8 @@
{ VMODE_1280_960_75, &mac_modedb[12] },
/* 1280x1024 */
{ VMODE_1280_1024_75, &mac_modedb[13] },
+ /* 1600x1024 */
+ { VMODE_1600_1024_60, &mac_modedb[14] },
{ -1, NULL }
};
@@ -188,6 +194,7 @@
{ 0x730, VMODE_768_576_50I }, /* PAL (Alternate) */
{ 0x73a, VMODE_1152_870_75 }, /* 3rd party 19" */
{ 0x73f, VMODE_640_480_67 }, /* no sense lines connected at all */
+ { 0xBEEF, VMODE_1600_1024_60 }, /* 22" Apple Cinema Display */
{ -1, VMODE_640_480_60 }, /* catch-all, must be last */
};
diff -urN linux-2.4.0-ac4/include/video/macmodes.h
linux-2.4.0-ac4-ppc/include/video/macmodes.h
--- linux-2.4.0-ac4/include/video/macmodes.h Thu Feb 10 04:43:57 2000
+++ linux-2.4.0-ac4-ppc/include/video/macmodes.h Mon Jan 8 10:44:29 2001
@@ -38,7 +38,8 @@
#define VMODE_1152_870_75 18 /* 1152x870, 75Hz */
#define VMODE_1280_960_75 19 /* 1280x960, 75Hz */
#define VMODE_1280_1024_75 20 /* 1280x1024, 75Hz */
-#define VMODE_MAX 20
+#define VMODE_1600_1024_60 22 /* 1600x1024, 60Hz 22" Cinema Display */
+#define VMODE_MAX 22
#define VMODE_CHOOSE 99
#define CMODE_NVRAM -1
Would someone please submit this patch to the proper place for me, or
explain to me exactly how to submit it?
--
____ |\/| Brian Kendig
\ /\ / ..__. brian at enchanter net You are in a maze of twisty
\/ \__\ _/ http://www.enchanter.net/ little passages, all alike.
\__ __ \_ Be insatiably curious.
\____\___\ Ask "why" a lot.
------------------------------
** FOR YOUR REFERENCE **
The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:
Internet: [EMAIL PROTECTED]
You can send mail to the entire list by posting to the
comp.os.linux.development.system newsgroup.
Linux may be obtained via one of these FTP sites:
ftp.funet.fi pub/Linux
tsx-11.mit.edu pub/linux
sunsite.unc.edu pub/Linux
End of Linux-Development-System Digest
******************************