From: D.Edmons <dem...@co...> - 2007-06-07 07:51:11
|
Gerald, In case 1 you use strchr(), in case 2 you use strcmp(). I don't know what your filesystem uses to determine whether a file is a directory or not, but it seems to me that this is a problem that needs redesigned. As the gentleman said on the fuse-devel list, your myfs_mkdir() will only get called if the file doesn't already exist (myfs_getattr() returns -ENOEN). If you have a file already with that name, myfs_mkdir() won't generally get called. Do 'rmdir mydir', 'mkdir mydir' or just 'mkdir uniquename'. Then you should get it right. I do like cramfs does. I have a routine myfs_lookup(), that is called from myfs_getattr() which searches the directory entries for the path. If the entry is found it fills the stbuf, otherwise it returns -NOENT. Here is my myfs_getattr(). It is short, to the point, and works....well, I do have a couple of bugs I haven't figured out yet, but I don't get errors. /* modified --D.E. */ int rtxfs_real_getattr(const char *path, struct stat *stbuf) { fprintf(stdout, "rtxfs_real_getattr(): path = %s\n", path); /* debug */ rtxfs_inode_context *node_context = rtxfs_lookup(path); if(!node_context) { // this is too common to report each one return -ENOENT; } else { printf("rtxfs_real_getattr(): found %s, size %d\n", path, node_context->inode->size); /* debug */ } memset(stbuf, 0, sizeof(struct stat)); stbuf->st_ino = ENTRYNO2INODE(node_context->raw->entry_no); stbuf->st_mode = node_context->inode->mode; stbuf->st_uid = getuid(); stbuf->st_gid = getgid(); stbuf->st_size = node_context->raw->size * BLKSIZ; stbuf->st_blksize = BLKSIZ; stbuf->st_blocks = node_context->raw->size; // Native size is in blocks stbuf->st_nlink = 1; /* Should this be 2 for directories? */ #define RT11TIME 1179495000 /* debug */ stbuf->st_atime = RT11TIME; // When in doubt, fake it.... stbuf->st_ctime = RT11TIME; stbuf->st_mtime = RT11TIME; return 0; } I hope this helps. Dale Sur...@gm... wrote: > hi, > i its crazy getattr effects my mkdir! > mkdir is only called with this code in getattr: > if(strcmp(path, "/") == 0) { > stbuf->st_mode = S_IFDIR | 0755; > stbuf->st_nlink = 2; > } > else if(strcmp(path, hello_path) == 0) { > stbuf->st_mode = S_IFREG | 0444; > stbuf->st_nlink = 1; > stbuf->st_size = strlen(hello_str); > } > else > res = -ENOENT; > > without "else res = -ENOENT" mkdir is not called!!! hmmmm.... > i tried to set the attributes for default (see Screenshot-4.png), but still the case that mkdir is not called! any idea? > > the error which i get with case 1 is: > mkdir: cannot create directory 'tmp/fuse/SOS': File exists > the error which i get with case 2 is: > mkdir: cannot create directory 'tmp/fuse/SOS': No such file or directory > > case2 calls mkdir (i also can see it with ls) but not case1! i printed out to syslog when mkdir is called!!! > > Gerald > > static int hello_getattr(const char *path, struct stat *stbuf) > { > int res = 0; > > memset(stbuf, 0, sizeof(struct stat)); > > ///////////// case 1: mkdir doesnt work with this code /////////////////////// > /*stbuf->st_dev = 2; > //stbuf->st_ino = 0; > > if(strrchr(path,'.')) { > stbuf->st_mode = S_IFREG | 0755; > stbuf->st_size = 5389; > } > else > stbuf->st_mode = S_IFDIR | 0444; > > stbuf->st_nlink = 1; > //stbuf->st_uid = 0; > //stbuf->st_gid = 0; > //stbuf->st_rdev = 0; > //stbuf->st_blksize = 4096; > //stbuf->st_blocks = 16; > stbuf->st_atime = 1181118196; > stbuf->st_mtime = 1181118191; > stbuf->st_ctime = 1181118191;*/ > ////////////////////////////////////////////////////////////////////// > > > ////////////// case 2: mkdir only works with this code with -ENOENT ////////// > if(strcmp(path, "/") == 0) { > stbuf->st_mode = S_IFDIR | 0755; > stbuf->st_nlink = 2; > } > else if(strcmp(path, hello_path) == 0) { > stbuf->st_mode = S_IFREG | 0444; > stbuf->st_nlink = 1; > stbuf->st_size = strlen(hello_str); > } > else > res = -ENOENT; > ///////////////////////////////////////////////////////////////////// > > return res; > } > > static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, > off_t offset, struct fuse_file_info *fi) > { > (void) offset; > (void) fi; > adn_dir_info_t info = {0}; > struct dirent *dir_entry; > struct stat stbuf; > > if(strcmp(path, "/") != 0) > return -ENOENT; > > memset(&stbuf, 0, sizeof(stbuf)); > stbuf.st_dev = 2; > //stbuf.st_ino = 0; > stbuf.st_mode = S_IFDIR; > stbuf.st_nlink = 1; > stbuf.st_uid = 0; > stbuf.st_gid = 0; > stbuf.st_rdev = 0; > //stbuf.st_size = 5389; > //stbuf.st_blksize = 4096; > ///stbuf.st_blocks = 16; > stbuf.st_atime = 1181118196; > stbuf.st_mtime = 1181118191; > stbuf.st_ctime = 1181118191; > filler(buf, ".", &stbuf, 0); > filler(buf, "..", &stbuf, 0); > > strcpy(info.dirname, path); > fatfs_opendir(&info); > memset(&stbuf, 0, sizeof(stbuf)); > > while((dir_entry = fatfs_readdir(&info)) != NULL) { > stbuf.st_dev = 2; > //stbuf.st_ino = 0; > > if(strrchr(dir_entry->d_name,'.')) { > stbuf.st_size = 5389; > stbuf.st_mode = S_IFREG; > } > else > stbuf.st_mode = S_IFDIR; > > stbuf.st_nlink = 1; > stbuf.st_uid = 0; > stbuf.st_gid = 0; > stbuf.st_rdev = 0; > //stbuf.st_size = 5389; > //stbuf.st_blksize = 4096; > //stbuf.st_blocks = 16; > stbuf.st_atime = 1181118196; > stbuf.st_mtime = 1181118191; > stbuf.st_ctime = 1181118191; > > filler(buf, dir_entry->d_name, &stbuf, 0); > } > > fatfs_closedir(&info); > > return 0; > } > > static int hello_mkdir(const char *path, mode_t mode) > { > int res; > adn_dir_info_t info = {0}; > > > strcpy(info.dirname, path); > res = fatfs_mkdir(&info); > > return 0; <--- i send always 0, that means tell vfs my fs_mkdir works fine in any case, just for now! > } > > > -------- Original-Nachricht -------- > Datum: Wed, 06 Jun 2007 01:10:40 -0700 > Von: "D.Edmons" <dem...@co...> > An: Sur...@gm... > CC: fus...@li... > Betreff: Re: [fuse-devel] mounting a block device > > >> Gerald, >> >> I really have no way of knowing, but doing: >> ls -al TEST >> will be more helpful. Also, do: >> stat TEST >> and this will tell you what attributes are >> being set. You need to set your attributes >> when myfs_getattr() is called. Do: >> man fstat >> and this will give you an idea of what needs >> to be set, then start fixing one bug at a time. >> This will make things work much better. >> >> Next, after ls/stat looks better, check all of >> your error returns in myfs_mkdir(). If you are >> sending a return other than 0, then make certain >> it is for the right reason. >> >> This has been my approach and it seems to be >> a slow way to make progress, but it does seem >> to work until you know what needs to be done >> and why. >> >> The biggest help is to use man to tell you what >> the function is actually being used for. >> >> Dale >> >> Sur...@gm... wrote: >> >>> Hi, >>> i did integrated readdir and mkdir! all files and directories are red >>> >> because i didnt set the attibutes like time, date, filesize,... >> >>> do you why i get this strange error at mkdir? because the creation of >>> >> the directory works fine for my filesystem! >> >>> now i want to mount with a formated partition and not with the file as >>> >> blockdevice! how could i mount to a partition? do i need some code like open >> which i used for the file in the init function? >> >>> Gerald >>> >>> >>> >>> -------- Original-Nachricht -------- >>> Datum: Tue, 05 Jun 2007 08:10:09 -0700 >>> Von: "D.Edmons" <dem...@co...> >>> An: Sur...@gm... >>> CC: fus...@li... >>> Betreff: Re: [fuse-devel] mounting a block device >>> >>> >>> >>>> cramfs was a link on the fuse website where the list >>>> of drivers is. or do a google. or check sourceforge. >>>> >>>> If you want a new driver, you'll have to write it. >>>> >>>> Dale >>>> >>>> Sur...@gm... wrote: >>>> >>>> >>>>> Hi, >>>>> thanks for your answere! >>>>> where could i find the sources of cramfs? >>>>> why do you need to do that myfuse /dev/sdb ~/mnt -d ? what do i have >>>>> >> to >> >>>>> >>>>> >>>> do if i use a file as an blockdevice? >>>> >>>> >>>>> is it possible to manually mount a blockdice + mointpoint with >>>>> >>>>> >>>> fusermount? somthing like: fusermount -n devicename -m mountpoint ? >>>> >>>> >>>>> Gerald >>>>> >>>>> -------- Original-Nachricht -------- >>>>> Datum: Tue, 05 Jun 2007 00:36:33 -0700 >>>>> Von: "D.Edmons" <dem...@co...> >>>>> An: Sur...@gm... >>>>> CC: fus...@li... >>>>> Betreff: Re: [fuse-devel] mounting a block device >>>>> >>>>> >>>>> >>>>> >>>>>> Gerald, >>>>>> >>>>>> For me a real good example was cramfs. I've now got my fs >>>>>> up and running for the read section. I'm still working on the >>>>>> write section. I've got it about 80%, but still have major >>>>>> issues. >>>>>> >>>>>> In a nutshell, you can parse out your own options in your main(), >>>>>> then pass fuse_main() just what it needs. In your myfs_init() you >>>>>> can open your block device and away you go. >>>>>> >>>>>> I had to rewrite everything in the cramfs, but it was a good >>>>>> skeleton to start with. I just wish there was a very similar >>>>>> driver that was read/write. >>>>>> >>>>>> Then I compile and run: >>>>>> myfuse /dev/sdb ~/mnt -d >>>>>> but don't pass /dev/sdb to fuse_main(). I also add and >>>>>> option to fuse_main() so that the mount name is changed >>>>>> to /dev/sdb. >>>>>> >>>>>> Hope this helps. >>>>>> >>>>>> >>>>>> Dale E. Edmons >>>>>> >>>>>> >>>>>> Sur...@gm... wrote: >>>>>> >>>>>> >>>>>> >>>>>>> hi, >>>>>>> >>>>>>> could someone explain how to mount a blockdevice for fuse? i saw in >>>>>>> >> an >> >>>>>>> >>>>>>> >>>>>>> >>>>>> ext2 example: >>>>>> >>>>>> >>>>>> >>>>>>> static struct fuse_lowlevel_ops ext2fs_ops = { >>>>>>> .init = op_init >>>>>>> >>>>>>> they are doing a ext2fs_open in op_init: >>>>>>> ret = ext2fs_open(fs_device_name, >>>>>>> EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK, >>>>>>> 0, 0, unix_io_manager, &fs); >>>>>>> >>>>>>> could i just use a open? do i need a fuse_mount to set the >>>>>>> >> mountpoint >> >>>>>>> >>>>>>> >>>> in >>>> >>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> the blockdevice? why is fuse_mount not taking the file descriptor >>>>>> >> which >> >>>>>> >>>>>> >>>> i >>>> >>>> >>>>>> get from open? >>>>>> >>>>>> >>>>>> >>>>>>> is it possible to manually mount a blockdice + mointpoint with >>>>>>> >>>>>>> >>>>>>> >>>>>> fusermount? somthing like: fusermount -n devicename -m mountpoint ? >>>>>> >>>>>> >>>>>> >>>>>>> thanks, >>>>>>> Gerald >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>> >>>>> >>>>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> > > > > ------------------------------------------------------------------------ > |