shithub: lwext4

Download patch

ref: 92053fed4a3c6e17c0c1c7596353c8c5465bdf1f
parent: 14560adaaf1776b4dd881d22027c6598b2792e61
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Sat Sep 26 22:12:57 EDT 2015

since EXT4_DIRECTORY_FILETYPE_* are duplication of EXT4_DIRENTRY_*, the former is replaced by the later.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -574,7 +574,7 @@
 }
 
 /*
- * NOTICE: if filetype is equal to EXT4_DIRECTORY_FILETYPE_UNKNOWN,
+ * NOTICE: if filetype is equal to EXT4_DIRENTRY_UNKNOWN,
  * 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 +621,8 @@
 		if (!len) {
 			/*If root open was request.*/
 			if (is_goal &&
-			    ((filetype == EXT4_DIRECTORY_FILETYPE_DIR) ||
-			     (filetype == EXT4_DIRECTORY_FILETYPE_UNKNOWN)))
+			    ((filetype == EXT4_DIRENTRY_DIR) ||
+			     (filetype == EXT4_DIRENTRY_UNKNOWN)))
 				break;
 
 			r = ENOENT;
@@ -643,7 +643,7 @@
 			r = ext4_fs_alloc_inode(
 			    &mp->fs, &child_ref,
 			    is_goal ? filetype
-				    : EXT4_DIRECTORY_FILETYPE_DIR);
+				    : EXT4_DIRENTRY_DIR);
 			if (r != EOK)
 				break;
 
@@ -679,11 +679,11 @@
 			break;
 
 		/*If expected file error*/
