Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Refactoring: Document and optimize function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkostoevr committed Apr 29, 2020
1 parent b885ec0 commit ededb0b
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions fat12.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef struct {
typedef struct {
char *image;
int imageSize;
char *errorMessage;
const char *errorMessage;
int bytesPerSector;
int sectorsPerClaster;
int reservedSectorCount;
Expand All @@ -33,21 +33,21 @@ typedef int (*ForEachCallback)(const char *, size_t, const uint8_t *, void *);
static void mkdir(const char *name);
// misc
static void mkdir_p(const char *_name); // create folder creating its parents
static uint16_t get16(void *_from, int index); // get uint16_t from array at offset
static uint32_t get32(void *_from, int index); // get uint32_t from array at offset
static uint16_t get16(const void *_from, int index); // get uint16_t from array at offset
static uint32_t get32(const void *_from, int index); // get uint32_t from array at offset
// fat12
static int fat12__getItemNameSize(void *_folderEntry);
static void fat12__getItemName(void *_folderEntry, void *_name);
static int fat12__getNextClaster(Fat12 *this, int currentClaster);
static int fat12__getFile(Fat12 *this, void *_buffer, int size, int claster);
static int fat12__getOffsetByClaster(Fat12 *this, int claster);
static int fat12__forEachFile_handleFolderEntry(Fat12 *this, int folderEntryOffset, String *name,
static int fat12__getItemNameSize(const void *_folderEntry);
static void fat12__getItemName(const void *_folderEntry, void *_name);
static int fat12__getNextClaster(const Fat12 *this, int currentClaster);
static int fat12__getFile(const Fat12 *this, void *_buffer, int size, int claster);
static int fat12__getOffsetByClaster(const Fat12 *this, int claster);
static int fat12__forEachFile_handleFolderEntry(const Fat12 *this, int folderEntryOffset, String *name,
ForEachCallback callback, void *callbackParam);
static int fat12__forEachFile_handleFolder(Fat12 *this, int claster, String *name,
static int fat12__forEachFile_handleFolder(const Fat12 *this, int claster, String *name,
ForEachCallback callback, void *callbackParam);
static int fat12__forEachFile(Fat12 *this, ForEachCallback callback, void *callbackParam);
static int fat12__forEachFile(const Fat12 *this, ForEachCallback callback, void *callbackParam);
static int fat12__open(Fat12 *this, const char *img);
static int fat12__error(Fat12 *this, char *errorMessage);
static int fat12__error(Fat12 *this, const char *errorMessage);

static void mkdir(const char *name) {
struct {
Expand Down Expand Up @@ -76,21 +76,21 @@ static void mkdir_p(const char *_name) {
}
}

static uint32_t get32(void *_from, int index) {
uint8_t *from = _from;
static uint32_t get32(const void *_from, int index) {
const uint8_t *from = _from;
return from[index] |
(from[index + 1] << 8) |
(from[index + 2] << 16) |
(from[index + 3] << 24);
}

static uint16_t get16(void *_from, int index) {
uint8_t *from = _from;
static uint16_t get16(const void *_from, int index) {
const uint8_t *from = _from;

return from[index] | (from[index + 1] << 8);
}

static int fat12__getNextClaster(Fat12 *this, int currentClaster) {
static int fat12__getNextClaster(const Fat12 *this, int currentClaster) {
int nextClasterOffset = this->firstFat + currentClaster + (currentClaster >> 1);

if (currentClaster % 2 == 0) {
Expand All @@ -100,7 +100,7 @@ static int fat12__getNextClaster(Fat12 *this, int currentClaster) {
}
}

static int fat12__getFile(Fat12 *this, void *_buffer, int size, int claster) {
static int fat12__getFile(const Fat12 *this, void *_buffer, int size, int claster) {
int offset = 0;
char *buffer = _buffer;

Expand All @@ -117,13 +117,13 @@ static int fat12__getFile(Fat12 *this, void *_buffer, int size, int claster) {
return 1;
}

static int fat12__getOffsetByClaster(Fat12 *this, int claster) {
static int fat12__getOffsetByClaster(const Fat12 *this, int claster) {
return this->dataRegion + (claster - 2)
* this->bytesPerSector * this->sectorsPerClaster;
}

static int fat12__getItemNameSize(void *_folderEntry) {
uint8_t *folderEntry = _folderEntry;
static int fat12__getItemNameSize(const void *_folderEntry) {
const uint8_t *folderEntry = _folderEntry;

// Long File Name entry, not a file itself
if ((folderEntry[11] & 0x0f) == 0x0f) { return 0; }
Expand Down Expand Up @@ -166,8 +166,8 @@ static int fat12__getItemNameSize(void *_folderEntry) {
return 0; // WAT?
}

static void fat12__getItemName(void *_folderEntry, void *_name) {
uint8_t *folderEntry = _folderEntry;
static void fat12__getItemName(const void *_folderEntry, void *_name) {
const uint8_t *folderEntry = _folderEntry;
uint8_t *name = _name;

if ((folderEntry[11 - 32] & 0x0f) != 0x0f) {
Expand Down Expand Up @@ -225,7 +225,7 @@ static void fat12__getItemName(void *_folderEntry, void *_name) {
}


static int fat12__forEachFile_handleFolderEntry(Fat12 *this, int folderEntryOffset, String *name,
static int fat12__forEachFile_handleFolderEntry(const Fat12 *this, int folderEntryOffset, String *name,
ForEachCallback callback, void *callbackParam) {
int nameSize = 0;

Expand Down Expand Up @@ -269,7 +269,7 @@ static int fat12__forEachFile_handleFolderEntry(Fat12 *this, int folderEntryOffs
return 1;
}

static int fat12__forEachFile_handleFolder(Fat12 *this, int claster, String *name,
static int fat12__forEachFile_handleFolder(const Fat12 *this, int claster, String *name,
ForEachCallback callback, void *callbackParam) {
for (; claster < 0xff7; claster = fat12__getNextClaster(this, claster)) {
int offset = fat12__getOffsetByClaster(this, claster);
Expand All @@ -283,7 +283,7 @@ static int fat12__forEachFile_handleFolder(Fat12 *this, int claster, String *nam
return 1;
}

static int fat12__forEachFile(Fat12 *this, ForEachCallback callback, void *callbackParam) {
static int fat12__forEachFile(const Fat12 *this, ForEachCallback callback, void *callbackParam) {
String name = { 0 };

name.capacity = 4096;
Expand Down Expand Up @@ -342,12 +342,12 @@ static int fat12__open(Fat12 *this, const char *img) {
return 1;
}

static int fat12__error(Fat12 *this, char *errorMessage) {
static int fat12__error(Fat12 *this, const char *errorMessage) {
this->errorMessage = errorMessage;
return 0;
}

static int handleError(Fat12 *fat12) {
static int handleError(const Fat12 *fat12) {
con_printf("Error in Fat12: %s\n", fat12->errorMessage);
con_exit(0);
return -1;
Expand Down

0 comments on commit ededb0b

Please sign in to comment.