flashdisk

  1# This file was automatically generated by SWIG (https://www.swig.org).
  2# Version 4.2.1
  3#
  4# Do not make changes to this file unless you know what you are doing - modify
  5# the SWIG interface file instead.
  6
  7from sys import version_info as _swig_python_version_info
  8from mock_rtems import _flashdisk as _flashdisk
  9
 10try:
 11    import builtins as __builtin__
 12except ImportError:
 13    import __builtin__
 14
 15def _swig_repr(self):
 16    try:
 17        strthis = "proxy of " + self.this.__repr__()
 18    except __builtin__.Exception:
 19        strthis = ""
 20    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
 21
 22
 23def _swig_setattr_nondynamic_instance_variable(set):
 24    def set_instance_attr(self, name, value):
 25        if name == "this":
 26            set(self, name, value)
 27        elif name == "thisown":
 28            self.this.own(value)
 29        elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
 30            set(self, name, value)
 31        else:
 32            raise AttributeError("You cannot add instance attributes to %s" % self)
 33    return set_instance_attr
 34
 35
 36def _swig_setattr_nondynamic_class_variable(set):
 37    def set_class_attr(cls, name, value):
 38        if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
 39            set(cls, name, value)
 40        else:
 41            raise AttributeError("You cannot add class attributes to %s" % cls)
 42    return set_class_attr
 43
 44
 45def _swig_add_metaclass(metaclass):
 46    """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
 47    def wrapper(cls):
 48        return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
 49    return wrapper
 50
 51
 52class _SwigNonDynamicMeta(type):
 53    """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
 54    __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
 55
 56
 57RTEMS_FLASHDISK_DEVICE_BASE_NAME = _flashdisk.RTEMS_FLASHDISK_DEVICE_BASE_NAME
 58r"""
 59    Flash disk driver for RTEMS provides support for block based
 60    file systems on flash devices. The driver is not a flash file
 61    system nor does it try to compete with flash file systems. It
 62    currently does not journal how-ever block sequence numbering
 63    could be added to allow recovery of a past positions if
 64    a power down occurred while being updated.
 65
 66    This flash driver provides block device support for most flash
 67    devices. The driver has been tested on NOR type devices such
 68    as the AMLV160 or M28W160. Support for NAND type devices may
 69    require driver changes to allow speedy recover of the block
 70    mapping data and to also handle the current use of word programming.
 71    Currently the page descriptors are stored in the first few pages
 72    of each segment.
 73
 74    The driver supports devices, segments and pages. You provide
 75    to the driver the device descriptions as a table of device
 76    descriptors. Each device descriptor contain a table of
 77    segment descriptions or segment descriptors. The driver uses
 78    this information to manage the devices.
 79
 80    A device is made up of segments. These are also called
 81    sectors or blocks. It is the smallest erasable part of a device.
 82    A device can have differing size segments at different
 83    offsets in the device. The segment descriptors support repeating
 84    segments that are continuous in the device. The driver breaks the
 85    segments up into pages. The first pages of a segment contain
 86    the page descriptors. A page descriptor hold the page flags,
 87    a CRC for the page of data and the block number the page
 88    holds. The block can appear in any order in the devices. A
 89    page is active if it hold a current block of data. If the
 90    used bit is set the page is counted as used. A page moves
 91    from erased to active to used then back to erased. If a block
 92    is written that is already in a page, the block is written to
 93    a new page the old page is flagged as used.
 94
 95    At initialization time each segment's page descriptors are
 96    read into memory and scanned to determine the active pages,
 97    the used pages and the bad pages. If a segment has any erased
 98    pages it is queue on the available queue. If the segment has
 99    no erased pages it is queue on the used queue.
100
101    The available queue is sorted from the least number available
102    to the most number of available pages. A segment that has just
103    been erased will placed at the end of the queue. A segment that
104    has only a few available pages will be used sooner and once
105    there are no available pages it is queued on the used queue.
106    The used queue hold segments that have no available pages and
107    is sorted from the least number of active pages to the most
108    number of active pages.
109
110    The driver is required to compact segments. Compacting takes
111    the segment with the most number of available pages from the
112    available queue then takes segments with the least number of
113    active pages from the used queue until it has enough pages
114    to fill the empty segment. As the active pages are moved
115    they flagged as used and once the segment has only used pages
116    it is erased.
117
118    A flash block driver like this never knows if a page is not
119    being used by the file-system. A typical file system is not
120    design with the idea of erasing a block on a disk once it is
121    not being used. The file-system will normally use a flag
122    or a location as a marker to say that part of the disk is
123    no longer in use. This means a number of blocks could be
124    held in active pages but are no in use by the file system.
125    The file system may also read blocks that have never been
126    written to disk. This complicates the driver and may make
127    the wear, usage and erase patterns harsher than a flash
128    file system. The driver may also suffer from problems if
129    power is lost.
130
131    There are some flash disk specific IO control request types.
132    To use open the device and issue the ioctl() call.
133
134    .. code-block:: c++
135
136         int fd = open ("/dev/flashdisk0", O_WRONLY, 0);
137         if (fd < 0)
138         {
139           printf ("driver open failed: %s\n", strerror (errno));
140           exit (1);
141         }
142         if (ioctl (fd, RTEMS_FDISK_IOCTL_ERASE_DISK) < 0)
143         {
144           printf ("driver erase failed: %s\n", strerror (errno));
145           exit (1);
146         }
147         close (fd);
148     *
149    The base name of the flash disks.
150    """
151class rtems_fdisk_monitor_data(object):
152    r"""
153    Flash Disk Monitoring Data allows a user to obtain
154    the current status of the disk.
155    """
156
157    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
158    __repr__ = _swig_repr
159    block_size = property(_flashdisk.rtems_fdisk_monitor_data_block_size_get, _flashdisk.rtems_fdisk_monitor_data_block_size_set, doc=r"""block_size : uint32_t""")
160    block_count = property(_flashdisk.rtems_fdisk_monitor_data_block_count_get, _flashdisk.rtems_fdisk_monitor_data_block_count_set, doc=r"""block_count : uint32_t""")
161    unavail_blocks = property(_flashdisk.rtems_fdisk_monitor_data_unavail_blocks_get, _flashdisk.rtems_fdisk_monitor_data_unavail_blocks_set, doc=r"""unavail_blocks : uint32_t""")
162    device_count = property(_flashdisk.rtems_fdisk_monitor_data_device_count_get, _flashdisk.rtems_fdisk_monitor_data_device_count_set, doc=r"""device_count : uint32_t""")
163    segment_count = property(_flashdisk.rtems_fdisk_monitor_data_segment_count_get, _flashdisk.rtems_fdisk_monitor_data_segment_count_set, doc=r"""segment_count : uint32_t""")
164    page_count = property(_flashdisk.rtems_fdisk_monitor_data_page_count_get, _flashdisk.rtems_fdisk_monitor_data_page_count_set, doc=r"""page_count : uint32_t""")
165    blocks_used = property(_flashdisk.rtems_fdisk_monitor_data_blocks_used_get, _flashdisk.rtems_fdisk_monitor_data_blocks_used_set, doc=r"""blocks_used : uint32_t""")
166    segs_available = property(_flashdisk.rtems_fdisk_monitor_data_segs_available_get, _flashdisk.rtems_fdisk_monitor_data_segs_available_set, doc=r"""segs_available : uint32_t""")
167    segs_used = property(_flashdisk.rtems_fdisk_monitor_data_segs_used_get, _flashdisk.rtems_fdisk_monitor_data_segs_used_set, doc=r"""segs_used : uint32_t""")
168    segs_failed = property(_flashdisk.rtems_fdisk_monitor_data_segs_failed_get, _flashdisk.rtems_fdisk_monitor_data_segs_failed_set, doc=r"""segs_failed : uint32_t""")
169    seg_erases = property(_flashdisk.rtems_fdisk_monitor_data_seg_erases_get, _flashdisk.rtems_fdisk_monitor_data_seg_erases_set, doc=r"""seg_erases : uint32_t""")
170    pages_desc = property(_flashdisk.rtems_fdisk_monitor_data_pages_desc_get, _flashdisk.rtems_fdisk_monitor_data_pages_desc_set, doc=r"""pages_desc : uint32_t""")
171    pages_active = property(_flashdisk.rtems_fdisk_monitor_data_pages_active_get, _flashdisk.rtems_fdisk_monitor_data_pages_active_set, doc=r"""pages_active : uint32_t""")
172    pages_used = property(_flashdisk.rtems_fdisk_monitor_data_pages_used_get, _flashdisk.rtems_fdisk_monitor_data_pages_used_set, doc=r"""pages_used : uint32_t""")
173    pages_bad = property(_flashdisk.rtems_fdisk_monitor_data_pages_bad_get, _flashdisk.rtems_fdisk_monitor_data_pages_bad_set, doc=r"""pages_bad : uint32_t""")
174    info_level = property(_flashdisk.rtems_fdisk_monitor_data_info_level_get, _flashdisk.rtems_fdisk_monitor_data_info_level_set, doc=r"""info_level : uint32_t""")
175
176    def __init__(self):
177        r"""__init__(rtems_fdisk_monitor_data self) -> rtems_fdisk_monitor_data"""
178        _flashdisk.rtems_fdisk_monitor_data_swiginit(self, _flashdisk.new_rtems_fdisk_monitor_data())
179    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_monitor_data
180
181# Register rtems_fdisk_monitor_data in _flashdisk:
182_flashdisk.rtems_fdisk_monitor_data_swigregister(rtems_fdisk_monitor_data)
183class rtems_fdisk_segment_desc(object):
184    r"""
185    Flash Segment Descriptor holds, number of continuous segments in the
186    device of this type, the base segment number in the device, the address
187    offset of the base segment in the device, and the size of segment.
188
189    Typically this structure is part of a table of segments in the
190    device which is referenced in the flash disk configuration table.
191    The reference is kept in the driver and used all the time to
192    manage the flash device, therefore it must always exist.
193    """
194
195    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
196    __repr__ = _swig_repr
197    count = property(_flashdisk.rtems_fdisk_segment_desc_count_get, _flashdisk.rtems_fdisk_segment_desc_count_set, doc=r""" Number of segments of this type in a row.""")
198    segment = property(_flashdisk.rtems_fdisk_segment_desc_segment_get, _flashdisk.rtems_fdisk_segment_desc_segment_set, doc=r""" The base segment number.""")
199    offset = property(_flashdisk.rtems_fdisk_segment_desc_offset_get, _flashdisk.rtems_fdisk_segment_desc_offset_set, doc=r""" Address offset of base segment in device.""")
200    size = property(_flashdisk.rtems_fdisk_segment_desc_size_get, _flashdisk.rtems_fdisk_segment_desc_size_set, doc=r""" Size of the segment in bytes.""")
201
202    def __init__(self):
203        r"""__init__(rtems_fdisk_segment_desc self) -> rtems_fdisk_segment_desc"""
204        _flashdisk.rtems_fdisk_segment_desc_swiginit(self, _flashdisk.new_rtems_fdisk_segment_desc())
205    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_segment_desc
206
207# Register rtems_fdisk_segment_desc in _flashdisk:
208_flashdisk.rtems_fdisk_segment_desc_swigregister(rtems_fdisk_segment_desc)
209class rtems_fdisk_driver_handlers(object):
210    r"""
211    Flash Low Level driver handlers.
212
213    Typically this structure is part of a table of handlers in the
214    device which is referenced in the flash disk configuration table.
215    The reference is kept in the driver and used all the time to
216    manage the flash device, therefore it must always exist.
217    """
218
219    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
220    __repr__ = _swig_repr
221    read = property(_flashdisk.rtems_fdisk_driver_handlers_read_get, _flashdisk.rtems_fdisk_driver_handlers_read_set, doc=r"""
222    Read data from the device into the buffer. Return an errno
223    error number if the device cannot be read. A segment descriptor
224    can describe more than one segment in a device if the device has
225    repeating segments. The segment number is the device segment to
226    access and the segment descriptor must reference the segment
227    being requested. For example the segment number must resided in
228    the range [base, base + count).
229
230    :param sd: The segment descriptor.
231    :param device: The device to read data from.
232    :param segment: The segment within the device to read.
233    :param offset: The offset in the segment to read.
234    :param buffer: The buffer to read the data into.
235    :param size: The amount of data to read.
236    """)
237    write = property(_flashdisk.rtems_fdisk_driver_handlers_write_get, _flashdisk.rtems_fdisk_driver_handlers_write_set, doc=r"""
238    Write data from the buffer to the device. Return an errno
239    error number if the device cannot be written to. A segment
240    descriptor can describe more than segment in a device if the
241    device has repeating segments. The segment number is the device
242    segment to access and the segment descriptor must reference
243    the segment being requested. For example the segment number must
244    resided in the range [base, base + count).
245
246    :param sd: The segment descriptor.
247    :param device: The device to write data from.
248    :param segment: The segment within the device to write to.
249    :param offset: The offset in the segment to write.
250    :param buffer: The buffer to write the data from.
251    :param size: The amount of data to write.
252    """)
253    blank = property(_flashdisk.rtems_fdisk_driver_handlers_blank_get, _flashdisk.rtems_fdisk_driver_handlers_blank_set, doc=r"""
254    Blank a segment in the device. Return an errno error number
255    if the device cannot be read or is not blank. A segment descriptor
256    can describe more than segment in a device if the device has
257    repeating segments. The segment number is the device segment to
258    access and the segment descriptor must reference the segment
259    being requested. For example the segment number must resided in
260    the range [base, base + count).
261
262    :param sd: The segment descriptor.
263    :param device: The device to read data from.
264    :param segment: The segment within the device to read.
265    :param offset: The offset in the segment to checl.
266    :param size: The amount of data to check.
267    """)
268    verify = property(_flashdisk.rtems_fdisk_driver_handlers_verify_get, _flashdisk.rtems_fdisk_driver_handlers_verify_set, doc=r"""
269    Verify data in the buffer to the data in the device. Return an
270    errno error number if the device cannot be read. A segment
271    descriptor can describe more than segment in a device if the
272    device has repeating segments. The segment number is the
273    segment to access and the segment descriptor must reference
274    the device segment being requested. For example the segment number
275    must resided in the range [base, base + count).
276
277    :param sd: The segment descriptor.
278    :param device: The device to verify data in.
279    :param segment: The segment within the device to verify.
280    :param offset: The offset in the segment to verify.
281    :param buffer: The buffer to verify the data in the device with.
282    :param size: The amount of data to verify.
283    """)
284    erase = property(_flashdisk.rtems_fdisk_driver_handlers_erase_get, _flashdisk.rtems_fdisk_driver_handlers_erase_set, doc=r"""
285    Erase the segment. Return an errno error number if the
286    segment cannot be erased. A segment descriptor can describe
287    more than segment in a device if the device has repeating
288    segments. The segment number is the device segment to access and
289    the segment descriptor must reference the segment being requested.
290
291    :param sd: The segment descriptor.
292    :param device: The device to erase the segment of.
293    :param segment: The segment within the device to erase.
294    """)
295    erase_device = property(_flashdisk.rtems_fdisk_driver_handlers_erase_device_get, _flashdisk.rtems_fdisk_driver_handlers_erase_device_set, doc=r"""
296    Erase the device. Return an errno error number if the
297    segment cannot be erased. A segment descriptor can describe
298    more than segment in a device if the device has repeating
299    segments. The segment number is the segment to access and
300    the segment descriptor must reference the segment being requested.
301
302    :param sd: The segment descriptor.
303    :param device: The device to erase.
304    """)
305
306    def __init__(self):
307        r"""__init__(rtems_fdisk_driver_handlers self) -> rtems_fdisk_driver_handlers"""
308        _flashdisk.rtems_fdisk_driver_handlers_swiginit(self, _flashdisk.new_rtems_fdisk_driver_handlers())
309    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_driver_handlers
310
311# Register rtems_fdisk_driver_handlers in _flashdisk:
312_flashdisk.rtems_fdisk_driver_handlers_swigregister(rtems_fdisk_driver_handlers)
313class rtems_fdisk_device_desc(object):
314    r"""
315    Flash Device Descriptor holds the segments in a device.
316
317    The placing of the segments in a device decriptor allows the low level
318    driver to share the segment descriptors for a number of devices.
319
320    Typically this structure is part of a table of segments in the
321    device which is referenced in the flash disk configuration table.
322    The reference is kept in the driver and used all the time to
323    manage the flash device, therefore it must always exist.
324    """
325
326    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
327    __repr__ = _swig_repr
328    segment_count = property(_flashdisk.rtems_fdisk_device_desc_segment_count_get, _flashdisk.rtems_fdisk_device_desc_segment_count_set, doc=r""" Number of segments.""")
329    segments = property(_flashdisk.rtems_fdisk_device_desc_segments_get, _flashdisk.rtems_fdisk_device_desc_segments_set, doc=r""" Array of segments.""")
330    flash_ops = property(_flashdisk.rtems_fdisk_device_desc_flash_ops_get, _flashdisk.rtems_fdisk_device_desc_flash_ops_set, doc=r""" Device handlers.""")
331
332    def __init__(self):
333        r"""__init__(rtems_fdisk_device_desc self) -> rtems_fdisk_device_desc"""
334        _flashdisk.rtems_fdisk_device_desc_swiginit(self, _flashdisk.new_rtems_fdisk_device_desc())
335    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_device_desc
336
337# Register rtems_fdisk_device_desc in _flashdisk:
338_flashdisk.rtems_fdisk_device_desc_swigregister(rtems_fdisk_device_desc)
339class rtems_flashdisk_config(object):
340    r"""
341    RTEMS Flash Disk configuration table used to initialise the
342    driver.
343
344    The unavailable blocks count is the number of blocks less than the
345    available number of blocks the file system is given. This means there
346    will always be that number of blocks available when the file system
347    thinks the disk is full. The compaction code needs blocks to compact
348    with so you will never be able to have all the blocks allocated to the
349    file system and be able to full the disk.
350
351    The compacting segment count is the number of segments that are
352    moved into a new segment. A high number will mean more segments with
353    low active page counts and high used page counts will be moved into
354    avaliable pages how-ever this extends the compaction time due to
355    time it takes the erase the pages. There is no pont making this number
356    greater than the maximum number of pages in a segment.
357
358    The available compacting segment count is the level when compaction occurs
359    when writing. If you set this to 0 then compaction will fail because
360    there will be no segments to compact into.
361
362    The info level can be 0 for off with error, and abort messages allowed.
363    Level 1 is warning messages, level 1 is informational messages, and level 3
364    is debugging type prints. The info level can be turned off with a compile
365    time directive on the command line to the compiler of:
366
367        -DRTEMS_FDISK_TRACE=0
368    """
369
370    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
371    __repr__ = _swig_repr
372    block_size = property(_flashdisk.rtems_flashdisk_config_block_size_get, _flashdisk.rtems_flashdisk_config_block_size_set, doc=r""" The block size.""")
373    device_count = property(_flashdisk.rtems_flashdisk_config_device_count_get, _flashdisk.rtems_flashdisk_config_device_count_set, doc=r""" The number of devices.""")
374    devices = property(_flashdisk.rtems_flashdisk_config_devices_get, _flashdisk.rtems_flashdisk_config_devices_set, doc=r""" The device descriptions.""")
375    flags = property(_flashdisk.rtems_flashdisk_config_flags_get, _flashdisk.rtems_flashdisk_config_flags_set, doc=r"""
376    Set of flags to control
377                                                         driver.
378    """)
379    unavail_blocks = property(_flashdisk.rtems_flashdisk_config_unavail_blocks_get, _flashdisk.rtems_flashdisk_config_unavail_blocks_set, doc=r"""
380    Number of blocks not available to the file system.  This number must be
381    greater than or equal to the number of blocks in the largest segment to
382    avoid starvation of erased blocks.
383    """)
384    compact_segs = property(_flashdisk.rtems_flashdisk_config_compact_segs_get, _flashdisk.rtems_flashdisk_config_compact_segs_set, doc=r"""
385    Max number of segs to
386                                                         compact in one pass.
387    """)
388    avail_compact_segs = property(_flashdisk.rtems_flashdisk_config_avail_compact_segs_get, _flashdisk.rtems_flashdisk_config_avail_compact_segs_set, doc=r"""
389    The number of segments when compaction occurs when writing.  In case the
390    number of segments in the available queue is less than or equal to this
391    number the compaction process will be triggered.  The available queue
392    contains all segments with erased blocks.
393    """)
394    info_level = property(_flashdisk.rtems_flashdisk_config_info_level_get, _flashdisk.rtems_flashdisk_config_info_level_set, doc=r""" Default info level.""")
395
396    def __init__(self):
397        r"""__init__(rtems_flashdisk_config self) -> rtems_flashdisk_config"""
398        _flashdisk.rtems_flashdisk_config_swiginit(self, _flashdisk.new_rtems_flashdisk_config())
399    __swig_destroy__ = _flashdisk.delete_rtems_flashdisk_config
400
401# Register rtems_flashdisk_config in _flashdisk:
402_flashdisk.rtems_flashdisk_config_swigregister(rtems_flashdisk_config)
403RTEMS_FDISK_BACKGROUND_ERASE = _flashdisk.RTEMS_FDISK_BACKGROUND_ERASE
404r"""Leave the erasing of used segment to the background handler."""
405RTEMS_FDISK_BACKGROUND_COMPACT = _flashdisk.RTEMS_FDISK_BACKGROUND_COMPACT
406r"""Leave the compacting of of used segment to the background handler."""
407RTEMS_FDISK_CHECK_PAGES = _flashdisk.RTEMS_FDISK_CHECK_PAGES
408r"""
409    Check the pages during initialisation to see which pages are
410    valid and which are not. This could slow down initialising the
411    disk driver.
412    """
413RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE = _flashdisk.RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE
414r"""
415    Blank check the flash device before writing to them. This is needed if
416    you think you have a driver or device problem.
417    """
418
419def rtems_fdisk_initialize(major, minor, arg):
420    r"""
421    Flash disk device driver initialization. Place in a table as the
422    initialisation entry and remainder of the entries are the
423    RTEMS block device generic handlers.
424
425    :type major: rtems_device_major_number
426    :param major: Flash disk major device number.
427    :type minor: rtems_device_minor_number
428    :param minor: Minor device number, not applicable.
429    :type arg: void
430    :param arg: Initialization argument, not applicable.
431    :rtype: rtems_device_driver
432    :return: The rtems_device_driver is actually just
433                rtems_status_code.
434    """
435    return _flashdisk.rtems_fdisk_initialize(major, minor, arg)
436
437cvar = _flashdisk.cvar
438rtems_flashdisk_configuration = cvar.rtems_flashdisk_configuration
RTEMS_FLASHDISK_DEVICE_BASE_NAME = See C documentation

