Skip to content

Commit 54743b6

Browse files
authored
Merge pull request #52 from nateinaction/fix-blockdevice
Fix BlockDevice Protocol
2 parents e6b488b + 1aebecd commit 54743b6

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

circuitpython_typing/__init__.py

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -93,51 +93,23 @@ class BlockDevice(Protocol):
9393
include `storage.VfsFat`.
9494
"""
9595

96-
def readblocks(self, block_num: int, buf: bytearray) -> None:
96+
def readblocks(self, start_block: int, buf: WriteableBuffer) -> None:
9797
"""Read aligned, multiples of blocks. Starting at
98-
the block given by the index ``block_num``, read blocks
99-
from the device into ``buf`` (an array of bytes). The number
100-
of blocks to read is given by the length of ``buf``,
101-
which will be a multiple of the block size.
98+
the block given by the index ``start_block``, read blocks
99+
from the device into ``buf``. The number of blocks to
100+
read is given by the length of ``buf``, which will be a
101+
multiple of the block size.
102102
"""
103103

104-
def writeblocks(self, block_num: int, buf: bytearray) -> None:
104+
def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None:
105105
"""Write aligned, multiples of blocks, and require that
106106
the blocks that are written to be first erased (if necessary)
107107
by this method. Starting at the block given by the index
108-
``block_num``, write blocks from ``buf`` (an array of bytes) to the
109-
device. The number of blocks to write is given by the length
108+
``start_block``, write blocks from ``buf`` to the device.
109+
The number of blocks to write is given by the length
110110
of ``buf``, which will be a multiple of the block size.
111111
"""
112112

113-
def ioctl(self, operation: int, arg: Optional[int] = None) -> Optional[int]:
114-
"""Control the block device and query its parameters. The operation to
115-
perform is given by ``operation`` which is one of the following integers:
116-
117-
* 1 - initialise the device (``arg`` is unused)
118-
* 2 - shutdown the device (``arg`` is unused)
119-
* 3 - sync the device (``arg`` is unused)
120-
* 4 - get a count of the number of blocks, should return an integer (``arg`` is unused)
121-
* 5 - get the number of bytes in a block, should return an integer,
122-
or ``None`` in which case the default value of 512 is used (``arg`` is unused)
123-
* 6 - erase a block, arg is the block number to erase
124-
125-
As a minimum ``ioctl(4, ...)`` must be intercepted; for littlefs ``ioctl(6, ...)``
126-
must also be intercepted. The need for others is hardware dependent.
127-
128-
Prior to any call to ``writeblocks(block, ...)`` littlefs issues ``ioctl(6, block)``.
129-
This enables a device driver to erase the block prior to a write if the hardware
130-
requires it. Alternatively a driver might intercept ``ioctl(6, block)`` and return 0
131-
(success). In this case the driver assumes responsibility for detecting the need
132-
for erasure.
133-
134-
Unless otherwise stated ``ioctl(operation, arg)`` can return ``None``. Consequently an
135-
implementation can ignore unused values of ``operation``. Where ``operation`` is
136-
intercepted, the return value for operations 4 and 5 are as detailed above. Other
137-
operations should return 0 on success and non-zero for failure, with the value returned
138-
being an ``OSError`` errno code.
139-
"""
140-
141113

142114
# These types may not be in adafruit-blinka, so use the string form instead of a resolved name.
143115

0 commit comments

Comments
 (0)