On Wed, Sep 05, 2018 at 01:15:50PM +0200, Jan Kiszka wrote:
> On 2018-09-05 13:04, Andreas Reichel wrote:
> > On Tue, Sep 04, 2018 at 05:44:01PM +0200, Jan Kiszka wrote:
> > > On 2018-09-03 16:09, [ext] Andreas J. Reichel wrote:
> > > > From: Andreas Reichel <[email protected]>
> > > >
> > > > To compare device paths it is necessary to be able to split off
> > > > sub-paths from the right hand side. Implement a simple function
> > > > for that purpose.
> > > >
> > > > Signed-off-by: Andreas Reichel <[email protected]>
> > > > ---
> > > > include/utils.h | 1 +
> > > > utils.c | 25 +++++++++++++++++++++++++
> > > > 2 files changed, 26 insertions(+)
> > > >
> > > > diff --git a/include/utils.h b/include/utils.h
> > > > index b8eddd1..846e8be 100644
> > > > --- a/include/utils.h
> > > > +++ b/include/utils.h
> > > > @@ -41,5 +41,6 @@ EFI_STATUS get_volumes(VOLUME_DESC **volumes, UINTN
> > > > *count);
> > > > EFI_STATUS close_volumes(VOLUME_DESC *volumes, UINTN count);
> > > > EFI_DEVICE_PATH *FileDevicePathFromConfig(EFI_HANDLE device,
> > > > CHAR16 *payloadpath);
> > > > +CHAR16 *dirname(CHAR16 *input);
> > > > #endif // __H_UTILS__
> > > > diff --git a/utils.c b/utils.c
> > > > index 5aff01b..94226fb 100644
> > > > --- a/utils.c
> > > > +++ b/utils.c
> > > > @@ -271,3 +271,28 @@ EFI_DEVICE_PATH
> > > > *FileDevicePathFromConfig(EFI_HANDLE device,
> > > > return appendeddevpath;
> > > > }
> > > > +
> > > > +CHAR16 *dirname(CHAR16 *input)
> > > > +{
> > > > + CHAR16 *dst;
> > > > + UINTN len;
> > > > +
> > > > + len = StrLen(input);
> > > > +
> > > > + dst = mmalloc((len + 1) * sizeof(CHAR16));
> > > > + if (!dst) {
> > > > + return NULL;
> > > > + }
> > > > +
> > > > + StrCpy(dst, input);
> > > > +
> > > > + for (UINTN i = len; i > 0; i--)
> > > > + {
> > > > + if (dst[i] == L'/') {
> > > > + dst[i] = L'\0';
> > > > + break;
> > > > + }
> > > > + }
> > > > +
> > > > + return dst;
> > > > +}
> > > >
> > >
> > > There are two corner cases that the POSIX dirname addresses specially
> > > while
> > > this one does not:
> > >
> > > - dirname("/dir/") = "/" => you return "/dir"
> > > - dirname("") and dirname("file") = "." => you return "" and "file",
> > > respectively
> > >
> > > And there is another, more major difference: dirname() works with static
> > > result buffers or modifies the input.
> > >
> > > Given these deviations, we should either adjust to POSIX or at least call
> > > that thing slightly differently (GetDirname?).
> >
> > Okay look, before, it was called "RemoveLastNodeFromDevicePath" or
>
> How would that function deal with the corner cases?
>
There ARE no such corner cases... there is no leading slash and there
are no empty strings and there is no file... so we are talking about
implementing
for theoretical scenarious which simply are not there with UEFI device.
Or am I wrong and you saw an implementation where this happens?
> > something like that, which was exactly what it did.
> > Then you wanted to call that dirname... because the function did similar
> > things like dirname.
> > Now you tell me that this function behaves differently than dirname in
> > POSIX?
> >
> > This is NOT dirname and I called it so because you wanted it.
> > Please tell me, what exactly do you want because somehow I don't
> > understand you.
>
> If you want "ExtractDevicePath" rather than something generic, call it like
> that. But generally it is better to follow existing, understood standards.
>
By that you imply "follow POSIX standard", but we have no POSIX within
UEFI. So why should we follow Posix standard. You cannot follow a
standard where it does not exist.
I already told you, the name was good as it was "RemoveLastNodeFrom..."
because it is not extract nor anything else... it already was a
devicepath. Because a partition is also a 'device' in UEFI obviously.
Maybe that is a point for confusion?
But I really don't like to argue about this function name anymore...
Please chose one of the following:
a) GetPathToDeviceFromDevicePath
b) GetPathToDevice
c) ExtractPathToDevice
d) ExtractDevicePathToDevice
e) RemoveLastNode
f) RemoveLastNodeFromDevicePath
g) TrimToSlashFromRight
But anyhow this will never be and need not be something generic. And by
no means POSIX here.
If you name me a breaking condition that happens because you have it,
I will fix it.
Andreas
> Jan
>
> --
> Siemens AG, Corporate Technology, CT RDA IOT SES-DE
> Corporate Competence Center Embedded Linux
--
Andreas Reichel
Dipl.-Phys. (Univ.)
Software Consultant
[email protected], +49-174-3180074
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterfoehring
Geschaeftsfuehrer: Henrik Klagges, Dr. Robert Dahlke, Gerhard Mueller
Sitz: Unterfoehring * Amtsgericht Muenchen * HRB 135082
--
You received this message because you are subscribed to the Google Groups "EFI
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/efibootguard-dev/20180905114411.GA15276%40iiotirae.
For more options, visit https://groups.google.com/d/optout.