Programming => Operating Systems => macOS / Mac OS X => Topic started by: inferno on November 24, 2019, 01:40:00 am
Title: manipulating file permissions and extended attributes on macOS
Post by: inferno on November 24, 2019, 01:40:00 am
Hi all, I need to read and edit files/directories permissions and extended attributes (both POSIX and ACL) on macOS platform (64bit Mojave 10.14 and Catalina/10.15) using OS calls, not CLI utilities (like chmod or xattr). For extended attributes I found this solution https://forum.lazarus.freepascal.org/index.php?topic=24096.0 (https://forum.lazarus.freepascal.org/index.php?topic=24096.0) but SysCall unit is not available on macOS. Any idea how to call syscall() on macOS? It is available in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h and also codes including those related to extended attributes are available in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/syscall.h
Any chance to port syscall.pp, syscall.inc, syscallh.inc and some other necessary *.inc files from FreeBSD to macOS/Darwin? I found that do_syscall() implementation (syscall.inc, syscallh.inc) for other operating systems are the assembler code...
For POSIX/ACL permissions there ara available C functions, but again - no units on macOS platform :(
For POSIX permissions I found some useful functions in BaseUnix unit which is fortunetly available on macOS: https://www.freepascal.org/docs-html/rtl/baseunix/fpaccess.html (https://www.freepascal.org/docs-html/rtl/baseunix/fpaccess.html) , https://www.freepascal.org/docs-html/rtl/baseunix/fpfstat.html (https://www.freepascal.org/docs-html/rtl/baseunix/fpfstat.html) , https://www.freepascal.org/docs-html/rtl/baseunix/fpchmod.html (https://www.freepascal.org/docs-html/rtl/baseunix/fpchmod.html) , https://www.freepascal.org/docs-html/rtl/baseunix/fpchown.html (https://www.freepascal.org/docs-html/rtl/baseunix/fpchown.html). But all of them use UID/GID only. Any idea how to get real names from UID/GID?
Also I though about another approach - calling all the above functions directly as a C code. I found this: ftp://ftp.freepascal.org/fpc/docs-pdf/CinFreePascal.pdf (http://ftp://ftp.freepascal.org/fpc/docs-pdf/CinFreePascal.pdf). Is it possible do use this technique on macOS?
Best regards, Inferno
Title: Re: manipulating file permissions and extended attributes on macOS
Post by: wittbo on November 25, 2019, 08:00:33 pm
I don't have any experience with SysCall or something else like this.
I have been used RunCommand (on MacOS!), which can execute every shell command. No problem. https://www.freepascal.org/docs-html/fcl/process/runcommand.html https://wiki.freepascal.org/Executing_External_Programs
Title: Re: manipulating file permissions and extended attributes on macOS
Post by: inferno on November 26, 2019, 01:06:16 pm
Thank wittbo, this approach works well also for me but I'm looking for a solution based on direct system function calls. It looks the only way is binding to macOS sytem libraries based on the Darwin headers...
Best regards, Inferno
Title: Re: manipulating file permissions and extended attributes on macOS
Post by: trev on December 03, 2019, 01:48:35 am