Lazarus

Programming => General => Topic started by: vicot on March 31, 2014, 09:28:52 pm

Title: How to write bindings for a filesystem?
Post by: vicot 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
Title: Re: How to write bindings for a filesystem?
Post by: BigChimp 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
Title: Re: How to write bindings for a filesystem?
Post by: dgaspary on April 03, 2014, 02:34:58 am
Fpc has a FUSE binding.

Maybe is a good starting point.
Title: Re: How to write bindings for a filesystem?
Post by: vicot 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

Title: Re: How to write bindings for a filesystem?
Post by: engkin 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 (http://man7.org/linux/man-pages/man2/fgetxattr.2.html) and setxattr (http://man7.org/linux/man-pages/man2/setxattr.2.html)? 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;
Title: Re: How to write bindings for a filesystem?
Post by: vicot on April 03, 2014, 08:40:53 pm
Are you talking about getxattr (http://man7.org/linux/man-pages/man2/fgetxattr.2.html) and setxattr (http://man7.org/linux/man-pages/man2/setxattr.2.html)? 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).

Title: Re: How to write bindings for a filesystem?
Post by: engkin 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 (http://man7.org/linux/man-pages/man5/attr.5.html):
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 (http://man7.org/linux/man-pages/man5/attr.5.html#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.
Title: Re: How to write bindings for a filesystem?
Post by: vicot 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 (http://man7.org/linux/man-pages/man5/attr.5.html):
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 (http://man7.org/linux/man-pages/man5/attr.5.html#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.
Title: Re: How to write bindings for a filesystem?
Post by: engkin 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.
Title: Re: How to write bindings for a filesystem?
Post by: vicot 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