]>
git.ipfire.org Git - people/ms/u-boot.git/blob - fs/ext4/ext4fs.c
2 * (C) Copyright 2011 - 2012 Samsung Electronics
3 * EXT4 filesystem implementation in Uboot by
4 * Uma Shankar <uma.shankar@samsung.com>
5 * Manjunatha C Achar <a.manjunatha@samsung.com>
7 * ext4ls and ext4load : Based on ext2 ls and load support in Uboot.
8 * Ext4 read optimization taken from Open-Moko
12 * esd gmbh <www.esd-electronics.com>
13 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
15 * based on code from grub2 fs/ext2.c and fs/fshelp.c by
16 * GRUB -- GRand Unified Bootloader
17 * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
19 * ext4write : Based on generic ext4 protocol.
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 #include <ext_common.h>
39 #include "ext4_common.h"
41 int ext4fs_symlinknest
;
42 struct ext_filesystem ext_fs
;
44 struct ext_filesystem
*get_fs(void)
49 void ext4fs_free_node(struct ext2fs_node
*node
, struct ext2fs_node
*currroot
)
51 if ((node
!= &ext4fs_root
->diropen
) && (node
!= currroot
))
56 * Taken from openmoko-kernel mailing list: By Andy green
57 * Optimized read file API : collects and defers contiguous sector
58 * reads into one potentially more efficient larger sequential read action
60 int ext4fs_read_file(struct ext2fs_node
*node
, int pos
,
61 unsigned int len
, char *buf
)
65 int log2blocksize
= LOG2_EXT2_BLOCK_SIZE(node
->data
);
66 int blocksize
= 1 << (log2blocksize
+ DISK_SECTOR_BITS
);
67 unsigned int filesize
= __le32_to_cpu(node
->inode
.size
);
68 int previous_block_number
= -1;
69 int delayed_start
= 0;
70 int delayed_extent
= 0;
71 int delayed_skipfirst
= 0;
73 char *delayed_buf
= NULL
;
76 /* Adjust len so it we can't read past the end of the file. */
80 blockcnt
= ((len
+ pos
) + blocksize
- 1) / blocksize
;
82 for (i
= pos
/ blocksize
; i
< blockcnt
; i
++) {
84 int blockoff
= pos
% blocksize
;
85 int blockend
= blocksize
;
87 blknr
= read_allocated_block(&(node
->inode
), i
);
91 blknr
= blknr
<< log2blocksize
;
94 if (i
== blockcnt
- 1) {
95 blockend
= (len
+ pos
) % blocksize
;
97 /* The last portion is exactly blocksize. */
103 if (i
== pos
/ blocksize
) {
104 skipfirst
= blockoff
;
105 blockend
-= skipfirst
;
110 if (previous_block_number
!= -1) {
111 if (delayed_next
== blknr
) {
112 delayed_extent
+= blockend
;
113 delayed_next
+= blockend
>> SECTOR_BITS
;
115 status
= ext4fs_devread(delayed_start
,
121 previous_block_number
= blknr
;
122 delayed_start
= blknr
;
123 delayed_extent
= blockend
;
124 delayed_skipfirst
= skipfirst
;
126 delayed_next
= blknr
+
127 (blockend
>> SECTOR_BITS
);
130 previous_block_number
= blknr
;
131 delayed_start
= blknr
;
132 delayed_extent
= blockend
;
133 delayed_skipfirst
= skipfirst
;
135 delayed_next
= blknr
+
136 (blockend
>> SECTOR_BITS
);
139 if (previous_block_number
!= -1) {
141 status
= ext4fs_devread(delayed_start
,
147 previous_block_number
= -1;
149 memset(buf
, 0, blocksize
- skipfirst
);
151 buf
+= blocksize
- skipfirst
;
153 if (previous_block_number
!= -1) {
155 status
= ext4fs_devread(delayed_start
,
156 delayed_skipfirst
, delayed_extent
,
160 previous_block_number
= -1;
166 int ext4fs_ls(const char *dirname
)
168 struct ext2fs_node
*dirnode
;
174 status
= ext4fs_find_file(dirname
, &ext4fs_root
->diropen
, &dirnode
,
177 printf("** Can not find directory. **\n");
181 ext4fs_iterate_dir(dirnode
, NULL
, NULL
, NULL
);
182 ext4fs_free_node(dirnode
, &ext4fs_root
->diropen
);
187 int ext4fs_read(char *buf
, unsigned len
)
189 if (ext4fs_root
== NULL
|| ext4fs_file
== NULL
)
192 return ext4fs_read_file(ext4fs_file
, 0, len
, buf
);