suriyaaOS - Windows 10上的Cygwin - Makefile-error:目标'modules / ext2.o'的配方失败

时间:2015-08-10 16:00:09

标签: c++ windows github

嗨Stackoverflowers!

我目前未能编写好的C ++目标文件(对于我自己的虚拟操作系统“suriyaaOS”)并且不知道原因。 -.-

  

我的完整项目来源:https://github.com/SuriyaaKudoIsc/suriyaaosIssue on GitHub

这是我的 kernel/modules/Makefile

OBJS:=  $(OBJS) modules/module.o \
        modules/null.o modules/stdtty.o modules/x86serial.o\
        modules/ide.o modules/bochsvbe.o \
        modules/ext2.o modules/dospartition.o \
        modules/clock_x86.o modules/keys.o

这是我的 kernel/modules/ext2.cc

#include <os.h>
#include <ext2.h>


File* ext2_mount(char* name,u32 flag,File* suriyaa){
    int ret=ext2_check_disk(suriyaa);
    if (ret!=RETURN_OK){
        io.print("ext2: can't mount %s in %s \n",suriyaa->getName(),name);
        return NULL;
    }
    else{   
        io.print("ext2:  mount %s in %s \n",suriyaa->getName(),name);
        Ext2* ret=new Ext2(name);
        ret->ext2inode=EXT2_INUM_ROOT;
        ext2_get_disk_info(suriyaa,ret);
        ret->scan();
        return ret;
    }
}

module("module.ext2",MODULE_FILESYSTEM,Ext2,ext2_mount)

Ext2::~Ext2(){

}

Ext2::Ext2(char* n) : File(n,TYPE_DIRECTORY)
{
    map=NULL;
}

void Ext2::scan(){
    ext2_scan(this);
}

u32 Ext2::close(){
    return NOT_DEFINED;
}

u32 Ext2::open(u32 flag){
    ext2_inode *inodee=ext2_read_inode(disk,ext2inode);
    map=ext2_read_file(disk,inodee);
    kfree(inodee);
    return RETURN_OK;
}

u32 Ext2::read(u32 pos,u8* buffer,u32 sizee){
    u32 bufsize=sizee;
    if ((pos + bufsize) > (size))
        bufsize = (u32)(size) - pos;
    memcpy((char*)buffer, (char *) (map + pos), bufsize);
    return bufsize;
}

u32 Ext2::write(u32 pos,u8* buffer,u32 sizee){
    return NOT_DEFINED;
}

u32 Ext2::ioctl(u32 id,u8* buffer){
    return NOT_DEFINED;
}

u32 Ext2::remove(){
    delete this;
    return RETURN_OK;
}



/*
 *  EXT2 specification
 */
int ext2_read_sb(File* suriya,ext2_super_block *sb)
{
    if (suriyaa!=NULL){
        suriyaa->read((u32)1024,(u8 *) sb,sizeof(ext2_super_block));
        return RETURN_OK;
    }
    else
        return ERROR_PARAM;
}

int ext2_read_gd(File* fsuriyaa,ext2_group_desc *gd,ext2_disk* info)
{
    if (fsuriyaa!=NULL){
        u32 offset;
        offset = ((info->blocksize == 1024) ? 2048 : info->blocksize);
        int gd_size = (info->groups * ((int)sizeof(struct ext2_group_desc)));
        fsuriyaa->read(offset,(u8*) gd,gd_size);
        return RETURN_OK;
    }
    else
        return ERROR_PARAM;
}

