-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs.h
122 lines (89 loc) · 3.71 KB
/
fs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef __FILESYSTEM_H__
#define __FILESYSTEM_H__
#include "disk.h"
// ------- Caution -----------------------------------------
#define FS_DISK_CAPACITY (BLOCK_SIZE*512) /* 수정 */
#define MAX_FD_ENTRY_MAX (64)
#define NUM_OF_INODE_PER_BLOCK (BLOCK_SIZE / sizeof(Inode)) /* block 당 inode 개수 */
#define NUM_OF_DIRENT_PER_BLOCK (BLOCK_SIZE / sizeof(DirEntry)) /* block 당 directory entry 개수 */
#define NUM_OF_DIRECT_BLOCK_PTR (5) /* direct block pointer의 개수 */
#define MAX_NAME_LEN (12)
#define FILESYS_INFO_BLOCK (0) /* file system info block no. */
#define INODE_BYTEMAP_BLOCK_NUM (1) /* inode bitmap block no. */
#define BLOCK_BYTEMAP_BLOCK_NUM (2) /* block bitmap block no. */
#define INODELIST_BLOCK_FIRST (3) /* the first block no. of inode list */
#define INODELIST_BLOCKS (4) /* the number of blocks in inode list */
// ----------------------------------------------------------
typedef enum __fileType {
FILE_TYPE_FILE,
FILE_TYPE_DIR,
FILE_TYPE_DEV
} FileType;
typedef struct __dirEntry {
char name[MAX_NAME_LEN]; // file name
int inodeNum;
} DirEntry;
/* 추가 */
typedef struct __dirEntryInfo {
char name[MAX_NAME_LEN];
int inodeNum;
FileType type;
} DirEntryInfo;
typedef struct _FileSysInfo {
int blocks; // 디스크에 저장된 전체 블록 개수
int rootInodeNum; // 루트 inode의 번호
int diskCapacity; // 디스크 용량 (Byte 단위)
int numAllocBlocks; // 파일 또는 디렉토리에 할당된 블록 개수
int numFreeBlocks; // 할당되지 않은 블록 개수
int numAllocInodes; // 할당된 inode 개수
int blockBitmapBlock; // block bitmap의 시작 블록 번호
int inodeBitmapBlock; // inode bitmap의 시작 블록 번호
int inodeListBlock; // inode list의 시작 블록 번호
int dataRegionBlock; // data region의 시작 블록 번호 (수정)
} FileSysInfo;
typedef struct _Inode {
int allocBlocks;
int size;
int type;
int dirBlockPtr[NUM_OF_DIRECT_BLOCK_PTR];
} Inode;
typedef struct __File {
int fileOffset;
int inodeNum;
}File;
typedef struct __FileDesc {
int bUsed;
File* pOpenFile;
}FileDesc;
typedef struct _FileStatus {
int allocBlocks;
int size;
int type;
int dirBlockPtr[NUM_OF_DIRECT_BLOCK_PTR];
} FileStatus;
extern FileDesc pFileDesc[MAX_FD_ENTRY_MAX];
extern FileSysInfo* pFileSysInfo;
extern int CreateFile(const char* szFileName);
extern int OpenFile(const char* szFileName);
extern int WriteFile(int fileDesc, char* pBuffer, int length);
extern int ReadFile(int fileDesc, char* pBuffer, int length);
extern int CloseFile(int fileDesc);
extern int RemoveFile(const char* szFileName);
extern int MakeDir(const char* szDirName);
extern int RemoveDir(const char* szDirName);
extern int EnumerateDirStatus(const char* szDirName, DirEntryInfo* pDirEntry, int dirEntrys );
extern void CreateFileSystem();
extern void OpenFileSystem();
extern void CloseFileSystem();
extern int GetFileStatus(const char* szPathName, FileStatus* pStatus);
extern void FileSysInit(void);
/* File system internal functions */
extern void SetInodeBitmap(int inodeno);
extern void ResetInodeBitmap(int inodeno);
extern void SetBlockBitmap(int blkno);
extern void ResetBlockBitmap(int blkno);
extern void PutInode(int inodeno, Inode* pInode);
extern void GetInode(int inodeno, Inode* pInode);
extern int GetFreeInodeNum(void);
extern int GetFreeBlockNum(void);
#endif /* FILESYSTEM_H_ */