Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed 24S_OS_miniOS.pdf
Binary file not shown.
Binary file added 24S_OS_miniOS_Report.pdf
Binary file not shown.
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

27 changes: 27 additions & 0 deletions miniOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Compiler and Compiler Flags
CC=gcc
CFLAGS=-Wall -g -Iinclude
# Linker flags
LDFLAGS=-lreadline

# The build target executable:
TARGET=minios
# Source, Object files
SRCS=kernel/kernel.c kernel/file_manage.c

OBJS=$(SRCS:.c=.o)

# Include directory
INCLUDE_DIR=include

all: $(TARGET)

$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)
# To obtain object files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

# Clean up:
clean:
rm -f $(OBJS) $(TARGET)
27 changes: 27 additions & 0 deletions miniOS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# miniOS

miniOS-project/
├── README.md # 프로젝트 설명 및 사용 방법 문서
├── Makefile # 전체 프로젝트 빌드 자동화를 위한 메이크파일
├── boot/ # 부트로더 소스 코드
O └── boot.asm # 부트로더 어셈블리 코드
├── kernel/ # 커널 소스 코드
O ├── kernel.c # 커널 메인 C 소스 파일
O └── ...
├── drivers/ # 디바이스 드라이버 코드
O ├── keyboard.c # 키보드 드라이버
O ├── screen.c # 화면(비디오) 드라이버
O └── ...
├── lib/ # 커널 라이브러리 및 공통 유틸리티
O ├── stdio.c # 기본 입출력 함수
O ├── string.c # 문자열 처리 함수
O └── ...
├── include/ # 헤더 파일
O ├── kernel.h # 커널 관련 공통 헤더
O ├── drivers/ # 드라이버 헤더 파일
O └── lib/ # 라이브러리 헤더 파일
└── scripts/ # 빌드 및 유틸리티 스크립트
O ├── build.sh # 빌드 스크립트
O └── run_qemu.sh # QEMU를 통해 OS 이미지 실행 스크립트


1 change: 1 addition & 0 deletions miniOS/boot/boot.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions miniOS/directory_structure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DIR root
DIR clipboard
1 change: 1 addition & 0 deletions miniOS/drivers/basic_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions miniOS/include/basic_include.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions miniOS/include/system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

// include/linux/sched.h
//SSU struct task_struct {

void minisystem();
void file_system();
319 changes: 319 additions & 0 deletions miniOS/kernel/file_manage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 파일 노드를 정의합니다.
typedef struct FileNode {
char fileName[256];
struct FileNode* next;
} FileNode;

// 디렉토리 구조체를 정의합니다.
typedef struct Directory {
char dirName[256];
FileNode* files;
struct Directory* parent;
struct Directory* next;
struct Directory* subDirs;
} Directory;

// 루트 디렉토리와 현재 디렉토리를 정의합니다.
Directory* rootDir = NULL;
Directory* currentDir = NULL;
Directory* clipboardDir = NULL;

// 파일 노드를 생성합니다.
FileNode* createFileNode(const char* fileName) {
FileNode* newNode = (FileNode*)malloc(sizeof(FileNode));
if (newNode == NULL) {
perror("Failed to create file node");
exit(EXIT_FAILURE);
}
strncpy(newNode->fileName, fileName, 255);
newNode->fileName[255] = '\0';
newNode->next = NULL;
return newNode;
}

// 디렉토리를 생성합니다.
Directory* createDirectory(const char* dirName, Directory* parent) {
Directory* newDir = (Directory*)malloc(sizeof(Directory));
if (newDir == NULL) {
perror("Failed to create directory");
exit(EXIT_FAILURE);
}
strncpy(newDir->dirName, dirName, 255);
newDir->dirName[255] = '\0';
newDir->files = NULL;
newDir->parent = parent;
newDir->next = NULL;
newDir->subDirs = NULL;
return newDir;
}

// 새로운 서브 디렉토리를 현재 디렉토리에 추가합니다.
void addSubDirectory(const char* dirName) {
Directory* newDir = createDirectory(dirName, currentDir);
newDir->next = currentDir->subDirs;
currentDir->subDirs = newDir;
currentDir = newDir;
printf("New directory '%s' created and moved into it.\n", dirName);
}

// 현재 디렉토리를 상위 디렉토리로 이동합니다.
void moveToParentDirectory() {
if (currentDir->parent != NULL) {
currentDir = currentDir->parent;
printf("Moved to parent directory '%s'.\n", currentDir->dirName);
} else {
printf("Already in the root directory.\n");
}
}

// 현재 디렉토리의 서브 디렉토리로 이동합니다.
void moveToDirectory(const char* dirName) {
Directory* subDir = currentDir->subDirs;
while (subDir != NULL) {
if (strcmp(subDir->dirName, dirName) == 0) {
currentDir = subDir;
printf("Moved to directory '%s'.\n", dirName);
return;
}
subDir = subDir->next;
}
printf("Directory '%s' not found in current directory.\n", dirName);
}

// 새로운 파일을 생성합니다.
void newfile(const char* fileName) {
FileNode* newFile = createFileNode(fileName);
newFile->next = currentDir->files;
currentDir->files = newFile;
printf("File '%s' created successfully.\n", fileName);
}

// 클립보드 디렉토리를 비웁니다.
void clearClipboard() {
FileNode* current = clipboardDir->files;
while (current != NULL) {
FileNode* temp = current;
current = current->next;
free(temp);
}
clipboardDir->files = NULL;
}

// 파일을 현재 디렉토리에서 clipboard 디렉토리로 복사합니다.
void copy(const char* fileName) {
if (currentDir == clipboardDir) {
printf("Cannot copy files from the clipboard directory.\n");
return;
}

FileNode* current = currentDir->files;

while (current != NULL && strcmp(current->fileName, fileName) != 0) {
current = current->next;
}

if (current == NULL) {
printf("File '%s' not found in current directory.\n", fileName);
return;
}

// 클립보드 디렉토리를 비웁니다.
clearClipboard();

// 파일을 복사하여 clipboard 디렉토리로 이동합니다.
FileNode* copiedFile = createFileNode(fileName);
copiedFile->next = clipboardDir->files;
clipboardDir->files = copiedFile;
printf("File '%s' copied to clipboard.\n", fileName);
}

// 파일을 제거합니다.
void removeFile(const char* fileName) {
FileNode* prev = NULL;
FileNode* current = currentDir->files;

while (current != NULL && strcmp(current->fileName, fileName) != 0) {
prev = current;
current = current->next;
}

if (current == NULL) {
printf("File '%s' not found in current directory.\n", fileName);
return;
}

if (prev == NULL) {
currentDir->files = current->next;
} else {
prev->next = current->next;
}

free(current);
printf("File '%s' removed from current directory.\n", fileName);
}

// 파일을 현재 디렉토리로 붙여넣습니다.
void paste() {
if (clipboardDir->files == NULL) {
printf("Clipboard is empty.\n");
return;
}

FileNode* fileToPaste = clipboardDir->files;

// 파일을 현재 디렉토리로 이동합니다.
FileNode* pastedFile = createFileNode(fileToPaste->fileName);
pastedFile->next = currentDir->files;
currentDir->files = pastedFile;

// 클립보드를 비웁니다.
clearClipboard();

printf("File '%s' pasted to current directory.\n", pastedFile->fileName);
}

// 디렉토리 구조를 시각적으로 출력합니다.
void printDirectoryStructure(Directory* dir) {
printf("now - %s\n", dir->dirName);
FileNode* currentFile = dir->files;
while (currentFile != NULL) {
printf("|--- %s\n", currentFile->fileName);
currentFile = currentFile->next;
}

Directory* currentSubDir = dir->subDirs;
while (currentSubDir != NULL) {
printf("|--- <DIR> %s\n", currentSubDir->dirName);
currentSubDir = currentSubDir->next;
}
}