Flash disk driver for RTEMS provides support for block based file systems on flash devices. The driver is not a flash file system nor does it try to compete with flash file systems. It currently does not journal how-ever block sequence numbering could be added to allow recovery of a past positions if a power down occurred while being updated.

This flash driver provides block device support for most flash devices. The driver has been tested on NOR type devices such as the AMLV160 or M28W160. Support for NAND type devices may require driver changes to allow speedy recover of the block mapping data and to also handle the current use of word programming. Currently the page descriptors are stored in the first few pages of each segment.

The driver supports devices, segments and pages. You provide to the driver the device descriptions as a table of device descriptors. Each device descriptor contain a table of segment descriptions or segment descriptors. The driver uses this information to manage the devices.

A device is made up of segments. These are also called sectors or blocks. It is the smallest erasable part of a device. A device can have differing size segments at different offsets in the device. The segment descriptors support repeating segments that are continuous in the device. The driver breaks the segments up into pages. The first pages of a segment contain the page descriptors. A page descriptor hold the page flags, a CRC for the page of data and the block number the page holds. The block can appear in any order in the devices. A page is active if it hold a current block of data. If the used bit is set the page is counted as used. A page moves from erased to active to used then back to erased. If a block is written that is already in a page, the block is written to a new page the old page is flagged as used.

