Jffs2reset Implementation Analysis

Source: Internet
Author: User

See the following in script Reset2default:

#!/usr/bin/lua

Local HWM = require "HWM"

Hwm.myexec ("Jffs2reset-y")
Os.exit (0)

Do not know the function of Jffs2reset, Baidu, found that the introduction of the few, in this, their own research.

First, execute the command "jffs2reset-y" to get the following result:

root@hbg:/# jffs2reset-y
/dev/mtdblock3 is mounted as/overlay, only erasing files

As you can tell, the content of the/DEV/MTDBLOCK3 is erased after the result is executed.

View partitions

root@hbg:/# CAT/PROC/MTD
Dev:size erasesize Name
mtd0:00040000 00010000 "U-boot"
mtd1:00010000 00010000 "U-boot-env"
mtd2:00e30000 00010000 "Rootfs"
mtd3:00a10000 00010000 "Rootfs_data"
mtd4:00150000 00010000 "Kernel"

learned that the content in Mtd3 is Rootfs_data, which is the related configuration part of the device.

To view the source code for Jffs2reset (located in fstools-2015-02-25.1):

File is jffs2reset.c

int main (int argc, char **argv)
{
if (!strcmp (*ARGV, "Jffs2mark"))
Return Jffs2_mark (argc, argv);
Return Jffs2_reset (argc, argv); With the parameter "-y", so go to this branch
}

To view the function Jffs2_reset, you can get the following:

static int
Jffs2_reset (int argc, char **argv)
{
struct volume *v;
Char *mp;

if (Ask_user (argc, argv))//See if the default parameter is "-y" and if no, you need to print the usage information
return-1;

if (Find_filesystem ("overlay")) {//Find the partition where the overlay is located
fprintf (stderr, "Overlayfs not found\n");
return-1;
}

v = volume_find ("Rootfs_data"); Find the volume where the Rootfs_data is located
if (!v) {
fprintf (stderr, "No rootfs_data was found\n");
return-1;
}

MP = Find_mount_point (v->blk, 1); Find mount points
if (MP) {
fprintf (stderr, "%s is mounted as%s, only erasing files\n", V->BLK, MP);
Foreachdir (MP, Handle_rmdir);
Mount (MP, "/", NULL, Ms_remount, 0); Re-mount
} else {
fprintf (stderr, "%s is not mounted, erasing it\n", v->blk);
Volume_erase_all (v);
}

return 0;
}

where Find_filesystem ("overlay") is called when looking in/proc/filesystems

root@hbg:/# Cat/proc/filesystems
Nodev Sysfs
Nodev Rootfs
Nodev Bdev
Nodev proc
Nodev TMPFS
Nodev Debugfs
Nodev SOCKFS
Nodev Pipefs
Nodev Anon_inodefs
Nodev devpts
Squashfs
Nodev Ramfs
Nodev JFFS2
Nodev OVERLAYFS
Nodev Mtd_inodefs
Ext3
Ext2
Ext4
Ntfs
Vfat
root@hbg:/#

MP = Find_mount_point (v->blk, 1); is to find/proc/mounts, where the value of V->BLK is overlay

root@hbg:/# cat/proc/mounts
Rootfs/rootfs RW 0 0
/dev/root/rom SQUASHFS ro,relatime 0 0
PROC/PROC proc Rw,noatime 0 0
Sysfs/sys Sysfs rw,noatime 0 0
Tmpfs/tmp Tmpfs rw,nosuid,nodev,noatime 0 0
/dev/mtdblock3/overlay JFFS2 rw,noatime 0 0
OVERLAYFS:/OVERLAY/OVERLAYFS Rw,relatime,lowerdir=/,upperdir=/overlay 0 0
Tmpfs/dev Tmpfs rw,relatime,size=512k,mode=755 0 0
Devpts/dev/pts devpts rw,relatime,mode=600 0 0
Debugfs/sys/kernel/debug Debugfs rw,noatime 0 0

Postscript:

Start equivalent to command:

Mtd-r Erase Rootfs_data


Transferred from: http://www.cnblogs.com/rohens-hbg/p/5604548.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.