Check-in [a0455de065]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:StorageKit: XAttr support: take advantage of Genode's xattr support (ticket 4346) and Genode's VFS plug-in for NTFS (currently "vfs_fuse.lib.so" but will be renamed to "vfs_fuse-ntfs.lib.so") being introduced in ticket genode-world:193, augmented with my patch for NTFS-native xattr support... And use those to (finally) get attribute read/write support in HoG :-) Details: - unearthed some important Haiku FIXME's, e.g. two instances of upstream code allocating 10+ KB on the stack (!) ; - fs_attr_extattr.h will host the Genode ioctl opcodes, until the ticket is resolved and a proper home is found for them ; - function _kern_open_attr_dir() had mismatching header and implementation signatures, had to fix that for the code to link ; maybe upstream does not see that problem because they don't need to resolve that symbol at link time, or use the (generic) stub ? ; - add (back) handling of AHCI block device/image in Qemu ; - augment "jam t6" test level with vfs_fuse.lib.so and an NTFS test image ; TESTS: we pass all attribute tests in Qemu, yay. Next up, an attribute indexer to support BQuery (and will have to bring BFS r/o support up to date too).
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a0455de065f4e6c9101c10f3515df39ad249cea1
User & Date: ttcoder 2021-12-29 11:21:50.656
Context
2022-01-08
17:15
Indexer: this new component will allow us to support BQuery ; first steps: the 'skeleton' is mostly complete, already can snoop on attribute creation/change/deletion ; will implement storage and querying next. check-in: 388b73909b user: ttcoder tags: trunk
2021-12-29
11:21
StorageKit: XAttr support: take advantage of Genode's xattr support (ticket 4346) and Genode's VFS plug-in for NTFS (currently "vfs_fuse.lib.so" but will be renamed to "vfs_fuse-ntfs.lib.so") being introduced in ticket genode-world:193, augmented with my patch for NTFS-native xattr support... And use those to (finally) get attribute read/write support in HoG :-) Details: - unearthed some important Haiku FIXME's, e.g. two instances of upstream code allocating 10+ KB on the stack (!) ; - fs_attr_extattr.h will host the Genode ioctl opcodes, until the ticket is resolved and a proper home is found for them ; - function _kern_open_attr_dir() had mismatching header and implementation signatures, had to fix that for the code to link ; maybe upstream does not see that problem because they don't need to resolve that symbol at link time, or use the (generic) stub ? ; - add (back) handling of AHCI block device/image in Qemu ; - augment "jam t6" test level with vfs_fuse.lib.so and an NTFS test image ; TESTS: we pass all attribute tests in Qemu, yay. Next up, an attribute indexer to support BQuery (and will have to bring BFS r/o support up to date too). check-in: a0455de065 user: ttcoder tags: trunk
2021-10-29
13:06
Genode 21.08 support: - Use new LibC foldername/hash in jam files ; - Modify USB-HID usage in jam files (the monolithic all-in-one usb_drv has been retired, must now package and refer to 2 distinct components, "usb_host_drv" and "usb_hid_drv") ; - TESTING: the past few weeks I had succeeded in getting USB mouse/kbd to work on my T410 (probably with the "bios handover" flag?), will test to check for regression when going from 21.05 to 21.08, looks good so far; QEMU testing is conclusive check-in: d33a06ff8d user: ttcoder tags: new-genode-rev, trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to genode-haiku/haiku-on-genode/kits/storage/Node.cpp.
643
644
645
646
647
648
649

650

651
652
653
654
655
656
657
{
	if (fCStatus == B_OK && fAttrFd < 0) {
		fAttrFd = _kern_open_attr_dir(fFd, NULL, false);
		if (fAttrFd < 0)
			return fAttrFd;

		// set close on exec flag

		fcntl(fAttrFd, F_SETFD, FD_CLOEXEC);

	}

	return fCStatus;
}


status_t







>

>







643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
{
	if (fCStatus == B_OK && fAttrFd < 0) {
		fAttrFd = _kern_open_attr_dir(fFd, NULL, false);
		if (fAttrFd < 0)
			return fAttrFd;

		// set close on exec flag
#ifndef HoG_GENODE
		fcntl(fAttrFd, F_SETFD, FD_CLOEXEC);
#endif
	}

	return fCStatus;
}


status_t
Changes to genode-haiku/haiku-on-genode/sys-libroot/README.md.


1
2
3
4



























Dir contents : in upstream, much of this is labelled "Kernel Kit" (and the headers are located in haiku/headers/os/kernel) but it is in fact not implemented in libbe.so like a "kit" would be, but is located in libroot.so instead. Not that this nuance changes things much for us, since we go for all-in-one library anyway.

I'm not sure of the layout yet, hence stuffing the files inside an "interim" subfolder for now. (interim/ contains stuff from haiku/headers/os/kernel and haiku/headers/private/libroot)
























>
>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# Contents

Dir contents : in upstream, much of this is labelled "Kernel Kit" (and the headers are located in haiku/headers/os/kernel) but it is in fact not implemented in libbe.so like a "kit" would be, but is located in libroot.so instead. Not that this nuance changes things much for us, since we go for all-in-one library anyway.

I'm not sure of the layout yet, hence stuffing the files inside an "interim" subfolder for now. (interim/ contains stuff from haiku/headers/os/kernel and haiku/headers/private/libroot)

That's in contrast to librootbuild-variant/ which is a somewhat well-established part of the source,
for working with files and their attributes on top of a non-Haiku kernel.

# File basics