At initialization time each segment's page descriptors are read into memory and scanned to determine the active pages, the used pages and the bad pages. If a segment has any erased pages it is queue on the available queue. If the segment has no erased pages it is queue on the used queue.

The available queue is sorted from the least number available to the most number of available pages. A segment that has just been erased will placed at the end of the queue. A segment that has only a few available pages will be used sooner and once there are no available pages it is queued on the used queue. The used queue hold segments that have no available pages and is sorted from the least number of active pages to the most number of active pages.

The driver is required to compact segments. Compacting takes the segment with the most number of available pages from the available queue then takes segments with the least number of active pages from the used queue until it has enough pages to fill the empty segment. As the active pages are moved they flagged as used and once the segment has only used pages it is erased.

A flash block driver like this never knows if a page is not being used by the file-system. A typical file system is not design with the idea of erasing a block on a disk once it is not being used. The file-system will normally use a flag or a location as a marker to say that part of the disk is no longer in use. This means a number of blocks could be held in active pages but are no in use by the file system. The file system may also read blocks that have never been written to disk. This complicates the driver and may make the wear, usage and erase patterns harsher than a flash file system. The driver may also suffer from problems if power is lost.

There are some flash disk specific IO control request types. To use open the device and issue the ioctl() call.

int fd = open ("/dev/flashdisk0", O_WRONLY, 0);
    if (fd < 0)
    {
      printf ("driver open failed: %s\n", strerror (errno));
      exit (1);
    }
    if (ioctl (fd, RTEMS_FDISK_IOCTL_ERASE_DISK) < 0)
    {
      printf ("driver erase failed: %s\n", strerror (errno));
      exit (1);
    }
    close (fd);
