Skip to content

Commit 2f63753

Browse files
author
Ian Seyler
committed
bmfslite - Update list output
1 parent 7f3940b commit 2f63753

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BareMetal OS -- License
33
===============================================================================
44

5-
Copyright (C) 2008-2023 Return Infinity -- http://www.returninfinity.com
5+
Copyright (C) 2008-2024 Return Infinity -- http://www.returninfinity.com
66

77
All rights reserved.
88

doc/BareMetal File System Lite.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# BareMetal File System Lite (BMFS-Lite) - Version 1
32

43
BMFS-Lite is a new in-memory file system ([RAM Drive](https://en.wikipedia.org/wiki/RAM_drive)) used by BareMetal-OS. Based on BMFS, the design is extremely simplified compared to conventional file systems. The system is also geared more toward a small number of files (utilities, demos).

src/bmfslite.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ void bmfs_list(void)
231231
int tint;
232232

233233
printf("BMFS-Lite Drive Size: %d bytes\n", disksize);
234-
printf("Name | Size (B)| Reserved (B)\n");
235-
printf("==========================================================================\n");
234+
printf("Name | Size | Reserved | Block\n");
235+
printf("============================================================\n");
236236
for (tint = 0; tint < 64; tint++) // Max 64 entries
237237
{
238238
memcpy(pentry, Directory+(tint*64), 64);
@@ -246,21 +246,15 @@ void bmfs_list(void)
246246
}
247247
else // Valid entry
248248
{
249-
printf("%-32s %20lld %20lld\n", entry.FileName, (long long int)entry.FileSize, (long long int)(entry.ReservedBlocks*2));
249+
printf("%-32s %8lld %10lld %7lld\n", entry.FileName, (long long int)entry.FileSize, (long long int)(entry.ReservedBlocks*blockSize), entry.StartingBlock);
250250
}
251251
}
252252
}
253253

254254

255255
void bmfs_format(void)
256256
{
257-
// memset(DiskInfo, 0, 512);
258-
// memset(Directory, 0, 4096);
259-
// memcpy(DiskInfo, fs_tag, 4); // Add the 'BMFS' tag
260-
// fseek(disk, 1024, SEEK_SET); // Seek 1KiB in for disk information
261-
// fwrite(DiskInfo, 512, 1, disk); // Write 512 bytes for the DiskInfo
262-
// fseek(disk, 4096, SEEK_SET); // Seek 4KiB in for directory
263-
// fwrite(Directory, 4096, 1, disk); // Write 4096 bytes for the Directory
257+
// Todo - overwrite entire file with zeros
264258
}
265259

266260

@@ -477,6 +471,12 @@ void bmfs_create(char *filename, unsigned long long maxsize)
477471
unsigned long long new_file_start = 0;
478472
unsigned long long prev_file_end = 1;
479473

474+
if(strlen(filename) > 31)
475+
{
476+
printf("bmfs error: Filename too long.\n");
477+
return;
478+
}
479+
480480
// Make a copy of Directory to play with
481481
memcpy(dir_copy, Directory, 4096);
482482

@@ -654,7 +654,7 @@ void bmfs_write(char *filename)
654654
rewind(tfile);
655655
if (0 == bmfs_find(filename, &tempentry, &slot))
656656
{
657-
bmfs_create(filename, (tempfilesize+blockSize)/blockSize);
657+
bmfs_create(filename, (tempfilesize+blockSize)/blockSize*2);
658658
bmfs_find(filename, &tempentry, &slot);
659659
}
660660
if ((tempentry.ReservedBlocks*blockSize) < tempfilesize)
@@ -707,7 +707,7 @@ void bmfs_write(char *filename)
707707
// Update directory
708708
tempfilesize = ftell(tfile);
709709
memcpy(Directory+(slot*64)+48, &tempfilesize, 8);
710-
fseek(disk, 0, SEEK_SET); // Seek 4KiB in for directory
710+
fseek(disk, 0, SEEK_SET); // Seek to directory
711711
fwrite(Directory, 4096, 1, disk); // Write new directory to disk
712712
}
713713
fclose(tfile);

0 commit comments

Comments
 (0)