ObjFW  Check-in [a19dde73d4]

Overview
Comment:Add support for extended attributes on FreeBSD
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a19dde73d4b5c33fc89a35b8ba44808382e56f06930f738cde78814a4e273fdd
User & Date: js on 2024-04-07 23:23:19
Other Links: manifest | tags
Context
2024-04-08
00:21
Don't depend on EXTATTR_NAMESPACE_NAMES on NetBSD check-in: e38777bbf2 user: js tags: trunk
2024-04-07
23:23
Add support for extended attributes on FreeBSD check-in: a19dde73d4 user: js tags: trunk
22:05
Add support for extended attributes on NetBSD check-in: 153f39636e user: js tags: trunk
Changes

Modified src/OFFileIRIHandler.m from [fa2705caf0] to [cf4978d29a].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#include <sys/time.h>
#if defined(OF_LINUX) || defined(OF_MACOS)
# include <sys/xattr.h>
#endif
#ifdef OF_NETBSD
# include <sys/extattr.h>
#endif
#ifdef OF_HAIKU
# include <ctype.h>
# include <kernel/fs_attr.h>
#endif
#ifdef OF_WINDOWS







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#include <sys/time.h>
#if defined(OF_LINUX) || defined(OF_MACOS)
# include <sys/xattr.h>
#endif
#if defined(OF_FREEBSD) || defined(OF_NETBSD)
# include <sys/extattr.h>
#endif
#ifdef OF_HAIKU
# include <ctype.h>
# include <kernel/fs_attr.h>
#endif
#ifdef OF_WINDOWS
153
154
155
156
157
158
159





160
161
162
163
164
165
166

#ifdef OF_WINDOWS
static int (*_wutime64FuncPtr)(const wchar_t *, struct __utimbuf64 *);
static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD);
static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR,
    LPSECURITY_ATTRIBUTES);
#endif






#ifdef OF_WINDOWS
static OFTimeInterval
filetimeToTimeInterval(const FILETIME *filetime)
{
	return (double)((int64_t)filetime->dwHighDateTime << 32 |
	    filetime->dwLowDateTime) / 10000000.0 - 11644473600.0;







>
>
>
>
>







153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

#ifdef OF_WINDOWS
static int (*_wutime64FuncPtr)(const wchar_t *, struct __utimbuf64 *);
static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD);
static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR,
    LPSECURITY_ATTRIBUTES);
#endif

#if defined(OF_FREEBSD) || defined(OF_NETBSD)
static const char *namespaces[] = EXTATTR_NAMESPACE_NAMES;
static int numNamespaces = sizeof(namespaces) / sizeof(*namespaces);
#endif

#ifdef OF_WINDOWS
static OFTimeInterval
filetimeToTimeInterval(const FILETIME *filetime)
{
	return (double)((int64_t)filetime->dwHighDateTime << 32 |
	    filetime->dwLowDateTime) / 10000000.0 - 11644473600.0;
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398

399

400

401
402
403

404

405

406
407
408
409
410
411
412

	return 0;
#else
	return statWrapper(path, buffer);
#endif
}

#ifdef OF_NETBSD
static void
parseAttributeName(OFString **name, int *namespace)
{
	size_t pos = [*name rangeOfString: @"."].location;
	OFString *namespaceName;


	if (pos == OFNotFound)
		@throw [OFInvalidArgumentException exception];

	namespaceName = [*name substringToIndex: pos];



	if (extattr_string_to_namespace(

	    [namespaceName cStringWithEncoding: [OFLocale encoding]],
	    namespace) == -1)
		@throw [OFInvalidArgumentException exception];



	*name = [*name substringFromIndex: pos + 1];

}
#endif

static void
setTypeAttribute(OFMutableFileAttributes attributes, Stat *s)
{
	if (S_ISREG(s->st_mode))







|





>





>

>
|
>
|
|
<
>
|
>
|
>







386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421
422
423

	return 0;
#else
	return statWrapper(path, buffer);
#endif
}

#if defined(OF_FREEBSD) || defined(OF_NETBSD)
static void
parseAttributeName(OFString **name, int *namespace)
{
	size_t pos = [*name rangeOfString: @"."].location;
	OFString *namespaceName;
	const char *cNamespace;

	if (pos == OFNotFound)
		@throw [OFInvalidArgumentException exception];

	namespaceName = [*name substringToIndex: pos];
	cNamespace = [namespaceName cStringWithEncoding: [OFLocale encoding]];

	*name = [*name substringFromIndex: pos + 1];

	for (int i = 0; i < numNamespaces; i++) {
		if (strcmp(namespaces[i], cNamespace) == 0) {
			*namespace = i;

			return;
		}
	}

	@throw [OFInvalidArgumentException exception];
}
#endif

