[solved]minix 1.0 i_node problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
wellwell
Posts: 8
Joined: Wed Jul 24, 2019 6:26 am

[solved]minix 1.0 i_node problem

Post by wellwell »

I am writing a minix 1.0 file system now. I have created an i_node on my file system. However, after i am running the command fsck to check the i_node, it showed i am not created i_node successful.
I can not find the directory I created on the file system as well.
dd if=/dev/zero of=filesystem.img bs=512 count=72
72+0 records in
72+0 records out
36864 bytes (37 kB, 36 KiB) copied, 0.000397821 s, 92.7 MB/s
mkfs.minix -1 filesystem.img
32 inodes
36 blocks
Firstdatazone=5 (5)
Zonesize=1024
Maxsize=268966912
fsck.minix -f filesystem.img
Forcing filesystem check on filesystem.img.
Inode 1 (mode = 0040755), i_nlinks=6, counted=2.
Inode 2 not used, marked used in the bitmap.
Inode 3 not used, marked used in the bitmap.
Inode 4 not used, marked used in the bitmap.
Inode 5 not used, marked used in the bitmap.
Inode 6 not used, marked used in the bitmap.
Zone 6: marked in use, no file uses it.
Zone 7: marked in use, no file uses it.
Zone 8: marked in use, no file uses it.
Zone 9: marked in use, no file uses it.
Zone 10: marked in use, no file uses it.
hexdump -C filesystem.img
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000400 20 00 24 00 01 00 01 00 05 00 00 00 00 1c 08 10 | .$.............|
00000410 8f 13 01 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000800 7f 00 00 00 fe ff ff ff ff ff ff ff ff ff ff ff |................|
00000810 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00000c00 7f 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff |................|
00000c10 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00001000 ed 41 e8 03 40 00 00 00 90 7b 8c 5d e8 06 05 00 |.A..@....{.]....|
00001010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001020 ed 41 e8 03 00 04 00 00 00 00 00 00 e8 03 06 00 |.A..............|
00001030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001040 ed 41 e8 03 00 04 00 00 00 00 00 00 e8 02 07 00 |.A..............|
00001050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001060 ed 41 e8 03 00 04 00 00 00 00 00 00 e8 02 08 00 |.A..............|
00001070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001080 ed 41 e8 03 00 04 00 00 00 00 00 00 e8 02 09 00 |.A..............|
00001090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000010a0 ed 41 e8 03 00 04 00 00 00 00 00 00 e8 02 0a 00 |.A..............|
000010b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001400 01 00 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001420 01 00 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001440 02 00 74 65 73 74 64 69 72 31 00 00 00 00 00 00 |..testdir1......|
00001450 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001460 04 00 74 65 73 74 64 69 72 32 00 00 00 00 00 00 |..testdir2......|
00001470 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001480 05 00 74 65 73 74 64 69 72 33 00 00 00 00 00 00 |..testdir3......|
00001490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000014a0 06 00 74 65 73 74 64 69 72 34 00 00 00 00 00 00 |..testdir4......|
000014b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001800 02 00 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001820 01 00 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001830 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001840 03 00 74 65 73 74 64 69 72 32 00 00 00 00 00 00 |..testdir2......|
00001850 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001c00 03 00 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001c20 02 00 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001c30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00002000 04 00 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002020 01 00 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00002400 05 00 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002420 01 00 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00002800 06 00 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002820 01 00 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002830 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00009000

Code: Select all

void write_data(int dev_number,int block_number,uint8_t *data){
	memcpy(idequeue.data,data,BSIZE);
	ide_command(dev_number,block_number,IDE_CMD_WRITE);
	ide_wait(TRUE);
}

Code: Select all

int insert_inode(char *name, int parent_i_inode,bool isdir,struct d_inode *inodes,uint8_t *inode_bitmap,uint8_t *block_bitmap){
    int empty_inode=find_empty_inode(inode_bitmap,BLOCK_SIZE)-1;
    printk("empty_inode:%d\n",empty_inode);
    /*  inode bitmap */
    setBitmap(inode_bitmap,empty_inode+1,TRUE);
    write_data(0,2,inode_bitmap);
    if(isdir){
        inodes[empty_inode].i_mode=I_MODE_DIR;
        struct dir_entry entrys[32];
        memset(entrys,0,sizeof(struct dir_entry)*32);
        entrys[0].i_inode=empty_inode+1;
        strcpy(entrys[0].filename,".");
        entrys[1].i_inode=parent_i_inode+1;
        strcpy(entrys[1].filename,"..");
        int empty_block=find_empty_block(block_bitmap,BLOCK_SIZE);
        inodes[empty_inode].i_zone[0]=empty_block;
        //write_dirblock(fd,empty_block,entrys);
		write_data(0,empty_block,entrys);
        setBitmap(block_bitmap,empty_block-4,TRUE);
        //write_zmap(fd,block_bitmap);
		write_data(0,3,block_bitmap);
        inodes[empty_inode].i_size=BLOCK_SIZE;
        inodes[empty_inode].i_nlinks=2;
    }else{
        inodes[empty_inode].i_mode=I_MODE_NORMAL;

        inodes[empty_inode].i_size=0;
        inodes[empty_inode].i_nlinks=1;
    }

    /* for i_node */
    inodes[empty_inode].i_gid=0xe8;
    inodes[empty_inode].i_time=0x00;//time(NULL);
    inodes[empty_inode].i_uid=I_UID;

    inodes[parent_i_inode].i_nlinks+=1;
    
    //write_inode(fd,inode);
    write_data(0,4,inodes);
    /* parent entry*/
    struct dir_entry entrys[32];
	memset(entrys,0,sizeof(struct dir_entry)*32);
    wcls_entry(parent_i_inode,entrys,inodes);
    for(int i=0;i<32;i++){
		printk("entrys%d inode:%d %s\n",i,entrys[i].i_inode,entrys[i].filename);
        if(entrys[i].i_inode==0){
            entrys[i].i_inode=empty_inode+1;
            strcpy(entrys[i].filename,name);
            break;
        }
    }
    /* write inodes */
    write_data(0,inodes[parent_i_inode].i_zone[0],entrys);
    return empty_inode;
}
Last edited by wellwell on Fri Nov 01, 2019 11:39 pm, edited 5 times in total.
User avatar
iansjack
Member
Member
Posts: 4705
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: minix 1.0 i_node problem

Post by iansjack »

Do you suppose it would help if people could see the code that you used to create the i_node?
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: minix 1.0 i_node problem

Post by bzt »

iansjack wrote:Do you suppose it would help if people could see the code that you used to create the i_node?
+1, please share your code so that we can see!

However, you said
wellwell wrote:I can not find the directory I created on the file system as well.
and

Code: Select all

Inode 2 not used, marked used in the bitmap.
Inode 3 not used, marked used in the bitmap.
Zone 6: marked in use, no file uses it.
Zone 7: marked in use, no file uses it.
Suggests that you've created the i_node just fine, but you forgot to link it into the directory structure. Or that linking failed.
That's why fsck is complaining about Inode 2 being unused (probably i_nlinks=0) and Zone 6 not used by files.

Cheers,
bzt
Post Reply