Ticket #59124: patch-legacysupport-fsgetpath.diff
File patch-legacysupport-fsgetpath.diff, 6.2 KB (added by kencu (Ken), 5 years ago) |
---|
-
README.md
commit 5a75fd349b106b876e45b663aa0f60d87a80fff3 Author: Ken Cunningham <kencu@macports.org> Date: Sat Sep 28 17:48:27 2019 -0700 fsgetpath: implement replacement for 10.6+ needed for systems prior to 10.13 two methods of implementing fsgetpath are available we'll use the simpler syscall method for now other method is included in source, protected by blocker not simple to write a test for this at present diff --git a/README.md b/README.md index 8ad1092..95d9056 100644
a b Wrapped headers are: 93 93 <td>Adds <code>openat</code> function</td> 94 94 <td>OSX10.9</td> 95 95 </tr> 96 <tr> 97 <td><code>sys/fsgetpath.h</code></td> 98 <td>Adds missing <code>fsgetpath</code> function</td> 99 <td>OSX10.12</td> 100 </tr> 96 101 <tr> 97 102 <td><code>sys/mman.h</code></td> 98 103 <td>Adds missing <code>MAP_ANONYMOUS</code> definition</td> -
include/MacportsLegacySupport.h
diff --git a/include/MacportsLegacySupport.h b/include/MacportsLegacySupport.h index 1337a2a..65d2cb0 100644
a b 34 34 35 35 /* defines for when legacy support is required for various functions */ 36 36 37 /* fsgetpath */ 38 #define __MP_LEGACY_SUPPORT_FSGETPATH__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300) 39 37 40 /* clock_gettime */ 38 41 #define __MP_LEGACY_SUPPORT_GETTIME__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) 39 42 -
new file include/sys/fsgetpath.h
diff --git a/include/sys/fsgetpath.h b/include/sys/fsgetpath.h new file mode 100644 index 0000000..8dc4702
- + 1 /* 2 * Copyright (c) 2019 Ken Cunningham <kencu@macports.org> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef _MACPORTS_FSGETPATH_H_ 18 #define _MACPORTS_FSGETPATH_H_ 19 20 /* MP support header */ 21 #include "MacportsLegacySupport.h" 22 23 #if defined(__has_include_next) 24 #if __has_include_next(<sys/fsgetpath.h>) 25 26 /* Include the primary system sys/fsgetpath.h */ 27 #include_next <sys/fsgetpath.h> 28 29 #endif 30 #endif 31 32 #if __MP_LEGACY_SUPPORT_FSGETPATH__ 33 34 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 35 36 __MP__BEGIN_DECLS 37 extern ssize_t fsgetpath(char * __restrict buf, size_t bufsize, fsid_t* fsid, uint64_t objid); 38 __MP__END_DECLS 39 40 #else 41 #error "No implementation of fsgetpath is presently available for MacOSX prior to 10.6" 42 #endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 */ 43 44 #endif /* __MP_LEGACY_SUPPORT_FSGETPATH__ */ 45 46 #endif /* _MACPORTS_FSGETPATH_H_ */ -
new file src/fsgetpath.c
diff --git a/src/fsgetpath.c b/src/fsgetpath.c new file mode 100644 index 0000000..9b146db
- + 1 /* 2 * Copyright (c) 2019 Ken Cunningham <kencu@macports.org> 3 * from an example posted in Apple Developer Support 4 * https://forums.developer.apple.com/thread/103162 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 20 // MP support header 21 #include "MacportsLegacySupport.h" 22 #if __MP_LEGACY_SUPPORT_FSGETPATH__ 23 24 25 #if 1 26 /* implement using a syscall available macOS 10.6 to 10.12 */ 27 /* this should be thoroughly vetted as a syscall, but is private API */ 28 #include <unistd.h> 29 #include <sys/syscall.h> 30 #include <sys/types.h> 31 #include <sys/mount.h> 32 ssize_t fsgetpath(char * buf, size_t buflen, fsid_t * fsid, uint64_t obj_id) { 33 return (ssize_t)syscall(SYS_fsgetpath, buf, (size_t)buflen, fsid, (uint64_t)obj_id); 34 } 35 #endif 36 37 38 #if 0 39 /* implement with a compatability function that presently compiles on 10.6 and over */ 40 /* this may be better (see linked post above) but it's hard to thoroughly test it. */ 41 /* this may also be able to be expanded to cover 10.4 and 10.5 if we can workaround ATTR_CMN_FULLPATH */ 42 #include <stdio.h> 43 #include <errno.h> 44 #include <string.h> 45 #include <getopt.h> 46 #include <sys/attr.h> 47 #include <sys/mount.h> 48 49 ssize_t fsgetpath(char * buf, size_t buflen, fsid_t * fsid, uint64_t obj_id) { 50 char volfsPath[64]; // 8 for `/.vol//\0`, 10 for `fsid->val[0]`, 20 for `obj_id`, rounded up for paranoia 51 52 snprintf(volfsPath, sizeof(volfsPath), "/.vol/%ld/%llu", (long) fsid->val[0], (unsigned long long) obj_id); 53 54 struct { 55 uint32_t length; 56 attrreference_t pathRef; 57 char buffer[MAXPATHLEN]; 58 } __attribute__((aligned(4), packed)) attrBuf; 59 60 struct attrlist attrList; 61 memset(&attrList, 0, sizeof(attrList)); 62 attrList.bitmapcount = ATTR_BIT_MAP_COUNT; 63 attrList.commonattr = ATTR_CMN_FULLPATH; 64 65 int success = getattrlist(volfsPath, &attrList, &attrBuf, sizeof(attrBuf), 0) == 0; 66 if ( ! success ) { 67 return -1; 68 } 69 if (attrBuf.pathRef.attr_length > buflen) { 70 errno = ENOSPC; 71 return -1; 72 } 73 strlcpy(buf, ((const char *) &attrBuf.pathRef) + attrBuf.pathRef.attr_dataoffset, buflen); 74 return attrBuf.pathRef.attr_length; 75 } 76 #endif 77 78 #endif /* __MP_LEGACY_SUPPORT_FSGETPATH__ */