68 #ifndef GSC_FS_MAX_FILE_NUM 69 #define GSC_FS_MAX_FILE_NUM 2 75 static struct st_file_desc {
89 file_desc[i].flg_used = 0;
105 if((
'0' <= path[0]) && (path[0] <=
'9')) {
106 devno = path[0] -
'0';
130 fs = filesystems[devno];
150 DTFPRINTF(0x01,
"path = %s, flgas = %08X\n", path, flags);
158 if(file_desc[i].flg_used == 0) {
159 file_desc[i].fs = fs;
160 fdesc = fs->open(path, flags);
162 file_desc[i].fs_desc = fdesc;
163 file_desc[i].flg_used = 1;
172 SYSERR_PRINT(
"cannot open file \"%s\" (GSC_FS_MAX_FILE_NUM)\n", path);
177 #define ACCESS_SIZE 0x4000 193 DTFPRINTF(0x02,
"fd = %d, buf = %p, count = %d\n", fd, buf, count);
195 fs = file_desc[fd].fs;
201 rtn = fs->read(file_desc[fd].fs_desc, buf, count);
221 DTFPRINTF(0x02,
"fd = %d, buf = %p, count = %d\n", fd, buf, count);
223 fs = file_desc[fd].fs;
229 rtn = fs->write(file_desc[fd].fs_desc, buf, count);
249 DTFPRINTF(0x02,
"fd = %d, offset = %d, whence = %d\n", fd, offset, whence);
251 fs = file_desc[fd].fs;
257 rtn = fs->seek(file_desc[fd].fs_desc, offset, whence);
275 DTFPRINTF(0x01,
"fd = %d\n", fd);
277 fs = file_desc[fd].fs;
283 rtn = fs->tell(file_desc[fd].fs_desc);
302 DTFPRINTF(0x01,
"fd = %d\n", fd);
304 fs = file_desc[fd].fs;
310 rtn = fs->close(file_desc[fd].fs_desc);
313 file_desc[fd].flg_used = 0;
316 SYSERR_PRINT(
"cannot close file (%d)\n", fd);
334 DTFPRINTF(0x01,
"dir = %p, name = %s\n", dir, name);
341 if(fs->opendir != 0) {
342 dir = fs->opendir(name);
361 DTFPRINTF(0x02,
"dir = %p, info = %p\n", dir, finfo);
368 if(fs->readdir != 0) {
369 rtn = fs->readdir(dir, finfo);
387 DTFPRINTF(0x01,
"dir = %p\n", dir);
394 if(fs->closedir != 0) {
395 rtn = fs->closedir(dir);
414 DTFPRINTF(0x02,
"path = %s, info = %p\n", path, finfo);
422 rtn = fs->stat(path, finfo);
442 DTFPRINTF(0x02,
"path = %s, sect = %p, fs = %p\n", path, sect, fso);
449 if(fs->getfree != 0) {
450 rtn = fs->getfree(path, sect, fso);
468 DTFPRINTF(0x01,
"fd = %d\n", fd);
470 fs = file_desc[fd].fs;
476 rtn = fs->sync(file_desc[fd].fs_desc);
494 DTFPRINTF(0x02,
"path = %s\n", path);
501 if(fs->unlink != 0) {
502 rtn = fs->unlink(path);
520 DTFPRINTF(0x02,
"path = %s\n", path);
528 rtn = fs->mkdir(path);
534 #if FF_USE_CHMOD != 0 543 int chmod_file(
const uchar *path,
unsigned char flag)
548 DTFPRINTF(0x02,
"path = %s, flag = %d\n", path, flag);
556 rtn = fs->chmod(path, flag);
578 DTFPRINTF(0x02,
"oldpath = %s, newpath = %s\n", oldpath, newpath);
585 if(fs->rename != 0) {
586 rtn = fs->rename(oldpath, newpath);
604 int mkfs_file(
const uchar *path,
unsigned char part,
unsigned short alloc)
609 DTFPRINTF(0x02,
"path = %s, part = %d, alloc = %d\n", ath, part, alloc);
617 rtn = fs->mkfs(path, part, alloc);
652 if((*p ==
'\\') || *p ==
'/') {
705 char * size2str(
char *str, t_size size)
707 t_size size_g = (1024L*1024*1024L);
708 t_size size_m = (1024L*1024);
709 t_size size_k = 1024L;
712 if((size/size_g) < 10) {
713 tsnprintf(str, SIZE_STR_LEN,
"%1d.%1dG", (
int)(size/size_g), (
int)((size-((size/size_g))*size_g))/1024/1024/100);
715 tsnprintf(str, SIZE_STR_LEN,
"%3dG", (
int)(size/size_g));
717 }
else if(size >= size_m) {
718 if((size/size_m) < 10) {
719 tsnprintf(str, SIZE_STR_LEN,
"%1d.%1dM", (
int)(size/size_m), (
int)((size-((size/size_m))*size_m))/1024/100);
721 tsnprintf(str, SIZE_STR_LEN,
"%3dM", (
int)(size/size_m));
723 }
else if(size >= size_k) {
724 if((size/size_k) < 10) {
725 tsnprintf(str, SIZE_STR_LEN,
"%1d.%1dK", (
int)(size/size_k), (
int)((size-((size/size_k))*size_k))/100);
727 tsnprintf(str, SIZE_STR_LEN,
"%3dK", (
int)(size/size_k));
730 tsnprintf(str, SIZE_STR_LEN,
"%3dB", (
int)size);
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
t_ssize seek_file(int fd, t_ssize offset, int whence)
ファイルアクセス位置の設定
t_ssize write_file(int fd, const void *buf, t_size count)
ファイルにデータを書き込む
t_ssize read_file(int fd, void *buf, t_size count)
ファイルからデータを読み出す
t_size tell_file(int fd)
ファイルアクセス位置の取得
int unlink_file(const uchar *path)
ファイルを消去する
int closedir_file(FS_DIR *dir)
ディレクトリを閉じる
FS_DIR * opendir_file(const uchar *name)
ディレクトリを開く
struct st_filesystem * get_filesystem(const uchar *path)
ファイル名からファイルシステムを調べる
int stat_file(const uchar *path, FS_FILEINFO *finfo)
ファイルステータスを読み出す
int rename_file(const uchar *oldpath, const uchar *newpath)
ファイル/ディレクトリ名を変更する
int getfree_file(const uchar *path, unsigned long *sect, void **fso)
論理ドライブの未使用クラスタ数を取得する
int mkdir_file(const uchar *path)
ディレクトリを作成する
struct st_storage_info storage[GSC_FS_VOLUME_NUM]
ストレージデバイステーブル
int close_file(int fd)
ファイルを閉じる
int get_diskno(const uchar *path)
ファイル名からストレージ番号を調べる
unsigned int strleng(const uchar *str)
文字列長
void init_file(void)
全てのファイルディスクリプタを初期化する
uchar * get_filename_extension(uchar *ext, const uchar *filename, unsigned int len)
ファイル拡張子を取得する
int readdir_file(FS_DIR *dir, FS_FILEINFO *finfo)
ディレクトリを読み出す
#define GSC_FS_VOLUME_NUM
$gsc 最大ストレージデバイスボリューム数
uchar * strncopy(uchar *dest, const uchar *src, unsigned int n)
文字列コピー
int open_file(const uchar *path, int flags)
ファイルを開く
int sync_file(int fd)
キャッシュされたデータをフラッシュする
uchar * get_last_filename(uchar *filename, const uchar *fullpath, unsigned int len)
ファイルパスからファイル名のみを取得する
#define GSC_FS_MAX_FILE_NUM
$gsc オープンできる最大ファイル数
int tsnprintf(char *str, unsigned int size, const char *fmt,...)
簡易snprintf