void ext2_get_disk_info(File*suriyaa,Ext2 *fp)
{
    ext2_disk* info=(ext2_disk*)kmalloc(sizeof(ext2_disk));
    info->sb=(ext2_super_block*)kmalloc(sizeof(ext2_super_block));
    info->suriyaa=suriyaa;
    int i, j;
    ext2_read_sb(suriyaa,info->sb);
    info->blocksize = 1024 << ((info->sb)->s_log_block_size);
    i = (info->sb->s_blocks_count / info->sb->s_blocks_per_group) + ((info->sb->s_blocks_count % info->sb->s_blocks_per_group) ? 1 : 0);
    j = (info->sb->s_inodes_count / info->sb->s_inodes_per_group) + ((info->sb->s_inodes_count % info->sb->s_inodes_per_group) ? 1 : 0);
    info->groups = (i > j) ? i : j;
    int gd_size = info->groups * ((int)sizeof(ext2_group_desc));
    info->gd = (ext2_group_desc *) kmalloc(gd_size);
    ext2_read_gd(info->suriyaa,info->gd,info);
    fp->disk=info;
    return;
}
int ext2_check_disk(File *suriyaa)
{
    ext2_super_block *sb=(ext2_super_block *)kmalloc(sizeof(ext2_super_block));
    if (ext2_read_sb(suriyaa,sb)!=RETURN_OK)
        return ERROR_PARAM;
    if (sb->s_magic==0xEF53){
        kfree(sb);
        return RETURN_OK;
    }
    else{
        kfree(sb);
        return ERROR_PARAM;
    }
}
ext2_inode *ext2_read_inode(ext2_disk* hd, int i_num)
{
    int gr_num, index;
    u32 offset;
    ext2_inode *inode;
    ext2_group_desc * info=hd->gd;
    inode = (ext2_inode *) kmalloc((hd->sb)->s_inode_size);//sizeof(ext2_inode));
    gr_num = (i_num - 1) / ((hd->sb)->s_inodes_per_group);
    index = (i_num - 1) % ((hd->sb)->s_inodes_per_group);
    offset = (info[gr_num].bg_inode_table * (hd->blocksize)) + (index * ((hd->sb)->s_inode_size));
    if ((hd->suriyaa)!=NULL){
        (hd->suriyaa)->read(offset,(u8*) inode,(hd->sb)->s_inode_size);
    }
    return inode;
}
int ext2_is_directory(Ext2 *fp)
{
    ext2_inode *inod=ext2_read_inode(fp->disk,fp->ext2inode);
    int ret=(inod->i_mode & EXT2_S_IFDIR) ? 1 : 0;
    kfree(inod);
    return ret;
}
char *ext2_read_file(ext2_disk *hd,ext2_inode *inode)
{
    File *suriyaa=hd->suriyaa;

    char *mmap_base, *mmap_head, *buf;

    int *p, *pp, *ppp;
    int i, j, k;
    int n, size;

    buf = (char *) kmalloc(hd->blocksize);
    p = (int *) kmalloc(hd->blocksize);
    pp = (int *) kmalloc(hd->blocksize);
    ppp = (int *) kmalloc(hd->blocksize);

    /* taille totale du fichier */
    size = inode->i_size;
    mmap_head = mmap_base = (char*)kmalloc(size);
    /* direct block number */
    for (i = 0; i < 12 && inode->i_block[i]; i++) {
        suriyaa->read((u32)(inode->i_block[i] * hd->blocksize),(u8*) buf, (hd->blocksize));
        n = ((size > (int)hd->blocksize) ? (int)hd->blocksize : size);
        memcpy(mmap_head, buf, n);
        mmap_head += n;
        size -= n;
    }
    /* indirect block number */
    if (inode->i_block[12]) {
        suriyaa->read((u32)(inode->i_block[12] * hd->blocksize), (u8*) p, (hd->blocksize));


        for (i = 0; i < (int)hd->blocksize / 4 && p[i]; i++) {
            suriyaa->read((u32)(p[i] * hd->blocksize),(u8*)buf, (hd->blocksize));
            n = ((size > (int)hd->blocksize) ? (int)hd->blocksize : size);
            memcpy(mmap_head, buf, n);
            mmap_head += n;
            size -= n;
        }
    }

    /* bi-indirect block number */
    if (inode->i_block[13]) {
        suriyaa->read((u32)(inode->i_block[13] * hd->blocksize), (u8*) p, (hd->blocksize));

        for (i = 0; i < (int)hd->blocksize / 4 && p[i]; i++) {
            suriyaa->read((u32)(p[i] * (int)hd->blocksize), (u8*) pp,(hd->blocksize));
            for (j = 0; j < (int)hd->blocksize / 4 && pp[j]; j++) {
                suriyaa->read((u32)(pp[j] * hd->blocksize),(u8*)buf,(hd->blocksize));
                n = ((size > (int)hd-> blocksize) ? (int)hd->blocksize : size);
                memcpy(mmap_head, buf, n);
                mmap_head += n;
                size -= n;
            }
        }
    }
    /* tri-indirect block number */
    if (inode->i_block[14]) {
        suriyaa->read((u32)(inode->i_block[14] * hd->blocksize), (u8*) p,(hd->blocksize));
        for (i = 0; i < (int)hd->blocksize / 4 && p[i]; i++) {
            suriyaa->read((u32)(p[i] * hd->blocksize), (u8*) pp,(hd->blocksize));
            for (j = 0; j < (int)hd->blocksize / 4 && pp[j]; j++) {
                suriyaa->read((u32)(pp[j] * hd->blocksize), (u8*) ppp,(hd->blocksize));
                for (k = 0; k < (int)hd->blocksize / 4 && ppp[k]; k++) {
                    suriyaa->read((u32)(ppp[k] * hd->blocksize),(u8*)buf,(hd->blocksize));
                    n = ((size > (int)hd->blocksize) ? (int)hd->blocksize : size);
                    memcpy(mmap_head, buf, n);
                    mmap_head += n;
                    size -= n;
                }
            }
        }
    }
    kfree(buf);
    kfree(p);
    kfree(pp);
    kfree(ppp);;
    return mmap_base;
}
int ext2_scan(Ext2 *dir)
{
    ext2_directory_entry *dentry;
    Ext2 *leaf;
    u32 dsize;
    char *filename;
    int f_toclose;
    ext2_inode *inode = ext2_read_inode(dir->disk, dir->ext2inode);
    if (dir->getType()!=TYPE_DIRECTORY) {
        return ERROR_PARAM;
    }

    if (!dir->map) {
        dir->map = ext2_read_file(dir->disk, inode);
        f_toclose = 1;
    } else {
        f_toclose = 0;
    }

    dsize = inode->i_size;
    dentry = (ext2_directory_entry *) dir->map;
    while (inode && dsize) {
                filename = (char *) kmalloc(dentry->name_len + 1);
                memcpy(filename,(char*)&(dentry->name), dentry->name_len);
                filename[dentry->name_len] = 0;
                if (strcmp(".", filename) && strcmp("..", filename)) {
                    if (dir->find(filename)==NULL) {
                        leaf= new Ext2(filename);
                        leaf->ext2inode = dentry->inode;
                        leaf->disk=dir->disk;
                        if (ext2_is_directory(leaf))
                            leaf->setType(TYPE_DIRECTORY);
                        else
                            leaf->setType(TYPE_FILE);
                        dir->addChild(leaf);
                        leaf->map = 0;
                        ext2_inode *inod=ext2_read_inode((ext2_disk*)leaf->disk,leaf->ext2inode);
                        leaf->setSize(inod->i_size);
                        kfree(inod);
                    }
                }
                kfree(filename);
        dsize -= dentry->rec_len;
        dentry = (ext2_directory_entry *) ((char *) dentry + dentry->rec_len);
    }
    kfree(inode);
    if (f_toclose == 1) {
        kfree(dir->map);
        dir->map = 0;
    }
    return 0;
}

