FUSE를 처음다뤄보고있는데 어디가 문젠지 모르겠네요

Samuro의 이미지

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 지정에 문제는 없는지...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.