projects
/
lwext4.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix compile warnings for 16 bit machines
[lwext4.git]
/
lwext4
/
ext4.c
diff --git
a/lwext4/ext4.c
b/lwext4/ext4.c
index f42f5cc70b38d46c2ebe92cda20d982cefc14d14..0cdf045afcff648175034de89e8574107fc5fd17 100644
(file)
--- a/
lwext4/ext4.c
+++ b/
lwext4/ext4.c
@@
-44,6
+44,7
@@
#include "ext4_inode.h"
#include "ext4_super.h"
#include "ext4_dir_idx.h"
#include "ext4_inode.h"
#include "ext4_super.h"
#include "ext4_dir_idx.h"
+#include "ext4_xattr.h"
#include "ext4.h"
#include <stdlib.h>
#include "ext4.h"
#include <stdlib.h>
@@
-180,7
+181,7
@@
static int ext4_has_children(bool *has_children, struct ext4_inode_ref *enode)
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,
struct ext4_inode_ref *child, const char *name,
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,
struct ext4_inode_ref *child, const char *name,
- uint32_t name_len)
+ uint32_t name_len
, bool rename
)
{
/* Check maximum name length */
if (name_len > EXT4_DIRECTORY_FILENAME_LEN)
{
/* Check maximum name length */
if (name_len > EXT4_DIRECTORY_FILENAME_LEN)
@@
-196,7
+197,7
@@
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,
*/
if (ext4_inode_is_type(&mp->fs.sb, child->inode,
EXT4_INODE_MODE_DIRECTORY) &&
*/
if (ext4_inode_is_type(&mp->fs.sb, child->inode,
EXT4_INODE_MODE_DIRECTORY) &&
-
ext4_inode_get_links_count(child->inode) == 0
) {
+
!rename
) {
rc = ext4_dir_add_entry(child, ".", strlen("."), child);
if (rc != EOK) {
ext4_dir_remove_entry(parent, name, strlen(name));
rc = ext4_dir_add_entry(child, ".", strlen("."), child);
if (rc != EOK) {
ext4_dir_remove_entry(parent, name, strlen(name));
@@
-231,6
+232,10
@@
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,
child->dirty = true;
parent->dirty = true;
} else {
child->dirty = true;
parent->dirty = true;
} else {
+ /*
+ * In case we want to rename a directory,
+ * we reset the original '..' pointer.
+ */
if (ext4_inode_is_type(&mp->fs.sb, child->inode,
EXT4_INODE_MODE_DIRECTORY)) {
int has_flag_index =
if (ext4_inode_is_type(&mp->fs.sb, child->inode,
EXT4_INODE_MODE_DIRECTORY)) {
int has_flag_index =
@@
-263,7
+268,8
@@
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,
ext4_fs_inode_links_count_inc(parent);
parent->dirty = true;
ext4_fs_inode_links_count_inc(parent);
parent->dirty = true;
- } else {
+ }
+ if (!rename) {
ext4_fs_inode_links_count_inc(child);
child->dirty = true;
}
ext4_fs_inode_links_count_inc(child);
child->dirty = true;
}
@@
-445,18
+451,25
@@
int ext4_umount(const char *mount_point)
return ext4_block_fini(mp->fs.bdev);
}
return ext4_block_fini(mp->fs.bdev);
}
+static struct ext4_mountpoint *ext4_get_mount(const char *path)
+{
+ int i;
+ for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
+
+ if (!_mp[i].mounted)
+ continue;
+
+ if (!strncmp(_mp[i].name, path, strlen(_mp[i].name)))
+ return &_mp[i];
+ }
+ return 0;
+}
+
int ext4_mount_point_stats(const char *mount_point,
struct ext4_mount_stats *stats)
{
int ext4_mount_point_stats(const char *mount_point,
struct ext4_mount_stats *stats)
{
- uint32_t i;
- struct ext4_mountpoint *mp = 0;
+ struct ext4_mountpoint *mp = ext4_get_mount(mount_point);
- for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
- if (!strcmp(_mp[i].name, mount_point)) {
- mp = &_mp[i];
- break;
- }
- }
if (!mp)
return ENOENT;
if (!mp)
return ENOENT;
@@
-498,20
+511,6
@@
int ext4_mount_setup_locks(const char *mount_point,
/********************************FILE OPERATIONS*****************************/
/********************************FILE OPERATIONS*****************************/
-static struct ext4_mountpoint *ext4_get_mount(const char *path)
-{
- int i;
- for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
-
- if (!_mp[i].mounted)
- continue;
-
- if (!strncmp(_mp[i].name, path, strlen(_mp[i].name)))
- return &_mp[i];
- }
- return 0;
-}
-
static int ext4_path_check(const char *path, bool *is_goal)
{
int i;
static int ext4_path_check(const char *path, bool *is_goal)
{
int i;
@@
-574,7
+573,7
@@
static bool ext4_parse_flags(const char *flags, uint32_t *file_flags)
}
/*
}
/*
- * NOTICE: if filetype is equal to EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN,
+ * NOTICE: if filetype is equal to EXT4_DIRE
NTRY
_UNKNOWN,
* any filetype of the target dir entry will be accepted.
*/
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
* any filetype of the target dir entry will be accepted.
*/
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
@@
-621,8
+620,8
@@
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
if (!len) {
/*If root open was request.*/
if (is_goal &&
if (!len) {
/*If root open was request.*/
if (is_goal &&
- ((filetype == EXT4_DIRE
CTORY_FILETYPE
_DIR) ||
- (filetype == EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN)))
+ ((filetype == EXT4_DIRE
NTRY
_DIR) ||
+ (filetype == EXT4_DIRE
NTRY
_UNKNOWN)))
break;
r = ENOENT;
break;
r = ENOENT;
@@
-632,6
+631,9
@@
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
r = ext4_dir_find_entry(&result, &ref, path, len);
if (r != EOK) {
r = ext4_dir_find_entry(&result, &ref, path, len);
if (r != EOK) {
+ /*Destroy last result*/
+ ext4_dir_destroy_result(&ref, &result);
+
if (r != ENOENT)
break;
if (r != ENOENT)
break;
@@
-643,15
+645,13
@@
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
r = ext4_fs_alloc_inode(
&mp->fs, &child_ref,
is_goal ? filetype
r = ext4_fs_alloc_inode(
&mp->fs, &child_ref,
is_goal ? filetype
- : EXT4_DIRE
CTORY_FILETYPE
_DIR);
+ : EXT4_DIRE
NTRY
_DIR);
if (r != EOK)
break;
if (r != EOK)
break;
- /*Destroy last result*/
- ext4_dir_destroy_result(&ref, &result);
/*Link with root dir.*/
/*Link with root dir.*/
- r = ext4_link(mp, &ref, &child_ref, path, len);
+ r = ext4_link(mp, &ref, &child_ref, path, len
, false
);
if (r != EOK) {
/*Fail. Free new inode.*/
ext4_fs_free_inode(&child_ref);
if (r != EOK) {
/*Fail. Free new inode.*/
ext4_fs_free_inode(&child_ref);
@@
-679,11
+679,11
@@
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
break;
/*If expected file error*/
break;
/*If expected file error*/
- if (inode_type != EXT4_DIRE
CTORY_FILETYPE
_DIR && !is_goal) {
+ if (inode_type != EXT4_DIRE
NTRY
_DIR && !is_goal) {
r = ENOENT;
break;
}
r = ENOENT;
break;
}
- if (filetype != EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN) {
+ if (filetype != EXT4_DIRE
NTRY
_UNKNOWN) {
if ((inode_type != filetype) && is_goal) {
r = ENOENT;
break;
if ((inode_type != filetype) && is_goal) {
r = ENOENT;
break;
@@
-715,7
+715,7
@@
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
if (is_goal) {
if ((f->flags & O_TRUNC) &&
if (is_goal) {
if ((f->flags & O_TRUNC) &&
- (inode_type == EXT4_DIRE
CTORY_FILETYPE
_REG_FILE)) {
+ (inode_type == EXT4_DIRE
NTRY
_REG_FILE)) {
r = ext4_fs_truncate_inode(&ref, 0);
if (r != EOK) {
r = ext4_fs_truncate_inode(&ref, 0);
if (r != EOK) {
@@
-731,6
+731,7
@@
static int ext4_generic_open2(ext4_file *f, const char *path, int flags,
if (f->flags & O_APPEND)
f->fpos = f->fsize;
if (f->flags & O_APPEND)
f->fpos = f->fsize;
+
}
r = ext4_fs_put_inode_ref(&ref);
}
r = ext4_fs_put_inode_ref(&ref);
@@
-749,19
+750,20
@@
static int ext4_generic_open(ext4_file *f, const char *path, const char *flags,
return EINVAL;
if (file_expect == true)
return EINVAL;
if (file_expect == true)
- filetype = EXT4_DIRE
CTORY_FILETYPE
_REG_FILE;
+ filetype = EXT4_DIRE
NTRY
_REG_FILE;
else
else
- filetype = EXT4_DIRE
CTORY_FILETYPE
_DIR;
+ filetype = EXT4_DIRE
NTRY
_DIR;
return ext4_generic_open2(f, path, iflags, filetype, parent_inode,
name_off);
}
static int __ext4_create_hardlink(const char *path,
return ext4_generic_open2(f, path, iflags, filetype, parent_inode,
name_off);
}
static int __ext4_create_hardlink(const char *path,
- struct ext4_inode_ref *child_ref)
+ struct ext4_inode_ref *child_ref,
+ bool rename)
{
bool is_goal = false;
{
bool is_goal = false;
- uint8_t inode_type = EXT4_DIRE
CTORY_FILETYPE
_DIR;
+ uint8_t inode_type = EXT4_DIRE
NTRY
_DIR;
uint32_t next_inode;
int r;
uint32_t next_inode;
int r;
@@
-799,14
+801,19
@@
static int __ext4_create_hardlink(const char *path,
r = ext4_dir_find_entry(&result, &ref, path, len);
if (r != EOK) {
r = ext4_dir_find_entry(&result, &ref, path, len);
if (r != EOK) {
+ /*Destroy last result*/
+ ext4_dir_destroy_result(&ref, &result);
+
if (r != ENOENT || !is_goal)
break;
if (r != ENOENT || !is_goal)
break;
+ /*Link with root dir.*/
+ r = ext4_link(mp, &ref, child_ref, path, len, rename);
+ break;
+ } else if (r == EOK && is_goal) {
/*Destroy last result*/
ext4_dir_destroy_result(&ref, &result);
/*Destroy last result*/
ext4_dir_destroy_result(&ref, &result);
-
- /*Link with root dir.*/
- r = ext4_link(mp, &ref, child_ref, path, len);
+ r = EEXIST;
break;
}
break;
}
@@
-818,7
+825,7
@@
static int __ext4_create_hardlink(const char *path,
if (r != EOK)
break;
if (r != EOK)
break;
- if (inode_type == EXT4_DIRE
CTORY_FILETYPE
_REG_FILE) {
+ if (inode_type == EXT4_DIRE
NTRY
_REG_FILE) {
if (is_goal)
r = EEXIST;
else
if (is_goal)
r = EEXIST;
else
@@
-850,10
+857,10
@@
static int __ext4_create_hardlink(const char *path,
return r;
}
return r;
}
-static int
__ext4_remove_hardlink
(const char *path,
- uint32_t name_off,
- struct ext4_inode_ref *parent_ref,
- struct ext4_inode_ref *child_ref)
+static int
ext4_remove_orig_reference
(const char *path,
+
uint32_t name_off,
+
struct ext4_inode_ref *parent_ref,
+
struct ext4_inode_ref *child_ref)
{
bool is_goal;
int r;
{
bool is_goal;
int r;
@@
-868,11
+875,16
@@
static int __ext4_remove_hardlink(const char *path,
len = ext4_path_check(path, &is_goal);
len = ext4_path_check(path, &is_goal);
- /*
Unlink from parent
*/
- r = ext4_
unlink(mp, parent_ref, child
_ref, path, len);
+ /*
Remove entry from parent directory
*/
+ r = ext4_
dir_remove_entry(parent
_ref, path, len);
if (r != EOK)
goto Finish;
if (r != EOK)
goto Finish;
+ if (ext4_inode_is_type(&mp->fs.sb, child_ref->inode,
+ EXT4_INODE_MODE_DIRECTORY)) {
+ ext4_fs_inode_links_count_dec(parent_ref);
+ parent_ref->dirty = true;
+ }
Finish:
return r;
}
Finish:
return r;
}
@@
-898,7
+910,7
@@
int ext4_flink(const char *path, const char *hardlink_path)
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDONLY,
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDONLY,
- EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN,
+ EXT4_DIRE
NTRY
_UNKNOWN,
&parent_inode, &name_off);
if (r != EOK)
goto Finish;
&parent_inode, &name_off);
if (r != EOK)
goto Finish;
@@
-913,7
+925,14
@@
int ext4_flink(const char *path, const char *hardlink_path)
child_loaded = true;
child_loaded = true;
- r = __ext4_create_hardlink(hardlink_path, &child_ref);
+ /* Creating hardlink for directory is not allowed. */
+ if (ext4_inode_is_type(&mp->fs.sb, child_ref.inode,
+ EXT4_INODE_MODE_DIRECTORY)) {
+ r = EINVAL;
+ goto Finish;
+ }
+
+ r = __ext4_create_hardlink(hardlink_path, &child_ref, false);
Finish:
if (child_loaded)
Finish:
if (child_loaded)
@@
-940,7
+959,7
@@
int ext4_frename(const char *path, const char *new_path)
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDONLY,
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDONLY,
- EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN,
+ EXT4_DIRE
NTRY
_UNKNOWN,
&parent_inode, &name_off);
if (r != EOK)
goto Finish;
&parent_inode, &name_off);
if (r != EOK)
goto Finish;
@@
-962,11
+981,12
@@
int ext4_frename(const char *path, const char *new_path)
child_loaded = true;
child_loaded = true;
- r = __ext4_create_hardlink(new_path, &child_ref);
+ r = __ext4_create_hardlink(new_path, &child_ref
, true
);
if (r != EOK)
goto Finish;
if (r != EOK)
goto Finish;
- r = __ext4_remove_hardlink(path, name_off, &parent_ref, &child_ref);
+ r = ext4_remove_orig_reference(path, name_off,
+ &parent_ref, &child_ref);
if (r != EOK)
goto Finish;
if (r != EOK)
goto Finish;
@@
-1025,7
+1045,7
@@
int ext4_fremove(const char *path)
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDWR,
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDWR,
- EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN,
+ EXT4_DIRE
NTRY
_UNKNOWN,
&parent_inode, &name_off);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
&parent_inode, &name_off);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@
-1097,7
+1117,7
@@
int ext4_fill_raw_inode(const char *path,
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDONLY,
EXT4_MP_LOCK(mp);
r = ext4_generic_open2(&f, path, O_RDONLY,
- EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN,
+ EXT4_DIRE
NTRY
_UNKNOWN,
NULL, NULL);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
NULL, NULL);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@
-1150,7
+1170,7
@@
int ext4_fopen2(ext4_file *f, const char *path, int flags)
if (!mp)
return ENOENT;
if (!mp)
return ENOENT;
- filetype = EXT4_DIRE
CTORY_FILETYPE
_REG_FILE;
+ filetype = EXT4_DIRE
NTRY
_REG_FILE;
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
@@
-1610,7
+1630,7
@@
int ext4_chmod(const char *path, uint32_t mode)
EXT4_MP_LOCK(mp);
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
NTRY
_UNKNOWN, 0, 0);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
@@
-1645,7
+1665,7
@@
int ext4_chown(const char *path, uint32_t uid, uint32_t gid)
EXT4_MP_LOCK(mp);
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
NTRY
_UNKNOWN, 0, 0);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
@@
-1680,7
+1700,7
@@
int ext4_file_set_atime(const char *path, uint32_t atime)
EXT4_MP_LOCK(mp);
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
NTRY
_UNKNOWN, 0, 0);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
@@
-1714,7
+1734,7
@@
int ext4_file_set_mtime(const char *path, uint32_t mtime)
EXT4_MP_LOCK(mp);
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
NTRY
_UNKNOWN, 0, 0);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
@@
-1748,7
+1768,7
@@
int ext4_file_set_ctime(const char *path, uint32_t ctime)
EXT4_MP_LOCK(mp);
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
CTORY_FILETYPE
_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRE
NTRY
_UNKNOWN, 0, 0);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
@@
-1854,7
+1874,7
@@
int ext4_fsymlink(const char *target, const char *path)
if (!mp)
return ENOENT;
if (!mp)
return ENOENT;
- filetype = EXT4_DIRE
CTORY_FILETYPE
_SYMLINK;
+ filetype = EXT4_DIRE
NTRY
_SYMLINK;
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
@@
-1887,7
+1907,7
@@
int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt)
memset(buf, 0, sizeof(bufsize));
memset(buf, 0, sizeof(bufsize));
- filetype = EXT4_DIRE
CTORY_FILETYPE
_SYMLINK;
+ filetype = EXT4_DIRE
NTRY
_SYMLINK;
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
@@
-2155,7
+2175,10
@@
int ext4_dir_open(ext4_dir *d, const char *path)
return r;
}
return r;
}
-int ext4_dir_close(ext4_dir *d) { return ext4_fclose(&d->f); }
+int ext4_dir_close(ext4_dir *d)
+{
+ return ext4_fclose(&d->f);
+}
const ext4_direntry *ext4_dir_entry_next(ext4_dir *d)
{
const ext4_direntry *ext4_dir_entry_next(ext4_dir *d)
{
@@
-2200,6
+2223,11
@@
Finish:
return de;
}
return de;
}
+void ext4_dir_entry_rewind(ext4_dir *d)
+{
+ d->next_off = 0;
+}
+
/**
* @}
*/
/**
* @}
*/