Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Raw partitions on SDCard: (7 Items)
   
Raw partitions on SDCard  
Hi All,
I am trying to create a RAW partitions on SDCard and then do a read write to it.Can anybody give info on this creation 
and read write method.

thanks,
with regards,
praveen kumar
Re: Raw partitions on SDCard  
Hi Praveen,
Have you looked in the docs, in Building Embedded Systems?
http://www.qnx.com/developers/docs/660/topic/com.qnx.doc.neutrino.building/
topic/bsp_Flash_filesystem.html
N

On 2014-09-09 3:05 , "Praveen Kumar" <community-noreply@qnx.com> wrote:

>Hi All,
>I am trying to create a RAW partitions on SDCard and then do a read write
>to it.Can anybody give info on this creation and read write method.
>
>thanks,
>with regards,
>praveen kumar
>
>
>
>_______________________________________________
>
>OSTech
>http://community.qnx.com/sf/go/post111677
>To cancel your subscription to this discussion, please e-mail
>ostech-core_os-unsubscribe@community.qnx.com

Re: Raw partitions on SDCard  
Use fdisk to create a partition OF ANY TYPE (say 77).  Do not format the partition!
# fdisk /dev/hd2   ...and use menu

Do this to read/accept new partition table.
# mount -e /dev/hd2

From your program you can..
fd = open( "/dev/hd2t77", O_RDWR );
len = read( fd, buf, 512 )l;

or
# hd /dev/hd2t77

or to read entire partition
# dd if=/dev/hd2t77 of=/dev/null


Re: Raw partitions on SDCard  
Hi,
Thanks for the immediate reply.I used the fdisk method to create a RAW partition on SD Card giving the below command 
fdisk /dev/hd0 add -t 3 -p 10
Then i tried to write to the partition opening the partition in a c program with the following code
int fdd = open("/dev/hd0t3",O_RDWR);
then i am trying to write a structure data to the partition in the following manner

write(fdd,(const void*)&wrbuff,sizeof(wrbuff));//where the wrbuff has the members char,float,int

when i try to read back from the partition 
read(fdd,(void*)&rdbuff,sizeof(rdbuff));//another instance of the same buffer 
the data is not getting read back correctly am i doing any mistake in my code please advice.
Thanks with regards
Praveen Kumar V S
Re: Raw partitions on SDCard  
Are you using the same fd or you are calling open() again before the read()? If it's the same fd then you need to seek()
 back to the beginning before the read().

Could you post a complete minimal program that reproduces the issue you see?

--
Mate

  Original Message
From: Praveen Kumar
Sent: Friday, September 12, 2014 20:31
To: ostech-core_os
Reply To: ostech-core_os@community.qnx.com
Subject: Re: Raw partitions on SDCard


Hi,
Thanks for the immediate reply.I used the fdisk method to create a RAW partition on SD Card giving the below command
fdisk /dev/hd0 add -t 3 -p 10
Then i tried to write to the partition opening the partition in a c program with the following code
int fdd = open("/dev/hd0t3",O_RDWR);
then i am trying to write a structure data to the partition in the following manner

write(fdd,(const void*)&wrbuff,sizeof(wrbuff));//where the wrbuff has the members char,float,int

when i try to read back from the partition
read(fdd,(void*)&rdbuff,sizeof(rdbuff));//another instance of the same buffer
the data is not getting read back correctly am i doing any mistake in my code please advice.
Thanks with regards
Praveen Kumar V S




_______________________________________________

OSTech
http://community.qnx.com/sf/go/post111701
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: Raw partitions on SDCard  
Is rdbuff and wrbuff the same size?   And do you use lseek to adjust the offset before you read?

Sent from my BlackBerry 10 smartphone on the Fido network.
  Original Message
From: Praveen Kumar
Sent: Friday, September 12, 2014 7:31 AM
To: ostech-core_os
Reply To: ostech-core_os@community.qnx.com
Subject: Re: Raw partitions on SDCard


Hi,
Thanks for the immediate reply.I used the fdisk method to create a RAW partition on SD Card giving the below command
fdisk /dev/hd0 add -t 3 -p 10
Then i tried to write to the partition opening the partition in a c program with the following code
int fdd = open("/dev/hd0t3",O_RDWR);
then i am trying to write a structure data to the partition in the following manner

write(fdd,(const void*)&wrbuff,sizeof(wrbuff));//where the wrbuff has the members char,float,int

when i try to read back from the partition
read(fdd,(void*)&rdbuff,sizeof(rdbuff));//another instance of the same buffer
the data is not getting read back correctly am i doing any mistake in my code please advice.
Thanks with regards
Praveen Kumar V S




_______________________________________________

OSTech
http://community.qnx.com/sf/go/post111701
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: Raw partitions on SDCard  
Hi,
This is my minimal code

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mount.h>
struct databuffer
{
    char chardata;
    float floatdata;
    int intdata;
};

int main(int argc, char *argv[]) {

struct databuffer datbuf,rddatbuf;
int fdd=0,readcount=0;
fdd = open("/dev/hd0t3",O_RDWR);
    if(fdd < 0)
    {
    	printf("fd open error");
    }
    datbuf.chardata='a';
    datbuf.floatdata=1.152;
    datbuf.intdata=20;

    write(fdd,(const void*)&datbuf,sizeof(datbuf));


    read(fdd,(void*)&rddatbuf,sizeof(rddatbuf));
    printf("%c___,%f___,%d___\n",rddatbuf.chardata,rddatbuf.floatdata,rddatbuf.intdata);
    close(fdd);
return 0; 
}

As said in your mail i have not used the lseek i need to add it before the read command.I have another problem i am 
trying to open a new file in the file system and write to it but my program is crashing.
My sample code
The code is crashing on the fopen call itself is there anything to be done before fopen
int mountret=mount("/dev/hd0t1","/usr",_MOUNT_REMOUNT,"dos",'\0',-1);

    fd=fopen("/usr/test/data.txt",'a');
    if(fd==NULL)
    {
       printf("fopen error");
    }
    datbuf.chardata='a';
        datbuf.floatdata=1.152;
        datbuf.intdata=20;

        fwrite((const void*)&datbuf,sizeof(datbuf),1,fd);
        fclose(fd); 


Thanks for your response it is very helpful.

With Regards,
Praveen Kumar