The traditional problem with entry_ref FDs (a file denomination that only the Haiku kernel and VFS
know about) is handled by librootbuild-variant/ which has special book-keeping code to map file
descriptors to file paths and vice versa.
We re-use that code with few changes in this project.

# File Attributes

Extended attributes are handled in librootbuild-variant/ (as a mix of BSD and Linux-style xattr),
via ioctl opcodes into Genode's VFS, which translates them into paths like

	/boot/Music/PinkFloyd/.TheWall.mp3/attr/user.haiku.Audio:Artist

which then land in e.g. the FUSE-NTFS-3g driver.
The ioctl() calls are placed in BSD-style functions, patched for Linux-style xattr
behavior, since Genode's FreeBSD headers provide prototypes for said functions ;
though on second thought we could also have ignored that and gone straight for xattr (?)


Changes to genode-haiku/haiku-on-genode/sys-libroot/interim/stubbed-libroot_stubs.c.
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__times", "times@@", "1_ALPHA4");
DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__times_beos", "times@", "BASE");
#endif  // ~not HoG_GENODE

#else  // HoG_GENODE : layers 6-7 (needs only a few stubs yet)

int real_time_clock() { return -1; }
int _kern_open_attr_dir() { return -1; }
int _kern_remove_dir() { return -1; }
int find_paths_etc() { return -1; }
int _kern_open_query() { return -1; }
int find_path_for_path_etc() { return -1; }
int parsedate() { return -1; }
int find_path_etc() { return -1; }








<







3073
3074
3075
3076
3077
3078
3079

3080
3081
3082
3083
3084
3085
3086
DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__times", "times@@", "1_ALPHA4");
DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__times_beos", "times@", "BASE");
#endif  // ~not HoG_GENODE

#else  // HoG_GENODE : layers 6-7 (needs only a few stubs yet)

int real_time_clock() { return -1; }

int _kern_remove_dir() { return -1; }
int find_paths_etc() { return -1; }
int _kern_open_query() { return -1; }
int find_path_for_path_etc() { return -1; }
int parsedate() { return -1; }
int find_path_etc() { return -1; }

Changes to genode-haiku/haiku-on-genode/sys-libroot/librootbuild-variant/Jamfile.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
		fs_attr.o
		fs_descriptors.o
		fs_freebsd.o
		fs.o
		misc.o
		;
	Library haiku.lib.a :
		fs_attr.cpp
		fs_descriptors.cpp
		fs_freebsd.cpp
		fs.cpp
		misc.cpp
		;
}








|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
		fs_attr.o
		fs_descriptors.o
		fs_freebsd.o
		fs.o
		misc.o
		;
	Library haiku.lib.a :
		fs_attr.cpp  # compilation will #include (!) file <fs_attr_untyped.cpp>
		fs_descriptors.cpp
		fs_freebsd.cpp
		fs.cpp
		misc.cpp
		;
}

Changes to genode-haiku/haiku-on-genode/sys-libroot/librootbuild-variant/fs.cpp.
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

