Operating System - HP-UX
1751845 Members
5149 Online
108782 Solutions
New Discussion юеВ

How to get offset of a file in a raw device

 
E.A
Occasional Advisor

How to get offset of a file in a raw device

Hello everybody,

I'm looking for a C function, to get a file's position (offset) within a raw device.

My program currently searches through the device until it finds a specific string within a known file and returns the file's offset.
This is very inefficient, therefore I was wondering if there is a function to get the position of the file from the filesystem ?

Thank you very much in advance.







Change is the transformation of what is already known
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: How to get offset of a file in a raw device

I'm not sure if any of the pstat(2) functions will provide this? Are you using anything tricky like LVM, mirroring, etc?

Re: How to get offset of a file in a raw device

I'd imagine there'd be some way of getting the starting block of a file out of fsdb (see the man page for fsdb_vxfs), but that's *not* a C function, but a command (use with caution if you don't want to break your filesystem)

However just finding the starting block of a file won't necessarily help, as there's nothing to force the file to be contiguous on the disk, so unless you really understand the structure of the VxFS filesystem (and as Dennis pointed out, any underlying volume management software), I'm not sure you're going to be able to easily acheive this. To my knowledge the internal structure of VxFS and LVM/VxVM are *not* in the public domain, and there are no published interfaces to access these from user land.

Can I ask _why_ you want to do this?

HTH

Duncan

I am an HPE Employee
Accept or Kudo

Re: How to get offset of a file in a raw device

Dennis,

would pstat be aware of anything below VFS level? I wouldn't have expected it to have any knowledge of VxFS or a volume manager?

Duncan

I am an HPE Employee
Accept or Kudo
E.A
Occasional Advisor

Re: How to get offset of a file in a raw device

thanks for the quick replies and suggestions.

As Duncan said, it's possible to get the position of the file with fsdb.
My file will never exceed the blocksize of the filesystem, therefore it won't get "splitted".

And because fsdb is able to do it, I thought there might be a function to integrate in my program.

The program is doing several "measurements" with filesystems replicated by XP continous acces. There are some SLA requirements we need to observe and report, therefore I started to write this program, to make things easier.

Because the sVol is read only - I have to access the raw device to locate and analyse my monitored "testfile".
As I said, currently the program reads through the block device until it finds the unique (hopefully unique :-) ) string within the file - upon finding the string I can read everything I want from the file.
Basically all that works fine.

But everytime the binary searches through the device it unnecessarily generates a high i/o load.

So basically I have the possibility to access the filesystem functions on the p-Vol side and transmit the location of the file to the other program running on the s-Vol side. (Upon startup both programs establish a TCP connection, to exchange data)

I've looked into the pstat() documentation and it looks like it provides lots of file properties, but is not able to provide the offset of the underlying raw device.

I'm using vxfs with LVM.

I appreciating your time to help me.
Greetings
Change is the transformation of what is already known

Re: How to get offset of a file in a raw device

I really think you're going to struggle here...

I remember we talked in your other post:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1295679

about measuring the time taken to transfer a write from the pvol to the svol using pairsyncwait

are there additional measurements on top of this you need to make? what are they? maybe there's a better way of doing that.

incidentally you mention reading from the block device... I hop you're not doing that at the svol end as you will be using buffer cache - not a good thing when the svol is changing without the host being aware. I'd expect you'd need to use the raw device (which is probably harder but there you go...)

HTH

Duncan

I am an HPE Employee
Accept or Kudo
E.A
Occasional Advisor

Re: How to get offset of a file in a raw device

it seems like there is really no way to get the physical location of a file within a raw device. (...according to my research till now)
I'd like to stick on the solution through my own binary, because of personal education ;-)
I'm trying to raise my C skills.

Yes - I was talking about the raw device, sorry I confused it.

Please let me know, if somebody knows a function accessible through C, that does the desired job. But it seems that is not possible.

greetings




Change is the transformation of what is already known