*

The base name of the flash disks.

class rtems_fdisk_monitor_data:
152class rtems_fdisk_monitor_data(object):
153    r"""
154    Flash Disk Monitoring Data allows a user to obtain
155    the current status of the disk.
156    """
157
158    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
159    __repr__ = _swig_repr
160    block_size = property(_flashdisk.rtems_fdisk_monitor_data_block_size_get, _flashdisk.rtems_fdisk_monitor_data_block_size_set, doc=r"""block_size : uint32_t""")
161    block_count = property(_flashdisk.rtems_fdisk_monitor_data_block_count_get, _flashdisk.rtems_fdisk_monitor_data_block_count_set, doc=r"""block_count : uint32_t""")
162    unavail_blocks = property(_flashdisk.rtems_fdisk_monitor_data_unavail_blocks_get, _flashdisk.rtems_fdisk_monitor_data_unavail_blocks_set, doc=r"""unavail_blocks : uint32_t""")
163    device_count = property(_flashdisk.rtems_fdisk_monitor_data_device_count_get, _flashdisk.rtems_fdisk_monitor_data_device_count_set, doc=r"""device_count : uint32_t""")
164    segment_count = property(_flashdisk.rtems_fdisk_monitor_data_segment_count_get, _flashdisk.rtems_fdisk_monitor_data_segment_count_set, doc=r"""segment_count : uint32_t""")
165    page_count = property(_flashdisk.rtems_fdisk_monitor_data_page_count_get, _flashdisk.rtems_fdisk_monitor_data_page_count_set, doc=r"""page_count : uint32_t""")
166    blocks_used = property(_flashdisk.rtems_fdisk_monitor_data_blocks_used_get, _flashdisk.rtems_fdisk_monitor_data_blocks_used_set, doc=r"""blocks_used : uint32_t""")
167    segs_available = property(_flashdisk.rtems_fdisk_monitor_data_segs_available_get, _flashdisk.rtems_fdisk_monitor_data_segs_available_set, doc=r"""segs_available : uint32_t""")
168    segs_used = property(_flashdisk.rtems_fdisk_monitor_data_segs_used_get, _flashdisk.rtems_fdisk_monitor_data_segs_used_set, doc=r"""segs_used : uint32_t""")
169    segs_failed = property(_flashdisk.rtems_fdisk_monitor_data_segs_failed_get, _flashdisk.rtems_fdisk_monitor_data_segs_failed_set, doc=r"""segs_failed : uint32_t""")
170    seg_erases = property(_flashdisk.rtems_fdisk_monitor_data_seg_erases_get, _flashdisk.rtems_fdisk_monitor_data_seg_erases_set, doc=r"""seg_erases : uint32_t""")
171    pages_desc = property(_flashdisk.rtems_fdisk_monitor_data_pages_desc_get, _flashdisk.rtems_fdisk_monitor_data_pages_desc_set, doc=r"""pages_desc : uint32_t""")
172    pages_active = property(_flashdisk.rtems_fdisk_monitor_data_pages_active_get, _flashdisk.rtems_fdisk_monitor_data_pages_active_set, doc=r"""pages_active : uint32_t""")
173    pages_used = property(_flashdisk.rtems_fdisk_monitor_data_pages_used_get, _flashdisk.rtems_fdisk_monitor_data_pages_used_set, doc=r"""pages_used : uint32_t""")
174    pages_bad = property(_flashdisk.rtems_fdisk_monitor_data_pages_bad_get, _flashdisk.rtems_fdisk_monitor_data_pages_bad_set, doc=r"""pages_bad : uint32_t""")
175    info_level = property(_flashdisk.rtems_fdisk_monitor_data_info_level_get, _flashdisk.rtems_fdisk_monitor_data_info_level_set, doc=r"""info_level : uint32_t""")
176
177    def __init__(self):
178        r"""__init__(rtems_fdisk_monitor_data self) -> rtems_fdisk_monitor_data"""
179        _flashdisk.rtems_fdisk_monitor_data_swiginit(self, _flashdisk.new_rtems_fdisk_monitor_data())
180    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_monitor_data

