xiaolongyuan 发表于 2005-3-22 19:32:34

移植linux 0.11文件系统到ucosii下

搞了几天,终于搞定了.
其他文件系统太庞大了,不敢动.还是这个简单点,还有赵炯博士的书可以看.
具体做的事情有:

1. 去掉关于块设备,字符设备,pipe等
2. 修改底层的设备读写函数,就是那个ll_rw_block
3. 望 ucosii 的 OS_TCB中加入文件控制项
4. 修改原来的汇编函数为C.
5. 利用给的那个ucosii4skyeye例子中的ucos_shell实现了简单的操作(2个
:D , cd, pwd)
e.g.: cd bin

6 还删除了其中关于多用户检测部分



下午刚弄出来, 这个虽然没什么用,但是还是可以作为学习文件系统实现的好材料.
希望和感兴趣的大虾&小虾交流.

我的源码给出来了
其中:
1 顶层目录中的文件放到 /ucosii4skyeye/samples/ucos_shell/shelltask下
(ucosii4skyeye就是下载的那个例子)
2. head 中的 fs.h ucos_ii.h 放到 kernel下 覆盖即可(放心,我没怎么改~~)
3. skyeye.conf 覆盖掉原来的ucos_shell下那个.
4. rootimage-0.11从    http://www.oldlinux.org/Linux.old/images/rootimage-0.11.Z
下载, 解压后放在ucos_shell下即可.
5. 编译还是看原来例子说明.
   运行后可以用 pwd, cd 两个命令

chyyuu 发表于 2005-3-22 22:52:20

好文!

chyyuu 发表于 2005-3-22 22:53:18

如果你在北京,希望能更进一步联系。能给我发个email吗?

sundy2000 发表于 2005-3-23 10:04:42

刚下了你的例子,还没有仔细看。发现head目录中没有fs.h.

xiaolongyuan 发表于 2005-3-23 10:34:43

对不起,倏忽了.
现在传上fs.h

/*
* This file has definitions for some important file table
* structures etc.
*/

#ifndef _FS_H
#define _FS_H

#include <sys/types.h>
#include "fs_task.h"

/* devices are as follows: (same as minix, so we can use the minix
* file system. These are major numbers.)
*
* 0 - unused (nodev)
* 1 - /dev/mem
* 2 - /dev/fd
* 3 - /dev/hd
* 4 - /dev/ttyx
* 5 - /dev/tty
* 6 - /dev/lp
* 7 - unnamed pipes
*/

#define IS_SEEKABLE(x) ((x)>=1 && (x)<=3)

#define READ 0
#define WRITE 1
#define READA 2                /* read-ahead - don't pause */
#define WRITEA 3        /* "write-ahead" - silly, but somewhat useful */

void buffer_init(long buffer_end,long buffer_start);

#define MAJOR(a) (((unsigned)(a))>>8)
#define MINOR(a) ((a)&0xff)

#define NAME_LEN 14
#define ROOT_INO 1

#define I_MAP_SLOTS 8
#define Z_MAP_SLOTS 8
#define SUPER_MAGIC 0x137F

//#define NR_OPEN 20
#define NR_INODE 32
#define NR_FILE 64
#define NR_SUPER 8
#define NR_HASH 307
#define NR_BUFFERS nr_buffers
#define BLOCK_SIZE 1024
#define BLOCK_SIZE_BITS 10
#ifndef NULL
#define NULL ((void *) 0)
#endif


#define O_ACCMODE        00003
#define O_RDONLY           00
#define O_WRONLY           01
#define O_RDWR                   02
#define O_CREAT                00100        /* not fcntl */
#define O_EXCL                00200        /* not fcntl */
#define O_NOCTTY        00400        /* not fcntl */
#define O_TRUNC                01000        /* not fcntl */
#define O_APPEND        02000
#define O_NONBLOCK        04000        /* not fcntl */
#define O_NDELAY        O_NONBLOCK
#define BUFFER_END 0x200000

#define I_TYPE          0170000
#define I_DIRECTORY        0040000
#define I_REGULAR       0100000
#define I_BLOCK_SPECIAL 0060000
#define I_CHAR_SPECIAL0020000
#define I_NAMED_PIPE        0010000
#define I_SET_UID_BIT   0004000
#define I_SET_GID_BIT   0002000
#ifndef ERROR
#define ERROR         1
#endif
/*xly*/
#include <stdio.h>
#define panic   printf
#define printkprintf
#define CURRENT_TIME0
#define cli()
#define sti()
#include "stat.h"

//typedef int off_t;


#define INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct d_inode)))
#define DIR_ENTRIES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct dir_entry)))

#define PIPE_HEAD(inode) ((inode).i_zone)
#define PIPE_TAIL(inode) ((inode).i_zone)
#define PIPE_SIZE(inode) ((PIPE_HEAD(inode)-PIPE_TAIL(inode))&(PAGE_SIZE-1))
#define PIPE_EMPTY(inode) (PIPE_HEAD(inode)==PIPE_TAIL(inode))
#define PIPE_FULL(inode) (PIPE_SIZE(inode)==(PAGE_SIZE-1))
#define INC_PIPE(head) \
__asm__("incl %0\n\tandl $4095,%0"::"m" (head))

typedef char buffer_block;

