資源簡(jiǎn)介
C語(yǔ)言自編DES加密算法S盒與P盒,原理簡(jiǎn)單明了,注釋全面,需要的同學(xué)拿去吧!
代碼片段和文件信息
#define?DATA_BLOCK?263680
#define?BLOCK_SIZE?512
#define?DISK_START?0
#define?BLOCK_BITMAP?512
#define?INODE_BITMAP?1024
#define?INODE_TABLE?1536
#define?INODE_SIZE?64
#include?
#include?
#include?
#include?
struct?group_desc{
????char?bg_volume_name[16];?/*卷名*/
????unsigned?short?bg_block_bitmap;?/*保存塊位圖的塊號(hào)*/
????unsigned?short?bg_inode_bitmap;?/*保存索引結(jié)點(diǎn)位圖的塊號(hào)*/
????unsigned?short?bg_inode_table;?/*索引結(jié)點(diǎn)表的起始?jí)K號(hào)*/
????unsigned?short?bg_free_blocks_count;?/*本組空閑塊的個(gè)數(shù)*/
????unsigned?short?bg_free_inodes_count;?/*本組空閑索引結(jié)點(diǎn)的個(gè)數(shù)*/
????unsigned?short?bg_used_dirs_count;?/*本組目錄的個(gè)數(shù)*/
????char?bg_pad[4];?/*填充(0xff)*/
};
struct?inode{
????unsigned?short?i_mode;?/*文件類型及訪問(wèn)權(quán)限*/???????
????unsigned?short?i_blocks;?/*文件的數(shù)據(jù)塊個(gè)數(shù)*/
????unsigned?long?i_size;?/*大小(?字節(jié))*/
????unsigned?long?i_atime;?/*訪問(wèn)時(shí)間*/
????unsigned?long?i_ctime;?/*創(chuàng)建時(shí)間*/
????unsigned?long?i_mtime;?/*修改時(shí)間*/
????unsigned?long?i_dtime;?/*刪除時(shí)間*/
????unsigned?short?i_block[8];?/*指向數(shù)據(jù)塊的指針*/
????char?i_pad[24];?/*填充(0xff)*/
};
struct?dir_entry{???//目錄項(xiàng)結(jié)構(gòu)
????unsigned?short?inode;?/*索引節(jié)點(diǎn)號(hào)*/
????unsigned?short?rec_len;?/*目錄項(xiàng)長(zhǎng)度*/
????unsigned?short?name_len;?/*文件名長(zhǎng)度*/
????char?file_type;?/*文件類型(1:?普通文件,?2:?目錄..?)*/
????char?name[9];?/*文件名*/
};
char?Buffer[512];??//針對(duì)數(shù)據(jù)塊的?緩沖區(qū)
char?tempbuf[4097];?//
unsigned?char?bitbuf[512];?//位圖緩沖區(qū)
unsigned?short?index_buf[256];
short?fopen_table[16];?//??文件打開表
unsigned?short?last_alloc_inode;?//??最近分配的節(jié)點(diǎn)號(hào)
unsigned?short?last_alloc_block;?//??最近分配的數(shù)據(jù)塊號(hào)
unsigned?short?current_dir;???//??????當(dāng)前目錄的節(jié)點(diǎn)號(hào)
struct?group_desc?super_block[1];?//???組描述符緩沖區(qū)
struct?inode?inode_area[1];??//???節(jié)點(diǎn)緩沖區(qū)
struct?dir_entry?dir[32];???//??目錄項(xiàng)緩沖區(qū)
char?current_path[256];????//????當(dāng)前路徑名
unsigned?short?current_dirlen;
FILE?*fp;
/*************************************????????alloc??????????*******************************************************/
void?update_group_desc()
{
????fseek(fpDISK_STARTSEEK_SET);
????fwrite(super_blockBLOCK_SIZE1fp);
}
void?reload_group_desc()//載入組描述符
{
????fseek(fpDISK_STARTSEEK_SET);
????fread(super_blockBLOCK_SIZE1fp);
}
void?update_inode_bitmap()//更新inode位圖?
{
????fseek(fpINODE_BITMAPSEEK_SET);
????fwrite(bitbufBLOCK_SIZE1fp);
}
void?reload_inode_bitmap()//載入inode位圖?
{
????fseek(fpINODE_BITMAPSEEK_SET);
????fread(bitbufBLOCK_SIZE1fp);
}
void?update_block_bitmap()//更新block位圖?
{
????fseek(fpBLOCK_BITMAPSEEK_SET);
????fwrite(bitbufBLOCK_SIZE1fp);
}
void?reload_block_bitmap()//載入block位圖?
{
????fseek(fpBLOCK_BITMAPSEEK_SET);
????fread(bitbufBLOCK_SIZE1fp);
}
void?update_inode_entry(unsigned?short?i)//更新第i個(gè)inode入口?
{
????fseek(fpINODE_TABLE+(i-1)*INODE_SIZESEEK_SET);
????fwrite(inode_areaINODE_SIZE1fp);
}
void?reload_inode_entry(unsigned?short?i)//載入第i個(gè)inode入口
{
????fseek(fpINODE_TABLE+(i-1)*INODE_SIZESEEK_SET);
????fread(inode_areaINODE_SIZE1fp);
}
void?reload_dir(unsigned?short?i)//更新第i個(gè)目錄?
{
????fs
評(píng)論
共有 條評(píng)論