Esempio n. 1
0
File: ulib.py Progetto: jtauber/pyv6
def stat(name):
    fd = open_(name, O_RDONLY)
    if fd < 0:
        return -1
    r, st = fstat(fd)
    close(fd)
    return r, st
Esempio n. 2
0
File: ls.py Progetto: jtauber/pyv6
def ls(path):
    
    fd = open_(path, 0)
    if fd < 0:
        printf(2, "ls: cannot open %s\n", path)
        return
    
    n, st = fstat(fd)
    if n < 0:
        printf(2, "ls: cannot stat %s\n", path)
        close(fd)
        return
    
    if st.type == T_FILE:
        printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size)
    
    elif st.type == T_DIR:
        if strlen(path) + 1 + DIRSIZ + 1 > 512:
            printf(1, "ls: path too long\n")
        else:
            prefix = path + "/"
            
            #while (read(fd, &de, sizeof(de)) == sizeof(de))
            while True:
                n, de = read(fd, 20)  # @@@ 20 = sizeof(de)
                if n != 20:
                    break
                de_inum = int(de[:6])
                de_name = de[6:].strip()  # @@@
                
                if de_inum == 0:
                    continue
                path = prefix + de_name
                
                n, st = stat(path)
                if n < 0:
                    printf(1, "ls: cannot stat %s\n", path)
                    continue
                
                printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size)
    close(fd)