tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / fs / ext4 / ext4_rw.c
1 #include <linux/types.h>
2 #include <common.h>
3 #include <part.h>
4 #include <ext4fs.h>
5
6 #if 0
7 int ext4_read_content(int dev,int part,const char *filename, void *buf, int offset, int len)
8 {
9         disk_partition_t info;
10         block_dev_desc_t *dev_desc;
11
12         dev_desc = get_dev("mmc", dev);
13         if(NULL == dev_desc){
14                 printf("ext4_read_content get dev error\n");
15                 return 1;
16         }
17
18         get_partition_info(dev_desc,part,&info);
19         /* set the device as block device */
20         ext4fs_set_blk_dev(dev_desc, &info);
21
22         /* mount the filesystem */
23         if (!ext4fs_mount(info.size)) {
24                 printf("Bad ext4 partition part=%d\n",  part);
25                 goto fail;
26         }
27
28         /* start read */
29         if (ext4_read_file(filename, (unsigned char *)buf, offset,len) == -1) {
30                 printf("** Error ext4_read_file() **\n");
31                 goto fail;
32         }
33         printf("ext4_read_content %s\n",buf);
34         ext4fs_close();
35         return 0;
36 fail:
37         ext4fs_close();
38
39         return 1;
40 }
41 #endif
42
43 int ext4_read_content(int dev, wchar_t* partition_name, const char *filename, void *buf, int offset, int len)
44 {
45         disk_partition_t info;
46         block_dev_desc_t *dev_desc;
47
48         dev_desc = get_dev("mmc", dev);
49         if(NULL == dev_desc){
50                 printf("ext4_read_content get dev error\n");
51                 return 1;
52         }
53
54         if(get_partition_info_by_name (dev_desc, partition_name, &info) == -1){
55                 printf("## Valid EFI partition not found ##\n");
56                 return 1;
57         }
58
59         /* set the device as block device */
60         ext4fs_set_blk_dev(dev_desc, &info);
61
62         /* mount the filesystem */
63         if (!ext4fs_mount(info.size)) {
64 //              printf("Bad ext4 partition part=%d\n",  part);
65                 goto fail;
66         }
67
68         /* start read */
69         if (ext4_read_file(filename, (unsigned char *)buf, offset,len) == -1) {
70                 printf("** Error ext4_read_file() **\n");
71                 goto fail;
72         }
73
74         ext4fs_close();
75         return 0;
76 fail:
77         ext4fs_close();
78
79         return 1;
80 }
81
82
83 int ext4_write_content(int dev, wchar_t* partition_name,char* filename,unsigned char *ram_address,int file_size)
84 {
85         disk_partition_t info;
86         block_dev_desc_t *dev_desc;
87
88         dev_desc = get_dev("mmc", dev);
89         if(NULL == dev_desc){
90                 printf("ext4_write_data get dev error\n");
91                 return 1;
92         }
93
94         if(get_partition_info_by_name (dev_desc, partition_name, &info) == -1){
95                 printf("## Valid EFI partition not found ##\n");
96                 return 1;
97         }
98
99         /* set the device as block device */
100         ext4fs_set_blk_dev(dev_desc, &info);
101
102         /* mount the filesystem */
103         if (!ext4fs_mount(info.size)) {
104 //              printf("Bad ext4 partition part=%d\n",  part);
105                 goto fail;
106         }
107
108         /* start write */
109         if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
110                 printf("** Error ext4fs_write() **\n");
111                 goto fail;
112         }
113         ext4fs_close();
114         return 0;
115 fail:
116         ext4fs_close();
117
118         return 1;
119 }
120
121
122 #if 0
123 int ext4_write_content(int dev,int part,char* filename,unsigned char *ram_address,int file_size)
124 {
125         disk_partition_t info;
126         block_dev_desc_t *dev_desc;
127
128         dev_desc = get_dev("mmc", dev);
129         if(NULL == dev_desc){
130                 printf("ext4_write_data get dev error\n");
131                 return 1;
132         }
133
134         get_partition_info(dev_desc,part,&info);
135         /* set the device as block device */
136         ext4fs_set_blk_dev(dev_desc, &info);
137
138         /* mount the filesystem */
139         if (!ext4fs_mount(info.size)) {
140                 printf("Bad ext4 partition part=%d\n",  part);
141                 goto fail;
142         }
143
144         /* start write */
145         if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
146                 printf("** Error ext4fs_write() **\n");
147                 goto fail;
148         }
149         ext4fs_close();
150         return 0;
151 fail:
152         ext4fs_close();
153
154         return 1;
155 }
156 #endif
157