⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 make_wosfs.c

📁 altera epxa1的例子程序
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h> 
#include <sys/types.h>
#include "../inc/wosfs.h"


typedef struct
{
    ns_wosfs_volume_header      h;
    ns_wosfs_directory_entry    de[0x20];
} type_fs;

union
{
    type_fs         fs;
    unsigned char   buf[0x20000];
} flash;

// +---------------------------------
// | Local prototypes
int add_file(int index, char *fname, unsigned long *wptr);
int filelength(FILE *fp);

// +----------------------------------
// |filelength
// |
// | This routine is used to compute the
// | length of the file being place in 
// | filesystem
// |
/*
int filelength(FILE *fp)

{	int i = 0;
	unsigned char temp_charater; 
	FILE *tempfile;
	tempfile = fp;
	
	while((feof(tempfile)) == 0)
	{	
		temp_charater = (unsigned char)fgetc(tempfile);  //side effect of fgetc is that it increments the char pointer in the file
		i++;
	}
   
    return i - 1;
}
*/
// +----------------------------------
// | add_file
// |
// | This routine is used to add a file
// | to the filesystem. 

int add_file(int index, char *fname, unsigned long *wptr)
{                 
    int fh;
    int result;   
    int flen;
    FILE *Ip;
   
    flen = 0;
    Ip = fopen(fname,"rb");
    if (Ip)
    {  
    	    	    	  	
      if ((fh = open(fname, _O_RDONLY)) != -1)
        {
            flen = lseek(fh,0L,SEEK_END); 
            close(fh);
        }
    	
        printf( "%3d: %s - %ld bytes\n", index, fname, flen);
        strcpy(flash.fs.de[index].name, fname);
        flash.fs.de[index].location = *wptr;
        flash.fs.de[index].file_length = flen;
        fread(&flash.buf[*wptr], 1, flen,  Ip);
        fclose(Ip);

        *wptr += flen;
        return 1;
    }
    return 0;
}  


main()
{
    int i;
    FILE *Op;
    unsigned long wptr;
    int index;    

    flash.fs.h.signature  = 0x89674523;

    // size of directory = 8 + 40*num_files
    wptr = 0x200;      

    index = 0;
    index += add_file(index, "index.html", &wptr);
    index += add_file(index, "exc-nios.gif", &wptr);
    index += add_file(index, "404_page.html", &wptr);
    index += add_file(index, "static_page.html", &wptr);
    index += add_file(index, "template_page.html.template", &wptr);
    index += add_file(index, "recon_control.html", &wptr);
    //index += add_file(index, "test.pdf", &wptr);
    printf("total 0x%x (%d) bytes\n",wptr,wptr);

    flash.fs.h.file_count = index;


    Op = fopen("flash.h","wt");
    fprintf(Op, "unsigned char flash[0x%x] =\n",wptr);
    fprintf(Op, "{\n");
    for (i=0; i<wptr; i++)
    {
        if (!(i & 0x0f)) fprintf(Op,"\n    ");
        fprintf(Op, "0x%02x, ",flash.buf[i]);
    }   
    fprintf(Op, "\n};\n");
    fclose(Op);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -