티스토리 뷰
Dark Cloud 시스템을 만들면서 FUSE라는 것을 활용하게 되었는데,
FUSE는 유닉스 계열 OS에 적재할 수 있는 커널 모듈로 File System in Userspace의 약자이다.
FUSE를 이용하면 컴퓨터에 OS와 같은 권한이 아닌 사용자가 커널 코드를 편집하지 않고도 자신의 파일 시스템을 만들 수 있다.
즉, 유저레벨에서 파일시스템을 만들고 해당 파일시스템에 발생하는 이벤트들을 쉽게 처리할 수 있다는 의미이다.
다시말하면, 사용자 정의의 파일시스템을 만들고 파일시스템에 이벤트가 발생했을 때 ( open, read, write, close ) 사용자의 다른 이벤트로 우회시켜서 처리할 때 유용하다는 것이다. 이 점이 마음에 들어 FUSE를 활용하게 되었다.
ubuntu 에서 fuse를 활용하려면 먼저 설치를 해야한다.
$ sudo apt-get install libfuse-dev
이어서 fuse공식 사이트에 올라와있는 fuse 예제를 통해 FUSE를 이해해보자
hello.c /* fuse example source 작성 */
출처 : http://fuse.sourceforge.net/doxygen/index.html
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU GPL.
See the file COPYING.
*/
#define FUSE_USE_VERSION 30
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
static const char *hello_str = "Hello World!\n";
static const char *hello_path = "/hello";
static int hello_getattr(const char *path, struct stat *stbuf)
{
int res = 0;
memset(stbuf, 0, sizeof(struct stat));
if (strcmp(path, "/") == 0) {
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
} else if (strcmp(path, hello_path) == 0) {
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
stbuf->st_size = strlen(hello_str);
} else
res = -ENOENT;
return res;
}
off_t offset, struct fuse_file_info *fi)
{
(void) offset;
(void) fi;
if (strcmp(path, "/") != 0)
return -ENOENT;
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
filler(buf, hello_path + 1, NULL, 0);
return 0;
}
{
if (strcmp(path, hello_path) != 0)
return -ENOENT;
if ((fi->flags & 3) != O_RDONLY)
return -EACCES;
return 0;
}
static int hello_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
size_t len;
(void) fi;
if(strcmp(path, hello_path) != 0)
return -ENOENT;
len = strlen(hello_str);
if (offset < len) {
if (offset + size > len)
size = len - offset;
memcpy(buf, hello_str + offset, size);
} else
size = 0;
return size;
}
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
{
return fuse_main(argc, argv, &hello_oper, NULL);
}
$ mkdir mnt
$ ./hello mnt
$ cat mnt/hello
Hello World 메시지를 확인할 수 있다.
'Study > System >' 카테고리의 다른 글
Module 2: Data Center Environment (0) | 2013.04.24 |
---|---|
Module 1: Introduction to Information Storage (0) | 2013.04.22 |
LXR (0) | 2013.04.17 |
중첩 인터럽트(Nested Interrupt) (0) | 2013.04.01 |
O(1) 스케쥴러 vs CFS 스케쥴러 (0) | 2013.03.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- jakeyoon
- Developing on AWS
- GDG
- 안드로이드폰
- 릴레이대회본선
- 그래비트랙스
- 윤재석
- WatchFaceHack
- 하쭈서쭈
- GDG SSU
- 서버개발자
- AndroidWear
- 해커톤
- 리눅스2.6
- yjaeseok
- 리눅스 커널 2.6
- 소설네트워크2
- 핸즈온머신러닝
- 안드로이드
- Linux
- jaeseokyoon
- 창조경제혁신센터
- 리눅스
- 창의과학교구
- 리눅스 커널 2.6 구조와 원리
- Jake Yoon
- watchface
- gdgssu
- 숭실대
- gdg watchfacehack
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함