Flash Disk Monitoring Data allows a user to obtain the current status of the disk.

rtems_fdisk_monitor_data()
177    def __init__(self):
178        r"""__init__(rtems_fdisk_monitor_data self) -> rtems_fdisk_monitor_data"""
179        _flashdisk.rtems_fdisk_monitor_data_swiginit(self, _flashdisk.new_rtems_fdisk_monitor_data())

__init__(rtems_fdisk_monitor_data self) -> rtems_fdisk_monitor_data

thisown
158    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

The membership flag

block_size
block_count
unavail_blocks
device_count
segment_count
page_count
blocks_used
segs_available
segs_used
segs_failed
seg_erases
pages_desc
pages_active
pages_used
pages_bad
info_level
class rtems_fdisk_segment_desc:
184class rtems_fdisk_segment_desc(object):
185    r"""
186    Flash Segment Descriptor holds, number of continuous segments in the
187    device of this type, the base segment number in the device, the address
188    offset of the base segment in the device, and the size of segment.
189
190    Typically this structure is part of a table of segments in the
191    device which is referenced in the flash disk configuration table.
192    The reference is kept in the driver and used all the time to
193    manage the flash device, therefore it must always exist.
194    """
195
196    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
197    __repr__ = _swig_repr
198    count = property(_flashdisk.rtems_fdisk_segment_desc_count_get, _flashdisk.rtems_fdisk_segment_desc_count_set, doc=r""" Number of segments of this type in a row.""")
199    segment = property(_flashdisk.rtems_fdisk_segment_desc_segment_get, _flashdisk.rtems_fdisk_segment_desc_segment_set, doc=r""" The base segment number.""")
200    offset = property(_flashdisk.rtems_fdisk_segment_desc_offset_get, _flashdisk.rtems_fdisk_segment_desc_offset_set, doc=r""" Address offset of base segment in device.""")
201    size = property(_flashdisk.rtems_fdisk_segment_desc_size_get, _flashdisk.rtems_fdisk_segment_desc_size_set, doc=r""" Size of the segment in bytes.""")
202
203    def __init__(self):
204        r"""__init__(rtems_fdisk_segment_desc self) -> rtems_fdisk_segment_desc"""
205        _flashdisk.rtems_fdisk_segment_desc_swiginit(self, _flashdisk.new_rtems_fdisk_segment_desc())
206    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_segment_desc