-		if (inode_type != EXT4_DIRECTORY_FILETYPE_DIR && !is_goal) {
+		if (inode_type != EXT4_DIRENTRY_DIR && !is_goal) {
 			r = ENOENT;
 			break;
 		}
-		if (filetype != EXT4_DIRECTORY_FILETYPE_UNKNOWN) {
+		if (filetype != EXT4_DIRENTRY_UNKNOWN) {
 			if ((inode_type != filetype) && is_goal) {
 				r = ENOENT;
 				break;
@@ -715,7 +715,7 @@
 	if (is_goal) {
 
 		if ((f->flags & O_TRUNC) &&
-		    (inode_type == EXT4_DIRECTORY_FILETYPE_REG_FILE)) {
+		    (inode_type == EXT4_DIRENTRY_REG_FILE)) {
 
 			r = ext4_fs_truncate_inode(&ref, 0);
 			if (r != EOK) {
@@ -749,9 +749,9 @@
 		return EINVAL;
 
 	if (file_expect == true)
-		filetype = EXT4_DIRECTORY_FILETYPE_REG_FILE;
+		filetype = EXT4_DIRENTRY_REG_FILE;
 	else
-		filetype = EXT4_DIRECTORY_FILETYPE_DIR;
+		filetype = EXT4_DIRENTRY_DIR;
 
 	return ext4_generic_open2(f, path, iflags, filetype, parent_inode,
 				  name_off);
@@ -761,7 +761,7 @@
 		struct ext4_inode_ref *child_ref)
 {
 	bool is_goal = false;
-	uint8_t inode_type = EXT4_DIRECTORY_FILETYPE_DIR;
+	uint8_t inode_type = EXT4_DIRENTRY_DIR;
 	uint32_t next_inode;
 
 	int r;
@@ -818,7 +818,7 @@
 		if (r != EOK)
 			break;
 
-		if (inode_type == EXT4_DIRECTORY_FILETYPE_REG_FILE) {
+		if (inode_type == EXT4_DIRENTRY_REG_FILE) {
 			if (is_goal)
 				r = EEXIST;
 			else
@@ -898,7 +898,7 @@
 	EXT4_MP_LOCK(mp);
 
 	r = ext4_generic_open2(&f, path, O_RDONLY,
-			       EXT4_DIRECTORY_FILETYPE_UNKNOWN,
+			       EXT4_DIRENTRY_UNKNOWN,
 			       &parent_inode, &name_off);
 	if (r != EOK)
 		goto Finish;
@@ -940,7 +940,7 @@
 	EXT4_MP_LOCK(mp);
 
 	r = ext4_generic_open2(&f, path, O_RDONLY,
-			EXT4_DIRECTORY_FILETYPE_UNKNOWN,
+			EXT4_DIRENTRY_UNKNOWN,
 			&parent_inode, &name_off);
 	if (r != EOK)
 		goto Finish;
@@ -1025,7 +1025,7 @@
 
 	EXT4_MP_LOCK(mp);
 	r = ext4_generic_open2(&f, path, O_RDWR,
-			       EXT4_DIRECTORY_FILETYPE_UNKNOWN,
+			       EXT4_DIRENTRY_UNKNOWN,
 			       &parent_inode, &name_off);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
@@ -1097,7 +1097,7 @@
 	EXT4_MP_LOCK(mp);
 
 	r = ext4_generic_open2(&f, path, O_RDONLY,
-			       EXT4_DIRECTORY_FILETYPE_UNKNOWN,
+			       EXT4_DIRENTRY_UNKNOWN,
 			       NULL, NULL);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
@@ -1150,7 +1150,7 @@
 	if (!mp)
 		return ENOENT;
 
-        filetype = EXT4_DIRECTORY_FILETYPE_REG_FILE;
+        filetype = EXT4_DIRENTRY_REG_FILE;
 
 	EXT4_MP_LOCK(mp);
 	ext4_block_cache_write_back(mp->fs.bdev, 1);
@@ -1610,7 +1610,7 @@
 
 	EXT4_MP_LOCK(mp);
 
-	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRENTRY_UNKNOWN, 0, 0);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
 		return r;
@@ -1645,7 +1645,7 @@
 
 	EXT4_MP_LOCK(mp);
 
-	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRENTRY_UNKNOWN, 0, 0);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
 		return r;
@@ -1680,7 +1680,7 @@
 
 	EXT4_MP_LOCK(mp);
 
-	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRENTRY_UNKNOWN, 0, 0);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
 		return r;
@@ -1714,7 +1714,7 @@
 
 	EXT4_MP_LOCK(mp);
 
-	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRENTRY_UNKNOWN, 0, 0);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
 		return r;
@@ -1748,7 +1748,7 @@
 
 	EXT4_MP_LOCK(mp);
 
-	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRECTORY_FILETYPE_UNKNOWN, 0, 0);
+	r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DIRENTRY_UNKNOWN, 0, 0);
 	if (r != EOK) {
 		EXT4_MP_UNLOCK(mp);
 		return r;
@@ -1854,7 +1854,7 @@
 	if (!mp)
 		return ENOENT;
 
-	filetype = EXT4_DIRECTORY_FILETYPE_SYMLINK;
+	filetype = EXT4_DIRENTRY_SYMLINK;
 
 	EXT4_MP_LOCK(mp);
 	ext4_block_cache_write_back(mp->fs.bdev, 1);
@@ -1887,7 +1887,7 @@
 
 	memset(buf, 0, sizeof(bufsize));
 
-	filetype = EXT4_DIRECTORY_FILETYPE_SYMLINK;
+	filetype = EXT4_DIRENTRY_SYMLINK;
 
 	EXT4_MP_LOCK(mp);
 	ext4_block_cache_write_back(mp->fs.bdev, 1);
--- a/lwext4/ext4.h
+++ b/lwext4/ext4.h
@@ -123,15 +123,6 @@
 } ext4_file;
 
 /*****************************DIRECTORY DESCRIPTOR***************************/
-/**@brief   Directory entry types. Copy from ext4_types.h*/
-enum { EXT4_DIRENTRY_UNKNOWN = 0,
-       EXT4_DIRENTRY_REG_FILE,
-       EXT4_DIRENTRY_DIR,
-       EXT4_DIRENTRY_CHRDEV,
-       EXT4_DIRENTRY_BLKDEV,
-       EXT4_DIRENTRY_FIFO,
-       EXT4_DIRENTRY_SOCK,
-       EXT4_DIRENTRY_SYMLINK };
 
 /**@brief   Directory entry descriptor. Copy from ext4_types.h*/
 typedef struct {
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -210,15 +210,15 @@
 	switch (ext4_inode_type(sb, child->inode)) {
 	case EXT4_INODE_MODE_DIRECTORY:
 		ext4_dir_entry_ll_set_inode_type(sb, entry,
-						 EXT4_DIRECTORY_FILETYPE_DIR);
+						 EXT4_DIRENTRY_DIR);
 		break;
 	case EXT4_INODE_MODE_FILE:
 		ext4_dir_entry_ll_set_inode_type(
-		    sb, entry, EXT4_DIRECTORY_FILETYPE_REG_FILE);
+		    sb, entry, EXT4_DIRENTRY_REG_FILE);
 		break;
 	case EXT4_INODE_MODE_SOFTLINK:
 		ext4_dir_entry_ll_set_inode_type(
-		    sb, entry, EXT4_DIRECTORY_FILETYPE_SYMLINK);
+		    sb, entry, EXT4_DIRENTRY_SYMLINK);
 		break;
 	default:
 		/* FIXME: right now we only support 3 inode type. */
--- a/lwext4/ext4_dir.h
+++ b/lwext4/ext4_dir.h
@@ -146,7 +146,7 @@
 	    (ext4_get32(sb, minor_rev_level) >= 5))
 		return de->in.inode_type;
 
-	return EXT4_DIRECTORY_FILETYPE_UNKNOWN;
+	return EXT4_DIRENTRY_UNKNOWN;
 }
 /**@brief Set i-node type of directory entry.
  * @param sb   Superblock
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -646,11 +646,11 @@
 static uint32_t ext4_fs_correspond_inode_mode(int filetype)
 {
 	switch (filetype) {
-	case EXT4_DIRECTORY_FILETYPE_DIR:
+	case EXT4_DIRENTRY_DIR:
 		return EXT4_INODE_MODE_DIRECTORY;
-	case EXT4_DIRECTORY_FILETYPE_REG_FILE:
+	case EXT4_DIRENTRY_REG_FILE:
 		return EXT4_INODE_MODE_FILE;
-	case EXT4_DIRECTORY_FILETYPE_SYMLINK:
+	case EXT4_DIRENTRY_SYMLINK:
 		return EXT4_INODE_MODE_SOFTLINK;
 	default:
 		/* FIXME: right now we only support 3 file type. */