这是我的 kernel/modules/ext2.h

#ifndef __EXT2__
#define __EXT2__

#include <runtime/types.h>
#include <core/file.h>
#include <io.h>

/*
 *  Ext2 specification
 */
struct ext2_super_block {
    u32 s_inodes_count; /* Total number of inodes */
    u32 s_blocks_count; /* Total number of blocks */
    u32 s_r_blocks_count;   /* Total number of blocks reserved for the super user */
    u32 s_free_blocks_count;    /* Total number of free blocks */
    u32 s_free_inodes_count;    /* Total number of free inodes */
    u32 s_first_data_block; /* Id of the block containing the superblock structure */
    u32 s_log_block_size;   /* Used to compute block size = 1024 << s_log_block_size */
    u32 s_log_frag_size;    /* Used to compute fragment size */
    u32 s_blocks_per_group; /* Total number of blocks per group */
    u32 s_frags_per_group;  /* Total number of fragments per group */
    u32 s_inodes_per_group; /* Total number of inodes per group */
    u32 s_mtime;        /* Last time the file system was mounted */
    u32 s_wtime;        /* Last write access to the file system */
    u16 s_mnt_count;    /* How many `mount' since the last was full verification */
    u16 s_max_mnt_count;    /* Max count between mount */
    u16 s_magic;        /* = 0xEF53 */
    u16 s_state;        /* File system state */
    u16 s_errors;       /* Behaviour when detecting errors */
    u16 s_minor_rev_level;  /* Minor revision level */
    u32 s_lastcheck;    /* Last check */
    u32 s_checkinterval;    /* Max. time between checks */
    u32 s_creator_os;   /* = 5 */
    u32 s_rev_level;    /* = 1, Revision level */
    u16 s_def_resuid;   /* Default uid for reserved blocks */
    u16 s_def_resgid;   /* Default gid for reserved blocks */
    u32 s_first_ino;    /* First inode useable for standard files */
    u16 s_inode_size;   /* Inode size */
    u16 s_block_group_nr;   /* Block group hosting this superblock structure */
    u32 s_feature_compat;
    u32 s_feature_incompat;
    u32 s_feature_ro_compat;
    u8 s_uuid[16];      /* Volume id */
    char s_volume_name[16]; /* Volume name */
    char s_last_mounted[64];    /* Path where the file system was last mounted */
    u32 s_algo_bitmap;  /* For compression */
    u8 s_padding[820];
} __attribute__ ((packed));


