some question about open fail on /dev/sda nodes

2009-08-16 Thread loody
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.
my program is like below:
(gdb) list
1       #includestdio.h
2       #includefcntl.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:4Driver 'sr' needs updating - please use bus_type methods
[    4.319499]  sda1 sda2 sda3  sda56usb 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



Re: some question about open fail on /dev/sda nodes

2009-08-16 Thread Manish Katiyar
On Sun, Aug 16, 2009 at 3:09 PM, loodymilo...@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       #includestdio.h
 2       #includefcntl.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:4Driver 'sr' needs updating - please use bus_type 
 methods
 [    4.319499]  sda1 sda2 sda3  sda56usb 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





-- 
Thanks -
Manish

--
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



Re: some question about open fail on /dev/sda nodes

2009-08-16 Thread John Meraj

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, loodymilo...@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   #includestdio.h
2   #includefcntl.h
3   int main(void)
4   {
5   int fd=0;
6fd = open(/dev/sda1, O_RDONLY);
7
8printf(%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
8printf(%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:4Driver 'sr' needs updating - please use bus_type methods
[4.319499]  sda1 sda2 sda3  sda56usb 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


 



   




Re: some question about open fail on /dev/sda nodes

2009-08-16 Thread Siddu
Resending

On Sun, Aug 16, 2009 at 7:38 PM, Siddu siddu.s...@gmail.com 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.
 my program is like below:
 (gdb) list
 1   #includestdio.h
 2   #includefcntl.h
 3   int main(void)
 4   {
 5   int fd=0;
 6fd = open(/dev/sda1, O_RDONLY);
 7
 8printf(%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
 8printf(%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:4Driver 'sr' needs updating - please use bus_type
 methods
 [4.319499]  sda1 sda2 sda3  sda56usb 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

 Try to run the following code as root and also as normal user  . You ll see
 the difference
 #include stdio.h
 #include fcntl.h


 int main ( int argc , char *argv[] ) {
   int fd = 0;

   fd = open( /dev/sda1 , O_RDONLY );

   if ( fd == -1 ) {
   perror( The System Error Message was  );
   }
   else {
   printf(The File Descriptor is : %d \n, fd );
   }
   return 0;
 }



  --
 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




 --
 Regards,
 ~Sid~




-- 
Regards,
~Sid~