fatlib - HobbyOSs/opennask GitHub Wiki

How to use fatlib

See: fatlib – standalone FAT filesystem library

  • fat_open_virt
DRIVE *fat_open_virt(struct fat_dops *dops, void *priv, int rw)

仮想のimgファイルを作ってそこにデータを書き込める(はず)。

  • fat_dopsのコールバック関数定義は以下の通り

注意

  1. fatlibのコールバック関数あC99のものなのでC++では使用できない。[C言語]指示付きの初期化子 (Designated Initializer)
  2. コールバック関数は右のリンクの形で実装する。コールバック関数の登録とかのコード
struct fat_dops {
/*
 * return value:
 *   0		success (*len bytes read/written)
 *   Exxx	errno error (*len updated to actual byte count)
 * error should not be returned if *len remains unchanged
 * *len will never be <= 0 on entry
 * if on write buf==NULL region should be zeroed
 * information in pos+len..pos+discard-1 is not important for fs
 */
	int (*read)(void *priv, char *buf, long pos, int *len);
	int (*write)(void *priv, const char *buf, long pos, int *len, int discard);
	void (*free)(void *priv, long pos, int len); /* region no longer used */
	int (*sync)(void *priv);
	void (*close)(void *priv);
};

例) fat_open_virtの使用

static int im_write(void *priv, char *buf, long pos, int *len) {
  // 実装
}

// fat_dops
struct fat_dops dops;
dops.write = im_write;

...

fat_open_virt(&dops, 0, 0);

  • fat_open_image
DRIVE *fat_open_image(const char *path, int rw)

実際のimgファイルを読んでそこにデータを書き込める(はず)。

  • fat_drive_close
void fat_drive_close(DRIVE*)

DRIVE* をクローズする