clang format

This commit is contained in:
Andrew Pamment 2022-07-08 10:51:43 +10:00
parent d7308fcf4a
commit 55e9efd57b
8 changed files with 83 additions and 89 deletions

View File

@ -405,20 +405,20 @@ void putstr(char *str) {
}
void goto_xy(int newx, int newy) {
if (newx >= char_width) {
newx = char_width - 1;
}
if (newy >= char_height) {
newy = char_height -1;
}
if (newx < 0) {
newx = 0;
}
if (newy < 0) {
newy = 0;
}
x = newx;
y = newy;
if (newx >= char_width) {
newx = char_width - 1;
}
if (newy >= char_height) {
newy = char_height - 1;
}
if (newx < 0) {
newx = 0;
}
if (newy < 0) {
newy = 0;
}
x = newx;
y = newy;
update_cursor(1);
}

View File

@ -112,7 +112,8 @@ struct ether_t *ether_find_from_ipv4(unsigned int ipv4) {
for (i = 0; i < ptr_vector_len(&ether_devs); i++) {
card = ptr_vector_get(&ether_devs, i);
if (card->ipv4 == 0) continue;
if (card->ipv4 == 0)
continue;
if ((ipv4 & card->mask) == (card->ipv4 & card->mask) || card->default_gw != 0) {
return card;
}

View File

@ -24,11 +24,11 @@ extern unsigned long timer_ticks;
extern void tcp_send(struct ether_t *ether, struct socket_t *sock, unsigned short flags, unsigned char *packet, unsigned int len, int thrice);
void socket_timeout() {
for (int i = 0; i < ptr_vector_len(&sockets); i++) {
struct socket_t *s = ptr_vector_get(&sockets, i);
if (!s->ether) continue;
if (!s->ether)
continue;
if (s->socket_type == 1 && s->status == SOCKET_STATUS_CONNECTED) {
if (s->tcp_keep_alive + 720000 < timer_ticks) {
if (s->tcp_keep_alive_probes == 0) {
@ -85,9 +85,11 @@ struct socket_t *socket_find(unsigned short dport, unsigned short sport, unsigne
for (i = 0; i < ptr_vector_len(&sockets); i++) {
struct socket_t *s = ptr_vector_get(&sockets, i);
if (!s->ether) continue;
if (!s->ether)
continue;
if (s->port_recv == dport && s->port_dest == sport && (s->addr == 0xffffffff || s->addr == src_ip)) {
if (s->status == SOCKET_STATUS_OPENED || s->status == SOCKET_STATUS_CONNECTED || s->status == SOCKET_STATUS_CLOSE2 || s->status == SOCKET_STATUS_FINACK || s->status == SOCKET_STATUS_FINACK2) {
if (s->status == SOCKET_STATUS_OPENED || s->status == SOCKET_STATUS_CONNECTED || s->status == SOCKET_STATUS_CLOSE2 || s->status == SOCKET_STATUS_FINACK ||
s->status == SOCKET_STATUS_FINACK2) {
s->tcp_keep_alive = timer_ticks;
s->tcp_keep_alive_probes = 0;
s->tcp_keep_alive_interval = 0;
@ -104,7 +106,8 @@ struct socket_t *socket_find(unsigned short dport, unsigned short sport, unsigne
for (i = 0; i < ptr_vector_len(&sockets); i++) {
struct socket_t *s = ptr_vector_get(&sockets, i);
if (!s->ether) continue;
if (!s->ether)
continue;
if (s->port_recv == dport && s->addr == 0) {
if (s->status == SOCKET_STATUS_LISTEN) {
struct task_t *task = (struct task_t *)s->data;
@ -424,7 +427,7 @@ int socket_connect(unsigned int serial, unsigned int dest_ip, unsigned short des
void socket_doclose(struct socket_t *sock) {
int i, j;
if (sock->socket_type == 1) {
if (sock->status == 1) {
if (sock->status == 1) {
sched_remove_socket_from_all_tasks(sock);
for (i = 0; i < ptr_vector_len(&sockets); i++) {

View File

@ -16,8 +16,6 @@
#define SOCKET_STATUS_FINACK 7
#define SOCKET_STATUS_FINACK2 8
struct socket_t {
struct ether_t *ether;
unsigned char status;

7
tcp.c
View File

@ -105,7 +105,7 @@ int tcp_process_socket(struct socket_t *sock) {
return ret;
}
static int tcp_ack(struct socket_t *sock, struct tcp_header_t* packet, int isSynAck, unsigned int len) {
static int tcp_ack(struct socket_t *sock, struct tcp_header_t *packet, int isSynAck, unsigned int len) {
int retval = 1;
int send_thrice = 0;
if (sock->tcp_sock.ack_number != 0 && !isSynAck && sock->tcp_sock.ack_number != htonl(packet->seq_number)) {
@ -130,7 +130,6 @@ static int tcp_ack(struct socket_t *sock, struct tcp_header_t* packet, int isSyn
tcp_send(sock->ether, sock, TCP_FLAGS_ACK, (void *)0, 0, send_thrice);
return retval;
}
void tcp_process_packet(struct ether_t *ether, unsigned int dest, unsigned int src, struct tcp_header_t *packet, unsigned int len) {
@ -147,8 +146,8 @@ void tcp_process_packet(struct ether_t *ether, unsigned int dest, unsigned int s
if ((htons(packet->flags) & TCP_FLAGS_SYN) && (htons(packet->flags) & TCP_FLAGS_ACK)) {
tcp_ack(sock, packet, 1, 1);
if (sock->status == SOCKET_STATUS_CLOSE) {
socket_doclose(sock);
return;
socket_doclose(sock);
return;
}
} else if (htons(packet->flags) & TCP_FLAGS_RES) {
sock->status = SOCKET_STATUS_CLOSE;

1
tcp.h
View File

@ -20,7 +20,6 @@ struct tcp_socket_t {
unsigned int ack_number;
};
struct tcp_data_t {
unsigned char *data;
unsigned int len;

90
vfs.c
View File

@ -1099,53 +1099,51 @@ int vfs_statfs_dev(struct vfs_device_t *device, struct statfs *sfs) {
sfs->fs_type = device->fs;
switch (device->fs) {
case 3:
{
struct minix_data *mdata = (struct minix_data *)device->fs_data;
sfs->total_inodes = mdata->sb.s_ninodes;
sfs->total_blocks = mdata->sb.s_zones;
sfs->blocksize = mdata->sb.s_blocksize;
case 3: {
struct minix_data *mdata = (struct minix_data *)device->fs_data;
sfs->total_inodes = mdata->sb.s_ninodes;
sfs->total_blocks = mdata->sb.s_zones;
sfs->blocksize = mdata->sb.s_blocksize;
sfs->free_inodes = 0;
for (int i = 0; i < (mdata->sb.s_imap_blocks * mdata->sb.s_blocksize) / 4; i++) {
if (mdata->s_imap[i] == 0xffffffff) {
continue;
}
if (mdata->s_imap[i] == 0) {
sfs->free_inodes += 32;
continue;
} else {
for (int x = 0; x < 32; x++) {
if (!(mdata->s_imap[i] & (1 << x))) {
sfs->free_inodes++;
}
}
}
}
sfs->free_blocks = 0;
for (int i = 0; i < (mdata->sb.s_zmap_blocks * mdata->sb.s_blocksize) / 4; i++) {
if (mdata->s_zmap[i] == 0xffffffff) {
continue;
}
if (mdata->s_zmap[i] == 0) {
sfs->free_blocks += 32;
continue;
} else {
for (int x = 0; x < 32; x++) {
if (!(mdata->s_zmap[i] & (1 << x))) {
sfs->free_blocks++;
}
}
}
}
sfs->free_inodes = 0;
for (int i = 0; i < (mdata->sb.s_imap_blocks * mdata->sb.s_blocksize) / 4; i++) {
if (mdata->s_imap[i] == 0xffffffff) {
continue;
}
break;
default:
return -1;
if (mdata->s_imap[i] == 0) {
sfs->free_inodes += 32;
continue;
} else {
for (int x = 0; x < 32; x++) {
if (!(mdata->s_imap[i] & (1 << x))) {
sfs->free_inodes++;
}
}
}
}
sfs->free_blocks = 0;
for (int i = 0; i < (mdata->sb.s_zmap_blocks * mdata->sb.s_blocksize) / 4; i++) {
if (mdata->s_zmap[i] == 0xffffffff) {
continue;
}
if (mdata->s_zmap[i] == 0) {
sfs->free_blocks += 32;
continue;
} else {
for (int x = 0; x < 32; x++) {
if (!(mdata->s_zmap[i] & (1 << x))) {
sfs->free_blocks++;
}
}
}
}
} break;
default:
return -1;
}
return 0;
}
@ -1190,9 +1188,6 @@ int vfs_statfs(char *path, struct statfs *sfs) {
return ret;
}
int vfs_fstat(int fileno, struct stat *s) {
if (fileno < 0 || fileno >= 256) {
return -1;
@ -1530,4 +1525,3 @@ int vfs_dup(int fno) {
return i;
}