ref: 03375d29a9383d054febf5bca6ed6f50827de35f
parent: 915c70b309ba95c4a798f9fc7234a8b843e6c90f
author: gkostka <[email protected]>
date: Mon Nov 30 04:38:20 EST 2015
ext4: introduce ext4_recover function
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -411,20 +411,10 @@
return r;
}
- /* TODO: journal mount checking. */
- if (ext4_sb_feature_com(&mp->fs.sb, EXT4_FCOM_HAS_JOURNAL)) {
- struct jbd_fs jbd_fs = {0};
- r = jbd_get_fs(&mp->fs, &jbd_fs);
- if (r != EOK)
- return r;
-
- r = jbd_recover(&jbd_fs);
- jbd_put_fs(&jbd_fs);
- }
-
return r;
}
+
int ext4_umount(const char *mount_point)
{
int i;
@@ -468,6 +458,34 @@
}
return 0;
}
+
+int ext4_recover(const char *mount_point)
+{
+ struct ext4_mountpoint *mp = ext4_get_mount(mount_point);
+ if (!mp)
+ return ENOENT;
+
+ int r = ENOTSUP;
+ if (ext4_sb_feature_com(&mp->fs.sb, EXT4_FCOM_HAS_JOURNAL)) {
+ struct jbd_fs *jbd_fs = calloc(1, sizeof(struct jbd_fs));
+ if (!jbd_fs)
+ return ENOMEM;
+
+
+ r = jbd_get_fs(&mp->fs, jbd_fs);
+ if (r != EOK) {
+ free(jbd_fs);
+ return r;
+ }
+
+ r = jbd_recover(jbd_fs);
+ jbd_put_fs(jbd_fs);
+ free(jbd_fs);
+ }
+
+ return r;
+}
+
int ext4_mount_point_stats(const char *mount_point,
struct ext4_mount_stats *stats)
--- a/lwext4/ext4.h
+++ b/lwext4/ext4.h
@@ -182,6 +182,13 @@
* @return standard error code */
int ext4_umount(const char *mount_point);
+
+/**@brief Journal recovery.
+ * @param mount_point mount point
+ * @warning Must be called after @ref ext4_mount
+ * @return standard error code */
+int ext4_recover(const char *mount_point);
+
/**@brief Some of the filesystem stats.*/
struct ext4_mount_stats {
uint32_t inodes_count;