struct ext2_group_desc {
    u32 bg_block_bitmap;    /* Id of the first block of the "block bitmap" */
    u32 bg_inode_bitmap;    /* Id of the first block of the "inode bitmap" */
    u32 bg_inode_table; /* Id of the first block of the "inode table" */
    u16 bg_free_blocks_count;   /* Total number of free blocks */
    u16 bg_free_inodes_count;   /* Total number of free inodes */
    u16 bg_used_dirs_count; /* Number of inodes allocated to directories */
    u16 bg_pad;     /* Padding the structure on a 32bit boundary */
    u32 bg_reserved[3]; /* Future implementation */
} __attribute__ ((packed));

struct ext2_inode {
    u16 i_mode;     /* File type + access rights */
    u16 i_uid;
    u32 i_size;
    u32 i_atime;
    u32 i_ctime;
    u32 i_mtime;
    u32 i_dtime;
    u16 i_gid;
    u16 i_links_count;
    u32 i_blocks;       /* 512 bytes blocks ! */
    u32 i_flags;
    u32 i_osd1;

    /*
     * [0] -> [11] : block number (32 bits per block)
     * [12]        : indirect block number
     * [13]        : bi-indirect block number
     * [14]        : tri-indirect block number
     */
    u32 i_block[15];

    u32 i_generation;
    u32 i_file_acl;
    u32 i_dir_acl;
    u32 i_faddr;
    u8 i_osd2[12];
} __attribute__ ((packed));

struct ext2_directory_entry {
    u32 inode;      /* inode number or 0 (unused) */
    u16 rec_len;        /* offset to the next dir. entry */
    u8 name_len;        /* name length */
    u8 file_type;
    char name;
} __attribute__ ((packed));


struct ext2_disk {
    ext2_super_block*   sb;
    ext2_group_desc*    gd;
    u32                 blocksize;
    u16                 groups;     /* Total number of groups */
    File*               suriyaa;
};


/* super_block: s_errors */
#define EXT2_ERRORS_CONTINUE    1
#define EXT2_ERRORS_RO      2
#define EXT2_ERRORS_PANIC   3
#define EXT2_ERRORS_DEFAULT 1