// 디렉토리 구조를 텍스트 파일에 저장합니다.
void saveDirectoryStructure(Directory* dir, FILE* file) {
if (dir == NULL) return;
fprintf(file, "DIR %s\n", dir->dirName);

FileNode* currentFile = dir->files;
while (currentFile != NULL) {
fprintf(file, "FILE %s\n", currentFile->fileName);
currentFile = currentFile->next;
}

Directory* currentSubDir = dir->subDirs;
while (currentSubDir != NULL) {
saveDirectoryStructure(currentSubDir, file);
currentSubDir = currentSubDir->next;
}
}

// 텍스트 파일로부터 디렉토리 구조를 읽어옵니다.
Directory* loadDirectoryStructure(FILE* file, Directory* parent) {
char line[512];
Directory* dir = NULL;
Directory* lastSubDir = NULL;
FileNode* lastFile = NULL;

while (fgets(line, sizeof(line), file) != NULL) {
char* token = strtok(line, " ");
if (strcmp(token, "DIR") == 0) {
char* dirName = strtok(NULL, "\n");
Directory* newDir = createDirectory(dirName, parent);
if (dir == NULL) {
dir = newDir;
} else if (lastSubDir != NULL) {
lastSubDir->next = newDir;
}
lastSubDir = newDir;

if (parent != NULL) {
newDir->next = parent->subDirs;
parent->subDirs = newDir;
}

loadDirectoryStructure(file, newDir);
} else if (strcmp(token, "FILE") == 0) {
char* fileName = strtok(NULL, "\n");
FileNode* newFile = createFileNode(fileName);
if (parent != NULL) {
if (lastFile == NULL) {
parent->files = newFile;
} else {
lastFile->next = newFile;
}
lastFile = newFile;
}
} else if (strcmp(token, "ENDDIR") == 0) {
break;
}
}
return dir;
}

// 사용자 입력에 따라 동작을 수행합니다.
void file_system() {
char command[256];
char fileName[256];
char dirName[256];

FILE* file = fopen("directory_structure.txt", "r");
if (file != NULL) {
rootDir = loadDirectoryStructure(file, NULL);
fclose(file);
} else {
rootDir = createDirectory("root", NULL);
clipboardDir = createDirectory("clipboard", rootDir);
rootDir->subDirs = clipboardDir; // 루트 디렉토리의 서브 디렉토리로 추가
}
currentDir = rootDir;

while (1) {
system("clear");
printDirectoryStructure(currentDir);
printf("\nEnter command (newfile, copy, paste, remove, mkdir, cd, exit): ");
scanf("%s", command);

if (strcmp(command, "newfile") == 0) {
printf("Enter file name to create: ");
scanf("%s", fileName);
newfile(fileName);
} else if (strcmp(command, "copy") == 0) {
printf("Enter file name to copy: ");
scanf("%s", fileName);
copy(fileName);
} else if (strcmp(command, "paste") == 0) {
paste();
} else if (strcmp(command, "remove") == 0) {
printf("Enter file name to remove: ");
scanf("%s", fileName);
removeFile(fileName);
} else if (strcmp(command, "mkdir") == 0) {
printf("Enter directory name to create: ");
scanf("%s", dirName);
addSubDirectory(dirName);
} else if (strcmp(command, "cd") == 0) {
printf("Enter directory name to move into: ");
scanf("%s", dirName);
if (strcmp(dirName, "..") == 0) {
moveToParentDirectory();
} else {
moveToDirectory(dirName);
}
} else if (strcmp(command, "exit") == 0) {
// 프로그램 종료 시 디렉토리 구조 저장
FILE* file = fopen("directory_structure.txt", "w");
if (file == NULL) {
perror("Failed to open file for writing");
exit(EXIT_FAILURE);
}
saveDirectoryStructure(rootDir, file);
fclose(file);
break;
} else {
printf("Invalid command.\n");
}
}
}
Binary file added miniOS/kernel/file_manage.o
Binary file not shown.
Loading