struct buffer_head {
        char * b_data;                        /* pointer to data block (1024 bytes) */
        unsigned long b_blocknr;        /* block number */
        unsigned short b_dev;                /* device (0 = free) */
        unsigned char b_uptodate;
        unsigned char b_dirt;                /* 0-clean,1-dirty */
        unsigned char b_count;                /* users using this block */
        unsigned char b_lock;                /* 0 - ok, 1 -locked */
        struct task_struct * b_wait;
        struct buffer_head * b_prev;
        struct buffer_head * b_next;
        struct buffer_head * b_prev_free;
        struct buffer_head * b_next_free;
};

struct d_inode {
        unsigned short i_mode;
        unsigned short i_uid;
        unsigned long i_size; //文件长度    如果该inode代表一个目录,这个长度就是 dir_entry的整数倍 , OK?
        unsigned long i_time;
        unsigned char i_gid;
        unsigned char i_nlinks;
        unsigned short i_zone;
};

struct m_inode {
        unsigned short i_mode;
        unsigned short i_uid;
        unsigned long i_size;
        unsigned long i_mtime;
        unsigned char i_gid;
        unsigned char i_nlinks;
        unsigned short i_zone;
/* these are in memory also */
        struct task_struct * i_wait;
        unsigned long i_atime;
        unsigned long i_ctime;
        unsigned short i_dev;
        unsigned short i_num;
        unsigned short i_count;
        unsigned char i_lock;
        unsigned char i_dirt;
        unsigned char i_pipe;
        unsigned char i_mount;
        unsigned char i_seek;
        unsigned char i_update;
};

struct file {
        unsigned short f_mode;
        unsigned short f_flags;
        unsigned short f_count;
        struct m_inode * f_inode;
        off_t f_pos;
};

struct super_block {
        unsigned short s_ninodes;
        unsigned short s_nzones;
        unsigned short s_imap_blocks;
        unsigned short s_zmap_blocks;
        unsigned short s_firstdatazone;
        unsigned short s_log_zone_size;
        unsigned long s_max_size;
        unsigned short s_magic;
/* These are only in memory */
        struct buffer_head * s_imap;
        struct buffer_head * s_zmap;
        unsigned short s_dev;
        struct m_inode * s_isup;
        struct m_inode * s_imount;
        unsigned long s_time;
        struct task_struct * s_wait;
        unsigned char s_lock;
        unsigned char s_rd_only;
        unsigned char s_dirt;
};

struct d_super_block {
        unsigned short s_ninodes;
        unsigned short s_nzones;
        unsigned short s_imap_blocks;
        unsigned short s_zmap_blocks;
        unsigned short s_firstdatazone;
        unsigned short s_log_zone_size;
        unsigned long s_max_size;
        unsigned short s_magic;
};

struct dir_entry {
        unsigned short inode;
        char name;
};

extern struct m_inode inode_table;
extern struct file file_table;
extern struct super_block super_block;
extern struct buffer_head * start_buffer;
extern int nr_buffers;

extern void check_disk_change(int dev);
extern int floppy_change(unsigned int nr);
extern int ticks_to_floppy_on(unsigned int dev);
extern void floppy_on(unsigned int dev);
extern void floppy_off(unsigned int dev);
extern void truncate(struct m_inode * inode);
extern void sync_inodes(void);
extern void wait_on(struct m_inode * inode);
extern int bmap(struct m_inode * inode,int block);
extern int create_block(struct m_inode * inode,int block);
extern struct m_inode * namei(const char * pathname);
extern int open_namei(const char * pathname, int flag, int mode,
        struct m_inode ** res_inode);
extern void iput(struct m_inode * inode);
extern struct m_inode * iget(int dev,int nr);
extern struct m_inode * get_empty_inode(void);
extern struct m_inode * get_pipe_inode(void);
extern struct buffer_head * get_hash_table(int dev, int block);
extern struct buffer_head * getblk(int dev, int block);
extern void ll_rw_block(int rw, struct buffer_head * bh);
extern void brelse(struct buffer_head * buf);
extern struct buffer_head * bread(int dev,int block);
extern void bread_page(unsigned long addr,int dev,int b);
extern struct buffer_head * breada(int dev,int block,...);
extern int new_block(int dev);
extern void free_block(int dev, int block);
extern struct m_inode * new_inode(int dev);
extern void free_inode(struct m_inode * inode);
extern int sync_dev(int dev);
extern struct super_block * get_super(int dev);
extern int ROOT_DEV;
extern char * iname(struct m_inode * inode, char * name);
extern void mount_root(void);

unsigned char get_fs_byte(const char * addr);
void put_fs_byte(char val, char * addr);

#endif

walimis 发表于 2005-3-24 13:42:21

很好!希望能有人来做ucosii4skeyey的工作,skyeye上的操作系统的支持,现在很缺人。

sundy2000 发表于 2005-3-25 13:02:42

下载下来尝试了一下,没有成功。有一些错误。比如
#include "fs_task.h"无此文件。改掉了一些。
运行没有反应。

lunasea20210 发表于 2008-1-25 13:34:35

太好了~

最近在做大作业,也在移植0.11的文件系统,搞了一半了。
太好了,学习学习~~

hellottsky 发表于 2009-9-23 01:13:04

赞一个,这个真是我需要的 啊~~
页: [1]
查看完整版本: 移植linux 0.11文件系统到ucosii下