Skip to content

Commit 98b9e7f

Browse files
switch: add lwext4 (#346)
1 parent 9e9bc13 commit 98b9e7f

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

switch/lwext4/PKGBUILD

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Maintainer: DarkMatterCore <pabloacurielz@gmail.com>
2+
3+
pkgname=switch-lwext4
4+
pkgver=1.0.0
5+
pkgcommithash=58bcf89a121b72d4fb66334f1693d3b30e4cb9c5
6+
pkgrel=1
7+
pkgdesc='ext2/ext3/ext4 filesystem library for microcontrollers'
8+
arch=('any')
9+
url='https://github.com/gkostka/lwext4'
10+
license=('GPL')
11+
options=(!strip libtool staticlibs)
12+
groups=('switch-portlibs')
13+
makedepends=('devkitA64' 'dkp-toolchain-vars' 'switch-cmake')
14+
15+
source=(
16+
"lwext4-${pkgver}.tar.gz::${url}/archive/${pkgcommithash}.tar.gz"
17+
"lwext4-${pkgver}.patch"
18+
)
19+
20+
prepare() {
21+
cd "lwext4-${pkgcommithash}"
22+
23+
patch -Np1 -i "${srcdir}/lwext4-${pkgver}.patch"
24+
25+
source /opt/devkitpro/switchvars.sh
26+
make lib_only
27+
28+
cp -fr build_lib_only/include/generated include/generated
29+
}
30+
31+
build() {
32+
cd "lwext4-${pkgcommithash}"
33+
source /opt/devkitpro/switchvars.sh
34+
make -C build_lib_only
35+
}
36+
37+
package() {
38+
cd "lwext4-${pkgcommithash}"
39+
40+
source /opt/devkitpro/switchvars.sh
41+
42+
for file in $(find include -type f -name *.h); do
43+
install -Dm644 ${file} "${pkgdir}${PORTLIBS_PREFIX}/${file}"
44+
done
45+
46+
install -Dm644 build_lib_only/src/liblwext4.a "${pkgdir}${PORTLIBS_PREFIX}/lib/liblwext4.a"
47+
install -Dm644 LICENSE "${pkgdir}${PORTLIBS_PREFIX}/licenses/${pkgname}/LICENSE"
48+
}
49+
sha256sums=('8f7cce20f5dad2719cb22982e64c75069af51741555c98d34a247a5d8f154890'
50+
'59d674ca846c0ccbef189d7153ba864bb8940d26be65826843fb00bdcc58b519')

switch/lwext4/lwext4-1.0.0.patch

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index eec0993..ce64c51 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -30,11 +30,21 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL msp430g2210)
6+
add_definitions(-DCONFIG_DEBUG_ASSERT=0)
7+
#...
8+
elseif(LIB_ONLY)
9+
- add_definitions(-DCONFIG_DEBUG_PRINTF=0)
10+
- add_definitions(-DCONFIG_DEBUG_ASSERT=0)
11+
- add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=1)
12+
+ if (CMAKE_BUILD_TYPE STREQUAL Release)
13+
+ add_definitions(-DCONFIG_DEBUG_PRINTF=0)
14+
+ add_definitions(-DCONFIG_DEBUG_ASSERT=0)
15+
+ else()
16+
+ add_definitions(-DCONFIG_DEBUG_PRINTF=1)
17+
+ add_definitions(-DCONFIG_DEBUG_ASSERT=1)
18+
+ endif()
19+
+ add_definitions(-DCONFIG_HAVE_OWN_ASSERT=0)
20+
add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
21+
add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
22+
+ add_definitions(-DCONFIG_EXT4_BLOCKDEVS_COUNT=8)
23+
+ add_definitions(-DCONFIG_EXT4_MOUNTPOINTS_COUNT=8)
24+
+ add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=0)
25+
+ add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
26+
+ add_definitions(-DCONFIG_USE_USER_MALLOC=0)
27+
else()
28+
#Generic example target
29+
if (WIN32)
30+
@@ -74,8 +84,6 @@ macro(output_configure)
31+
endmacro()
32+
output_configure()
33+
34+
-add_subdirectory(blockdev)
35+
-
36+
#Library build
37+
add_subdirectory(src)
38+
#Detect all possible warnings for lwext4 target
39+
diff --git a/Makefile b/Makefile
40+
index 12ee5c7..413317d 100644
41+
--- a/Makefile
42+
+++ b/Makefile
43+
@@ -65,7 +65,7 @@ mingw:
44+
lib_only:
45+
rm -R -f build_lib_only
46+
mkdir build_lib_only
47+
- cd build_lib_only && cmake $(COMMON_DEFINITIONS) -DLIB_ONLY=TRUE ..
48+
+ cd build_lib_only && aarch64-none-elf-cmake $(COMMON_DEFINITIONS) -DLIB_ONLY=TRUE ..
49+
50+
all:
51+
generic
52+
diff --git a/src/ext4.c b/src/ext4.c
53+
index 90ce45e..2bdd520 100644
54+
--- a/src/ext4.c
55+
+++ b/src/ext4.c
56+
@@ -461,14 +461,13 @@ int ext4_umount(const char *mount_point)
57+
if (r != EOK)
58+
goto Finish;
59+
60+
- mp->mounted = 0;
61+
-
62+
ext4_bcache_cleanup(mp->fs.bdev->bc);
63+
ext4_bcache_fini_dynamic(mp->fs.bdev->bc);
64+
65+
r = ext4_block_fini(mp->fs.bdev);
66+
Finish:
67+
mp->fs.bdev->fs = NULL;
68+
+ memset(mp, 0, sizeof(struct ext4_mountpoint));
69+
return r;
70+
}
71+
72+
@@ -1616,7 +1615,7 @@ static int ext4_ftruncate_no_lock(ext4_file *file, uint64_t size)
73+
/*Sync file size*/
74+
file->fsize = ext4_inode_get_size(&file->mp->fs.sb, ref.inode);
75+
if (file->fsize <= size) {
76+
- r = EOK;
77+
+ r = ENOTSUP;
78+
goto Finish;
79+
}
80+
81+
@@ -1659,11 +1658,12 @@ int ext4_ftruncate(ext4_file *f, uint64_t size)
82+
EXT4_MP_LOCK(f->mp);
83+
84+
ext4_trans_start(f->mp);
85+
+
86+
r = ext4_ftruncate_no_lock(f, size);
87+
- if (r != EOK)
88+
- ext4_trans_abort(f->mp);
89+
- else
90+
+ if (r == EOK || r == ENOTSUP)
91+
ext4_trans_stop(f->mp);
92+
+ else
93+
+ ext4_trans_abort(f->mp);
94+
95+
EXT4_MP_UNLOCK(f->mp);
96+
return r;
97+
@@ -3146,8 +3146,10 @@ int ext4_dir_mk(const char *path)
98+
99+
/*Check if exist.*/
100+
r = ext4_generic_open(&f, path, "r", false, 0, 0);
101+
- if (r == EOK)
102+
+ if (r == EOK) {
103+
+ r = EEXIST;
104+
goto Finish;
105+
+ }
106+
107+
/*Create new directory.*/
108+
r = ext4_generic_open(&f, path, "w", false, 0, 0);

0 commit comments

Comments
 (0)