FUSE 샘플 코드가 이해가 안되서 질문합니다.
글쓴이: ygt / 작성시간: 목, 2008/12/04 - 9:15오후
/* 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. gcc -Wall `pkg-config fuse --cflags --libs` hello.c -o hello */ #define FUSE_USE_VERSION 26 #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; } static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, 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; } static int hello_open(const char *path, struct fuse_file_info *fi) { 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; } static struct fuse_operations hello_oper = { .getattr = hello_getattr, .readdir = hello_readdir, .open = hello_open, .read = hello_read, }; int main(int argc, char *argv[]) { return fuse_main(argc, argv, &hello_oper, NULL); }
<질문1> 먼저 퓨즈를 사용한 과제중임을 미리 밝힙니다. 하지만 무슨 과제 다 해주세요 이런 류는 아니고-_-; 직접 해보려는데 기초부터 이해가 잘 가지 않아서 도움을 받고 싶습니다.
퓨즈 받아서 설치하고 샘플 코드를 빈 폴더에 마운트 해보았습니다.
그런데 빈폴더에 hello 라는 파일이 생겨나더라구요.
그 내용은 처음 전역변수로 생성된 스트링이고...
제가 코드를 읽어보기로는 위의 4가지 함수는 전부 어떤 값을 읽어오는 것이지 값을 입력하는 역할이 아닌 것으로 생각되구요.
memcpy가 들어있는 read가 약간 수상하긴 하지만...이게 write도 아니구요. -_-;
어떤 과정으로 hello 파일이 생성된건지 알고 싶습니다.
fuse 에서 파일 create 를 구현해야하는데 저 과정을 알면 좀 힌트가 될 것 같습니다.
<질문2>
파일 오픈 할 때 보면
if ( (fi->flags & 3) != O_RDONLY)
이런 부분이 있는데 파일 열때 상황 별로 flag 값이 정해져있는것 같은데 어디가면 이런 것 표를 볼 수 있을까요?
Forums:
댓글 달기