From: Luis F. <lui...@gm...> - 2007-10-30 12:56:47
|
Hello Peter You may define a struct like this: typedef struct FD { int fd; your_db_primary_key_type db; int used; } fd_t; and have a table like this: fd_t my_fds[some_proper_size]; and then the open function would do something like this: int fd =3D -1; your_db_primary_key_type db =3D (some_invalid_key); if (we_have_to_open_a_file) { fd =3D open(fname,fi->flags); (handle_errors()) } if (we_have_to_access_the_db) { db =3D your_db_open_function(); } if (no_error) { fi->fh =3D your_allocation_function(); if (no_error) { my_fds[fi->fh].fd =3D fd; my_fds[fi->fh].db =3D db; return(0); } } (handle other errors) return(-errno); Best Regards Luis Otavio Furquim 2007/10/30, Peter Buelow <pe...@pu...>: > > Allen Pulsifer wrote: > > Like I said, my fi->fh is a pointer to malloc'ed memory. It is not an > > integer. At this memory location I store a structure. You could do th= e > > same, and use that structure to store your open file descriptors, your > > database handles, your birthday and social security number or whatever > you > > find useful for satisfying read and write requests. > > > > > > > > > OK, so I apparently completely misunderstand how the fi->fh works then. > When is it malloc'd and free'd? What controls the allocated size? If > it's the case that it can be anything, then when an app calls man 3 > open, how does it get a descriptor back? > > Basically, when I call open, or fopen, or iostream::open, I get a > descriptor associated by the OS. I thought that was managed to some > degree by the fuse open association. Because of this, I wrote the simple > function below (some path management removed) that works great, and > returns a descriptor in fi->fh. > > int fs_open(const char *path, struct fuse_file_info *fi) > { > int eno =3D 0; > > if ((fi->fh =3D open(path, fi->flags)) < 0) { > eno =3D errno; > opqe_fs("open: %s: %s (%d)\n", full_path, strerror(errno), errno)= ; > return -eno; > } > > return 0; > } > > I assume this is wrong now, but if so, how should it work? > > -Pete > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > fuse-devel mailing list > fus...@li... > https://lists.sourceforge.net/lists/listinfo/fuse-devel > --=20 Luis Ot=E1vio de Colla Furquim N=E3o alimente os pingos Don't feed the tribbles http://www.furquim.org/chironfs/ |