Пример #1
0
def create(fname):
    for fdn in range(1, 24):  #A
        if (io.read_fdc(fdn, 0) == 193):
            entry = 24  #B
            lenlimit = False
            lseek(0, 0, True)  #C
            slot = bytearray(8)
            n = 0
            for j in range(0, 24):
                n = j
                if (io.bti(io.oft, 72) == 0):
                    entry = j
                    break
                if (lenlimit == False and read(0, slot, 8) == 0):  #D
                    lenlimit = True
                if (entry == 24 and (io.bti(slot, 0) == 0)):  #E
                    entry = j
                elif (io.bts(slot, 0) == fname):  #F
                    return 1
                if (entry == 24 and j < 23 and lenlimit):
                    entry = j
                    break
            if (entry == 24):  #G
                return 1
            lseek(0, entry * 8, True)  #H
            write(0, io.stb(fname) + io.itb(fdn), 8)  #I
            io.write_fdc(0, fdn, 0)  #J
            return 0
    return 1
Пример #2
0
def read(index, mem_area, count):
    if (io.bti(io.oft, index * 76 + 72) == 193):  #A
        return 193
    pos = io.bti(io.oft, index * 76 + 64)
    bn = 4 if int(pos / 64) == 0 else 8 if int(pos / 64) == 1 else 12
    readmax = io.bti(io.oft, index * 76 + 72) - pos  #B
    nread = min(count, readmax)
    for j in range(0, nread):  #C
        mem_area[j] = io.oft[index * 76 + pos % 64]  #D
        pos += 1
        lseek(index, pos, False)  #E
    return nread
Пример #3
0
def write(index, mem_area, count):
    flen = io.bti(io.oft, index * 76 + 72)
    if (flen == 193):
        return 193
    pos = io.bti(io.oft, index * 76 + 64)
    bn = 4 if int(pos / 64) == 0 else 8 if int(pos / 64) == 1 else 12
    nwrite = min(count, 192 - pos)
    for j in range(0, nwrite):  #A
        io.oft[index * 76 + pos % 64] = mem_area[j]  #B
        pos += 1
        lseek(index, pos, True)
    io.insert_int(min(flen + nwrite, 192), io.oft, index * 76 + 72)  #C
    return nwrite
Пример #4
0
def close_file(index):
    if (index > 3 or io.bti(io.oft, index * 76 + 72) == 193):  #A
        return 1
    fdn = io.bti(io.oft, index * 76 + 68)  #B
    pos = io.bti(io.oft, index * 76 + 64)  #B
    bn = 4 if int(pos / 64) == 0 else 8 if int(pos / 64) == 1 else 12  #C
    blockn = io.read_fdc(fdn, bn)
    io.write_block(blockn, io.ofte_buff(index))  #D
    io.write_fdc(io.bti(io.oft, index * 76 + 72), fdn, 0)  #E
    if (index > 0):
        io.insert_int(0, io.oft, index * 76 + 68)  #F
        io.insert_int(193, io.oft, index * 76 + 72)  #F
    return 0
Пример #5
0
def directory():
    lseek(0, 0, False)
    slot = bytearray(8)
    files = []
    for i in range(0, 24):
        read(0, slot, 8)
        fname = io.bts(slot, 0)
        if (fname in files):
            break
        if (io.bti(slot, 0) != 0):
            files.append(fname)
    return files
Пример #6
0
def lseek(index, pos, overlim):
    flen = io.bti(io.oft, index * 76 + 72)
    if ((not overlim and pos > flen) or flen == 193):
        return 1
    curr = io.bti(io.oft, index * 76 + 64)
    cbn = 4 if int(curr / 64) == 0 else 8 if int(curr / 64) == 1 else 12
    fdn = io.bti(io.oft, index * 76 + 68)
    if (io.read_fdc(fdn, cbn) == 0):  #A
        io.allocate_block(fdn, 4)
    else:
        if (int(pos / 64) != int(curr / 64)):  #B
            io.write_block(io.read_fdc(fdn, cbn), io.ofte_buff(index))  #C
            bn = 4 if int(pos / 64) == 0 else 8 if int(pos / 64) == 1 else 12
            blockn = io.read_fdc(fdn, bn)  #D
            if (blockn == 0):  #E
                c = io.allocate_block(fdn, bn)  #F
                if (c[0] == 0 and overlim == True):
                    io.read_block(c[1], index)
            else:
                io.read_block(blockn, index)  #G
    io.insert_int(pos, io.oft, index * 76 + 64)  #H
    return 0
Пример #7
0
def open_file(fname):
    lseek(0, 0, False)
    slot = bytearray(8)
    for i in range(0, 24):
        read(0, slot, 8)
        if (io.bts(slot, 0) == fname):  #A
            fdn = io.bti(slot, 4)
            index = 4
            for j in range(1, 4):
                if (io.bti(io.oft, j * 76 + 68) == fdn):  #B
                    return 1
                elif (index == 4 and io.bti(io.oft, j * 76 + 72) == 193):  #C
                    index = j
            if (index == 4):  #D
                return 4
            io.insert_int(0, io.oft, index * 76 + 64)  #E
            io.insert_int(fdn, io.oft, index * 76 + 68)  #E
            io.insert_int(io.read_fdc(fdn, 0), io.oft, index * 76 + 72)  #E
            blockn = io.read_fdc(fdn, 4)
            if (blockn > 0):
                io.read_block(blockn, index)  #F
            return index
    return 4
Пример #8
0
def destroy(fname):
    lseek(0, 0, False)
    slot = bytearray(8)
    for entry in range(0, 24):
        read(0, slot, 8)
        if (io.bts(slot, 0) == fname):  #A
            fdn = io.bti(slot, 4)  #B
            io.write_fdc(193, fdn, 0)  #C
            for bn in [4, 8, 12]:
                blockn = io.read_fdc(fdn, bn)
                if (blockn > 0):
                    io.deallocate_block(blockn, fdn, bn)  #D
            lseek(0, entry * 8, False)
            io.insert_int(0, io.oft, (entry % 8) * 8)  #E
            io.insert_int(0, io.oft, (entry % 8) * 8 + 4)  #E
            return 0
    return 1