xt4 file system formatting process - data structure mode

1. Update the root directory (Update Root Directory)

    Load inode2 to set the number of hard links to 2+1=3 [Add to the default directory] Add the directory "lost+found" to the directory table pointed to by inode2, and set its inode to 11, which is the first non-reserved inode. (load inode 2 and set link-count to 3,jump to root entry set one dir "lost+found" with inode 11.)

2. Create a default directory (Create DefaultDir)
    Set the inode11 information, and make inode11.offset=inode2.offset+1. Create the directory information of the default directory, ". and .." in the inode11.offset position. (update inode 11, inode11.offset=inode2.offset+1,Create null entry ".&.." at inode11.offset.)

3. Update the GTD table (Update GTD)
    GDT[0].freeblock=BlockPerGroup-inode2.offset-1;
    GDT[0].freeblock_hi=BlockPerGroup-(GDT[n].inode_bitmap_hi)&0xFF-0x200;
    GDT[0].free_inodo_block=InodesPerGroup-11,GDT[n].free_inodo_block=0(n>0).

4. Update the data bitmap (Update Bitmap)
    Synchronize data bitmaps with GTD information. (sync bitmap by GDT.)

5. Update Super Block (Update SuperBlock)
    Update SuperBlock .freeblock and SuperBlock .freeInode by GDT.

char * getbitmap(unsigned int used){

if (used>4096*8)return 0;

static char buff[4096]; 

memset(&buff,4096,0);

int i,s=0;

int f= used/8;

int x=used % 8;

for (i=0,i<f,i++)buff[i]=0xff;

for (i=0,i<x,i++)s=s+1<<i;

buff[f]=s;

return &buff;

}