FUSE를 처음다뤄보고있는데 어디가 문젠지 모르겠네요
글쓴이: Samuro / 작성시간: 금, 2015/06/19 - 10:17오후
truncate로 만들어낸 128MB disk.img에 퓨즈로 만들 파일시스템을 얹으려고 하는데 소스포지에 있는 퓨즈 예제를 봐도 모르겠네요.
지금은 일단 파일 읽기 쓰기만 되도록 만들고싶은데, 다른건 둘째치고 disk.img를 파일시스템을 얹을 저장장치로 쓰려면 어떻게 해야하나요?
지금 이상태로 실행하면 루트 디렉토리에 disk.img가 생기는데 main의 mount에서 에러가 발생합니다.
아니면 소스포지의 예제말고 .img를 사용한 예제나 도움될만한 글이라도 추천해주시면 감사하겠습니다.
makefile
OSP=osp ############################################################################### all: gcc -Wall -o $(OSP) $(OSP).c `pkg-config fuse --cflags --libs` mkdir $(OSP)_fs truncate -s 128M /disk.img ./$(OSP) $(OSP)_fs clean: fusermount -u $(OSP)_fs rmdir $(OSP)_fs rm -f /disk.img
소스
//Disk image path to use storage media static const char *dsk_path = "/disk.img"; ////////Global variables int fd_disk; ///////////////////Fuse operations static int osp_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, dsk_path + 1, NULL, 0); printf("readdir"); return 0; } static int osp_getattr(const char *path, struct stat *stbuf) { int res; res = lstat(path, stbuf); if (res == -1) return -errno; printf("getattr"); return 0; } static int osp_open(const char *path, struct fuse_file_info *fi) { int res; res = open(dsk_path, fi->flags); if (res == -1) return -errno; close(res); printf("open"); return 0; } /* static int osp_create(const char *path, mode_t mode, struct fuse_file_info *fi) { return 0; }*/ static int osp_mknod(const char *path, mode_t mode, dev_t rdev) { int res; if (S_ISREG(mode)) { res = open(dsk_path, O_CREAT | O_EXCL | O_WRONLY, mode); if (res >= 0) res = close(res); } else if (S_ISFIFO(mode)) res = mkfifo(dsk_path, mode); else res = mknod(dsk_path, mode, rdev); if (res == -1) return -errno; printf("mknod"); return 0; } static int osp_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { // int fd; int res; (void) fi; // fd_disk = open(dsk_path, O_RDONLY); if (fd_disk == -1) return -errno; res = pread(fd_disk, buf, size, offset); if (res == -1) res = -errno; // close(fd_disk); printf("read"); return res; } static int osp_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { // int fd; int res; (void) fi; //fd_disk = open(dsk_path, O_WRONLY); if (fd_disk == -1) return -errno; res = pwrite(fd_disk, buf, size, offset); if (res == -1) res = -errno; // close(fd_disk); printf("write"); return res; } //static int osp_chmod(const char static struct fuse_operations osp_ops = { .readdir = osp_readdir, .getattr = osp_getattr, .open = osp_open, .read = osp_read, .write = osp_write, //.create = osp_create, .mknod = osp_mknod, }; int main(int argc, char *argv[]) { int res; int mn; mn=mount("/disk.img","/","ext2",0,NULL); if(mn==-1) printf("ssibal error\n"); fd_disk = open(dsk_path, O_RDWR); if(fd_disk == -1) return -1; res = fuse_main(argc, argv, &osp_ops, NULL); printf("mainend"); close(fd_disk); return res; }
대충 이렇게생겼는데, mount함수를 맞세 사용한것인지, 다른 함수들의 path 지정에 문제는 없는지...
Forums:
댓글 달기