static void
setTypeAttribute(OFMutableFileAttributes attributes, Stat *s)
{
	if (S_ISREG(s->st_mode))
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
690
691
692

			name += length + 1;
			size -= length + 1;
		}
	} @finally {
		OFFreeMemory(list);
	}
# elif defined(OF_NETBSD)
	names = [OFMutableArray array];

	for (size_t i = 0; extattr_namespaces[i] != 0; i++) {
		ssize_t size;
		char *list;

		if ((size = extattr_list_link(cPath, extattr_namespaces[i],
		    NULL, 0)) < 0)
			continue;

		list = OFAllocMemory(1, size);
		@try {
			OFString *namespace;
			char *cNamespace, *iter;

			if (extattr_namespace_to_string(
			    extattr_namespaces[i], &cNamespace) == -1)
				continue;

			namespace = [OFString stringWithCString: cNamespace
						       encoding: encoding];


			if ((size = extattr_list_link(cPath,
			    extattr_namespaces[i], list, size)) < 0)
				continue;

			iter = list;

			while (size > 0) {
				ssize_t length = *(unsigned char *)iter;
				OFString *name;







|


|



|
<




|
<
<
<
<
<
<
|
|
>

|
|







665
666
667
668
669
670
671
672
673
674
675
676
677
678
679

680
681
682
683
684






685
686
687
688
689
690
691
692
693
694
695
696
697

			name += length + 1;
			size -= length + 1;
		}
	} @finally {
		OFFreeMemory(list);
	}
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	names = [OFMutableArray array];

	for (int i = 0; i < numNamespaces; i++) {
		ssize_t size;
		char *list;

		if ((size = extattr_list_link(cPath, i, NULL, 0)) < 0)

			continue;

		list = OFAllocMemory(1, size);
		@try {
			OFString *namespace = [OFString






			    stringWithCString: namespaces[i]
				     encoding: encoding];
			char *iter;

			if ((size = extattr_list_link(cPath, i,
			    list, size)) < 0)
				continue;

			iter = list;

			while (size > 0) {
				ssize_t length = *(unsigned char *)iter;
				OFString *name;
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
		value = NULL;
	} @finally {
		OFFreeMemory(value);
	}

	if (type != NULL)
		*type = nil;
# elif defined(OF_NETBSD)
	int namespace;
	const char *cName;
	ssize_t size;

	parseAttributeName(&name, &namespace);
	cName = [name cStringWithEncoding: encoding];








|







1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
		value = NULL;
	} @finally {
		OFFreeMemory(value);
	}

	if (type != NULL)
		*type = nil;
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	int namespace;
	const char *cName;
	ssize_t size;

	parseAttributeName(&name, &namespace);
	cName = [name cStringWithEncoding: encoding];

1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_NETBSD)
	int namespace;
	const char *cName;

	if (size > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if (type != nil)







|







1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	int namespace;
	const char *cName;

	if (size > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if (type != nil)
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_NETBSD)
	int namespace;
	const char *cName;

	parseAttributeName(&name, &namespace);
	cName = [name cStringWithEncoding: encoding];

	if (extattr_delete_link(cPath, namespace, cName) != 0) {







|







1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	int namespace;
	const char *cName;

	parseAttributeName(&name, &namespace);
	cName = [name cStringWithEncoding: encoding];

	if (extattr_delete_link(cPath, namespace, cName) != 0) {

Modified src/OFFileManager.h from [575b6eb634] to [5fc4b31e8a].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    defined(OF_WINDOWS) || defined(DOXYGEN)
#  define OF_FILE_MANAGER_SUPPORTS_LINKS
# endif
# if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || \
    defined(OF_WINDOWS) || defined(DOXYGEN)
#  define OF_FILE_MANAGER_SUPPORTS_SYMLINKS
# endif
# if defined(OF_LINUX) || defined(OF_MACOS) || defined(OF_NETBSD) || \
    defined(OF_HAIKU) || defined(DOXYGEN)
#  define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
# endif
#endif

@class OFArray OF_GENERIC(ObjectType);
@class OFConstantString;
@class OFDate;







|
|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    defined(OF_WINDOWS) || defined(DOXYGEN)
#  define OF_FILE_MANAGER_SUPPORTS_LINKS
# endif
# if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || \
    defined(OF_WINDOWS) || defined(DOXYGEN)
#  define OF_FILE_MANAGER_SUPPORTS_SYMLINKS
# endif
# if defined(OF_LINUX) || defined(OF_MACOS) || defined(OF_FREEBSD) || \
    defined(OF_NETBSD) || defined(OF_HAIKU) || defined(DOXYGEN)
#  define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
# endif
#endif

@class OFArray OF_GENERIC(ObjectType);
@class OFConstantString;
@class OFDate;