VirtualBox

Ignore:
Timestamp:
Jun 29, 2022 6:18:57 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
152040
Message:

Main/UnattendedInstall: Minimalistic support for FreeBSD >= 10.0 sitting in my tree for too long, bugref:9781

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/UnattendedImpl.cpp

    r95156 r95436  
    449449    if (hrc == S_FALSE && mEnmOsType == VBOXOSTYPE_Unknown)
    450450        hrc = i_innerDetectIsoOSOs2(hVfsIso, &uBuf);
     451    if (hrc == S_FALSE && mEnmOsType == VBOXOSTYPE_Unknown)
     452        hrc = i_innerDetectIsoOSFreeBsd(hVfsIso, &uBuf);
    451453    if (mEnmOsType != VBOXOSTYPE_Unknown)
    452454    {
     
    21562158
    21572159
     2160/**
     2161 * Detect FreeBSD distro ISOs.
     2162 *
     2163 * @returns COM status code.
     2164 * @retval  S_OK if detected
     2165 * @retval  S_FALSE if not fully detected.
     2166 *
     2167 * @param   hVfsIso     The ISO file system.
     2168 * @param   pBuf        Read buffer.
     2169 */
     2170HRESULT Unattended::i_innerDetectIsoOSFreeBsd(RTVFS hVfsIso, DETECTBUFFER *pBuf)
     2171{
     2172    RT_NOREF(pBuf);
     2173
     2174    /*
     2175     * FreeBSD since 10.0 has a .profile file in the root which can be used to determine that this is FreeBSD
     2176     * along with the version.
     2177     */
     2178
     2179    RTVFSFILE hVfsFile;
     2180    HRESULT hrc = S_FALSE;
     2181    int vrc = RTVfsFileOpen(hVfsIso, ".profile", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
     2182    if (RT_SUCCESS(vrc))
     2183    {
     2184        static const uint8_t s_abFreeBsdHdr[] = "# $FreeBSD: releng/";
     2185        char abRead[32];
     2186
     2187        vrc = RTVfsFileRead(hVfsFile, &abRead[0], sizeof(abRead), NULL /*pcbRead*/);
     2188        if (   RT_SUCCESS(vrc)
     2189            && !memcmp(&abRead[0], &s_abFreeBsdHdr[0], sizeof(s_abFreeBsdHdr) - 1)) /* Skip terminator */
     2190        {
     2191            abRead[sizeof(abRead) - 1] = '\0';
     2192
     2193            /* Detect the architecture using the volume label. */
     2194            char szVolumeId[128];
     2195            size_t cchVolumeId;
     2196            vrc = RTVfsQueryLabel(hVfsIso, szVolumeId, 128, &cchVolumeId);
     2197            if (RT_SUCCESS(vrc))
     2198            {
     2199                /* Can re-use the Linux code here. */
     2200                if (!detectLinuxArchII(szVolumeId, &mEnmOsType, VBOXOSTYPE_FreeBSD))
     2201                    LogRel(("Unattended/FBSD: Unknown: arch='%s'\n", szVolumeId));
     2202
     2203                /* Detect the version from the string coming after the needle in .profile. */
     2204                AssertCompile(sizeof(s_abFreeBsdHdr) - 1 < sizeof(abRead));
     2205
     2206                char *pszVersionStart = &abRead[sizeof(s_abFreeBsdHdr) - 1];
     2207                char *pszVersionEnd = pszVersionStart;
     2208
     2209                while (RT_C_IS_DIGIT(*pszVersionEnd))
     2210                    pszVersionEnd++;
     2211                if (*pszVersionEnd == '.')
     2212                {
     2213                    pszVersionEnd++; /* Skip the . */
     2214
     2215                    while (RT_C_IS_DIGIT(*pszVersionEnd))
     2216                        pszVersionEnd++;
     2217
     2218                    /* Terminate the version string. */
     2219                    *pszVersionEnd = '\0';
     2220
     2221                    try { mStrDetectedOSVersion = pszVersionStart; }
     2222                    catch (std::bad_alloc &) { hrc = E_OUTOFMEMORY; }
     2223                }
     2224                else
     2225                    LogRel(("Unattended/FBSD: Unknown: version='%s'\n", &abRead[0]));
     2226            }
     2227            else
     2228            {
     2229                LogRel(("Unattended/FBSD: No Volume Label found\n"));
     2230                mEnmOsType = VBOXOSTYPE_FreeBSD;
     2231            }
     2232
     2233            hrc = S_OK;
     2234        }
     2235
     2236        RTVfsFileRelease(hVfsFile);
     2237    }
     2238
     2239    return hrc;
     2240}
     2241
     2242
    21582243HRESULT Unattended::prepare()
    21592244{
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette