anchor.diff:  ;;;; Copyright (c) 2017-2018 Bruno Cichon <ebrasca@librepanther.com>
   ;;;; This code is licensed under the MIT license.
  -;;;; For now only support reading fat32 FS.
  +;;;; For now support reading fat32 FS and some write operations.
   
   (defpackage :mezzano.fat32-file-system
     (:use :cl :mezzano.file-system)
  -  (:export #:read-fat32-structure
  -           #:read-fat32-info-structure
  -           #:read-sector
  -           #:read-cluster
  -           #:read-file
  -           #:file-p
  -           #:read-dir-from-file
  -           #:read-dir-from-cluster
  -           #:decode-time
  -           #:decode-date))
  +  (:export))
   
   (in-package :mezzano.fat32-file-system)
   
  
positive.code: 
  (defun check-media-type (media-type)
    (loop :for n :in '(#xF0 #xF8 #xF9 #xFA #xFB #xFC #xFD #xFE #xFF)
       :do (when (= n media-type)
             (return media-type))
       :finally (error "Bad media-type : ~a .
  Valid media-type ara #xF0 #xF8 #xF9 #xFA #xFB #xFC #xFD #xFE #xFF" media-type)))
  
  (defun check-fat-type-label32 (fat-type-label)
  
negative.code:      :reserved-1 nil
       :trail-signature trail-signature)))
  
  (defun root-dir-sectors ()
    0)
  
  (defun data-sectors (fat32)
    (- (fat32-total-sectors32 fat32)
       (+ (fat32-reserved-sector-count fat32)
          (* (fat32-table-count fat32)
             (fat32-table-size-32 fat32))
          (root-dir-sectors))))
  
  (defun total-clusters (fat32)
    (floor
     (/ (data-sectors fat32)
        (fat32-sectors-per-cluster fat32))))
  
  (defun first-data-sector (fat32)
    (+ (fat32-reserved-sector-count fat32)
       (* (fat32-table-count fat32)
          (fat32-table-size-32 fat32))
       (root-dir-sectors)))
  
  (defun first-root-dir-sector (fat32)
    (- (first-data-sector fat32)
       (root-dir-sectors)))
  
  (defun first-sector-of-cluster (fat32 cluster)
    (+ (* (- cluster 2)
          (fat32-sectors-per-cluster fat32))
       (first-data-sector fat32)))
  
  (defun bytes-per-cluster (fat32)
    (* (fat32-sectors-per-cluster fat32)
       (fat32-bytes-per-sector fat32)))
  
  (defun read-sector (disk sector)
    "Read sectors from disk"
    (let* ((array (make-array (* 1 (mezzano.supervisor:disk-sector-size disk))
                              :area :wired :element-type '(unsigned-byte 8))))
      (mezzano.supervisor:disk-read disk sector 1 array)
      array))
  
  (defun write-sector (disk sector array)
    "Write sectors to disk"
    (mezzano.supervisor:disk-write disk sector 1 array)
    t)
  
  (defun read-cluster (fat32 disk cluster-sector)
    "Read cluster from cluster"
    (let* ((spc (fat32-sectors-per-cluster fat32))
           (cluster (make-array (* spc (mezzano.supervisor:disk-sector-size disk))
                                :area :wired :element-type '(unsigned-byte 8))))
      (mezzano.supervisor:disk-read disk cluster-sector spc cluster)
      cluster))
  
  (defun write-cluster (disk cluster-sector fat32 array)
    "Write cluster to disk"
    (mezzano.supervisor:disk-write disk
                                   cluster-sector
                                   (fat32-sectors-per-cluster fat32)
                                   array)
    t)
  
  ;;; bit offsets
  (defconstant +attribute-read-only+ 0)
  (defconstant +attribute-hidden+ 1)
  (defconstant +attribute-system+ 2)
  