David Gibbs a écrit :
Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:
David Gibbs a ecrit :
Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:
I have a resource manager providing some pseudo files with different
sizes.
If I tried to open one of these files with Ped, my resource manager
enter in my io_read function with an offset setted to a strange value if
the size of the file is bigger that 42 bytes !?! and in that case,
iofunc_attr_p->nbytes - tocb->ocb.offset is always equal to 42 !!!
Any idea?
I think ped throws some formatting/highlighting type information at or
near the end of the file. I would bet that the header/size of the
initial information it looks at to check is 42 bytes, and it expects
it to be at the end of the file.
So, it seeks to the end, then reads the last 42 bytes to check if it
has saved attribute informaton there.
!!!??!! Maybe !!??!!
The last line of block styled file is:
#** PhEDIT attribute block ends (-0000163)**/
So, if the offset read index is first placed at the end of the file,
rewinding it of 42 characters place it on ‘P’ !
But I don’t understand the problem. If it works on a regular file, with or
without block syle, and it don’t works with my resource manager, I certainly
do something wrong in my replying, no?
Probably – you didn’t mention that there was actually an error/problem
reported by ped in your initial post, just that you got a strange-looking
initial read from the file, and I was explaining why I thought that happened.
If ped is having some sort of problem/error, then probably yes you are
doing something wrong in how you reply to it, but without out more details
on what ped is complaining about, or what you are actually doing, it is
hard to diagnose.
-David
QNX Training Services
dagibbs@qnx.com
In fact, I don’t know if ped complains about something, what I can say is that I
see the file I want to read from my server if its size is lower than 42 bytes. In
that case everything works fine in my server. If the file size is bigger than 42
bytes, Ped is blocked and I don’t see my file in the edit window. In that case,
during the first execution of my io_read handler, offset is not set to 0 so, I
can’t do the work that I need to do correctly and I can’t reply correctly.
in my handler, I assume that the first call to io_read must be done with offset to
0, maybe I’m wrong!
this is my io_read handler:
int io_read_database(resmgr_context_t *ctp, io_read_t *msg, datas_server_ocb_t
*tocb)
{
int nbytes, nleft, nparts;
iofunc_attr_t *iofunc_attr_p = (iofunc_attr_t *)(&tocb->ocb.attr->attr);
char *reply_msg = NULL;
if (optv) {
printf("%s: in io_read_database for %s\n", progname,
basename(database_path[0]));
}
if ((status = iofunc_read_verify(ctp, msg, &tocb->ocb, NULL)) != EOK) {
return(status);
}
if (S_ISDIR(iofunc_attr_p->mode)) {
return(io_read_records_list(ctp, msg, tocb));
} else if (S_ISREG(iofunc_attr_p->mode)) {
// no special xtypes
if (msg->i.xtype & _IO_XTYPE_MASK != _IO_XTYPE_NONE) {
return(ENOSYS);
}
if ((iofunc_attr_p->nbytes - tocb->ocb.offset) == 42) {
printf(" THE bug is comming back nbytes = %d, offset = %d\n",
(int)iofunc_attr_p->nbytes, (int)tocb->ocb.offset);
}
//figure out how many bytes are left
nleft = iofunc_attr_p->nbytes - tocb->ocb.offset;
// and how many bytes we can return to the client
nbytes = min(nleft, msg->i.nbytes);
if (nbytes) {
data_hash_t *data_hash;
if (tocb->record_buffer.name == NULL) {
// This is the case if we execute this function for the first time
for this access; look if we know the device
data_hash = (data_hash_t *)Tcl_GetHashValue((Tcl_HashEntry
*)((int)iofunc_attr_p->inode));
if (data_hash) {
if ((reply_msg = (char *) calloc(1, iofunc_attr_p->nbytes)) ==
NULL) {
return(errno);
}
pthread_rwlock_wrlock(&tocb->record_buffer_rwlock);
if (read_record(&tocb->record_buffer, data_hash) != 0) {
pthread_rwlock_unlock(&tocb->record_buffer_rwlock);
free(reply_msg);
reply_msg = NULL;
return(EFAULT);
}
} else {
free(reply_msg);
reply_msg = NULL;
return(EINVAL);
}
//create the output string
concatenate_database_record(&tocb->record_buffer, reply_msg);
}
SETIOV(ctp->iov, reply_msg +tocb->ocb.offset, nbytes);
_IO_SET_READ_NBYTES(ctp, nbytes);
// return it back to the client
//MsgReply(ctp->rcvid, nbytes, reply_msg + tocb->ocb.offset, nbytes);
//update flags and offset
iofunc_attr_p->flags |= IOFUNC_ATTR_ATIME | IOFUNC_ATTR_DIRTY_TIME;
tocb->ocb.offset += nbytes;
nparts = 1;
} else {
free(reply_msg);
reply_msg = NULL;
free_record_buffer(&tocb->record_buffer);
pthread_rwlock_trywrlock(&tocb->record_buffer_rwlock);
pthread_rwlock_unlock(&tocb->record_buffer_rwlock);
_IO_SET_READ_NBYTES(ctp, 0);
nparts = 0;
}
return(_RESMGR_NPARTS(nparts));
} else {
return(EBADF);
}
}
Thanks,
Alain.