Lazarus
Programming => General => Topic started 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
-
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
-
Fpc has a FUSE binding.
Maybe is a good starting point.
-
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
-
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:
ssize_t getxattr(const char *path, const char *name, void *value, size_t size);
maybe:
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;
-
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).
-
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):
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):
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.
-
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):
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):
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.
-
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.
-
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.