Flash Segment Descriptor holds, number of continuous segments in the device of this type, the base segment number in the device, the address offset of the base segment in the device, and the size of segment.

Typically this structure is part of a table of segments in the device which is referenced in the flash disk configuration table. The reference is kept in the driver and used all the time to manage the flash device, therefore it must always exist.

rtems_fdisk_segment_desc()
203    def __init__(self):
204        r"""__init__(rtems_fdisk_segment_desc self) -> rtems_fdisk_segment_desc"""
205        _flashdisk.rtems_fdisk_segment_desc_swiginit(self, _flashdisk.new_rtems_fdisk_segment_desc())

__init__(rtems_fdisk_segment_desc self) -> rtems_fdisk_segment_desc

thisown
196    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

The membership flag

count
segment
offset
size
class rtems_fdisk_driver_handlers:
210class rtems_fdisk_driver_handlers(object):
211    r"""
212    Flash Low Level driver handlers.
213
214    Typically this structure is part of a table of handlers in the
215    device which is referenced in the flash disk configuration table.
216    The reference is kept in the driver and used all the time to
217    manage the flash device, therefore it must always exist.
218    """
219
220    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
221    __repr__ = _swig_repr
222    read = property(_flashdisk.rtems_fdisk_driver_handlers_read_get, _flashdisk.rtems_fdisk_driver_handlers_read_set, doc=r"""
223    Read data from the device into the buffer. Return an errno
224    error number if the device cannot be read. A segment descriptor
225    can describe more than one segment in a device if the device has
226    repeating segments. The segment number is the device segment to
227    access and the segment descriptor must reference the segment
228    being requested. For example the segment number must resided in
229    the range [base, base + count).
230
231    :param sd: The segment descriptor.
232    :param device: The device to read data from.
233    :param segment: The segment within the device to read.
234    :param offset: The offset in the segment to read.
235    :param buffer: The buffer to read the data into.
236    :param size: The amount of data to read.
237    """)
238    write = property(_flashdisk.rtems_fdisk_driver_handlers_write_get, _flashdisk.rtems_fdisk_driver_handlers_write_set, doc=r"""
239    Write data from the buffer to the device. Return an errno
240    error number if the device cannot be written to. A segment
241    descriptor can describe more than segment in a device if the
242    device has repeating segments. The segment number is the device
243    segment to access and the segment descriptor must reference
244    the segment being requested. For example the segment number must
245    resided in the range [base, base + count).
246
247    :param sd: The segment descriptor.
248    :param device: The device to write data from.
249    :param segment: The segment within the device to write to.
250    :param offset: The offset in the segment to write.
251    :param buffer: The buffer to write the data from.
252    :param size: The amount of data to write.
253    """)
254    blank = property(_flashdisk.rtems_fdisk_driver_handlers_blank_get, _flashdisk.rtems_fdisk_driver_handlers_blank_set, doc=r"""
255    Blank a segment in the device. Return an errno error number
256    if the device cannot be read or is not blank. A segment descriptor
257    can describe more than segment in a device if the device has
258    repeating segments. The segment number is the device segment to
259    access and the segment descriptor must reference the segment
260    being requested. For example the segment number must resided in
261    the range [base, base + count).
262
263    :param sd: The segment descriptor.
264    :param device: The device to read data from.
265    :param segment: The segment within the device to read.
266    :param offset: The offset in the segment to checl.
267    :param size: The amount of data to check.
268    """)
269    verify = property(_flashdisk.rtems_fdisk_driver_handlers_verify_get, _flashdisk.rtems_fdisk_driver_handlers_verify_set, doc=r"""
270    Verify data in the buffer to the data in the device. Return an
271    errno error number if the device cannot be read. A segment
272    descriptor can describe more than segment in a device if the
273    device has repeating segments. The segment number is the
274    segment to access and the segment descriptor must reference
275    the device segment being requested. For example the segment number
276    must resided in the range [base, base + count).
277
278    :param sd: The segment descriptor.
279    :param device: The device to verify data in.
280    :param segment: The segment within the device to verify.
281    :param offset: The offset in the segment to verify.
282    :param buffer: The buffer to verify the data in the device with.
283    :param size: The amount of data to verify.
284    """)
285    erase = property(_flashdisk.rtems_fdisk_driver_handlers_erase_get, _flashdisk.rtems_fdisk_driver_handlers_erase_set, doc=r"""
286    Erase the segment. Return an errno error number if the
287    segment cannot be erased. A segment descriptor can describe
288    more than segment in a device if the device has repeating
289    segments. The segment number is the device segment to access and
290    the segment descriptor must reference the segment being requested.
291
292    :param sd: The segment descriptor.
293    :param device: The device to erase the segment of.
294    :param segment: The segment within the device to erase.
295    """)
296    erase_device = property(_flashdisk.rtems_fdisk_driver_handlers_erase_device_get, _flashdisk.rtems_fdisk_driver_handlers_erase_device_set, doc=r"""
297    Erase the device. Return an errno error number if the
298    segment cannot be erased. A segment descriptor can describe
299    more than segment in a device if the device has repeating
300    segments. The segment number is the segment to access and
301    the segment descriptor must reference the segment being requested.
302
303    :param sd: The segment descriptor.
304    :param device: The device to erase.
305    """)
306
307    def __init__(self):
308        r"""__init__(rtems_fdisk_driver_handlers self) -> rtems_fdisk_driver_handlers"""
309        _flashdisk.rtems_fdisk_driver_handlers_swiginit(self, _flashdisk.new_rtems_fdisk_driver_handlers())
310    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_driver_handlers

