Discussion:
[fuse-devel] Using my own inodes with FUSE
Amruta Gokhale
2009-12-06 19:55:44 UTC
Permalink
Hi,

I am implementing a simple file system which supports a single directory
(i.e. the root directory "/") and any number of files with read/write
support. I am creating and maintaining my own inodes. I am trying to get
this working with FUSE. But I am unable to make FUSE recognize my own
inodes. i.e. I can get this working, if I comment out the code related to
inodes. I am giving below the code for getattr() and readdir(). If anyone
could point out what's going wrong, I would really appreciate it.

Also, while running the program, I give the option "-o use_ino" to let the
filesystem create its inodes.

//This corresponds to the function getattr(). The inode-related functions
such as get_inodeNumber()
//and read_inode are implemented by me. One can assume that there is an
inode API which manages
//the inodes.
static int dfs_getattr(const char *path, struct stat *stbuf)
{
int inodeNumber;
inode_t inode;

// get the inode number from inode table
inodeNumber = get_inodeNumber((char *)path);

//If inode number is -1, it means that the path does not exist
if (inodeNumber == -1)
{
return -ENOENT;
}

// read inode information
inode = read_inode(inodeNumber);

// reset memory for the stat structure
memset(stbuf, 0, sizeof(struct stat));

// inode number
stbuf->st_ino = inodeNumber;

// total size, in bytes
stbuf->st_size = inode.size;

// file permissions and type
if (inode.type == REGULAR) // regular file
{
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
}
else // directory
{
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
}

// block size for filesystem I/O
//stbuf->st_blksize = inode.size;

// number of blocks allocated
stbuf->st_blocks = inode.numberOfBlocks;

// time of last access
stbuf->st_atime = inode.lastAccessed;

// time of last modification
stbuf->st_mtime = inode.lastModified;

// time of last status change
stbuf->st_ctime = inode.lastModifiedInode;

return 0;
}

//This corresponds to the readdir() function.
static int dfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
int i, max_inodeNumber;
char *filename;
struct stat stbuf;

if(strcmp(path, "/") != 0)
return -ENOENT;

filler(buf, ".", &stbuf, 0);
filler(buf, "..", NULL, 0);

//For each entry in inode table, extract file name and add it

max_inodeNumber = get_currentinode();
for(i=1; i <= max_inodeNumber; i++)
{
filename = get_filename(i);
if(strcmp(filename, "/") != 0)
{
filler(buf, filename, NULL, 0);
}
}
return 0;
}

Thanks,
Amruta
Nikolaus Rath
2009-12-07 14:36:21 UTC
Permalink
Post by Amruta Gokhale
I am implementing a simple file system which supports a single directory
(i.e. the root directory "/") and any number of files with read/write
support. I am creating and maintaining my own inodes. I am trying to get
this working with FUSE. But I am unable to make FUSE recognize my own
inodes. i.e. I can get this working, if I comment out the code related to
inodes. I am giving below the code for getattr() and readdir(). If anyone
could point out what's going wrong, I would really appreciate it.
It would probably be easier to help you if you would tell us exactly
*what* is "not working", i.e. what you mean by FUSE not recognizing your
inodes.


Best,


-Nikolaus
--
»Time flies like an arrow, fruit flies like a Banana.«

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
Amruta Gokhale
2009-12-07 19:49:35 UTC
Permalink
hanks for the quick reply.
As I understand it, FUSE uses and assigns its own inode numbers to the files
and directories.
And to override this and make FUSE use my inode implementation, I need to
give "-o use_ino" option.

What is not working is my inode implementation. So if I comment out my code
related to inodes,
everything works fine, and I can see the inode number assigned by FUSE.

For example, I create a directory "tmp" which would be the mount point for
my filesystem.
My program binary is named "dfs" which I run next.

Output without my inode implementation:
bash$mkdir tmp
bash$./dfs tmp
bash$ls -li
1 drwxr-xr-x 2 root root 0 1969-12-31 19:00 tmp
^^^ inode number assigned by FUSE

bash$mkdir tmp
bash$./dfs -o use_ino tmp
bash$ls -li
ls: cannot access tmp: No such file or directory
2613945 d????????? ? ? ? ? ? tmp
^^^^^ This was the inode number assigned by linux FS to the "tmp" directory.
I had assigned inode number "1" to the root directory. And I had other
information
stored in my inode. But none of this information is visible here.

Whey I tried debugging, the getattr() function prints the correct inode
information as I want, if I insert
some print statements. I am unable to understand why this doesn't work then.

Is there something special that I should do for using my own inodes
implementation?
Something like, do I need to implement functions in fuse__lowlevel__ops
structure?
Is there an example filesystem source code available, which implements its
own inodes and uses FUSE?

Thanks much in advance.
Amruta
Post by Nikolaus Rath
Post by Amruta Gokhale
I am implementing a simple file system which supports a single directory
(i.e. the root directory "/") and any number of files with read/write
support. I am creating and maintaining my own inodes. I am trying to get
this working with FUSE. But I am unable to make FUSE recognize my own
inodes. i.e. I can get this working, if I comment out the code related to
inodes. I am giving below the code for getattr() and readdir(). If anyone
could point out what's going wrong, I would really appreciate it.
It would probably be easier to help you if you would tell us exactly
*what* is "not working", i.e. what you mean by FUSE not recognizing your
inodes.
Best,
-Nikolaus
--
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
Nikolaus Rath
2009-12-08 02:31:27 UTC
Permalink
Post by Amruta Gokhale
As I understand it, FUSE uses and assigns its own inode numbers to the files
and directories.
And to override this and make FUSE use my inode implementation, I need to
give "-o use_ino" option.
That is correct.
Post by Amruta Gokhale
Is there something special that I should do for using my own inodes
implementation?
Something like, do I need to implement functions in fuse__lowlevel__ops
structure?
No, nothing like that is necessary.
Post by Amruta Gokhale
What is not working is my inode implementation.
bash$mkdir tmp
bash$./dfs -o use_ino tmp
bash$ls -li
ls: cannot access tmp: No such file or directory
2613945 d????????? ? ? ? ? ? tmp
^^^^^ This was the inode number assigned by linux FS to the "tmp" directory.
I had assigned inode number "1" to the root directory. And I had other
information
stored in my inode. But none of this information is visible here.
Whey I tried debugging, the getattr() function prints the correct
inode information as I want, if I insert some print statements. I am
unable to understand why this doesn't work then.
Since you are not able to understand why it does not work, I am
surprised that you still feel confident to judge if getattr() prints the
correct information.

If you want other people to help you, you really have to give them the
chance to look at the actual code and actual data rather than your
interpretations of them.

So I recommend that you either reduce your problem to a *short* example
file system that we can run and reproduce the problem ourselves (this is
always the best way to get help) or at least tell us *how* you debugged
the problem, *what* print statements you inserted *where*, and *what
exactly* they print when the fs is running.
Post by Amruta Gokhale
Is there an example filesystem source code available, which implements its
own inodes and uses FUSE?
Not that I know of, at least not a simple example.


Best,

-Nikolaus
--
»Time flies like an arrow, fruit flies like a Banana.«

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
Loading...