summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgkostka <kostka.grzegorz@gmail.com>2015-09-26 17:49:21 +0200
committergkostka <kostka.grzegorz@gmail.com>2015-09-26 17:49:21 +0200
commit1fcd1b0075c24a5627233fab0fc468040afde8f2 (patch)
tree031b35f77808265f45b90dde81c4a63f9b4fd509
parentdfa54d1e23c32059b292bbbb99d4251bf15e7517 (diff)
parent299dbe030a4dc518910e6a8cd2e37e640053506e (diff)
Merge branch 'master' of https://github.com/ngkaho1234/lwext4
-rw-r--r--lwext4/ext4.c155
-rw-r--r--lwext4/ext4.h21
-rw-r--r--lwext4/ext4_config.h5
-rw-r--r--lwext4/ext4_debug.h22
-rw-r--r--toolchain/generic.cmake9
5 files changed, 144 insertions, 68 deletions
diff --git a/lwext4/ext4.c b/lwext4/ext4.c
index 3499f4c..039b8d4 100644
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -874,10 +874,6 @@ static int __ext4_remove_hardlink(const char *path,
goto Finish;
Finish:
- if (r != EOK)
- ext4_fs_put_inode_ref(child_ref);
-
- ext4_fs_put_inode_ref(parent_ref);
return r;
}
@@ -1085,18 +1081,32 @@ Finish:
return r;
}
-int ext4_fill_raw_inode(const char *mount_point, uint32_t ino,
+int ext4_fill_raw_inode(const char *path,
+ uint32_t *ret_ino,
struct ext4_inode *inode)
{
int r;
+ ext4_file f;
struct ext4_inode_ref inode_ref;
- struct ext4_mountpoint *mp = ext4_get_mount(mount_point);
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
+ uint32_t ino;
if (!mp)
return ENOENT;
EXT4_MP_LOCK(mp);
+ r = ext4_generic_open2(&f, path, O_RDONLY,
+ EXT4_DIRECTORY_FILETYPE_UNKNOWN,
+ NULL, NULL);
+ if (r != EOK) {
+ EXT4_MP_UNLOCK(mp);
+ return r;
+ }
+
+ ino = f.inode;
+ ext4_fclose(&f);
+
/*Load parent*/
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
@@ -1108,48 +1118,30 @@ int ext4_fill_raw_inode(const char *mount_point, uint32_t ino,
ext4_fs_put_inode_ref(&inode_ref);
EXT4_MP_UNLOCK(mp);
- return r;
-}
-int ext4_fopen(ext4_file *f, const char *path, const char *flags)
-{
- struct ext4_mountpoint *mp = ext4_get_mount(path);
- int r;
-
- if (!mp)
- return ENOENT;
+ if (ret_ino)
+ *ret_ino = ino;
- EXT4_MP_LOCK(mp);
- ext4_block_cache_write_back(mp->fs.bdev, 1);
- r = ext4_generic_open(f, path, flags, true, 0, 0);
- ext4_block_cache_write_back(mp->fs.bdev, 0);
- EXT4_MP_UNLOCK(mp);
return r;
}
-int ext4_fopen2(ext4_file *f, const char *path, int flags, bool file_expect)
+int ext4_fopen(ext4_file *f, const char *path, const char *flags)
{
struct ext4_mountpoint *mp = ext4_get_mount(path);
int r;
- int filetype;
if (!mp)
return ENOENT;
- if (file_expect == true)
- filetype = EXT4_DIRECTORY_FILETYPE_REG_FILE;
- else
- filetype = EXT4_DIRECTORY_FILETYPE_DIR;
-
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
- r = ext4_generic_open2(f, path, flags, filetype, 0, 0);
+ r = ext4_generic_open(f, path, flags, true, 0, 0);
ext4_block_cache_write_back(mp->fs.bdev, 0);
EXT4_MP_UNLOCK(mp);
return r;
}
-int ext4_fopen_all(ext4_file *f, const char *path, int flags)
+int ext4_fopen2(ext4_file *f, const char *path, int flags)
{
struct ext4_mountpoint *mp = ext4_get_mount(path);
int r;
@@ -1158,10 +1150,7 @@ int ext4_fopen_all(ext4_file *f, const char *path, int flags)
if (!mp)
return ENOENT;
- if (flags & O_CREAT)
- return EINVAL;
-
- filetype = EXT4_DIRECTORY_FILETYPE_UNKNOWN;
+ filetype = EXT4_DIRECTORY_FILETYPE_REG_FILE;
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
@@ -1607,27 +1596,34 @@ uint64_t ext4_ftell(ext4_file *f) { return f->fpos; }
uint64_t ext4_fsize(ext4_file *f) { return f->fsize; }
-int ext4_fchmod(ext4_file *f, uint32_t mode)
+int ext4_chmod(const char *path, uint32_t mode)
{
int r;
uint32_t ino;
+ ext4_file f;
struct ext4_sblock *sb;
struct ext4_inode_ref inode_ref;
- struct ext4_mountpoint *mp = f->mp;
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
if (!mp)
return ENOENT;
EXT4_MP_LOCK(mp);
- ino = f->inode;
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+ if (r != EOK) {
+ EXT4_MP_UNLOCK(mp);
+ return r;
+ }
+ ino = f.inode;
+ sb = &mp->fs.sb;
+ ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
}
- sb = &f->mp->fs.sb;
ext4_inode_set_mode(sb, inode_ref.inode, mode);
inode_ref.dirty = true;
@@ -1636,19 +1632,26 @@ int ext4_fchmod(ext4_file *f, uint32_t mode)
return r;
}
-int ext4_fchown(ext4_file *f, uint32_t uid, uint32_t gid)
+int ext4_chown(const char *path, uint32_t uid, uint32_t gid)
{
int r;
+ ext4_file f;
uint32_t ino;
struct ext4_inode_ref inode_ref;
- struct ext4_mountpoint *mp = f->mp;
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
if (!mp)
return ENOENT;
EXT4_MP_LOCK(mp);
- ino = f->inode;
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+ if (r != EOK) {
+ EXT4_MP_UNLOCK(mp);
+ return r;
+ }
+ ino = f.inode;
+ ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@ -1664,19 +1667,26 @@ int ext4_fchown(ext4_file *f, uint32_t uid, uint32_t gid)
return r;
}
-int ext4_file_set_atime(ext4_file *f, uint32_t atime)
+int ext4_file_set_atime(const char *path, uint32_t atime)
{
int r;
+ ext4_file f;
uint32_t ino;
struct ext4_inode_ref inode_ref;
- struct ext4_mountpoint *mp = f->mp;
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
if (!mp)
return ENOENT;
EXT4_MP_LOCK(mp);
- ino = f->inode;
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+ if (r != EOK) {
+ EXT4_MP_UNLOCK(mp);
+ return r;
+ }
+ ino = f.inode;
+ ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@ -1691,19 +1701,26 @@ int ext4_file_set_atime(ext4_file *f, uint32_t atime)
return r;
}
-int ext4_file_set_mtime(ext4_file *f, uint32_t mtime)
+int ext4_file_set_mtime(const char *path, uint32_t mtime)
{
int r;
+ ext4_file f;
uint32_t ino;
struct ext4_inode_ref inode_ref;
- struct ext4_mountpoint *mp = f->mp;
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
if (!mp)
return ENOENT;
EXT4_MP_LOCK(mp);
- ino = f->inode;
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+ if (r != EOK) {
+ EXT4_MP_UNLOCK(mp);
+ return r;
+ }
+ ino = f.inode;
+ ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@ -1718,19 +1735,26 @@ int ext4_file_set_mtime(ext4_file *f, uint32_t mtime)
return r;
}
-int ext4_file_set_ctime(ext4_file *f, uint32_t ctime)
+int ext4_file_set_ctime(const char *path, uint32_t ctime)
{
int r;
+ ext4_file f;
uint32_t ino;
struct ext4_inode_ref inode_ref;
- struct ext4_mountpoint *mp = f->mp;
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
if (!mp)
return ENOENT;
EXT4_MP_LOCK(mp);
- ino = f->inode;
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+ if (r != EOK) {
+ EXT4_MP_UNLOCK(mp);
+ return r;
+ }
+ ino = f.inode;
+ ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@ -1848,6 +1872,39 @@ Finish:
return r;
}
+int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt)
+{
+ struct ext4_mountpoint *mp = ext4_get_mount(path);
+ int r;
+ ext4_file f;
+ int filetype;
+
+ if (!mp)
+ return ENOENT;
+
+ if (!buf)
+ return EINVAL;
+
+ memset(buf, 0, sizeof(bufsize));
+
+ filetype = EXT4_DIRECTORY_FILETYPE_SYMLINK;
+
+ EXT4_MP_LOCK(mp);
+ ext4_block_cache_write_back(mp->fs.bdev, 1);
+ r = ext4_generic_open2(&f, path, O_RDONLY, filetype, 0, 0);
+ if (r == EOK)
+ r = ext4_fread(&f, buf, bufsize, rcnt);
+ else
+ goto Finish;
+
+ ext4_fclose(&f);
+
+Finish:
+ ext4_block_cache_write_back(mp->fs.bdev, 0);
+ EXT4_MP_UNLOCK(mp);
+ return r;
+}
+
/*********************************DIRECTORY OPERATION************************/
int ext4_dir_rm(const char *path)
diff --git a/lwext4/ext4.h b/lwext4/ext4.h
index 6b76d05..192ecc9 100644
--- a/lwext4/ext4.h
+++ b/lwext4/ext4.h
@@ -297,7 +297,7 @@ int ext4_fopen(ext4_file *f, const char *path, const char *flags);
* /my_partition/my_file
* @param flags open file flags
* @return standard error code*/
-int ext4_fopen2(ext4_file *f, const char *path, int flags, bool file_expect);
+int ext4_fopen2(ext4_file *f, const char *path, int flags);
/**@brief File close function.
* @param f file handle
@@ -305,11 +305,12 @@ int ext4_fopen2(ext4_file *f, const char *path, int flags, bool file_expect);
int ext4_fclose(ext4_file *f);
/**@brief Fill in the ext4_inode buffer.
- * @param mount_point
- * @param inode no.
+ * @param path fetch inode data of the path
+ * @param ret_ino the inode id of the path
* @param ext4_inode buffer
* @return standard error code*/
-int ext4_fill_raw_inode(const char *mount_point, uint32_t ino,
+int ext4_fill_raw_inode(const char *path,
+ uint32_t *ret_ino,
struct ext4_inode *inode);
/**@brief File truncate function.
@@ -354,14 +355,16 @@ uint64_t ext4_ftell(ext4_file *f);
* @return file size */
uint64_t ext4_fsize(ext4_file *f);
-int ext4_fchmod(ext4_file *f, uint32_t mode);
-int ext4_fchown(ext4_file *f, uint32_t uid, uint32_t gid);
-int ext4_file_set_atime(ext4_file *f, uint32_t atime);
-int ext4_file_set_mtime(ext4_file *f, uint32_t mtime);
-int ext4_file_set_ctime(ext4_file *f, uint32_t ctime);
+int ext4_chmod(const char *path, uint32_t mode);
+int ext4_chown(const char *path, uint32_t uid, uint32_t gid);
+int ext4_file_set_atime(const char *path, uint32_t atime);
+int ext4_file_set_mtime(const char *path, uint32_t mtime);
+int ext4_file_set_ctime(const char *path, uint32_t ctime);
int ext4_fsymlink(const char *target, const char *path);
+int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt);
+
/*********************************DIRECTORY OPERATION***********************/
/**@brief Recursive directory remove.
diff --git a/lwext4/ext4_config.h b/lwext4/ext4_config.h
index 67fd3bf..020c4a9 100644
--- a/lwext4/ext4_config.h
+++ b/lwext4/ext4_config.h
@@ -112,6 +112,11 @@
#define CONFIG_DEBUG_ASSERT 1
#endif
+/**@brief Include assert codes from ext4_debug or standard library.*/
+#ifndef CONFIG_HAVE_OWN_ASSERT
+#define CONFIG_HAVE_OWN_ASSERT 1
+#endif
+
/**@brief Statistics of block device*/
#ifndef CONFIG_BLOCK_DEV_ENABLE_STATS
#define CONFIG_BLOCK_DEV_ENABLE_STATS 1
diff --git a/lwext4/ext4_debug.h b/lwext4/ext4_debug.h
index 71f3da8..b9d5cff 100644
--- a/lwext4/ext4_debug.h
+++ b/lwext4/ext4_debug.h
@@ -40,6 +40,10 @@
#include "ext4_config.h"
#include "ext4_errno.h"
+#if !CONFIG_HAVE_OWN_ASSERT
+#include <assert.h>
+#endif
+
#include <stdint.h>
#include <stdio.h>
@@ -101,13 +105,17 @@ uint32_t ext4_dmask_get(void);
#if CONFIG_DEBUG_ASSERT
/**@brief Debug assertion.*/
-#define ext4_assert(_v) \
- do { \
- if (!(_v)) { \
- printf("Assertion failed:\nmodule: %s\nline: %d\n", \
- __FILE__, __LINE__); \
- } \
- } while (0)
+ #if CONFIG_HAVE_OWN_ASSERT
+ #define ext4_assert(_v) \
+ do { \
+ if (!(_v)) { \
+ printf("Assertion failed:\nmodule: %s\nline: %d\n", \
+ __FILE__, __LINE__); \
+ } \
+ } while (0)
+ #else
+ #define ext4_assert(_v) assert(_v)
+ #endif
#else
#define ext4_assert(_v)
#endif
diff --git a/toolchain/generic.cmake b/toolchain/generic.cmake
index d9f5ef6..ee80574 100644
--- a/toolchain/generic.cmake
+++ b/toolchain/generic.cmake
@@ -13,8 +13,11 @@ set(SIZE size)
set(CMAKE_C_FLAGS "-std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
set(CMAKE_CXX_FLAGS "-fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
set(CMAKE_ASM_FLAGS "" CACHE INTERNAL "asm compiler flags")
-set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections" CACHE INTERNAL "exe link flags")
-
+if (APPLE)
+ set(CMAKE_EXE_LINKER_FLAGS "-dead_strip" CACHE INTERNAL "exe link flags")
+else (APPLE)
+ set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections" CACHE INTERNAL "exe link flags")
+endif (APPLE)
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags")
@@ -22,4 +25,4 @@ SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags")
SET(CMAKE_C_FLAGS_RELEASE "-O2" CACHE INTERNAL "c release compiler flags")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2" CACHE INTERNAL "cxx release compiler flags")
-SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") \ No newline at end of file
+SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")