Flash Low Level driver handlers.

Typically this structure is part of a table of handlers in the device which is referenced in the flash disk configuration table. The reference is kept in the driver and used all the time to manage the flash device, therefore it must always exist.

rtems_fdisk_driver_handlers()
307    def __init__(self):
308        r"""__init__(rtems_fdisk_driver_handlers self) -> rtems_fdisk_driver_handlers"""
309        _flashdisk.rtems_fdisk_driver_handlers_swiginit(self, _flashdisk.new_rtems_fdisk_driver_handlers())

__init__(rtems_fdisk_driver_handlers self) -> rtems_fdisk_driver_handlers

thisown
220    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

The membership flag

read
write
blank
verify
erase
erase_device
class rtems_fdisk_device_desc:
314class rtems_fdisk_device_desc(object):
315    r"""
316    Flash Device Descriptor holds the segments in a device.
317
318    The placing of the segments in a device decriptor allows the low level
319    driver to share the segment descriptors for a number of devices.
320
321    Typically this structure is part of a table of segments in the
322    device which is referenced in the flash disk configuration table.
323    The reference is kept in the driver and used all the time to
324    manage the flash device, therefore it must always exist.
325    """
326
327    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
328    __repr__ = _swig_repr
329    segment_count = property(_flashdisk.rtems_fdisk_device_desc_segment_count_get, _flashdisk.rtems_fdisk_device_desc_segment_count_set, doc=r""" Number of segments.""")
330    segments = property(_flashdisk.rtems_fdisk_device_desc_segments_get, _flashdisk.rtems_fdisk_device_desc_segments_set, doc=r""" Array of segments.""")
331    flash_ops = property(_flashdisk.rtems_fdisk_device_desc_flash_ops_get, _flashdisk.rtems_fdisk_device_desc_flash_ops_set, doc=r""" Device handlers.""")
332
333    def __init__(self):
334        r"""__init__(rtems_fdisk_device_desc self) -> rtems_fdisk_device_desc"""
335        _flashdisk.rtems_fdisk_device_desc_swiginit(self, _flashdisk.new_rtems_fdisk_device_desc())
336    __swig_destroy__ = _flashdisk.delete_rtems_fdisk_device_desc

Flash Device Descriptor holds the segments in a device.

The placing of the segments in a device decriptor allows the low level driver to share the segment descriptors for a number of devices.

Typically this structure is part of a table of segments in the device which is referenced in the flash disk configuration table. The reference is kept in the driver and used all the time to manage the flash device, therefore it must always exist.

rtems_fdisk_device_desc()
333    def __init__(self):
334        r"""__init__(rtems_fdisk_device_desc self) -> rtems_fdisk_device_desc"""
335        _flashdisk.rtems_fdisk_device_desc_swiginit(self, _flashdisk.new_rtems_fdisk_device_desc())

__init__(rtems_fdisk_device_desc self) -> rtems_fdisk_device_desc

thisown
327    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

The membership flag

