Opening Files in Resource Manager

Hi all,

I’m writing a resource manager in Neutrino that manages several files.
With some devctl()s, I need to access another file in my resource.
For example, if I have /foo/bar open, the devctl may require me to open
/baz/quux. Is there an easy way for me to get an OCB for the second
file, or do I have to maintain a list of files and traverse it
manually? I need to have a valid OCB for both files at the same time.

Cheers,
Kevin


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

“Kevin Lacquement” <klacquement@syscor.com> wrote in message
news:m27kx4mz73.fsf@aridhol.syscor.priv

Hi all,

I’m writing a resource manager in Neutrino that manages several files.
With some devctl()s, I need to access another file in my resource.
For example, if I have /foo/bar open, the devctl may require me to open
/baz/quux. Is there an easy way for me to get an OCB for the second
file, or do I have to maintain a list of files and traverse it
manually? I need to have a valid OCB for both files at the same time.

If you open a file from a resource manager the only thing you need to keep
track of is the fd of that file.

Cheers,
Kevin


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

“MC” == Mario Charest <> mcharest@zinformatic.com> > writes:

[…]

MC> If you open a file from a resource manager the only thing you need to keep
MC> track of is the fd of that file.

Argh…more coffee required.


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

“MC” == Mario Charest <> mcharest@zinformatic.com> > writes:

[…]

MC> If you open a file from a resource manager the only thing you need to keep
MC> track of is the fd of that file.

[…]

OK I’ve tried using fopen() and open() to open a file in my resource
manager. The file I’m trying to open is managed by the resource
manager. However, neither fopen() nor open() works. In both cases, I
receive a ‘failed’ return value (NULL for fopen() and -1 for open()).
However, in both cases, errno is still set to 0. When I trace the
program, my open callback doesn’t get called.

The cat program is able to read the file, so I don’t know what the
problem is. Anybody?


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

Previously, Kevin Lacquement wrote in comp.os.qnx:

OK I’ve tried using fopen() and open() to open a file in my resource
manager. The file I’m trying to open is managed by the resource
manager. However, neither fopen() nor open() works.

I think there must be some fundamental msunderstanding about
what you are trying to do. The meaning of “open” be it with
open() or fopen() is defined by a resource manager. When it
receives a message that requests it open something, it does
something that is internally defined. At the level of the
resource manager there are no files, except as defined by
that resource manager. So if your resource manager knows
how to open a file, it has an internal definition of what
that means, and should be able to execute it without
recourse to calling open().


The cat program is able to read the file, so I don’t know what the
problem is. Anybody?

Mitchell Schoenbrun --------- maschoen@pobox.com

“MS” == Mitchell Schoenbrun <> maschoen@pobox.com> > writes:

[…]

MS> I think there must be some fundamental msunderstanding about
MS> what you are trying to do. The meaning of “open” be it with
MS> open() or fopen() is defined by a resource manager. When it
MS> receives a message that requests it open something, it does
MS> something that is internally defined. At the level of the
MS> resource manager there are no files, except as defined by
MS> that resource manager. So if your resource manager knows
MS> how to open a file, it has an internal definition of what
MS> that means, and should be able to execute it without
MS> recourse to calling open().

One file has already been opened. I am currently processing a
devctl() call, which requires me to open another file, also managed by
my resource manager. It was previously suggested that, in order to do
this, I use open() or its relatives and keep the file descriptor. If
this is not the proper way, how can I access the file it wants?

Example:

The file “foo” is open. The devctl requires that the file “bar” be
opened. So, in the devctl(), I use the following line:

fd = open(fname, O_RDONLY);

Where fname is now “bar”, but was passed in via a message. However,
this open call fails by returning -1, but errno is still set to 0.


[…]

Cheers,
Kevin


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

“Kevin Lacquement” <klacquement@syscor.com> wrote in message
news:m2d76qvtlw.fsf@aridhol.syscor.priv

“MS” == Mitchell Schoenbrun <> maschoen@pobox.com> > writes:

[…]

