函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:scripts\dtc\libfdt\fdt_ro.c Create Date:2022-07-27 07:15:47
首页 Copyright©Brick

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
{
    int pdepth = 0, p = 0;
    int offset, depth, namelen;
    const char *name;
 
    FDT_RO_PROBE(fdt);
 
    if (buflen < 2)
        return -FDT_ERR_NOSPACE;
 
    for (offset = 0, depth = 0;
         (offset >= 0) && (offset <= nodeoffset);
         offset = fdt_next_node(fdt, offset, &depth)) {
        while (pdepth > depth) {
            do {
                p--;
            } while (buf[p-1] != '/');
            pdepth--;
        }
 
        if (pdepth >= depth) {
            name = fdt_get_name(fdt, offset, &namelen);
            if (!name)
                return namelen;
            if ((p + namelen + 1) <= buflen) {
                memcpy(buf + p, name, namelen);
                p += namelen;
                buf[p++] = '/';
                pdepth++;
            }
        }
 
        if (offset == nodeoffset) {
            if (pdepth < (depth + 1))
                return -FDT_ERR_NOSPACE;
 
            if (p > 1) /* special case so that root path is "/", not "" */
                p--;
            buf[p] = '\0';
            return 0;
        }
    }
 
    if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0))
        return -FDT_ERR_BADOFFSET;
    else if (offset == -FDT_ERR_BADOFFSET)
        return -FDT_ERR_BADSTRUCTURE;
 
    return offset; /* error from fdt_next_node() */
}