segment_count
segments
flash_ops
class rtems_flashdisk_config:
340class rtems_flashdisk_config(object):
341    r"""
342    RTEMS Flash Disk configuration table used to initialise the
343    driver.
344
345    The unavailable blocks count is the number of blocks less than the
346    available number of blocks the file system is given. This means there
347    will always be that number of blocks available when the file system
348    thinks the disk is full. The compaction code needs blocks to compact
349    with so you will never be able to have all the blocks allocated to the
350    file system and be able to full the disk.
351
352    The compacting segment count is the number of segments that are
353    moved into a new segment. A high number will mean more segments with
354    low active page counts and high used page counts will be moved into
355    avaliable pages how-ever this extends the compaction time due to
356    time it takes the erase the pages. There is no pont making this number
357    greater than the maximum number of pages in a segment.
358
359    The available compacting segment count is the level when compaction occurs
360    when writing. If you set this to 0 then compaction will fail because
361    there will be no segments to compact into.
362
363    The info level can be 0 for off with error, and abort messages allowed.
364    Level 1 is warning messages, level 1 is informational messages, and level 3
365    is debugging type prints. The info level can be turned off with a compile
366    time directive on the command line to the compiler of:
367
368        -DRTEMS_FDISK_TRACE=0
369    """
370
371    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
372    __repr__ = _swig_repr
373    block_size = property(_flashdisk.rtems_flashdisk_config_block_size_get, _flashdisk.rtems_flashdisk_config_block_size_set, doc=r""" The block size.""")
374    device_count = property(_flashdisk.rtems_flashdisk_config_device_count_get, _flashdisk.rtems_flashdisk_config_device_count_set, doc=r""" The number of devices.""")
375    devices = property(_flashdisk.rtems_flashdisk_config_devices_get, _flashdisk.rtems_flashdisk_config_devices_set, doc=r""" The device descriptions.""")
376    flags = property(_flashdisk.rtems_flashdisk_config_flags_get, _flashdisk.rtems_flashdisk_config_flags_set, doc=r"""
377    Set of flags to control
378                                                         driver.
379    """)
380    unavail_blocks = property(_flashdisk.rtems_flashdisk_config_unavail_blocks_get, _flashdisk.rtems_flashdisk_config_unavail_blocks_set, doc=r"""
381    Number of blocks not available to the file system.  This number must be
382    greater than or equal to the number of blocks in the largest segment to
383    avoid starvation of erased blocks.
384    """)
385    compact_segs = property(_flashdisk.rtems_flashdisk_config_compact_segs_get, _flashdisk.rtems_flashdisk_config_compact_segs_set, doc=r"""
386    Max number of segs to
387                                                         compact in one pass.
388    """)
389    avail_compact_segs = property(_flashdisk.rtems_flashdisk_config_avail_compact_segs_get, _flashdisk.rtems_flashdisk_config_avail_compact_segs_set, doc=r"""
390    The number of segments when compaction occurs when writing.  In case the
391    number of segments in the available queue is less than or equal to this
392    number the compaction process will be triggered.  The available queue
393    contains all segments with erased blocks.
394    """)
395    info_level = property(_flashdisk.rtems_flashdisk_config_info_level_get, _flashdisk.rtems_flashdisk_config_info_level_set, doc=r""" Default info level.""")
396
397    def __init__(self):
398        r"""__init__(rtems_flashdisk_config self) -> rtems_flashdisk_config"""
399        _flashdisk.rtems_flashdisk_config_swiginit(self, _flashdisk.new_rtems_flashdisk_config())
400    __swig_destroy__ = _flashdisk.delete_rtems_flashdisk_config

RTEMS Flash Disk configuration table used to initialise the driver.

The unavailable blocks count is the number of blocks less than the available number of blocks the file system is given. This means there will always be that number of blocks available when the file system thinks the disk is full. The compaction code needs blocks to compact with so you will never be able to have all the blocks allocated to the file system and be able to full the disk.

The compacting segment count is the number of segments that are moved into a new segment. A high number will mean more segments with low active page counts and high used page counts will be moved into avaliable pages how-ever this extends the compaction time due to time it takes the erase the pages. There is no pont making this number greater than the maximum number of pages in a segment.

The available compacting segment count is the level when compaction occurs when writing. If you set this to 0 then compaction will fail because there will be no segments to compact into.

The info level can be 0 for off with error, and abort messages allowed. Level 1 is warning messages, level 1 is informational messages, and level 3 is debugging type prints. The info level can be turned off with a compile time directive on the command line to the compiler of:

-DRTEMS_FDISK_TRACE=0
rtems_flashdisk_config()
397    def __init__(self):
398        r"""__init__(rtems_flashdisk_config self) -> rtems_flashdisk_config"""
399        _flashdisk.rtems_flashdisk_config_swiginit(self, _flashdisk.new_rtems_flashdisk_config())

__init__(rtems_flashdisk_config self) -> rtems_flashdisk_config

thisown
371    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

The membership flag

block_size
device_count
devices
flags
unavail_blocks
compact_segs
avail_compact_segs
info_level
RTEMS_FDISK_BACKGROUND_ERASE = See C documentation

Leave the erasing of used segment to the background handler.

RTEMS_FDISK_BACKGROUND_COMPACT = See C documentation

Leave the compacting of of used segment to the background handler.

RTEMS_FDISK_CHECK_PAGES = See C documentation

Check the pages during initialisation to see which pages are valid and which are not. This could slow down initialising the disk driver.

RTEMS_FDISK_BLANK_CHECK_BEFORE_WRITE = See C documentation

Blank check the flash device before writing to them. This is needed if you think you have a driver or device problem.

def rtems_fdisk_initialize(major, minor, arg):
420def rtems_fdisk_initialize(major, minor, arg):
421    r"""
422    Flash disk device driver initialization. Place in a table as the
423    initialisation entry and remainder of the entries are the
424    RTEMS block device generic handlers.
425
426    :type major: rtems_device_major_number
427    :param major: Flash disk major device number.
428    :type minor: rtems_device_minor_number
429    :param minor: Minor device number, not applicable.
430    :type arg: void
431    :param arg: Initialization argument, not applicable.
432    :rtype: rtems_device_driver
433    :return: The rtems_device_driver is actually just
434                rtems_status_code.
435    """
436    return _flashdisk.rtems_fdisk_initialize(major, minor, arg)

Flash disk device driver initialization. Place in a table as the initialisation entry and remainder of the entries are the RTEMS block device generic handlers.

Parameters
  • major: Flash disk major device number.
  • minor: Minor device number, not applicable.
  • arg: Initialization argument, not applicable.
Returns

The rtems_device_driver is actually just rtems_status_code.

cvar = See C documentation
rtems_flashdisk_configuration = See C documentation