@@ -665,7 +665,7 @@
 	/* Check if newly allocated i-node will be a directory */
 	bool is_dir;
 
-	is_dir = (filetype == EXT4_DIRECTORY_FILETYPE_DIR);
+	is_dir = (filetype == EXT4_DIRENTRY_DIR);
 
 	/* Allocate inode by allocation algorithm */
 	uint32_t index;
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -458,14 +458,15 @@
 
 #define EXT4_DIRECTORY_FILENAME_LEN 255
 
-#define EXT4_DIRECTORY_FILETYPE_UNKNOWN 0
-#define EXT4_DIRECTORY_FILETYPE_REG_FILE 1
-#define EXT4_DIRECTORY_FILETYPE_DIR 2
-#define EXT4_DIRECTORY_FILETYPE_CHRDEV 3
-#define EXT4_DIRECTORY_FILETYPE_BLKDEV 4
-#define EXT4_DIRECTORY_FILETYPE_FIFO 5
-#define EXT4_DIRECTORY_FILETYPE_SOCK 6
-#define EXT4_DIRECTORY_FILETYPE_SYMLINK 7
+/**@brief   Directory entry types. */
+enum { EXT4_DIRENTRY_UNKNOWN = 0,
+       EXT4_DIRENTRY_REG_FILE,
+       EXT4_DIRENTRY_DIR,
+       EXT4_DIRENTRY_CHRDEV,
+       EXT4_DIRENTRY_BLKDEV,
+       EXT4_DIRENTRY_FIFO,
+       EXT4_DIRENTRY_SOCK,
+       EXT4_DIRENTRY_SYMLINK };
 
 union ext4_directory_entry_ll_internal {
 	uint8_t name_length_high; /* Higher 8 bits of name length */