Amruta Gokhale
2009-12-06 19:55:44 UTC
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
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