// open_file
static int
open_file(const char *path, int openMode, int perms)
{
	TRACE();
	if( debug )
		printf("  openfile <%s>\n", path);
	
	// stat the node
	bool exists = true;
	struct stat st;
	if( debug )
		puts("  ..exists?");
	if (lstat(path, &st) < 0) {







|







903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

// open_file
static int
open_file(const char *path, int openMode, int perms)
{
	TRACE();
	if( debug )
		printf("  open_file <%s>  mode=0x%x  perms=%d\n", path, openMode, perms);
	
	// stat the node
	bool exists = true;
	struct stat st;
	if( debug )
		puts("  ..exists?");
	if (lstat(path, &st) < 0) {
942
943
944
945
946
947
948



949
950
951
952
953
954
955
			return error;

		descriptor = new SymlinkDescriptor(normalizedPath.c_str());
	} else {
		// open the file
		openMode &= ~O_NOTRAVERSE;
		int newFD = open(path, openMode, perms);



		if (newFD < 0)
#ifndef HoG_GENODE
			return errno;
#else
		{
			FixUp_Errno();
			return errno;







>
>
>







942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
			return error;

		descriptor = new SymlinkDescriptor(normalizedPath.c_str());
	} else {
		// open the file
		openMode &= ~O_NOTRAVERSE;
		int newFD = open(path, openMode, perms);
		if( debug >= 3 )
			printf("  called open() <%s> 0x%x <%d> , returned fd=%d\n", path, openMode, perms, newFD);

		if (newFD < 0)
#ifndef HoG_GENODE
			return errno;
#else
		{
			FixUp_Errno();
			return errno;
979
980
981
982
983
984
985



986
987
988
989
990
991
992

	if( debug )
		printf("  _kern_open(): get_path -> err %d\n", error);

	if (error != B_OK)
		return error;




	return open_file(realPath.c_str(), openMode, perms);
}

// _kern_open_entry_ref
int
_kern_open_entry_ref(dev_t device, ino_t node, const char *name,
	int openMode, int perms)







>
>
>







982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998

	if( debug )
		printf("  _kern_open(): get_path -> err %d\n", error);

	if (error != B_OK)
		return error;

	if( debug >= 3 )
		printf("  .. call open_file with <%s>\n", realPath.c_str());

	return open_file(realPath.c_str(), openMode, perms);
}

// _kern_open_entry_ref
int
_kern_open_entry_ref(dev_t device, ino_t node, const char *name,
	int openMode, int perms)
Changes to genode-haiku/haiku-on-genode/sys-libroot/librootbuild-variant/fs_attr_extattr.h.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
























24
25


26





27
28
29
30
31
32
33
34

35
36
37
38
39













40



41
42
43
44
45
46
47
48
49
50
51
52







53



54
55
56
57
58
59
60

61
62
63
64
65
66
67




68



69
70
71
72
73
74
75
76
77
78

79


80
81
82





83
84

85
86
87
88
89


90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114




115
116
117
118
119
120
121
*/


#include <string.h>
#include <sys/extattr.h>


///FIXME: move to cpp not h

#ifdef HoG_GENODE
	// Genode provides <sys/extattr.h> but does not seem to implement it; hence the stubs:

//+ #define TRACE() puts( __func__ );
#define TRACE() ;

























int	extattr_delete_fd(int _fd, int _attrnamespace, const char *_attrname)
{


	TRACE();





	return -1;
}
int	extattr_delete_link(const char *_path, int _attrnamespace,
	    const char *_attrname)
{
	TRACE();
	return -1;
}


ssize_t	extattr_get_fd(int _fd, int _attrnamespace, const char *_attrname,
	    void *_data, size_t _nbytes)
{
	TRACE();













	return -1;



}
ssize_t	extattr_get_link(const char *_path, int _attrnamespace,
	    const char *_attrname, void *_data, size_t _nbytes)
{
	TRACE();
	return -1;
}

ssize_t	extattr_list_fd(int _fd, int _attrnamespace, void *_data,
	    size_t _nbytes)
{
	TRACE();







	return -1;



}
ssize_t	extattr_list_link(const char *_path, int _attrnamespace, void *_data,
	    size_t _nbytes)
{
	TRACE();
	return -1;
}


//int  // in FreeBSD 8
ssize_t  // in FreeBSD 12
extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname,
	    const void *_data, size_t _nbytes)
{
	TRACE();




	return -1;



}

//int  // in FreeBSD 8
ssize_t  // in FreeBSD 12
extattr_set_link(const char *_path, int _attrnamespace,
	    const char *_attrname, const void *_data, size_t _nbytes)
{
	TRACE();
	return -1;
}

#endif




// the namespace all attributes live in





static const char* kAttributeNamespace = "haiku.";
static const int kAttributeNamespaceLen = 6;



static ssize_t
list_attributes(int fd, const char* path, char* buffer, size_t bufferSize)
{


	ssize_t bytesRead;
	if (fd >= 0) {
		bytesRead = extattr_list_fd(fd, EXTATTR_NAMESPACE_USER, buffer,
			bufferSize);
	} else {
		bytesRead = extattr_list_link(path, EXTATTR_NAMESPACE_USER, buffer,
			bufferSize);
	}

	if (bytesRead <= 0)
		return bytesRead;


	// The listing is in a different format than expected by the caller. Here
	// we get a sequence of (<namelen>, <unterminated name>) pairs, but expected
	// is a sequence of null-terminated names. Let's convert it.
	int index = *buffer;
	memmove(buffer, buffer + 1, bytesRead - 1);

	while (index < bytesRead - 1) {
		int len = buffer[index];
		buffer[index] = '\0';
		index += len + 1;
	}

	buffer[bytesRead - 1] = '\0';





	return bytesRead;
}


static ssize_t
get_attribute(int fd, const char* path, const char* attribute, void* buffer,







|

|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>

>
>
>
>
>
|







>





>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>












>
>
>
>
>
>
>
|
>
>
>







>







>
>
>
>
|
>
>
>










>
|
>
>



>
>
>
>
>


>





>
>












>













>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
*/


#include <string.h>
#include <sys/extattr.h>


///ToDo: move to cpp not h

#if defined( HoG_GENODE )
	// Genode provides <sys/extattr.h> but does not seem to implement it; hence the stubs:

//+ #define TRACE() puts( __func__ );
#define TRACE() ;


#include <sys/ioctl.h>
///XXXXX find a proper place for these
enum { XATTR_SET = 0xbe01, XATTR_GET, XATTR_LIST, XATTR_REMOVE };
#if 0
struct xattr_name_val_pair
{
	char const * name;
	void  * in_value;
	void       * out_value;
		///does Genode have a class "BinaryDataBuffer" or some such ?
};
#else
struct xattr_name_val_pair
{
	// attribute name
	const char * const name;
	// attribute value (for XATTR_GET/SET) or listing dest buffer (for XATTR_LIST)
	void * const data;
	size_t datasize;  // in/out
};
#endif


int	extattr_delete_fd(int _fd, int _attrnamespace, const char *_attrname)
{
	// Haiku's libroot-build will always use this instance (*delete_fd() and not *delete_link() below)
	
	TRACE();
	
	xattr_name_val_pair pair { .name = _attrname, .data = NULL, .datasize = 0 };
	int ret =
		ioctl( _fd, XATTR_REMOVE, &pair );
	
	return ret;
}
int	extattr_delete_link(const char *_path, int _attrnamespace,
	    const char *_attrname)
{
	TRACE();
	return -1;
}


ssize_t	extattr_get_fd(int _fd, int _attrnamespace, const char *_attrname,
	    void *_data, size_t _nbytes)
{
	TRACE();
	//printf(" [extattr_get_fd fd <%d> _attrnamespace 0x%x _attrname <%s> bufsize: %lu]\n", _fd, _attrnamespace, _attrname, _nbytes);
	//printf(" [extattr_get_fd] calling ioctl(%d, 0x%x)\n", _fd, XATTR_GET);
	
	// Haiku's libroot-build ignores <_attrnamespace> and always prefixes <_attrname> with "user."
	// (i.e. no need to test for EXTATTR_NAMESPACE_USER == _attrnamespace and add the prefix,
	// since the prefix is baked-in already, see below)
	
	xattr_name_val_pair pair { .name = _attrname, .data = _data, .datasize = _nbytes };
	int ret =
		// on success this returns 0, whereas we ought to return the number of read bytes
		ioctl( _fd, XATTR_GET, &pair );
	
	// hence the following:
	return ret == 0
		? pair.datasize  // success
		: ret  // failure
		;
}
ssize_t	extattr_get_link(const char *_path, int _attrnamespace,
	    const char *_attrname, void *_data, size_t _nbytes)
{
	TRACE();
	return -1;
}

ssize_t	extattr_list_fd(int _fd, int _attrnamespace, void *_data,
	    size_t _nbytes)
{
	TRACE();
	
	xattr_name_val_pair pair { .name = NULL, .data = _data, .datasize = _nbytes };
	int ret =
		// on success this returns 0, whereas we ought to return the number of read bytes
		ioctl( _fd, XATTR_LIST, &pair );
	
	// hence the following:
	return ret == 0
		? pair.datasize  // success
		: ret  // failure
		;
}
ssize_t	extattr_list_link(const char *_path, int _attrnamespace, void *_data,
	    size_t _nbytes)
{
	TRACE();
	return -1;
}


//int  // in FreeBSD 8
ssize_t  // in FreeBSD 12
extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname,
	    const void *_data, size_t _nbytes)
{
	TRACE();
	//printf(" [extattr_set_fd fd <%d> _attrnamespace 0x%x _attrname <%s> buf <%s>]\n", _fd, _attrnamespace, _attrname, (const char*)_data);
	//printf(" [extattr_set_fd] calling ioctl(%d, 0x%x)\n", _fd, XATTR_SET);
	
	xattr_name_val_pair pair { .name = _attrname, .data = (void*)_data, .datasize = _nbytes };
	return
		// here we return the "0" (on success) retcode directly; we don't bother
		// with returning the actual written bytes, since fs_write_attr() would not use it anyway (unlike fs_read_attr())
		ioctl( _fd, XATTR_SET, &pair );
}

//int  // in FreeBSD 8
ssize_t  // in FreeBSD 12
extattr_set_link(const char *_path, int _attrnamespace,
	    const char *_attrname, const void *_data, size_t _nbytes)
{
	TRACE();
	return -1;
}

#endif  // ~HoG_GENODE




// the namespace all attributes live in
#if defined( HoG_GENODE )
// use Linux-compatible xattr (i.e. prefix with "user.", more restrictive than BSD)
static const char* kAttributeNamespace = "user.haiku.";
static const int kAttributeNamespaceLen = 11;
#else  // upstream Haiku
static const char* kAttributeNamespace = "haiku.";
static const int kAttributeNamespaceLen = 6;
#endif  // ~upstream


static ssize_t
list_attributes(int fd, const char* path, char* buffer, size_t bufferSize)
{
	//printf( "  >>> list_attributes(%d, <%s>, %ld)\n", fd, path, bufferSize );
	
	ssize_t bytesRead;
	if (fd >= 0) {
		bytesRead = extattr_list_fd(fd, EXTATTR_NAMESPACE_USER, buffer,
			bufferSize);
	} else {
		bytesRead = extattr_list_link(path, EXTATTR_NAMESPACE_USER, buffer,
			bufferSize);
	}

	if (bytesRead <= 0)
		return bytesRead;

#ifndef HoG_GENODE
	// The listing is in a different format than expected by the caller. Here
	// we get a sequence of (<namelen>, <unterminated name>) pairs, but expected
	// is a sequence of null-terminated names. Let's convert it.
	int index = *buffer;
	memmove(buffer, buffer + 1, bytesRead - 1);

	while (index < bytesRead - 1) {
		int len = buffer[index];
		buffer[index] = '\0';
		index += len + 1;
	}

	buffer[bytesRead - 1] = '\0';
#else  // HoG_GENODE:
	// Dodge the above "translate BSD" code, since the underlying Genode code actually
	// relies on FUSE, which uses the Linux xattr convention, not the BSD convention.
#endif  // ~HoG_GENODE

	return bytesRead;
}


static ssize_t
get_attribute(int fd, const char* path, const char* attribute, void* buffer,
Changes to genode-haiku/haiku-on-genode/sys-libroot/librootbuild-variant/fs_attr_untyped.cpp.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
 * Distributed under the terms of the MIT License.
 */

/*!	Emulation BeOS-style attributes by mapping them to untyped attributes of
	the host platform (xattr on Linux, extattr on FreeBSD).
*/



///ToDo: check that ENODATA is harmless?

// HoG_GENODE:
// in the below we rem out all 3 "ENODATA" instances, seems
// Genode does not provide that constant (unlike ENOATTR, which does exist).




#ifdef BUILDING_FS_SHELL
#	include "compat.h"
#	define B_OK					0
#	define B_BAD_VALUE			EINVAL
#	define B_FILE_ERROR			EBADF











<
<

|

|
|







1
2
3
4
5
6
7
8
9
10
11


12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Copyright 2005-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
 * Distributed under the terms of the MIT License.
 */

/*!	Emulation BeOS-style attributes by mapping them to untyped attributes of
	the host platform (xattr on Linux, extattr on FreeBSD).
*/





// HoG_GENODE:
// in the below we rem out all 3 "ENODATA" instances:
// Genode does not provide that constant (unlike ENOATTR, which does exist).
// Genode's (ioctl-based) xattr support will always return ENOATTR rather than ENODATA,
// so we know for a fact that we won't meet that value and can safely ignore it.


#ifdef BUILDING_FS_SHELL
#	include "compat.h"
#	define B_OK					0
#	define B_BAD_VALUE			EINVAL
#	define B_FILE_ERROR			EBADF
133
134
135
136
137
138
139

140
141
142
143
144
145
146


namespace {

class AttributeDirectory;

typedef map<DIR*, AttributeDirectory*> AttrDirMap;

static AttrDirMap sAttributeDirectories;

// LongDirent
struct LongDirent : dirent {
	char name[B_FILE_NAME_LENGTH];
};








>







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


namespace {

class AttributeDirectory;

typedef map<DIR*, AttributeDirectory*> AttrDirMap;
#warning ///FIXME: add an MT-safe guard on this (see fs.cpp for an example), otherwise MT calls to GetNextAttr() will crash&burn...
static AttrDirMap sAttributeDirectories;

// LongDirent
struct LongDirent : dirent {
	char name[B_FILE_NAME_LENGTH];
};

289
290
291
292
293
294
295

296
297
298
299
300
301
302

private:
	status_t _CheckListing()
	{
		if (fListing && fListingLength >= 0)
			return B_OK;


		char listing[kMaxAttributeListingLength];

		// get the listing
		ssize_t length = list_attributes(fFileFD, fPath.c_str(), listing,
			kMaxAttributeListingLength);
		if (length < 0)
			return errno;







>







288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

private:
	status_t _CheckListing()
	{
		if (fListing && fListingLength >= 0)
			return B_OK;

#warning ///FIXME: xattr: this allocates 10240 bytes on the stack !
		char listing[kMaxAttributeListingLength];

		// get the listing
		ssize_t length = list_attributes(fFileFD, fPath.c_str(), listing,
			kMaxAttributeListingLength);
		if (length < 0)
			return errno;
458
459
460
461
462
463
464





465
466
467
468
469
470
471
}

// fs_read_attr
ssize_t
fs_read_attr(int fd, const char *_attribute, uint32 type, off_t pos,
	void *buffer, size_t readBytes)
{





	// check params
	if (pos < 0 || pos + readBytes > kMaxAttributeLength
		|| !_attribute || !buffer) {
		errno = B_BAD_VALUE;
		return -1;
	}








>
>
>
>
>







458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
}

// fs_read_attr
ssize_t
fs_read_attr(int fd, const char *_attribute, uint32 type, off_t pos,
	void *buffer, size_t readBytes)
{
#ifdef HoG_GENODE
	//if( debug )
	//	printf("fs_read_attr on fd %d  attrname<%s> type 0x%x pos <%ld> readBytes <%lu> buf <%p>   kMaxAttributeLength: %lu\n", fd, _attribute, type, pos, readBytes, buffer, kMaxAttributeLength);
#endif
	
	// check params
	if (pos < 0 || pos + readBytes > kMaxAttributeLength
		|| !_attribute || !buffer) {
		errno = B_BAD_VALUE;
		return -1;
	}

525
526
527
528
529
530
531





532
533
534
535
536
537
538
}

// fs_write_attr
ssize_t
fs_write_attr(int fd, const char *_attribute, uint32 type, off_t pos,
	const void *buffer, size_t writeBytes)
{





	// check params
	if (pos < 0 || pos + writeBytes > kMaxAttributeLength
		|| _attribute == NULL || (writeBytes > 0 && buffer == NULL)) {
		errno = B_BAD_VALUE;
		return -1;
	}








>
>
>
>
>







530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
}

// fs_write_attr
ssize_t
fs_write_attr(int fd, const char *_attribute, uint32 type, off_t pos,
	const void *buffer, size_t writeBytes)
{
#ifdef HoG_GENODE
	//if( debug )
	//	printf("fs_write_attr on fd %d  attrname<%s> type 0x%x pos <%ld> writeBytes <%lu> buf <%p>   kMaxAttributeLength: %lu\n", fd, _attribute, type, pos, writeBytes, buffer, kMaxAttributeLength);
#endif
	
	// check params
	if (pos < 0 || pos + writeBytes > kMaxAttributeLength
		|| _attribute == NULL || (writeBytes > 0 && buffer == NULL)) {
		errno = B_BAD_VALUE;
		return -1;
	}

634
635
636
637
638
639
640

641
642
643
644
645
646
647
648
649
650
651
652
653
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
		return -1;
	}

	// mangle the attribute name
	string attribute = mangle_attribute_name(_attribute);

	// read the attribute

	char attributeBuffer[sizeof(AttributeHeader) + kMaxAttributeLength];
	ssize_t bytesRead = sizeof(AttributeHeader) + kMaxAttributeLength;
	if (localFD.Path()) {
		bytesRead = get_attribute(-1, localFD.Path(), attribute.c_str(),
			attributeBuffer, bytesRead);
	} else {
		bytesRead = get_attribute(localFD.FD(), NULL, attribute.c_str(),
			attributeBuffer, bytesRead);
	}
	if (bytesRead < 0) {
		// Make sure, the error code is B_ENTRY_NOT_FOUND, if the attribute
		// doesn't exist.
		if (errno == ENOATTR)// || errno == ENODATA)
			errno = B_ENTRY_NOT_FOUND;
		return -1;
	}

	// check length for sanity
	if ((size_t)bytesRead < sizeof(AttributeHeader)) {
		fprintf(stderr, "fs_stat_attr(): attribute \"%s\" is shorter than the "

			"AttributeHeader!\n", attribute.c_str());



		errno = B_ERROR;
		return -1;
	}

	attrInfo->size = bytesRead - sizeof(AttributeHeader);
	attrInfo->type = ((AttributeHeader*)attributeBuffer)->type;

	return 0;
}


// #pragma mark - Private Syscalls


#ifndef BUILDING_FS_SHELL

// _kern_open_attr_dir

int
_kern_open_attr_dir(int fd, const char *path)





{
	// get node ref for the node
	struct stat st;
	status_t error = _kern_read_stat(fd, path, false, &st,
		sizeof(struct stat));
	if (error != B_OK) {
		errno = error;







>




















>

>
>
>

















>


>
>
>
>
>







644
645
646
647
648
649
650
651
652
653
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
		return -1;
	}

	// mangle the attribute name
	string attribute = mangle_attribute_name(_attribute);

	// read the attribute
#warning ///FIXME: xattr: this allocates a 40964 bytes buffer on the stack !!
	char attributeBuffer[sizeof(AttributeHeader) + kMaxAttributeLength];
	ssize_t bytesRead = sizeof(AttributeHeader) + kMaxAttributeLength;
	if (localFD.Path()) {
		bytesRead = get_attribute(-1, localFD.Path(), attribute.c_str(),
			attributeBuffer, bytesRead);
	} else {
		bytesRead = get_attribute(localFD.FD(), NULL, attribute.c_str(),
			attributeBuffer, bytesRead);
	}
	if (bytesRead < 0) {
		// Make sure, the error code is B_ENTRY_NOT_FOUND, if the attribute
		// doesn't exist.
		if (errno == ENOATTR)// || errno == ENODATA)
			errno = B_ENTRY_NOT_FOUND;
		return -1;
	}

	// check length for sanity
	if ((size_t)bytesRead < sizeof(AttributeHeader)) {
		fprintf(stderr, "fs_stat_attr(): attribute \"%s\" is shorter than the "
#ifndef HoG_GENODE
			"AttributeHeader!\n", attribute.c_str());
#else
			"AttributeHeader! (%ld < %ld)\n", attribute.c_str(), bytesRead, sizeof(AttributeHeader));
#endif
		errno = B_ERROR;
		return -1;
	}

	attrInfo->size = bytesRead - sizeof(AttributeHeader);
	attrInfo->type = ((AttributeHeader*)attributeBuffer)->type;

	return 0;
}


// #pragma mark - Private Syscalls


#ifndef BUILDING_FS_SHELL

// _kern_open_attr_dir
#ifndef HoG_GENODE
int
_kern_open_attr_dir(int fd, const char *path)
#else
// upstream has incorrect function signature, _this_ is what is declared in syscalls.h:
int
_kern_open_attr_dir(int fd, const char *path, bool traverseLeafLink)
#endif
{
	// get node ref for the node
	struct stat st;
	status_t error = _kern_read_stat(fd, path, false, &st,
		sizeof(struct stat));
	if (error != B_OK) {
		errno = error;
Changes to genode-haiku/jam/jamrules-qemu.
646
647
648
649
650
651
652

653
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
#############


actions RunQemu1
{
	qemu-system-x86_64 -no-kvm -display sdl -cpu core2duo -m 256 \
		$(QEMU_INPUT) \

		-device ich9-intel-hda  -serial mon:stdio -cdrom $(1)   -machine q35

#		-drive id=disk,file=/dev/disk/scsi/0/0/0/raw,format=raw,if=none -device ahci,id=ahci -device ide-drive,drive=disk,bus=ahci.0 -boot d
}






rule RunQemu  runfile
{
	local scenario = $(runfile:B) ;
	NotFile $(scenario) ;  # silences e.g. "warning: using independent target hog-demos"
	
	#++fix "warning: indep target ld.lib.so"... maybe similar to this?:
	#$(bulk_binaries:G=$(scenario)) ;
	# fixing "init" involved adding it to AddRawComponents above (was referenced but not copied)..
	

	Depends $(runfile) : $(scenario).iso ;
	
	Xorriso $(scenario).iso : $(scenario) ;
	RunQemu1 $(scenario).iso ;  # this action/rule needs to bear a name distinct from "RunQemu" due to using a $(1) which is different from RunQemu's $(1)
	
	Always $(scenario).iso ;

USB_INPUT = true ;
if $(USB_INPUT)
{
	# or "-usb -usbdevice mouse..." as the dde_linux/run file does ?
	QEMU_INPUT on $(scenario).iso += -usb -device usb-mouse -device usb-kbd -device usb-ehci,id=ehci ;
}










}



rule AddComponentAsStart  runfile : memory : binary : start_tag : extraconfig
{
	local conf ;







>

|
|
|
>
>
>
>
>
|
|








>






>

|
|
|
|
|
|
>
>
>
>
>
>
>
>
>







646
647
648
649
650
651
652
653
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
693
694
695
696
697
698
699
700
701
702
703
#############


actions RunQemu1
{
	qemu-system-x86_64 -no-kvm -display sdl -cpu core2duo -m 256 \
		$(QEMU_INPUT) \
		$(QEMU_AHCI) \
		-device ich9-intel-hda  -serial mon:stdio -cdrom $(1)   -machine q35
}


# Mandatory params:
#	- runfile, e.g. "test.run", from which we'll derive image name "test.iso"
# Optional params:
#	- ahci_disk_image: e.g. "/tmp/test_ntfs_image.raw"
#	(a disk image for Qemu to provide as a block device to e.g. ahci_drv)
#
rule RunQemu  runfile : ahci_disk_image
{
	local scenario = $(runfile:B) ;
	NotFile $(scenario) ;  # silences e.g. "warning: using independent target hog-demos"
	
	#++fix "warning: indep target ld.lib.so"... maybe similar to this?:
	#$(bulk_binaries:G=$(scenario)) ;
	# fixing "init" involved adding it to AddRawComponents above (was referenced but not copied)..
	
	# e.g. "test.iso" depends on "test.run"
	Depends $(runfile) : $(scenario).iso ;
	
	Xorriso $(scenario).iso : $(scenario) ;
	RunQemu1 $(scenario).iso ;  # this action/rule needs to bear a name distinct from "RunQemu" due to using a $(1) which is different from RunQemu's $(1)
	
	Always $(scenario).iso ;
	
USB_INPUT = true ;
	if $(USB_INPUT)
	{
		# or "-usb -usbdevice mouse..." as the dde_linux/run file does ?
		QEMU_INPUT on $(scenario).iso += -usb -device usb-mouse -device usb-kbd -device usb-ehci,id=ehci ;
	}
	
	if $(ahci_disk_image)
	{
		Always $(ahci_disk_image) ;  # if the image results from a creation & formatting process, make sure the formatting is made at each run, to restore state after each test-run !
		Depends $(scenario).iso : $(ahci_disk_image) ;
		
		QEMU_AHCI on $(scenario).iso = "-drive id=disk,file=$(ahci_disk_image),format=raw,if=none -device ahci,id=ahci -device ide-drive,drive=disk,bus=ahci.0 -boot d" ;
		#	-drive id=disk,file=/dev/disk/scsi/0/0/0/raw,format=raw,if=none -device ahci,id=ahci
		#	-device ide-drive,drive=disk,bus=ahci.0 -boot d
	}
}



rule AddComponentAsStart  runfile : memory : binary : start_tag : extraconfig
{
	local conf ;
Changes to genode-haiku/misc-tests/Jamfile.
8
9
10
11
12
13
14























15
16
17
18
19

20

21
22












23
24












25
26
27
28
29
30
31
32
33
34
35
36


37


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
	;

#xx Force recompilation in case hog_TEST_LEVEL changed (a new value of that constant does not by itself trigger a recompile of files that use it)...
Always [ FGristFiles basics-layers.o ] ;



























# --------------------
# --- hog-test.run ---
# --------------------


#///ToDo: "if hog_TEST_LEVEL >= 5...."...

AddInteractiveComponents hog-test.run
	;












AddComponentService  hog-test.run
	: 20M












	: basic-layers
	:
	: "<config ld_verbose=\"yes\">
			<libc  rtc=\"/dev/rtc\" stdin=\"/dev/null\" stdout=\"/dev/log\" stderr=\"/dev/log\"/>
			<vfs>
				<dir name=\"dev\">
					<log/>
					<null/>
				</dir>
				<inline name=\"beos.mp3\">
					A real mp3 file would hold binary data here
				</inline>


				<dir name=\"ram_rw\">


					<ram/>
				</dir>
				<dir name=\"boot\">
					<ram/>
				</dir>
			</vfs>
	</config>
\		<route>
\			<any-service>
\				<parent/><any-child/>
\			</any-service>
\		</route>
	"
	;

RunQemu
	hog-test.run
	;









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
|
>


>
>
>
>
>
>
>
>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>












>
>

>
>
|















|



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
	;

#xx Force recompilation in case hog_TEST_LEVEL changed (a new value of that constant does not by itself trigger a recompile of files that use it)...
Always [ FGristFiles basics-layers.o ] ;



# ---------------------
# --- support rules ---
# ---------------------

# These are similar to Genode's test-libc test infrastructure.

actions DiskCreate
{
	dd if=/dev/zero of=$(1) bs=1024 count=65536  2> /dev/null
	#sync  # otherwise mkfs tends to fail...
	# nope, still no go, still getting this on first run :-/... Another haiku cache bug? : ""mkfs: Initialization of "Data" failed: Bad data""
}
actions DiskFormatNTFS
{
	mkfs  --dont-ask  -t ntfs  $(1)  Data
}

rule DiskNtfsBlank
{
	DiskCreate $(1) ;
	DiskFormatNTFS $(1) ;
}


# --------------------
# --- hog-test.run ---
# --------------------

#///ToDo:
#if hog_TEST_LEVEL >= 5...."...
#{
AddInteractiveComponents hog-test.run
	;
#}

#if hog_TEST_LEVEL >= 6...
AddRawComponent
	hog-test.run : vfs_fuse.lib.so : vfs_fuse.lib.so
	;

NTFS_TEST_IMAGE_PATH =
	/tmp/hog_test_disk_image.raw
	;
DiskNtfsBlank $(NTFS_TEST_IMAGE_PATH) ;

AddComponentService  hog-test.run
	: 2M
	: ahci_drv
	: Block
	: "<config>
			<policy label_prefix=\"basic-layers\" device=\"0\" writeable=\"yes\" />
		</config>
		"
	;
#}

#/// "AddComponentAsStart.."
AddComponentService  hog-test.run
	: 27M
	: basic-layers
	:
	: "<config ld_verbose=\"yes\">
			<libc  rtc=\"/dev/rtc\" stdin=\"/dev/null\" stdout=\"/dev/log\" stderr=\"/dev/log\"/>
			<vfs>
				<dir name=\"dev\">
					<log/>
					<null/>
				</dir>
				<inline name=\"beos.mp3\">
					A real mp3 file would hold binary data here
				</inline>
# only in jam t6 level:
				<block name=\"blockdev\"/>
				<dir name=\"ram_rw\">
					<fuse block_path=\"/blockdev\"/>
# also for jam t6, otherwise just use a <ram> node:
#					<ram/>
				</dir>
				<dir name=\"boot\">
					<ram/>
				</dir>
			</vfs>
	</config>
\		<route>
\			<any-service>
\				<parent/><any-child/>
\			</any-service>
\		</route>
	"
	;

RunQemu
	hog-test.run : $(NTFS_TEST_IMAGE_PATH)
	;


Changes to genode-haiku/misc-tests/basics-layers.cpp.
224
225
226
227
228
229
230

231
232
233
234
235
236
237

//#pragma mark - t3

/***********************/
#if hog_TEST_LEVEL >= 3

// libbe.so

#include <storage/Directory.h>
#include <storage/Entry.h>
#include <storage/File.h>
#include <storage/FindDirectory.h>
#include <storage/Path.h>
#include <storage/SymLink.h>
#include <storage/VolumeRoster.h>







>







224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

//#pragma mark - t3

/***********************/
#if hog_TEST_LEVEL >= 3

// libbe.so
#include <fs_attr.h>  // struct attr_info
#include <storage/Directory.h>
#include <storage/Entry.h>
#include <storage/File.h>
#include <storage/FindDirectory.h>
#include <storage/Path.h>
#include <storage/SymLink.h>
#include <storage/VolumeRoster.h>
373
374
375
376
377
378
379



380
381
382
383








384



385






386
387
388
389
390
391
392
//	status_t result = 0;
//	result = find_directory( B_SYSTEM_DIRECTORY, &path );
//	CHECK( result == B_OK );
	//	check <path> value..
	
	int dummy_int = 0;
	



	// BNode : xattr (attributes) :
	BNode invalid_node;
	CHECK( B_FILE_ERROR == invalid_node.ReadAttr("foo_attr", B_INT32_TYPE, 0, &dummy_int, sizeof(dummy_int)) );
	








	//BNode



	//WriteStringAttr()... Read back.. check same..






	
	// BFile
	BFile file;
	CHECK( file.InitCheck() == B_NO_INIT );
	CHECK( B_ENTRY_NOT_FOUND == file.SetTo("/ram_rw_WrongPath/newfile", B_CREATE_FILE | B_WRITE_ONLY) );
	CHECK( B_OK == file.SetTo("/ram_rw/newfile", B_CREATE_FILE | B_WRITE_ONLY) );
	







>
>
>
|


|
>
>
>
>
>
>
>
>
|
>
>
>
|
>
>
>
>
>
>







374
375
376
377
378
379
380
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
413
//	status_t result = 0;
//	result = find_directory( B_SYSTEM_DIRECTORY, &path );
//	CHECK( result == B_OK );
	//	check <path> value..
	
	int dummy_int = 0;
	
	// *** required: ***
	// a <config> with read/writeable "/ram_rw" *NTFS* (or other xattr-supporting FS) node is required for the below:
	
	// BNode : xattr (extended attributes) :
	BNode invalid_node;
	CHECK( B_FILE_ERROR == invalid_node.ReadAttr("foo_attr", B_INT32_TYPE, 0, &dummy_int, sizeof(dummy_int)) );
	// setxattr:
	const BString
		out_value( "Pink Floyd" );
	BNode node_w_attrs( "/ram_rw/boot" );  // xattr's work even on directories (at least with NTFS)
	CHECK( B_OK == node_w_attrs.WriteAttrString("Audio:Artist", &out_value) );
	// getxattr: read it back, check value:
	BString in_value;
	CHECK( B_OK == node_w_attrs.ReadAttrString("Audio:Artist", &in_value) );
	CHECK( in_value == out_value );
	// listxattr
	static char xa_name[512] = {};
	struct attr_info xa_info = {};
	CHECK( node_w_attrs.GetNextAttrName(xa_name) == B_OK );
	CHECK( BString("Audio:Artist") == xa_name );
	CHECK( node_w_attrs.GetNextAttrName(xa_name) == B_ENTRY_NOT_FOUND );
	CHECK( B_OK == node_w_attrs.GetAttrInfo("Audio:Artist", &xa_info) );
	CHECK( xa_info.type == B_STRING_TYPE && xa_info.size == out_value.Length() +1 );
	// removexattr (when it exists, then when it doesn't)
	CHECK( node_w_attrs.RemoveAttr("Audio:Artist") == B_OK );
	CHECK( node_w_attrs.RemoveAttr("Audio:Artist") == B_ENTRY_NOT_FOUND );
	
	// BFile
	BFile file;
	CHECK( file.InitCheck() == B_NO_INIT );
	CHECK( B_ENTRY_NOT_FOUND == file.SetTo("/ram_rw_WrongPath/newfile", B_CREATE_FILE | B_WRITE_ONLY) );
	CHECK( B_OK == file.SetTo("/ram_rw/newfile", B_CREATE_FILE | B_WRITE_ONLY) );
	
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
	CHECK( 0 == dev_for_path("/boot/Station") );//
	//test IsReadonly(), IsPersistent(), KnowsMime()..
	CHECK( B_ERROR == volumeroster.GetNextVolume(&volume) );
	
	//BApp Resources.. (so that apps/clock will be able to load its clock backgrounds, and AutoCast will load its cc.png updater icon)
}

#endif


//#pragma mark - t5

/***********************/
#if hog_TEST_LEVEL >= 5








|







437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
	CHECK( 0 == dev_for_path("/boot/Station") );//
	//test IsReadonly(), IsPersistent(), KnowsMime()..
	CHECK( B_ERROR == volumeroster.GetNextVolume(&volume) );
	
	//BApp Resources.. (so that apps/clock will be able to load its clock backgrounds, and AutoCast will load its cc.png updater icon)
}

#endif  // ~hog_TEST_LEVEL >= 3


//#pragma mark - t5

/***********************/
#if hog_TEST_LEVEL >= 5