/* inode: i_mode */
#define EXT2_S_IFMT 0xF000      /* format mask  */
#define EXT2_S_IFSOCK   0xC000  /* socket */
#define EXT2_S_IFLNK    0xA000  /* symbolic link */
#define EXT2_S_IFREG    0x8000  /* regular file */
#define EXT2_S_IFBLK    0x6000  /* block device */
#define EXT2_S_IFDIR    0x4000  /* directory */
#define EXT2_S_IFCHR    0x2000  /* character device */
#define EXT2_S_IFIFO    0x1000  /* fifo */

#define EXT2_S_ISUID    0x0800  /* SUID */
#define EXT2_S_ISGID    0x0400  /* SGID */
#define EXT2_S_ISVTX    0x0200  /* sticky bit */
#define EXT2_S_IRWXU    0x01C0  /* user access rights mask */
#define EXT2_S_IRUSR    0x0100  /* read */
#define EXT2_S_IWUSR    0x0080  /* write */
#define EXT2_S_IXUSR    0x0040  /* execute */
#define EXT2_S_IRWXG    0x0038  /* group access rights mask */
#define EXT2_S_IRGRP    0x0020  /* read */
#define EXT2_S_IWGRP    0x0010  /* write */
#define EXT2_S_IXGRP    0x0008  /* execute */
#define EXT2_S_IRWXO    0x0007  /* others access rights mask */
#define EXT2_S_IROTH    0x0004  /* read */
#define EXT2_S_IWOTH    0x0002  /* write */
#define EXT2_S_IXOTH    0x0001  /* execute */

#define EXT2_INUM_ROOT  2

/*
 *  Driver class
 */
class Ext2 : public File
{
    public:
        Ext2(char* n);
        ~Ext2();


        u32     open(u32 flag);
        u32     close();
        u32     read(u32 pos,u8* buffer,u32 sizee);
        u32     write(u32 pos,u8* buffer,u32 sizee);
        u32     ioctl(u32 id,u8* buffer);
        u32     remove();
        void    scan();

        char*       map;
        ext2_disk*  disk;
        int         ext2inode;
    private:

};

int             ext2_check_disk(File *suriyaa);
void            ext2_get_disk_info(File*suriyaa,Ext2 *fp);
int             ext2_read_gd(File* fsuriyaa,ext2_group_desc *gd,ext2_disk* info);
int             ext2_read_sb(File* suriyaa,ext2_super_block *sb);
ext2_inode*     ext2_read_inode(ext2_disk* hd, int i_num);
int             ext2_is_directory(Ext2 *fp);
int             ext2_scan(Ext2 *dir);
char *          ext2_read_file(ext2_disk *hd,ext2_inode *inode);

#endif

当我输入带有make all路径的Windows 10 CMD:C:\Users\Suriyaa\suriyaaos时,我会收到输出:

C:\Users\Suriyaa\suriyaaos>make all
Building Kernel
make -C ./kernel
make[1]: Entering directory '/cygdrive/c/Users/Suriyaa/suriyaaos/kernel'
g++ -I ./ -I ./modules -I ./core -I ./arch/x86 -g -O2 -w -trigraphs -fno-builtin
  -fno-exceptions -fno-stack-protector -O0 -m32  -fno-rtti -nostdlib -nodefaultl
ibs  -D__x86__ -c modules/ext2.cc -o  modules/ext2.o
modules/ext2.cc: In function 'int ext2_read_sb(File*, ext2_super_block*)':
modules/ext2.cc:77:6: error: 'suriyaa' was not declared in this scope
  if (suriyaa!=NULL){
      ^
Makefile:58: recipe for target 'modules/ext2.o' failed
make[1]: *** [modules/ext2.o] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/Suriyaa/suriyaaos/kernel'
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 2
  

有谁知道问题出在哪里?

1 个答案:

答案 0 :(得分:2)

问题不在于POSTmakefile文件有关。

函数定义中变量的名称

ext2.cc
当您在代码中致电int ext2_read_sb(File* suriya,ext2_super_block *sb) 时,

suriya。 c文件中的函数定义中缺少suriyaa!=NULL。解决这个问题,这将解决错误。