MS> I think there must be some fundamental msunderstanding about
MS> what you are trying to do. The meaning of “open” be it with
MS> open() or fopen() is defined by a resource manager. When it
MS> receives a message that requests it open something, it does
MS> something that is internally defined. At the level of the
MS> resource manager there are no files, except as defined by
MS> that resource manager. So if your resource manager knows
MS> how to open a file, it has an internal definition of what
MS> that means, and should be able to execute it without
MS> recourse to calling open().

One file has already been opened. I am currently processing a
devctl() call, which requires me to open another file, also managed by
my resource manager. It was previously suggested that, in order to do
this, I use open() or its relatives and keep the file descriptor. If
this is not the proper way, how can I access the file it wants?

Example:

The file “foo” is open. The devctl requires that the file “bar” be
opened. So, in the devctl(), I use the following line:

fd = open(fname, O_RDONLY);

Where fname is now “bar”, but was passed in via a message. However,
this open call fails by returning -1, but errno is still set to 0.

This is very odd. If you write a test program can you open “bar” directly.
Are “bar” and “foo” handle by the same resource manager? If so
you have to be multi-threaded, is it?


[…]

Cheers,
Kevin


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

Kevin Lacquement (klacquement@syscor.com) wrote:
: >>>>> “MC” == Mario Charest <mcharest@zinformatic.com> writes:

: […]

: MC> If you open a file from a resource manager the only thing you need to keep
: MC> track of is the fd of that file.

: […]

: OK I’ve tried using fopen() and open() to open a file in my resource
: manager. The file I’m trying to open is managed by the resource
: manager. However, neither fopen() nor open() works. In both cases, I
: receive a ‘failed’ return value (NULL for fopen() and -1 for open()).
: However, in both cases, errno is still set to 0. When I trace the
: program, my open callback doesn’t get called.

: The cat program is able to read the file, so I don’t know what the
: problem is. Anybody?

You are asking for trouble by trying to have a thread in a resmgr
open a resource managed by the same resource manager – you are breaking
the send-hierarchy. Unless you are VERY careful you will shoot yourself
in the foot.

Why do you want to do this?

The other issue is that there’s a flag in resmgr_attach that allows you to
connect to yourself; unless you specify that flag you won’t be allowed to
connect to yourself, which is what you’re trying to do.

Connecting to yourself (he repeated) is a bad thing :slight_smile:

-RK

Robert Krten, PARSE Software Devices; email my initials at parse dot com
Consulting, Systems Architecture / Design, Drivers, Training, QNX 4 & Neutrino
Check out our new QNX 4 and Neutrino (QRTP) books at http://www.parse.com/
Wanted PDP-8/9/10/11/12 Systems/documentation/spare parts! Will trade books!

“MC” == Mario Charest <> mcharest@zinformatic.com> > writes:

[…]

MC> This is very odd. If you write a test program can you open “bar” directly.
MC> Are “bar” and “foo” handle by the same resource manager? If so
MC> you have to be multi-threaded, is it?

Yes, yes, and yes. It wouldn’t be so bad, except that the failures
don’t set errno, and the message never reaches my handler, or at least
doesn’t reach the callback functions that I have breakpointed.

Cheers,
Kevin


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey

“NS” == No Spam <> nospam@parse.com> > writes:

[…]


NS> You are asking for trouble by trying to have a thread in a resmgr
NS> open a resource managed by the same resource manager – you are breaking
NS> the send-hierarchy. Unless you are VERY careful you will shoot yourself
NS> in the foot.

NS> Why do you want to do this?

I need to receive information from the second file to process the
message in the first. I want to avoid keeping track of information
already held by procnto (eg the directory tree).

NS> The other issue is that there’s a flag in resmgr_attach that allows you to
NS> connect to yourself; unless you specify that flag you won’t be allowed to
NS> connect to yourself, which is what you’re trying to do.

Thanks, I see that now. It’s odd, though, that it wouldn’t set errno
when I tried this.

NS> Connecting to yourself (he repeated) is a bad thing :slight_smile:

It’s in a separate module; I can change it fairly easily once I figure
out a better way.

Cheers,
Kevin


He that breaks a thing to find out what it is has left the path of
wisdom – Gandalf the Grey