shithub: lwext4

Download patch

ref: d68a48bfeb7f77b46c64aa9dab1f93448c3ad601
parent: f4d662d77b4a0376d6a58475839f5a2a89b2c966
author: root <[email protected]>
date: Wed Sep 23 08:21:35 EDT 2015

ext4_fopen_all removed.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -1085,12 +1085,15 @@
 	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;
@@ -1097,6 +1100,17 @@
 
 	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,6 +1122,10 @@
 
 	ext4_fs_put_inode_ref(&inode_ref);
 	EXT4_MP_UNLOCK(mp);
+
+	if (ret_ino)
+		*ret_ino = ino;
+
 	return r;
 }
 
@@ -1149,28 +1167,6 @@
 	return r;
 }
 
-int ext4_fopen_all(ext4_file *f, const char *path, int flags)
-{
-	struct ext4_mountpoint *mp = ext4_get_mount(path);
-	int r;
-	int filetype;
-
-	if (!mp)
-		return ENOENT;
-
-	if (flags & O_CREAT)
-		return EINVAL;
-
-	filetype = EXT4_DIRECTORY_FILETYPE_UNKNOWN;
-
-	EXT4_MP_LOCK(mp);
-	ext4_block_cache_write_back(mp->fs.bdev, 1);
-	r = ext4_generic_open2(f, path, flags, filetype, 0, 0);
-	ext4_block_cache_write_back(mp->fs.bdev, 0);
-	EXT4_MP_UNLOCK(mp);
-	return r;
-}
-
 int ext4_fclose(ext4_file *f)
 {
 	ext4_assert(f && f->mp);
@@ -1607,13 +1603,14 @@
 
 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;
@@ -1620,7 +1617,14 @@
 
 	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);
@@ -1627,7 +1631,6 @@
 		return r;
 	}
 
-	sb = &f->mp->fs.sb;
 	ext4_inode_set_mode(sb, inode_ref.inode, mode);
 	inode_ref.dirty = true;
 
@@ -1636,12 +1639,13 @@
 	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;
@@ -1648,7 +1652,13 @@
 
 	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,12 +1674,13 @@
 	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;
@@ -1676,7 +1687,13 @@
 
 	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,12 +1708,13 @@
 	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;
@@ -1703,7 +1721,13 @@
 
 	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,12 +1742,13 @@
 	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;
@@ -1730,7 +1755,13 @@
 
 	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);
@@ -1843,6 +1874,41 @@
 	ext4_fclose(&f);
 
 Finish:
+	ext4_block_cache_write_back(mp->fs.bdev, 0);
+	EXT4_MP_UNLOCK(mp);
+	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);
+	EXT4_MP_UNLOCK(mp);
+	if (r == EOK)
+		r = ext4_fread(&f, buf, bufsize, rcnt);
+	else
+		goto Finish;
+
+	ext4_fclose(&f);
+
+Finish:
+	EXT4_MP_LOCK(mp);
 	ext4_block_cache_write_back(mp->fs.bdev, 0);
 	EXT4_MP_UNLOCK(mp);
 	return r;
--- a/lwext4/ext4.h
+++ b/lwext4/ext4.h
@@ -305,11 +305,12 @@
 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,13 +355,15 @@
  * @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***********************/