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

📄 def.h

📁 一个完整的SHELL实现源代码
💻 H
字号:
#ifndef KENSTA_FS_DEF_HEADER
#define KENSTA_FS_DEF_HEADER

typedef short int s_int;
typedef unsigned short int us_int;
typedef long int s_long;

#define NINODE 100
#define NBLOCK 16384   /* 16k blocks , 8M size image file */
#define NBUF   15
#define NFILE  100

/* super block, block #1
*/
typedef struct filsys
{
	s_int isize;	/* size in blocks of I-node area */
	s_int fsize;	/* size in blocks of entire volume */
	s_int nfree;	/* number of in core free blocks between 0 and 100 */
	s_int free[100];	/* in core free blocks */
	s_int ninode;	/* number of in core i nodes 0-100 */
	s_int inode[100];	/* in core free i nodes */
	char flock;	/* lock during free list manipulation */
	char ilock;	/* lock during i list manipulation */
	char fmod;	/* super block modified flag */
	char ronly;	/* mounted read-only flag */
	s_int time[2];	/* current date of last update */
	s_int pad[48];
}filsys;

/* Inode structure as it appears on the disk 
    sizeof(inode_o) = 32 bytes
*/
typedef struct inode_o
{
	s_int mode;
	char nlink;
	char uid;
	char gid;
	char size0;
	us_int size1;
	s_int addr[8];
	s_int atime[2];
	s_int mtime[2];		/* file: modify time; dir: record count */
}inode_o;

/* inode_o.mode enum */
#define IALLOC	0x8000	/* file is used */
#define IFMT	0x6000	/* type of file */
#define IFDIR	0x4000	/* directory */
#define IFCHR	0x2000	/* character special */
#define IFBLK	0x6000	/* block special,0 is regular */
#define ILARG	0x1000	/* large addressing algorithm */
#define ISUID	0x0800	/* set user id on execution */
#define ISGID	0x0400	/* set group id on execution */
#define ISVTX	0x0200	/* save swapped text even after use */
#define IREAD	0x0100	/* read write, execute permissions */
#define IWRITE	0x0080
#define IEXEC	0x0040

/* Inode structure 
*/
typedef struct inode 
{
	char flag;		/*  */
	char count;		/* using count */
	s_int dev;		/* not used in this system */
	s_int number;	/* ino */
	s_int mode;		/* look at inode_o.mode */
	char nlink;		/* directory entries */
	char uid;			/* owner */
	char gid;			/* group of owner */
	char size0;
	us_int size1;
	s_int adr[8];
	s_int lastr;		/* temp for mtime[0] */
}inode;

extern struct inode g_inode[NINODE];
extern struct filsys g_sblock;
/* inode.flags bit */
#define ILOCK	0x01	/* the inode is being used */
#define IUPD		0x02
#define IACC		0x04
#define IMOUNT	0x08
#define IWANT	0x10
#define ITEXT	0x20
#define IUSE		0x40	/* inode is used in g_inode */

typedef struct buf
{
	s_int flags;
	struct buf *forw;	
	struct buf *back;
	struct buf *av_forw;
	struct buf *av_back;
	s_int dev;
	s_int wcount;
	us_int  addr;
	us_int  xmen;
	us_int  blkno;
	us_int  error;
	us_int  resid;
}buf;

/* buf.flags bit */
#define B_WRITE		0x00
#define B_READ		0x01
#define	B_DONE		0x02
#define	B_ERROR 	0x04
#define	B_BUSY		0x08
#define	B_PHYS		0x10
#define	B_MAP		0x20
#define	B_WANTED	0x40
#define	B_RELOC		0x80
#define	B_ASYNC		0x100
#define	B_DELWRI	0x200

typedef struct file
{
	char flag;
	char count;
	s_int ino;
	us_int  offset[2];
}file;

/* file.flag */
#define FREAD	0x01
#define FWRITE	0x02
#define FPIPE	0x04
#define FCHG 	0x08

extern struct file g_file[NFILE];

typedef struct dir_rec
{
	char name[30]; /* file name or dir name not longer then 30 bytes */
	s_int ino;
}dir_rec;

extern char g_curdir_name[256];

struct passwd{
	char name[30];
	char gid,uid;
};

extern struct passwd g_user;

#endif

⌨️ 快捷键说明

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