Skip to content

Commit 4b91358

Browse files
DreamPearlscopeInfinity
authored andcommitted
Reformat using clang-format based on llvm code style
1 parent 158baea commit 4b91358

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2287
-2314
lines changed

external/src/mbr_builder.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Classical generic MBR
22
// https://en.wikipedia.org/wiki/Master_boot_record#PTE
33
#include <fuzzy/fs/mbr.h>
4-
#include<stdio.h>
4+
#include <stdio.h>
55

66
char DRIVE = 0x80;
77
char DRIVE_INACTIVE = 0x00;
88
// https://en.wikipedia.org/wiki/Partition_type
9-
char PARTITION_TYPE = 0x07; // Stealing exFAT
9+
char PARTITION_TYPE = 0x07; // Stealing exFAT
1010

1111
// https://en.wikipedia.org/wiki/Cylinder-head-sector
1212
void lba_to_chs(int lba, char chs[3]) {
@@ -26,28 +26,30 @@ void lba_to_chs(int lba, char chs[3]) {
2626

2727
void write_boot_signature(FILE *out) {
2828
fseek(out, 510, SEEK_SET);
29-
char boot_signature[2]={0x55, 0xAA};
29+
char boot_signature[2] = {0x55, 0xAA};
3030
fwrite(boot_signature, 1, sizeof(boot_signature), out);
3131
}
3232

33-
void write_partition_entry(FILE *out, int id, char drive, int lba, int sector_count) {
33+
void write_partition_entry(FILE *out, int id, char drive, int lba,
34+
int sector_count) {
3435
struct PartitionEntry entry;
3536
entry.drive = drive;
3637
entry.partition_type = PARTITION_TYPE;
3738
entry.lba = lba;
3839
entry.sector_count = sector_count;
3940
// TODO: write lba using lba_to_chs too
40-
fseek(out, MBR_PARTITION_BEGIN+id*sizeof(struct PartitionEntry), SEEK_SET);
41+
fseek(out, MBR_PARTITION_BEGIN + id * sizeof(struct PartitionEntry),
42+
SEEK_SET);
4143
fwrite(&entry, 1, sizeof(entry), out);
42-
printf("Added partition entry %d at lba: %d sector_count: %d\n",
43-
id, lba, sector_count);
44+
printf("Added partition entry %d at lba: %d sector_count: %d\n", id, lba,
45+
sector_count);
4446
}
4547

4648
void write_partition(FILE *out, FILE *in, int lba) {
4749
int count;
4850
char buffer[1024];
4951
rewind(in);
50-
fseek(out, lba*512, SEEK_SET);
52+
fseek(out, lba * 512, SEEK_SET);
5153
while ((count = fread(buffer, sizeof(char), sizeof(buffer), in)) > 0) {
5254
fwrite(buffer, sizeof(char), count, out);
5355
}
@@ -75,17 +77,17 @@ int main(int argc, char *argv[]) {
7577

7678
populate_outfile_using_image_prefix(out, image_prefix);
7779

78-
int lba, sector_count; // 4 bytes
80+
int lba, sector_count; // 4 bytes
7981
{
8082
fseek(out, 0L, SEEK_END);
8183
int file_size = ftell(out);
8284
rewind(out);
83-
lba=(file_size+511)/512;
85+
lba = (file_size + 511) / 512;
8486
}
8587
{
8688
fseek(part1, 0L, SEEK_END);
8789
int file_size = ftell(part1);
88-
sector_count=(file_size+511)/512;
90+
sector_count = (file_size + 511) / 512;
8991
}
9092

9193
write_boot_signature(out);

external/src/mkfs_ffs.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
mkfs.ffs binary implementation for Linux.
33
*/
44

5+
#include <dirent.h>
56
#include <fuzzy/fs/ffs.h>
67
#include <stdio.h>
78
#include <string.h>
8-
#include <dirent.h>
99
#include <sys/stat.h>
1010

11-
#define FILEENTRY_LOCATION(file_id) (FS_FFS_FIRST_BLOCK_SIZE+FS_FFS_FILEENTRY_SIZE*(file_id))
11+
#define FILEENTRY_LOCATION(file_id) \
12+
(FS_FFS_FIRST_BLOCK_SIZE + FS_FFS_FILEENTRY_SIZE * (file_id))
1213

1314
void write_first_block(FILE *out) {
1415
union FFSMetaData block;
15-
strncpy(block.content.signature, FS_FFS_SIGNATURE, sizeof(block.content.signature));
16+
strncpy(block.content.signature, FS_FFS_SIGNATURE,
17+
sizeof(block.content.signature));
1618

1719
rewind(out);
1820
fwrite(block.bytes, 1, sizeof(block.bytes), out);
1921
}
2022

2123
void write_file(int file_id, FILE *outfile, int *outfile_nextdata_block,
22-
const char *filename, FILE *srcfile,
23-
int is_executable) {
24+
const char *filename, FILE *srcfile, int is_executable) {
2425
fseek(srcfile, 0L, SEEK_END);
2526
int file_size = ftell(srcfile);
2627
rewind(srcfile);
@@ -42,9 +43,9 @@ void write_file(int file_id, FILE *outfile, int *outfile_nextdata_block,
4243
char buffer[512];
4344
size_t bytes_read;
4445
printf("Writting context at %d\n", ((*outfile_nextdata_block)));
45-
fseek(outfile, (*outfile_nextdata_block)*FS_BLOCK_SIZE, SEEK_SET);
46-
(*outfile_nextdata_block) += (file_size+FS_BLOCK_SIZE-1)/FS_BLOCK_SIZE;
47-
46+
fseek(outfile, (*outfile_nextdata_block) * FS_BLOCK_SIZE, SEEK_SET);
47+
(*outfile_nextdata_block) +=
48+
(file_size + FS_BLOCK_SIZE - 1) / FS_BLOCK_SIZE;
4849

4950
while ((bytes_read = fread(buffer, 1, sizeof(buffer), srcfile)) > 0) {
5051
fwrite(buffer, 1, bytes_read, outfile);
@@ -60,7 +61,6 @@ void write_nofile(int file_id, FILE *out) {
6061
fwrite(entry.bytes, 1, sizeof(entry.bytes), out);
6162
}
6263

63-
6464
int create_partition(char *src_dir, char *out_filepath) {
6565
printf("dir:%s partition: %s\n", src_dir, out_filepath);
6666
FILE *src = opendir(src_dir);
@@ -85,19 +85,22 @@ int create_partition(char *src_dir, char *out_filepath) {
8585
strncat(buffer_filename, "/", sizeof(buffer_filename));
8686
strncat(buffer_filename, de->d_name, sizeof(buffer_filename));
8787
if (file_id >= FS_FFS_FILEENTRY_COUNT) {
88-
fprintf("reached max supported files, ignoring file '%s'", buffer_filename);
88+
fprintf("reached max supported files, ignoring file '%s'",
89+
buffer_filename);
8990
continue;
9091
}
9192
struct stat file_stat;
9293
stat(buffer_filename, &file_stat);
9394
if (!S_ISREG(file_stat.st_mode)) {
94-
fprintf("skipping non-regular file '%s': %d", buffer_filename, file_stat.st_mode);
95+
fprintf("skipping non-regular file '%s': %d", buffer_filename,
96+
file_stat.st_mode);
9597
continue;
9698
}
9799
int is_executable = file_stat.st_mode & S_IXUSR;
98100

99101
FILE *file_src = fopen(buffer_filename, "rb");
100-
write_file(file_id++, out, &outfile_nextdata_block, de->d_name, file_src, is_executable);
102+
write_file(file_id++, out, &outfile_nextdata_block, de->d_name,
103+
file_src, is_executable);
101104
fclose(file_src);
102105
}
103106
while (file_id < FS_FFS_FILEENTRY_COUNT) {

include/fuzzy/drivers/pic/pic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <stddef.h>
44

5-
#define PIC_PIT_FREQ 1193182 // hz
5+
#define PIC_PIT_FREQ 1193182 // hz
66
#define PIC_PIT_MAX_COUNTER 0xFFFF
77

88
#define PIC_IRQ_PIT 0

include/fuzzy/drivers/port.h

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,32 @@
22

33
#include <stddef.h>
44

5-
#define PORT_PIC1_CMD 0x20
6-
#define PORT_PIC1_DATA 0x21
7-
#define PORT_PIC2_CMD 0xA0
8-
#define PORT_PIC2_DATA 0xA1
5+
#define PORT_PIC1_CMD 0x20
6+
#define PORT_PIC1_DATA 0x21
7+
#define PORT_PIC2_CMD 0xA0
8+
#define PORT_PIC2_DATA 0xA1
99

10-
#define PORT_PIT_DATA0 0x40
11-
#define PORT_PIT_DATA1 0x41
12-
#define PORT_PIT_DATA2 0x42
13-
#define PORT_PIT_CMD 0x43
14-
15-
#define PORT_PS2_DATA 0x60
16-
#define PORT_PS2_CMD 0x64
17-
#define PORT_PS2_STATUS 0x64
10+
#define PORT_PIT_DATA0 0x40
11+
#define PORT_PIT_DATA1 0x41
12+
#define PORT_PIT_DATA2 0x42
13+
#define PORT_PIT_CMD 0x43
1814

15+
#define PORT_PS2_DATA 0x60
16+
#define PORT_PS2_CMD 0x64
17+
#define PORT_PS2_STATUS 0x64
1918

2019
static inline void outb(uint16_t port, uint8_t data) {
21-
__asm__ volatile(
22-
"outb %0, %1 \n"
23-
: /* output */
24-
: "a" (data), "ir" (port) /* input */
25-
:
26-
);
20+
__asm__ volatile("outb %0, %1 \n"
21+
: /* output */
22+
: "a"(data), "ir"(port) /* input */
23+
:);
2724
}
2825

2926
static inline uint8_t inputb(uint16_t port) {
3027
uint8_t data;
31-
__asm__ volatile(
32-
"inb %1, %0 \n"
33-
: "=a" (data) /* output */
34-
: "ir" (port) /* input */
35-
:
36-
);
28+
__asm__ volatile("inb %1, %0 \n"
29+
: "=a"(data) /* output */
30+
: "ir"(port) /* input */
31+
:);
3732
return data;
3833
}

include/fuzzy/drivers/ps2/keyboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
43
void ps2_keyboard_init();
54

65
char ps2_keyboard_get_key_pressed_blocking();

include/fuzzy/drivers/ps2/ps2.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ void ps2_controller_wait_for_full_output();
1212
void interrupt_register_0x21_0x2C_irq1_ir12_keyboard_mouse();
1313
void irq1_handler();
1414
void irq12_handler();
15-

include/fuzzy/fs/ffs.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ data...
1515
Number of file which can be stored: 64
1616
*/
1717

18-
#include <stdint.h>
1918
#include <stddef.h>
19+
#include <stdint.h>
2020

21-
#define FS_FFS_FILENAME_LIMIT 100 // including NULL, same as dirent.h
22-
#define FFS_UNIQUE_PARITION_ID 0 // only paritition 0 is supported for now
21+
#define FS_FFS_FILENAME_LIMIT 100 // including NULL, same as dirent.h
22+
#define FFS_UNIQUE_PARITION_ID 0 // only paritition 0 is supported for now
2323

24-
enum FFSFileFlagMask {
25-
FFS_FILE_FLAG_EXECUTABLE = 1 << 0
26-
};
24+
enum FFSFileFlagMask { FFS_FILE_FLAG_EXECUTABLE = 1 << 0 };
2725

2826
union FFSMetaData {
2927
struct {
@@ -34,7 +32,7 @@ union FFSMetaData {
3432

3533
union FFSFileEntry {
3634
struct {
37-
int32_t start_block_id; // 0 implies no file.
35+
int32_t start_block_id; // 0 implies no file.
3836
int32_t filesize;
3937
char filename[FS_FFS_FILENAME_LIMIT];
4038
uint32_t flags;
@@ -47,24 +45,20 @@ union FFSFileEntry {
4745
#define FS_FFS_FILEENTRY_COUNT 128
4846

4947
#define FS_BLOCK_SIZE 512
50-
#define FS_FFS_BLOCK_DATA_START ((FS_FFS_FIRST_BLOCK_SIZE+FS_FFS_FILEENTRY_SIZE*FS_FFS_FILEENTRY_COUNT)/FS_BLOCK_SIZE)
51-
52-
#define FS_FFS_SIGNATURE "__FuzzyOS__FFS__" // 16 chars
48+
#define FS_FFS_BLOCK_DATA_START \
49+
((FS_FFS_FIRST_BLOCK_SIZE + \
50+
FS_FFS_FILEENTRY_SIZE * FS_FFS_FILEENTRY_COUNT) / \
51+
FS_BLOCK_SIZE)
5352

53+
#define FS_FFS_SIGNATURE "__FuzzyOS__FFS__" // 16 chars
5454

5555
int resolve_abs_lba(int parition_id, int partition_relative_lba);
5656

5757
int partition_read_block(int block_index, void *wr_buffer);
5858

5959
int verify_partition(int partition_id);
6060

61-
int fetch_file_entry(
62-
int partition_id,
63-
int entry_id,
64-
union FFSFileEntry *entry);
61+
int fetch_file_entry(int partition_id, int entry_id, union FFSFileEntry *entry);
6562

66-
int fetch_file_content(
67-
const int partition_id,
68-
const union FFSFileEntry *entry,
69-
char buffer[FS_BLOCK_SIZE],
70-
const int file_block_id);
63+
int fetch_file_content(const int partition_id, const union FFSFileEntry *entry,
64+
char buffer[FS_BLOCK_SIZE], const int file_block_id);

include/fuzzy/fs/mbr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ struct PartitionEntry {
77
char start_chs[3];
88
char partition_type;
99
char end_chs[3];
10-
int lba; // 4 bytes
11-
int sector_count; // 4 bytes
10+
int lba; // 4 bytes
11+
int sector_count; // 4 bytes
1212
};

include/fuzzy/kernel/interrupts/interrupts.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
* [32:48) ; [0x20:0x30) ; IRQ0-15
77
* 80 ; 0x32 ; syscall
88
*/
9-
#define IDT_SIZE 256
10-
#define IDT_IRQ_OFFSET 0x20
9+
#define IDT_SIZE 256
10+
#define IDT_IRQ_OFFSET 0x20
1111

1212
// Used by /usr/lib/process.c
13-
#define IDT_IRQ0_PIC (IDT_IRQ_OFFSET+0)
14-
#define IDT_IRQ1_KEYBOARD (IDT_IRQ_OFFSET+1)
15-
#define IDT_IRQ12_MOUSE (IDT_IRQ_OFFSET+12)
13+
#define IDT_IRQ0_PIC (IDT_IRQ_OFFSET + 0)
14+
#define IDT_IRQ1_KEYBOARD (IDT_IRQ_OFFSET + 1)
15+
#define IDT_IRQ12_MOUSE (IDT_IRQ_OFFSET + 12)
1616
// Used by /usr/lib/sys/syscall.asm
17-
#define IDT_SYSCALL 0x32
17+
#define IDT_SYSCALL 0x32
1818

19-
20-
extern void populate_idt_entry_32bit(int id,
21-
unsigned int address,
22-
unsigned char dpl, // 2-bit
23-
int is_trap
24-
);
19+
extern void populate_idt_entry_32bit(int id, unsigned int address,
20+
unsigned char dpl, // 2-bit
21+
int is_trap);

include/fuzzy/kernel/panic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
#define PANIC(err, message) panic((err), (message), __FILE__, __LINE__)
66

7-
#define ASSERT(ok) (ok || panic(0, "Assert Failed: " #ok, __FILE__, __LINE__))
7+
#define ASSERT(ok) (ok || panic(0, "Assert Failed: " #ok, __FILE__, __LINE__))
88

99
void panic_just_halt();
1010
int panic(int err, const char *message, const char *src_file,
11-
unsigned int line_number);
11+
unsigned int line_number);
1212
int panic_screen_init();

0 commit comments

Comments
 (0)