Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaned-up macOS port (not fsck-related) #14

Closed
wants to merge 3 commits into from

Conversation

gmerlino
Copy link

@gmerlino gmerlino commented Jan 5, 2018

Thanks to your latest advice:

#13 (comment)

I've cleaned up the PR: no more CDDL-encumbered code, just enough (otherwise missing) headers, slightly adapted from Linux ones, to let the compiler stop complaining. By the way, with this groundwork out of the way, it is a very straightforward port to FreeBSD, as well.

This is a quite different PR with respect to the fsck work in: argorain#1

I've tried to keep things as separate (and as simple) as possible, because I think it is valuable to have the macOS port merged even before the fsck is fully upstreamed.

Let me know your opinion.

Copy link
Owner

@pali pali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! See comments below. There is still ton of code (defines and structures) which is never used -- therefore it is a dead code. E.g. cdrom.h looks like bundled code. Also I doubt that pktsetup could work.

#elif __BYTE_ORDER == LITTLE_ENDIAN
#define __LITTLE_ENDIAN_BITFIELD
#endif
#endif /* __APPLE__ */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not invent new way for determining endiantity. We already use autoconf which has standard macros for it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's how it works without reshuffling too much the chain of ifdef'ed code.
You have to consider that I'm not actually determining there endianness, only perusing how it is pre-defined in the macOS-specific way (i.e., as in machine/endian.h). Indeed the right side of the defines (no double under-score) comes from the Darwin header.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autoconf has macro AC_C_BIGENDIAN to check for endianity, see:
https://www.gnu.org/software/autoconf/manual/autoconf.html

There is absolutely no reason for adding new special ifdef for Apple systems as autoconf can handle it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried, but it does not work. The ifdef'ed HAVE_SYS_ISA_DEFS_H part is a bit non-standard and makes the following (ifdef APPLE) necessary. Again, consider that it is not determining endianness, only doing what you do under HAVE_SYS_ISA_DEFS_H (e.g., define the __*) which are not available anywhere on a Darwin system otherwise.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why to use HAVE_SYS_ISA_DEFS_H? WORDS_BIGENDIAN should be defined only on big endian systems.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I did it in 0adadb6

* borrow the "Operation not supported" error from the network folks to
* accomplish this. Maybe someday we will get a more targeted error code,
* but this will do for now... */
#define EDRIVE_CANT_DO_THIS EOPNOTSUPP
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this EDRIVE_CANT_DO_THIS used? I do not see place where is needed this nor any other macros. So please do not include and bundle dead code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per other comments of mine, the alternative is to prune (Linux-verbatim) code to the minimum, of course it could make it life more difficult to reintroduce defines/etc later down the road, if needed by new (core) code in udftools.

Anyway, albeit we're talking about three/four self-contained files almost verbatim from /usr/include in Linux, if you feel like this is absolutely needed, please let me know, and I'll take care of the pruning.

#include <linux/fs.h>
#include <linux/fd.h>
#elif defined(__APPLE__)
#include <sys/disk.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment for which function (or macro?) is this sys/disk.h include file needed. I really do not know.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thanks, I'll add a comment straight away. It's the Darwin equivalent of fs.h (and also tackles fd.h).

#include <linux/cdrom.h>
#else
#include "darwin/cdrom.h"
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that your Darwin system implement pktcdvd interface from Linux kernel?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the actual working of everything in this PR: with these patches it all compiles, and runs (tried out all binaries with help/version switches). Of course, (possibly missing) functionality is to be tested (I'm willing to do it going forward, of course).

@@ -229,7 +229,7 @@ extern size_t decode_string(struct udf_disc *, const dstring *, char *, size_t,
extern size_t encode_string(struct udf_disc *, dstring *, const char *, size_t);

/* misc.c */
extern const char *appname;
const char *appname;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong change as variable appname is already defined in misc.c. Therefore it can be only declared, not defined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the kind of error I get in folder mkudffs, if I don't drop that extern:

/bin/sh ../libtool --tag=CC --mode=link gcc -g -O2 -o mkudffs main.o mkudffs.o defaults.o file.o options.o ../libudffs/libudffs.la
libtool: link: gcc -g -O2 -o mkudffs main.o mkudffs.o defaults.o file.o options.o ../libudffs/.libs/libudffs.a
Undefined symbols for architecture x86_64:
"_appname", referenced from:
_main in main.o
_split_space in mkudffs.o
_setup_anchor in mkudffs.o
_setup_partition in mkudffs.o
_setup_space in mkudffs.o
_setup_vat in mkudffs.o
_setup_vds in mkudffs.o

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is defined in misc.c which is linked into libudffs.a. If linker does not see appname in libudffs.a when building mkudffs binary, you would need to debug build process and find out what is happening there.

I do not know Apple nor Darwin systems, so I cannot help with this part.

@gmerlino
Copy link
Author

gmerlino commented Jan 5, 2018

Thanks for the comments, each of which I replied to already.
Based on your recommendations, and waiting for further feedback from your side, I'll add a comment for the inclusion sys/disk.h in the meantime.

About your general remarks: most of the code you deem as (partly) dead code, is actually just bundled code, e.g., cdrom.h is copied/adapted from Linux system headers, not available under Darwin otherwise.

The rationale, of course, is that the three/four additional (new) files are meant to be substitutes for basic data types/structures/constants which are otherwise Linux-only (but not bound to the kernel): indeed the same pattern I explored has been used, piece-wise, in other porting projects by third parties, so I guess it makes sense.

About pktsetup: I guess you are right, but as discussed in the corresponding comment, it's a (first) step, at least to make the binaries all compile, and be launched in, e.g., demo mode at least, i.e., for automated testing like Travis.

Copy link
Author

@gmerlino gmerlino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted my answers.

@pali
Copy link
Owner

pali commented Jan 5, 2018

Those currently used linux-only headers are there for communication with Linux kernel. They cannot be copied from Linux system to non-Linux and hoping that something would work. Their functionality needs to be replaced by target system and I'm sure target system would provide own headers file (with different API). All this needs to be tested that it is working.

I'm not going to merge any broken or nonfunctional code. Before merging it needs to be tested that port is working correctly.

@gmerlino
Copy link
Author

gmerlino commented Jan 5, 2018

The ifded'ed headers, e.g. sys/disk.h, are equivalent to (differently-named) Linux headers, indeed providing the same interface.

The additional ones, e.g., darwin/cdrom.h, have no straight equivalent available, on one hand, and once slightly adapted as I did, provide no dependencies on the Linux kernel, mostly constants; on the other, these lead to a start-to-finish compilation and binaries which can be started, so at least not (fully) broken, but (quite possibly) partially working.

I guess this can be an initial step to have the port. Of course, once certain binaries/features are tested (sooner rather than later), and found broken and/or incomplete, those can be excluded from compilation under macOS (or certain switches disabled, respectively) until fixed, but in the meantime the build can be obtained, and automated (e.g., my Homebrew formula and the convenience that it brings).

Let me know.

PS: it should be clearly stated in the documentation, anyway, if/which parts of (any) port are incomplete/broken. To add some perspective of mine, until recently (when you started being the new -- active -- maintainer) udftools was almost abandonware, so (partly) broken.

@gmerlino gmerlino closed this Jan 15, 2018
@gmerlino gmerlino deleted the upstream/master branch January 15, 2018 16:28
@gmerlino gmerlino restored the upstream/master branch January 15, 2018 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants