Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:33:13+00:00 2026-05-26T19:33:13+00:00

i m trying to modify fuse example to mount any directory. I want to

  • 0

i m trying to modify fuse example to mount any directory. I want to mount /home/nikhil in tmp.
i ran it as,
$ ./ni /home/nikhil tmp

It mounts tmp folder, but cannot access it.

$ls -ltr tmp 

ls: cannot access tmp: Operation not permitted

$ ls -ltr

ls: cannot access delete: Operation not permitted
total 11716
d????????? ? ? ? ? ? delete

My code is

#define FUSE_USE_VERSION 26

#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>

#define MAX 100
char *rootpath;

static void ni_fullpath(char fpath[MAX], const char *path){
    strcpy(fpath, rootpath);
    strncat(fpath, path, MAX);
}

static int ni_getattr(const char *path, struct stat *stbuf)
{
int res = 0;
char fpath[MAX];
memset(stbuf, 0, sizeof(struct stat));
    ni_fullpath(fpath, path);
res = lstat(fpath, stbuf);
return res;
}

static int ni_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
         off_t offset, struct fuse_file_info *fi)
{
(void) offset;
(void) fi;
// i didnt understand this
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
    ni_fullpath(fpath, path);
filler(buf, fpath + 1, NULL, 0);

return 0;
}

static int ni_open(const char *path, struct fuse_file_info *fi)
{
int fd;
char fpath[MAX];
ni_fullpath(fpath, path);
if ((fi->flags & 3) != O_RDONLY)
    return -EACCES;

fd = open(fpath, fi->flags);
return fd;
}

static int ni_read(const char *path, char *buf, size_t size, off_t offset,
          struct fuse_file_info *fi)
{
return pread(fi->fh, buf, size, offset);

}

static struct fuse_operations ni_oper = {
.getattr    = ni_getattr,
.readdir    = ni_readdir,
.open       = ni_open,
.read       = ni_read,    
};


void ni_usage(){
fprintf(stderr, "usage ni rootDir mountPoint");
abort();
}

int main(int argc, char *argv[])
{
printf("%s %s \n", argv[1], argv[2]);
rootpath = realpath(argv[1], NULL);

argv[1] = argv[2];
argc--;
return fuse_main(argc, argv, &ni_oper, NULL);
}   

Can anybody help what i m doing wrong ?
I m using ubuntu 1104 64 bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:33:13+00:00Added an answer on May 26, 2026 at 7:33 pm

    How about using uninitialized var fpath instead of path?

    static int ni_getattr(const char *path, struct stat *stbuf)
    {
       int res = 0;
       char fpath[MAX];
       memset(stbuf, 0, sizeof(struct stat));
    
       res = lstat(fpath, stbuf);
       return res;
    } 
    

    You probably missed ni_fullpath(fpath, path);

    And as far as I understand the 0 should be returned in open callback if success, so it should look like:

       ....
       fd = open(fpath, fi->flags);
       if (fd < 0)
           return -errno;
       fi->fh = fd;
       return 0;
    }
    

    List operation should uses readdir callback, and in your case it has very limited application. It’d be better to start code on the basis of fusexmp. Check how readdir is implemented there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but
I'm currently trying to modify some HttpWebRequest functions, but I can't do it through
I am trying to modify the amcap, an application from Windows SDK's example to
I'm trying to modify a shopping cart (zencart) to do what I want, so
I'm trying to modify the contents of one pointer using another. I want string2
I am trying to modify Apple's PhotoScroller example and I encountered a problem that
I'm trying to modify the example in the requests library documentation to include a
I'm trying to modify an example of a simple forest plot by introducing facets
I'm trying to modify my test so that any database work is rolled back
I'm trying to modify a code not written by me, so I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.