Files
lk/lib/fs/fat/fat_priv.h
Travis Geiselbrecht afa659732e [fs][fat] Implement first implementation of file create
Limitations:
Only supports simple 8.3 file names
Cannot create with size > 0
Timestamp is bogus
2022-09-05 21:54:36 -07:00

56 lines
1.7 KiB
C

/*
* Copyright (c) 2015 Steve White
* Copyright (c) 2022 Travis Geiselbrecht
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <lk/compiler.h>
#include <lib/bio.h>
#include <lib/fs.h>
#include "fat_fs.h"
// Individual files should
// #define LOCAL_TRACE FAT_GLOBAL_TRACE(0)
// can override here for all fat files
#define FAT_GLOBAL_TRACE(local) (local | 0)
typedef void *fsfilecookie;
/* file allocation table parsing */
uint32_t fat_next_cluster_in_chain(fat_fs *fat, uint32_t cluster);
uint32_t file_offset_to_cluster(fat_fs *fat, uint32_t start_cluster, off_t offset);
/* general io routines */
uint32_t fat_sector_for_cluster(fat_fs *fat, uint32_t cluster);
ssize_t fat_read_cluster(fat_fs *fat, void *buf, uint32_t cluster);
// general directory apis outside of an object
struct dir_entry {
fat_attribute attributes;
uint32_t length;
uint32_t start_cluster;
// TODO time
};
// used as a key for a file/dir in the open file table
struct dir_entry_location {
uint32_t starting_dir_cluster;
uint32_t dir_offset;
};
inline bool operator==(const dir_entry_location &a, const dir_entry_location &b) {
return (a.starting_dir_cluster == b.starting_dir_cluster && a.dir_offset == b.dir_offset);
}
// walk a path, returning the entry and the location where it was found
status_t fat_dir_walk(fat_fs *fat, const char *path, dir_entry *out_entry, dir_entry_location *loc);
// walk a path, allocating a new entry with the path name.
// returns the dir entry location
status_t fat_dir_allocate(fat_fs *fat, const char *path, fat_attribute attr, uint32_t starting_cluster, uint32_t size, dir_entry_location *loc);