little problems with stat

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 ?

Alain.

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

thomasf@qnx.com a écrit :

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 ?

I didn’t provide any io_stat() function.

thanks,
Alain.

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? 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

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.

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

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));

TF NOTE:
OK so in the case of looking at the mountpoint you are going to use
the fully initialized attribute which you have created in the init()
routine. This has the ocb calloc functions bound to the mount point
which is then “pointed to” by the attribute structure.

} 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));

TF NOTE:
So the big question here is … what information is in the
data_hash->iofunc_attr structure. I don’t see it being initialized
here, but the first thing to check would be to make sure that the
mount structure has been properly filled in in this attribute.
Drop it into the debugger and look at the structure and the values
of the data_hash->iofunc_attr and data_hash->iofunc_attr->mount
pointers. I’m willing to bet they aren’t properly initialized.

} else {
return(ENOENT);
}
} else {
return(ENOENT);
}
}



Thanks,
Alain.

Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com Neutrino Development Group
(613)-591-0931 http://www.qnx.com/~thomasf

thomasf@qnx.com a écrit :

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:

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));

TF NOTE:
OK so in the case of looking at the mountpoint you are going to use
the fully initialized attribute which you have created in the init()
routine. This has the ocb calloc functions bound to the mount point
which is then “pointed to” by the attribute structure.

} 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));

TF NOTE:
So the big question here is … what information is in the
data_hash->iofunc_attr structure. I don’t see it being initialized

here, but the first thing to check would be to make sure that the
mount structure has been properly filled in in this attribute.

Yes, each data_hash value is in fact registered as a file by my resource
manager and I store there attribute structure in a hash table.
These attribute structure are properly initialized by iofunc_attr_init().
My resource manager register several datas files in the directory databases.

Drop it into the debugger and look at the structure and the values
of the data_hash->iofunc_attr and data_hash->iofunc_attr->mount
pointers. I’m willing to bet they aren’t properly initialized.

My problem is in fact the same for each name declared by my resource manager.
the problem is that my resource manager doesn’t receive an io_open message,
so, it doesn’t allocate an ocb and doesn’t connect an attribute structure to
it so, the stat() function cannot received anything good!
What I didn’t say is that my resource manager (multi-threaded) received a
mount request to add a data file to my resource manager.
In my io_mount handler, I call stat() to know the given file is not yet
registered by my resource manager, the same who received the mount request. Is
it a problem?
I going to write a separate application to make a stat to my resource manager.

} else {
return(ENOENT);
}
} else {
return(ENOENT);
}
}

Thanks,
Alain.

Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com > Neutrino Development Group
(613)-591-0931 > http://www.qnx.com/~thomasf

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

if (resmgr_attach(dpp, &resmgr_attr, attach_name, _FTYPE_ANY,
_RESMGR_FLAG_DIR, &connect_funcs_database, &io_funcs_database,
database_attr_p)

In my io_mount handler, I call stat() to know the given file is not yet
registered by my resource manager, the same who received the mount request. Is
it a problem?

This is definitly a problem. I didn’t see RESMGR_FLAG_SELF flag is set in
above resmgr_attach() call, that is saying, your resource manager CAN NOT
open any name registed by itself.

I bet your stat() returns -1, with errno set to “No such file”.

-xtang

Xiaodan Tang a écrit :

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:

if (resmgr_attach(dpp, &resmgr_attr, attach_name, _FTYPE_ANY,
_RESMGR_FLAG_DIR, &connect_funcs_database, &io_funcs_database,
database_attr_p)

In my io_mount handler, I call stat() to know the given file is not yet
registered by my resource manager, the same who received the mount request. Is
it a problem?

This is definitly a problem. I didn’t see RESMGR_FLAG_SELF flag is set in
above resmgr_attach() call, that is saying, your resource manager CAN NOT
open any name registed by itself.

I bet your stat() returns -1, with errno set to “No such file”.

-xtang

Perfect! but could you give me the reason of this flag?

Thanks,
Alain.

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

Xiaodan Tang a ecrit :

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:

if (resmgr_attach(dpp, &resmgr_attr, attach_name, _FTYPE_ANY,
_RESMGR_FLAG_DIR, &connect_funcs_database, &io_funcs_database,
database_attr_p)

In my io_mount handler, I call stat() to know the given file is not yet
registered by my resource manager, the same who received the mount request. Is
it a problem?

This is definitly a problem. I didn’t see RESMGR_FLAG_SELF flag is set in
above resmgr_attach() call, that is saying, your resource manager CAN NOT
open any name registed by itself.

I bet your stat() returns -1, with errno set to “No such file”.

-xtang

Perfect! but could you give me the reason of this flag?

Deadlock. If it is your resource manager then you should be able to
do an internal lookup entirely within your manager to determine if
something is there or not without relying on the stat() operation.
If you aren’t careful about the operations that you do with the
SELF flag set it is very easy to get locked up.

Thomas

Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com Neutrino Development Group
(613)-591-0931 http://www.qnx.com/~thomasf

thomasf@qnx.com a écrit :

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:
Xiaodan Tang a ecrit :

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:

if (resmgr_attach(dpp, &resmgr_attr, attach_name, _FTYPE_ANY,
_RESMGR_FLAG_DIR, &connect_funcs_database, &io_funcs_database,
database_attr_p)

In my io_mount handler, I call stat() to know the given file is not yet
registered by my resource manager, the same who received the mount request. Is
it a problem?

This is definitly a problem. I didn’t see RESMGR_FLAG_SELF flag is set in
above resmgr_attach() call, that is saying, your resource manager CAN NOT
open any name registed by itself.

I bet your stat() returns -1, with errno set to “No such file”.

-xtang

Perfect! but could you give me the reason of this flag?

Deadlock. If it is your resource manager then you should be able to
do an internal lookup entirely within your manager to determine if
something is there or not without relying on the stat() operation.
If you aren’t careful about the operations that you do with the
SELF flag set it is very easy to get locked up.

Thomas

Thomas (toe-mah) Fletcher QNX Software Systems
thomasf@qnx.com > Neutrino Development Group
(613)-591-0931 > http://www.qnx.com/~thomasf

Ok, Thomas, the attribute structure, I think.

Thanks,
Alain.