c13c5be52549c43c8356c50588b196f668c38833 — Virgil Dupras 21 days ago ea87055
fs/fat2: remove

I'm changing my mind about porting ChaN's Fatfs module. It's an ok module, but
the code isn't that great and fitting it to sys/io and sys/file wouldn't be
without little bumps. I think I'm better of spending this time improving fs/fat.
5 files changed, 0 insertions(+), 106 deletions(-)

D fs/fs/fat2.c
D fs/fs/fat2.fs
M fs/tests/fs/all.fs
D fs/tests/fs/fat.fs
D license/chan-fatfs.txt
D fs/fs/fat2.c => fs/fs/fat2.c +0 -55
@@ 1,55 0,0 @@
/* Source: http://elm-chan.org/fsw/ff/00index_e.html
 * License: /license/chan-fatfs.txt
/* Differences with upstream
1. pdrv is a pointer to a Drive struct rather than a simple index.
2. Errors translate to aborts.
typedef unsigned int	UINT;	/* int must be 16-bit or 32-bit */
typedef unsigned char	BYTE;	/* char must be 8-bit */
typedef unsigned short	WORD;	/* 16-bit unsigned integer */
typedef unsigned int	DWORD;	/* 32-bit unsigned integer */

/* Type of file size and LBA variables */
typedef DWORD FSIZE_t;
typedef DWORD LBA_t;

#define FF_MAX_SS $1000
#define RES_OK 0

struct FATFS {
	BYTE	fs_type;		/* Filesystem type (0:not mounted) */
	Drive	*pdrv;			/* Volume hosting physical drive */
	BYTE	ldrv;			/* Logical drive number (used only when FF_FS_REENTRANT) */
	BYTE	n_fats;			/* Number of FATs (1 or 2) */
	BYTE	wflag;			/* win[] status (b0:dirty) */
	BYTE	fsi_flag;		/* FSINFO status (b7:disabled, b0:dirty) */
	WORD	id;				/* Volume mount ID */
	WORD	n_rootdir;		/* Number of root directory entries (FAT12/16) */
	WORD	csize;			/* Cluster size [sectors] */
	DWORD	last_clst;		/* Last allocated cluster */
	DWORD	free_clst;		/* Number of free clusters */
	DWORD	cdir;			/* Current directory start cluster (0:root) */
	DWORD	n_fatent;		/* Number of FAT entries (number of clusters + 2) */
	DWORD	fsize;			/* Number of sectors per FAT */
	LBA_t	volbase;		/* Volume base sector */
	LBA_t	fatbase;		/* FAT base sector */
	LBA_t	dirbase;		/* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */
	LBA_t	database;		/* Data base sector */
	LBA_t	winsect;		/* Current sector appearing in the win[] */
	BYTE	win[FF_MAX_SS];	/* Disk access window for Directory, FAT (and file data at tiny cfg) */

void sync_window(FATFS* fs) {
	if (fs->wflag) {	/* Is the disk access window dirty? */
		/* Write it back into the volume */
		disk_write(fs->pdrv, fs->win, fs->winsect, 1);
		fs->wflag = 0;	/* Clear window dirty flag */
		if (fs->winsect - fs->fatbase < fs->fsize) {	/* Is it in the 1st FAT? */
			if (fs->n_fats == 2) {
				/* Reflect it to 2nd FAT if needed */
				disk_write(fs->pdrv, fs->win, fs->winsect + fs->fsize, 1);

D fs/fs/fat2.fs => fs/fs/fat2.fs +0 -10
@@ 1,10 0,0 @@
?f<< /comp/c/lib.fs
?f<< /lib/endian.h

: disk_write ( drv buff sector count -- )
  over + for2 ( drv buff )
    2dup swap i rot> Drive :sec! ( drv buff ) over Drive secsz + next 2drop ;
:c void disk_write(uint pdrv, uchar *buff, uint sector, uint count);
cc<< /fs/fat2.c

S" FATFS" findTypedef CDecl :export

M fs/tests/fs/all.fs => fs/tests/fs/all.fs +0 -1
@@ 1,2 1,1 @@
f<< /tests/fs/dummy.fs
f<< /tests/fs/fat.fs

D fs/tests/fs/fat.fs => fs/tests/fs/fat.fs +0 -16
@@ 1,16 0,0 @@
?f<< /tests/harness.fs
?f<< /drv/ramdrive.fs
?f<< /fs/fat2.fs
\ tests for FAT FS
$200 4 RAMDrive :new structbind RAMDrive ramdrv
here FATFS SZ allot structbind FATFS fatfs
ramdrv :self to fatfs pdrv
$deadbeef fatfs win !
0 to fatfs fatbase
1234 to fatfs fsize
0 to fatfs winsect
1 to fatfs wflag
fatfs :self sync_window
ramdrv :buf( @ $deadbeef #eq

D license/chan-fatfs.txt => license/chan-fatfs.txt +0 -24
@@ 1,24 0,0 @@
FatFs License

FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.

/  FatFs - Generic FAT Filesystem Module  Rx.xx                               /
/ Copyright (C) 20xx, ChaN, all right reserved.
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
/ that the following condition is met:
/ 1. Redistributions of source code must retain the above copyright notice,
/    this condition and the following disclaimer.
/ This software is provided by the copyright holder and contributors "AS IS"
/ and any warranties related to this software are DISCLAIMED.
/ The copyright owner or contributors be NOT LIABLE for any damages caused
/ by use of this software.

Therefore FatFs license is one of the BSD-style licenses, but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, do not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses include GNU GPL. When you redistribute the FatFs source code with changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.