You can print a human readable string for error using 'strerror' function.

see -
man strerror
man errno

--
Thanks,
- John

On 08/16/2009 04:09 PM, Manish Katiyar wrote:
On Sun, Aug 16, 2009 at 3:09 PM, loody<milo...@gmail.com>  wrote:
Dear all:
I try to open /dev/sda1 with system call, open("/dev/sda1", O_RDONLY).
But each time it will return negative value, that means fail.
Have you checked for the errno ? I guess it is permission denied.


/home/mkatiyar>  dd if=/dev/sda1 of=/dev/zero
dd: opening `/dev/sda1': Permission denied

Thanks -
Manish

my program is like below:
(gdb) list
1       #include<stdio.h>
2       #include<fcntl.h>
3       int main(void)
4       {
5       int fd=0;
6        fd = open("/dev/sda1", O_RDONLY);
7
8        printf("%d\n",fd);
9       }
10
(gdb) b 8
Breakpoint 1 at 0x8048423: file test.c, line 8.
(gdb) r
Starting program: /home/cc/a.out

Breakpoint 1, main () at test.c:8
8        printf("%d\n",fd);
(gdb) p fd
$1 = -1
(gdb)


But I am quite sure I really get /dev/sda1 on my linux system.
below are the dmesg:
$ dmesg |grep sda
[    4.304624] sd 0:0:0:0: [sda] 117210240 512-byte hardware sectors (60012 MB)
[    4.304642] sd 0:0:0:0: [sda] Write Protect is off
[    4.304646] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    4.304672] sd 0:0:0:0: [sda] Write cache: enabled, read cache:
enabled, doesn't support DPO or FUA
[    4.304742] sd 0:0:0:0: [sda] 117210240 512-byte hardware sectors (60012 MB)
[    4.304757] sd 0:0:0:0: [sda] Write Protect is off
[    4.304760] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    4.304786] sd 0:0:0:0: [sda] Write cache: enabled, read cache:
enabled, doesn't support DPO or FUA
[    4.304790]  sda:<4>Driver 'sr' needs updating - please use bus_type methods
[    4.319499]  sda1 sda2 sda3<  sda5<6>usb 4-2: configuration #1
chosen from 1 choice
[    4.359729]  sda6>  sda4
[    4.359951] sd 0:0:0:0: [sda] Attached SCSI disk
[   22.637589] EXT3 FS on sda4, internal journal
[   23.586600] EXT3 FS on sda6, internal journal
$
Does that mean I use the wrong systemcall or we cannot open /dev/sda1 like this?
appreciate your help,
miloody

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ





Reply via email to