@@ -9,15 +9,18 @@
 | 
			
		||||
#include "fat12.h"
 | 
			
		||||
#include "io.h"
 | 
			
		||||
 | 
			
		||||
static int make_image(const char *name, uint32_t size) {
 | 
			
		||||
static int make_image(const char *name, uint32_t size)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    struct pang_io *io = pang_open(name);
 | 
			
		||||
    if (!io) {
 | 
			
		||||
    if (!io)
 | 
			
		||||
    {
 | 
			
		||||
        fprintf(stderr, "couldn't open %s: %s\n", name, strerror(errno));
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (-1 == fat12_mkfs(io, size)) {
 | 
			
		||||
    if (-1 == fat12_mkfs(io, size))
 | 
			
		||||
    {
 | 
			
		||||
        fprintf(stderr, "couldn't make fat12 on %s: %s\n", name, strerror(errno));
 | 
			
		||||
        pang_close(&io);
 | 
			
		||||
        return 1;
 | 
			
		||||
@@ -26,38 +29,46 @@ static int make_image(const char *name, uint32_t size) {
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int list_directory(void *data, const struct fat12_dirent *dirent) {
 | 
			
		||||
static int list_directory(void *data, const struct fat12_dirent *dirent)
 | 
			
		||||
{
 | 
			
		||||
    printf("%d  %d  %x  %d  %d  %s\n", dirent->ctime, dirent->mtime, dirent->file_attributes, dirent->size, dirent->first_cluster, dirent->filename);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int run_command(const char *cmd) {
 | 
			
		||||
static int run_command(const char *cmd)
 | 
			
		||||
{
 | 
			
		||||
    int ret = system(cmd);
 | 
			
		||||
    if (ret) {
 | 
			
		||||
    if (ret)
 | 
			
		||||
    {
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void memset_str(uint8_t *bfr, uint8_t *val, size_t count) {
 | 
			
		||||
static void memset_str(uint8_t *bfr, uint8_t *val, size_t count)
 | 
			
		||||
{
 | 
			
		||||
    int i;
 | 
			
		||||
    for (i = 0; i < count; i++) {
 | 
			
		||||
    for (i = 0; i < count; i++)
 | 
			
		||||
    {
 | 
			
		||||
        bfr[i] = val[i & 0x7];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv) {
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t tmp_bfr[32768];
 | 
			
		||||
    const char *img_name = "build/fat12-fragmented.img";
 | 
			
		||||
    int ret = 0;
 | 
			
		||||
    int fd;
 | 
			
		||||
    struct fat12_partition *part = fat12_alloc();
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    ret = make_image(img_name, 9 * 1024 * 1024);
 | 
			
		||||
    if (ret == -1) {
 | 
			
		||||
    if (ret == -1)
 | 
			
		||||
    {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (-1 == fat12_open(part, img_name)) {
 | 
			
		||||
    if (-1 == fat12_open(part, img_name))
 | 
			
		||||
    {
 | 
			
		||||
        fprintf(stderr, "couldn't open fat12 on %s: %s\n", img_name, strerror(errno));
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,15 +9,17 @@
 | 
			
		||||
#include "fat12.h"
 | 
			
		||||
#include "io.h"
 | 
			
		||||
 | 
			
		||||
static int make_image(const char *name, uint32_t size) {
 | 
			
		||||
 | 
			
		||||
static int make_image(const char *name, uint32_t size)
 | 
			
		||||
{
 | 
			
		||||
    struct pang_io *io = pang_open(name);
 | 
			
		||||
    if (!io) {
 | 
			
		||||
    if (!io)
 | 
			
		||||
    {
 | 
			
		||||
        fprintf(stderr, "couldn't open %s: %s\n", name, strerror(errno));
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (-1 == fat12_mkfs(io, size)) {
 | 
			
		||||
    if (-1 == fat12_mkfs(io, size))
 | 
			
		||||
    {
 | 
			
		||||
        fprintf(stderr, "couldn't make fat12 on %s: %s\n", name, strerror(errno));
 | 
			
		||||
        pang_close(&io);
 | 
			
		||||
        return 1;
 | 
			
		||||
@@ -26,7 +28,8 @@ static int make_image(const char *name, uint32_t size) {
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv) {
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
    int ret = 0;
 | 
			
		||||
 | 
			
		||||
    ret += make_image("build/fat12-1300k.img", 1300 * 1024);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user