Recent

Author Topic: How to write bindings for a filesystem?  (Read 6038 times)

vicot

  • Full Member
  • ***
  • Posts: 114
How to write bindings for a filesystem?
« on: March 31, 2014, 09:28:52 pm »
Since my recent post about filesystem bindings (http://forum.lazarus.freepascal.org/index.php/topic,23818.msg142683.html#msg142683) received no answer, I guess I must conclude that no such bindings exist yet for FreePascal.

Now, the question is: how to write bindings for a filesystem? (especially for XFS)
Could you please provide some guidelines/examples?

Thanks

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: How to write bindings for a filesystem?
« Reply #1 on: April 02, 2014, 04:45:23 pm »
No idea, but presumably there is a c library you can use...
http://wiki.lazarus.freepascal.org/Creating_bindings_for_C_libraries
and more generally
http://wiki.lazarus.freepascal.org/Category:C
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

dgaspary

  • Jr. Member
  • **
  • Posts: 55
Re: How to write bindings for a filesystem?
« Reply #2 on: April 03, 2014, 02:34:58 am »
Fpc has a FUSE binding.

Maybe is a good starting point.

vicot

  • Full Member
  • ***
  • Posts: 114
Re: How to write bindings for a filesystem?
« Reply #3 on: April 03, 2014, 02:40:20 pm »
Fpc has a FUSE binding.
Maybe is a good starting point.

Well, I am not so sure. I am afraid it would only complicate matters, because FUSE is not simply a filesystem, but something more complex. But anyway I will look into it. Thanks for the advice.

I forgot to mention that most probably the common filesystem functionalities won't even require any bindings, as I suppose they are POSIX-compliant.
Basically, what I need boils down to bindings for two filesystem commands (only): set extended attribute and read extended attribute.  Just a few lines of code in all.

I guess that it would take about half an hour for an expert programmer to write, test and upload the bindings for these two commands. But unfortunately, I am a newbie, and I would not know where to begin from.

Anyone willing to help writing the bindings for those two commands for the XFS filesystem?

Thanks in advance

« Last Edit: April 03, 2014, 02:42:45 pm by vicot »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: How to write bindings for a filesystem?
« Reply #4 on: April 03, 2014, 05:42:56 pm »
I'm not a Linux user so excuse my confusion and ignorance.

Basically, what I need boils down to bindings for two filesystem commands (only): set extended attribute and read extended attribute.  Just a few lines of code in all.
Are you talking about getxattr and setxattr? if so, both are already available to you using system calls. They should work on XFS as well (based on your kernel version?).

Edit:
For instance getxattr:
Code: [Select]
ssize_t getxattr(const char *path, const char *name, void *value, size_t size);
maybe:
Code: [Select]
uses
  BaseUnix, SysCall;
...
function fpgetxatt(path: pchar; name: pchar; value: pointer; size: size_t): ssize_t;
begin
  fpGetXAtt := do_syscall(syscall_nr_getxattr, TSysParam(path), TSysParam(name), TSysParam(value), TSysParam(size));
end;
« Last Edit: April 03, 2014, 06:13:24 pm by engkin »

vicot

  • Full Member
  • ***
  • Posts: 114
Re: How to write bindings for a filesystem?
« Reply #5 on: April 03, 2014, 08:40:53 pm »
Are you talking about getxattr and setxattr? if so, both are already available to you using system calls. They should work on XFS as well (based on your kernel version?).

Yes, I was talking about those! Thank you very, very much. If it works, you solved my problem.

Only one thing, are you sure that it should work for all filesystems, including XFS? I am asking because the way extended attributes (xattrs) are managed might be specific to a particular filesystem (unlike standard attributes such as date, time, permissions, whose management is guaranteed to be fully standardized).

« Last Edit: April 03, 2014, 09:26:28 pm by vicot »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: How to write bindings for a filesystem?
« Reply #6 on: April 03, 2014, 09:42:01 pm »
are you sure that it should work for all filesystems, including XFS?
According to extended attributes manual:
Quote
Currently, support for extended attributes is implemented on Linux by the ext2, ext3, ext4, XFS, JFS and reiserfs filesystems.
and if you scroll down that same page to the section titled FILESYSTEM DIFFERENCES:
Quote
In the XFS and reiserfs filesystem implementations, there is no practical limit on the number or size of extended attributes associated with a file, and the algorithms used to store extended attribute information on disk are scalable.

vicot

  • Full Member
  • ***
  • Posts: 114
Re: How to write bindings for a filesystem?
« Reply #7 on: April 03, 2014, 10:09:50 pm »
are you sure that it should work for all filesystems, including XFS?
According to extended attributes manual:
Quote
Currently, support for extended attributes is implemented on Linux by the ext2, ext3, ext4, XFS, JFS and reiserfs filesystems.
and if you scroll down that same page to the section titled FILESYSTEM DIFFERENCES:
Quote
In the XFS and reiserfs filesystem implementations, there is no practical limit on the number or size of extended attributes associated with a file, and the algorithms used to store extended attribute information on disk are scalable.

Excellent!!

One more question: is there any disadvantage in using a system call as opposed to having a direct binding? For example, in terms of performance.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: How to write bindings for a filesystem?
« Reply #8 on: April 03, 2014, 10:51:42 pm »
I don't know, but from what I read I really doubt it. Basically XFS is part of Linux kernel. Using a system call is the direct way to interact with it.

vicot

  • Full Member
  • ***
  • Posts: 114
Re: How to write bindings for a filesystem?
« Reply #9 on: April 04, 2014, 11:29:37 pm »
Just for the sake of completeness: I have just asked the last question on the Linux Questions forum, and the answer was that the difference in performance is insignificant.

 

TinyPortal © 2005-2018