Skip to content

Commit 9a8ff0b

Browse files
committed
hfsfuse: make extended attribute namespace configurable
Changes this to a build-time make parameter XATTR_NAMESPACE which can be used to select other namespaces than the OS default. Allows the platform dependent checks for this to be moved out to the build system and provides a means for accessing symlink extended attributes on Linux, which can't be read under the user namespace.
1 parent cc49395 commit 9a8ff0b

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ TARGETS = hfsfuse hfsdump
2222
FUSE_FLAGS = -DFUSE_USE_VERSION=28
2323
FUSE_LIB = -lfuse
2424

25+
XATTR_NAMESPACE = user.
2526
ifeq ($(OS), Darwin)
2627
APP_FLAGS += -I/usr/local/include
2728
APP_LIB += -L/usr/local/lib
29+
XATTR_NAMESPACE = #no namespaces on macOS
2830
ifeq ($(shell [ -e /usr/local/lib/libosxfuse.dylib ] && echo 1), 1)
2931
FUSE_FLAGS += -I/usr/local/include/osxfuse
3032
FUSE_LIB = -losxfuse
@@ -134,7 +136,7 @@ ifneq ($(filter-out $(non_build_targets),$(or $(MAKECMDGOALS),all)),)
134136
$(eval $(call cccheck,HAVE_ZLIB,,zlib.h))
135137
endif
136138

137-
$(foreach cfg,OS CC AR RANLIB INSTALL TAR PREFIX WITH_UBLIO WITH_UTF8PROC CONFIG_CFLAGS $(FEATURES),$(eval CONFIG:=$(CONFIG)$(cfg)=$$($(cfg))\n))
139+
$(foreach cfg,OS CC AR RANLIB INSTALL TAR PREFIX WITH_UBLIO WITH_UTF8PROC XATTR_NAMESPACE CONFIG_CFLAGS $(FEATURES),$(eval CONFIG:=$(CONFIG)$(cfg)=$$($(cfg))\n))
138140
$(foreach feature,$(FEATURES),$(if $(filter $($(feature)),1),$(eval CFLAGS+=-D$(feature))))
139141

140142
LIBS = lib/libhfsuser/libhfsuser.a lib/libhfs/libhfs.a
@@ -189,7 +191,7 @@ all: $(TARGETS)
189191
%.o: CPPFLAGS += $(INCLUDE)
190192
%.o: CFLAGS += $(LOCAL_CFLAGS)
191193

192-
src/hfsfuse.o: CPPFLAGS += $(FUSE_FLAGS)
194+
src/hfsfuse.o: CPPFLAGS += $(FUSE_FLAGS) -DXATTR_NAMESPACE=$(XATTR_NAMESPACE)
193195

194196
$(LIBS): always_check
195197
$(MAKE) -C $(dir $@)
@@ -239,4 +241,8 @@ config:
239241
@echo "$$CONFIG" > config.mak
240242

241243
dist: version
242-
git archive master -o "$(RELEASE_NAME).tar.gz" --prefix "$(RELEASE_NAME)/src/" --add-file src/version.h --prefix "$(RELEASE_NAME)/"
244+
#git archive master -o "$(RELEASE_NAME).tar.gz" --prefix "$(RELEASE_NAME)/src/" --add-file src/version.h --prefix "$(RELEASE_NAME)/"
245+
ln -s . $(RELEASE_NAME)
246+
$(RM) -- $(RELEASE_NAME).tar.gz
247+
git ls-files | sed "s/^/$(RELEASE_NAME)\//" | COPYFILE_DISABLE=1 $(TAR) --no-xattrs -czf $(RELEASE_NAME).tar.gz -T - -- $(RELEASE_NAME)/src/version.h
248+
$(RM) -- $(RELEASE_NAME)

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ Under Haiku only, all extended attribute values are hex encoded to allow binary
135135
catattr -r user.com.apple.ResourceFork file | xxd -r -p
136136
```
137137

138+
Extended attributes are presented in the preferred namespace for the OS, typically `user.`. Alternate namespaces may be chosen when building hfsfuse by setting the `XATTR_NAMESPACE` make var.
139+
This should include the trailing `.` as an empty value indicates no namespacing (such as on macOS.)
138140

139141
## Mac OS Classic file permissions
140142
HFS+ filesystems created on Mac OS Classic do not contain the typical set of Unix ownership and permission information for files and folders.

src/hfsfuse.c

+8-16
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,10 @@ static int hfsfuse_getxtimes(const char* path, struct timespec* bkuptime, struct
300300
}
301301
#endif
302302

303-
#ifdef __APPLE__
304-
#define attrname(name) name
305-
#else
306-
#define attrname(name) "user." name
307-
#endif
303+
#define STR_(x) #x
304+
#define STR(x) STR_(x)
305+
#define XATTR_NAMESPACE_STR STR(XATTR_NAMESPACE)
306+
#define attrname(name) XATTR_NAMESPACE_STR name
308307

309308
#define declare_attr(name, buf, bufsize, accum) do {\
310309
accum += strlen(attrname(name))+1;\
@@ -350,14 +349,9 @@ static int hfsfuse_listxattr(const char* path, char* attr, size_t size) {
350349
ssize_t u8len = hfs_unistr_to_utf8(&attr_keys[i].name, attrname);
351350
if(u8len <= 0)
352351
continue;
353-
ret += u8len + 1;
354-
#ifndef __APPLE__
355-
ret += 5; //user. prefix
356-
#endif
352+
ret += u8len + strlen(XATTR_NAMESPACE_STR) + 1;
357353
if(size >= (size_t)ret) {
358-
#ifndef __APPLE__
359-
attr = stpcpy(attr, "user.");
360-
#endif
354+
attr = stpcpy(attr, XATTR_NAMESPACE_STR);
361355
attr = stpcpy(attr, attrname)+1;
362356
}
363357
}
@@ -421,10 +415,8 @@ static int hfsfuse_getxattr_offset(const char* path, const char* attr, char* val
421415
memcpy(value, timebuf, 24);
422416
});
423417

424-
#ifndef __APPLE__
425-
if(!strncmp(attr,"user.",5))
426-
attr += 5;
427-
#endif
418+
if(!strncmp(attr,XATTR_NAMESPACE_STR,strlen(XATTR_NAMESPACE_STR)))
419+
attr += strlen(XATTR_NAMESPACE_STR);
428420

429421
hfs_attribute_record_t attrec;
430422
hfs_unistr255_t attrname;

0 commit comments

Comments
 (0)