Changeset 234 for trunk/src/helpers


Ignore:
Timestamp:
Dec 9, 2002, 9:15:24 PM (23 years ago)
Author:
umoeller
Message:

Minor changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh.c

    r229 r234  
    23792379
    23802380/*
     2381 *@@ FindEAValue:
     2382 *      returns the pointer to the EA value
     2383 *      if the EA with the given name exists
     2384 *      in the given FEA2LIST.
     2385 *
     2386 *      Within the FEA structure
     2387 *
     2388 +          typedef struct _FEA2 {
     2389 +              ULONG      oNextEntryOffset;  // Offset to next entry.
     2390 +              BYTE       fEA;               // Extended attributes flag.
     2391 +              BYTE       cbName;            // Length of szName, not including NULL.
     2392 +              USHORT     cbValue;           // Value length.
     2393 +              CHAR       szName[1];         // Extended attribute name.
     2394 +          } FEA2;
     2395 *
     2396 *      the EA value starts right after szName (plus its null
     2397 *      terminator). The first USHORT of the value should
     2398 *      normally signify the type of the EA, e.g. EAT_ASCII.
     2399 *      This returns a pointer to that type USHORT.
     2400 *
     2401 *@@added V0.9.16 (2001-10-25) [umoeller]
     2402 *@@changed V1.0.1 (2002-12-08) [umoeller]: moved this here from XWorkplace code, renamed from fsysFindEAValue
     2403 */
     2404
     2405PBYTE doshFindEAValue(PFEA2LIST pFEA2List2,      // in: file EA list
     2406                      PCSZ pcszEAName,           // in: EA name to search for (e.g. ".LONGNAME")
     2407                      PUSHORT pcbValue)          // out: length of value (ptr can be NULL)
     2408{
     2409    ULONG ulEANameLen;
     2410
     2411    /*
     2412    typedef struct _FEA2LIST {
     2413        ULONG     cbList;   // Total bytes of structure including full list.
     2414                            // Apparently, if EAs aren't supported, this
     2415                            // is == sizeof(ULONG).
     2416        FEA2      list[1];  // Variable-length FEA2 structures.
     2417    } FEA2LIST;
     2418
     2419    typedef struct _FEA2 {
     2420        ULONG      oNextEntryOffset;  // Offset to next entry.
     2421        BYTE       fEA;               // Extended attributes flag.
     2422        BYTE       cbName;            // Length of szName, not including NULL.
     2423        USHORT     cbValue;           // Value length.
     2424        CHAR       szName[1];         // Extended attribute name.
     2425    } FEA2;
     2426    */
     2427
     2428    if (!pFEA2List2)
     2429        return NULL;
     2430
     2431    if (    (pFEA2List2->cbList > sizeof(ULONG))
     2432                    // FAT32 and CDFS return 4 for anything here, so
     2433                    // we better not mess with anything else; I assume
     2434                    // any FS which doesn't support EAs will do so then
     2435         && (pcszEAName)
     2436         && (ulEANameLen = strlen(pcszEAName))
     2437       )
     2438    {
     2439        PFEA2 pThis = &pFEA2List2->list[0];
     2440        // maintain a current offset so we will never
     2441        // go beyond the end of the buffer accidentally...
     2442        // who knows what these stupid EA routines return!
     2443        ULONG ulOfsThis = sizeof(ULONG),
     2444              ul = 0;
     2445
     2446        while (ulOfsThis < pFEA2List2->cbList)
     2447        {
     2448            if (    (ulEANameLen == pThis->cbName)
     2449                 && (!memcmp(pThis->szName,
     2450                             pcszEAName,
     2451                             ulEANameLen))
     2452               )
     2453            {
     2454                if (pThis->cbValue)
     2455                {
     2456                    PBYTE pbValue =   (PBYTE)pThis
     2457                                    + sizeof(FEA2)
     2458                                    + pThis->cbName;
     2459                    if (pcbValue)
     2460                        *pcbValue = pThis->cbValue;
     2461                    return pbValue;
     2462                }
     2463                else
     2464                    // no value:
     2465                    return NULL;
     2466            }
     2467
     2468            if (!pThis->oNextEntryOffset)
     2469                // this was the last entry:
     2470                return NULL;
     2471
     2472            ulOfsThis += pThis->oNextEntryOffset;
     2473
     2474            pThis = (PFEA2)(((PBYTE)pThis) + pThis->oNextEntryOffset);
     2475            ul++;
     2476        } // end while
     2477    } // end if (    (pFEA2List2->cbList > sizeof(ULONG)) ...
     2478
     2479    return NULL;
     2480}
     2481
     2482/*
     2483 *@@ doshQueryLongname:
     2484 *      attempts to find the value of the .LONGNAME EA in the
     2485 *      given FEALIST and stores it in the pszLongname buffer,
     2486 *      which must be CCHMAXPATH in size.
     2487 *
     2488 *      Returns TRUE if a .LONGNAME was found and copied.
     2489 *
     2490 *@@added V0.9.16 (2001-10-25) [umoeller]
     2491 *@@changed V1.0.1 (2002-12-08) [umoeller]: moved this here from XWorkplace code, renamed from DecodeLongname
     2492 */
     2493
     2494BOOL doshQueryLongname(PFEA2LIST pFEA2List2,
     2495                       PSZ pszLongname,          // out: .LONGNAME if TRUE is returned
     2496                       PULONG pulNameLen)        // out: length of .LONGNAME string
     2497{
     2498    PBYTE pbValue;
     2499    if (pbValue = doshFindEAValue(pFEA2List2,
     2500                                  ".LONGNAME",
     2501                                  NULL))
     2502    {
     2503        PUSHORT pusType = (PUSHORT)pbValue;
     2504        if (*pusType == EAT_ASCII)
     2505        {
     2506            // CPREF: first word after EAT_ASCII specifies length
     2507            PUSHORT pusStringLength = pusType + 1;      // pbValue + 2
     2508            if (*pusStringLength)
     2509            {
     2510                ULONG cb = _min(*pusStringLength, CCHMAXPATH - 1);
     2511                memcpy(pszLongname,
     2512                       pbValue + 4,
     2513                       cb);
     2514                pszLongname[cb] = '\0';
     2515                *pulNameLen = cb;
     2516                return TRUE;
     2517            }
     2518        }
     2519    }
     2520
     2521    return FALSE;
     2522}
     2523
     2524/*
    23812525 *@@category: Helpers\Control program helpers\File management\XFILEs
    23822526 */
Note: See TracChangeset for help on using the changeset viewer.