LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   lseek function applied on open disk crashes my program. (https://www.linuxquestions.org/questions/linux-kernel-70/lseek-function-applied-on-open-disk-crashes-my-program-4175412629/)

basudebg 06-24-2012 01:20 PM

I originally started writing wxFile class and wxSeek functions, As that was crashing, I wanted to do away with it and use plain lseek. Even now I want get around the problem and want to call lseek function. Is there any way to do that? As the function is not reaching lseek at all in this case, there has to be some problem in compiling the code. So, how do I get rid of that?

I am not conversant with coredump, but I think this is a very complicated way to discover a bug in the library, as wxWidgets should clarify/correct it.

pan64 06-24-2012 01:29 PM

if you have a simple case just report it to the developers, you do not need to analyze or solve it. However the stack trace may give a lot of info about the problem.
So if you want to solve this I recommend you to make a library without wxWidgets and this implements your file i/o (you can also try to link statically the runtime). You will use this lib in your app with wxWidgets instead of the original runtime (so you will have my_lseek, my_open or similar)

Valery Reznic 06-24-2012 02:04 PM

Quote:

Originally Posted by basudebg (Post 4710740)
I originally started writing wxFile class and wxSeek functions, As that was crashing, I wanted to do away with it and use plain lseek. Even now I want get around the problem and want to call lseek function. Is there any way to do that? As the function is not reaching lseek at all in this case, there has to be some problem in compiling the code. So, how do I get rid of that?

I am not conversant with coredump, but I think this is a very complicated way to discover a bug in the library, as wxWidgets should clarify/correct it.

I see two ways to bypass wxWidget's lseek and call the real one:

use dlopen
Code:

handler = dlopen("libc.so.6", ...);
true_lseek = dlsym(handler, "lseek");
true_lseek(....);

Or write your own lseek function and call call lseek syscall directly.
But this (assembler) function shoul be changed for each new processor or operation system

So first solution is more portable

basudebg 06-24-2012 10:03 PM

Thank you for the help. I reported the issue to the developers but have not got their response yet. But the solution:

handler = dlopen("libc.so.6", ...);
true_lseek = dlsym(handler, "lseek");
true_lseek(....);

is the one probably I was looking for. It seems to work fine, at least the core dump is gone. I would say the issue is solved.

Valery Reznic 06-24-2012 11:23 PM

Quote:

Originally Posted by basudebg (Post 4710968)
Thank you for the help. I reported the issue to the developers but have not got their response yet. But the solution:

handler = dlopen("libc.so.6", ...);
true_lseek = dlsym(handler, "lseek");
true_lseek(....);

is the one probably I was looking for. It seems to work fine, at least the core dump is gone. I would say the issue is solved.

Glad it works for you. Let us know what response will you get from wxWidget developeers.

vramesh1981 06-25-2012 12:12 AM

Quote:

Originally Posted by basudebg (Post 4708391)
I open a disk using
int f= open(devicename,O_RDWR);
then I want to seek to a position. Here it is 0( could be anything).
lseek(f,0,SEEK_SET);

After this I want to write something. The device name is /dev/sdc ( a disk, it could be sda, sdb anything).

But just after lseek is executed, I get a coredumped message on the command prompt.

If I omit lseek, I can go on writing and after closing, can see the data. But I need lseek. Note that lseek64 also creashes the same way.

Am I doing something silly? Please help.
Basudeb

Here, you are trying to perform lseek on Block device (sdc) which is not supported. Since Block device read/write bytes in fixed size blocks. where as character device read/write bytes in a stream. Hence lseek can be performed only on character device.

basudebg 06-25-2012 12:16 AM

I have just completed lseek and write on a block device and verified. So, it works, but not with wxWidget, but by using dlopen and dlsym.


All times are GMT -5. The time now is 06:34 PM.