thomasf@qnx.com a écrit :
Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:
Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:
If I look at the doc, stat() is supposed to return 0 if the information
was successfully obtained and non 0 otherwise with errno setted.
If I look at the example, in the stat() doc chapter, I see that the
return of stat() is compared to -1 !?!
I think that the error is in the doc.
Now in my application, I want to verify if a mount point, declared by my
ressource manager exists.
So, I use stat() (Can I here?) and stat() return -1 but errno equals 0
!?!
Where is the true ?
POSIX sez:
5.6.2.3 Returns
Upon successful completion, a value of zero shall be returned. Otherwise
a value of -1 shall be returned and errno shall be set to indicate the
error.
Thomas
Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com > Neutrino Development Group
(613)-591-0931 > http://www.qnx.com/~thomasf
Ok, I made several tests on a registered pathname:
I want to test if /tmp/DataServer/databases/CP560_3.dat exists. It is
registered by my resource manager. And exists of course!
stat("/tmp" , &buf) returns 0
stat("/tmp/DataServer" , &buf) returns 0
stat("/tmp/DataServer/databases" , &buf) returns 0
stat("/tmp/DataServer/databases/CP560_3.dat" , &buf) returns -1, errno is
setted to 6 (No such device or address). Why ?
More importantly … did you provide an open handler?
Yes, see below.
If
you bind a properly filled in attribute structure in the
open handler and use the default stat structure then things
will just work.
stat(filename) is turned into
open() → connection message
stat() → fd/io message
close() → fd/io message.
Thomas
Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com > Neutrino Development Group
(613)-591-0931 > http://www.qnx.com/~thomasf
Ok, I find the problem but I don’t understand why.
My ocb_calloc function is not called on stat; So, I don’t have any
attribute
structure.
If I do a ls on this directory, io_open_database() and
database_ocb_calloc() are
called and everything is fine. my ocb_calloc() and ocb_free() are
calledBut, if I call stat() on this directory io_open_database() is not
called, same
for database_ocb_calloc().
It seems that calling stat() doesn’t generate an OPEN message!
I have the same problem for all my declared pathnames: directories and
files but
anything else works fine.
My pathname delcaration is:
static iofunc_funcs_t database_ocb_funcs = {
_IOFUNC_NFUNCS,
(void *)database_ocb_calloc,
database_ocb_free
};
static iofunc_mount_t database_mount = {0, 0, 0, 0,
&database_ocb_funcs};
void init(void)
{
datas_server_attr_t *database_attr_p;
if ((database_attr_p = malloc(sizeof(datas_server_attr_t))) == NULL)
{
exit(errno);
}
// This is the attribute structure initialization for the database
entry
(where we can see the databases files).
iofunc_attr_init(&database_attr_p->attr, S_IFDIR | 0555, 0, 0);
database_attr_p->device = PARAMETER_LIST + fd;
database_attr_p->attr.inode = fd;
database_attr_p->attr.nbytes = num_entries;
database_attr_p->attr.mount = &database_mount;
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs_database,
_RESMGR_IO_NFUNCS, &io_funcs_database);
connect_funcs_database.open = io_open_database;
io_funcs_database.read = io_read_database;
if (resmgr_attach(dpp, &resmgr_attr, attach_name, _FTYPE_ANY,
_RESMGR_FLAG_DIR, &connect_funcs_database, &io_funcs_database,
database_attr_p)
== -1) {
exit(errno);
}
}
int io_open_database(resmgr_context_t *ctp, io_open_t *msg,
RESMGR_HANDLE_T
*handle, void *extra) {
Tcl_HashEntry *nameHashEntry_p;
data_hash_t *data_hash = NULL;
//an empty path means a fully declared pathname. in the other case,
someone
open our directory
if (msg->connect.path[0] == 0) {
return(iofunc_open_default(ctp, msg, handle, extra));
} else if (nameHashEntry_p = Tcl_FindHashEntry(name_hash_table,
msg->connect.path)) {
// we look for the given name to know if we know it
data_hash = (data_hash_t *)Tcl_GetHashValue(nameHashEntry_p);
if (data_hash) {
// OK we allow to open this pathname
return(iofunc_open_default(ctp, msg, data_hash->iofunc_attr,
extra));
} else {
return(ENOENT);
}
} else {
return(ENOENT);
}
}
Thanks,
Alain.