Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,24 @@ $U/usys.o : $U/usys.S
$U/_forktest: $U/forktest.o $(ULIB)
# forktest has less library code linked in - needs to be small
# in order to be able to max out the proc table.
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $U/umalloc.o $U/printf.o
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $U/umalloc.o
$(OBJDUMP) -S $U/_forktest > $U/forktest.asm

# Compile psh_accessories.c
$U/psh_accessories.o: $U/psh_accessories.c
$(CC) $(CFLAGS) -c -o $U/psh_accessories.o $U/psh_accessories.c

# Link _sh including psh_accessories.o
$U/_sh: $U/sh.o $U/psh_accessories.o $(ULIB)
$(LD) $(LDFLAGS) -T $U/user.ld -o $U/_sh $U/sh.o $U/psh_accessories.o $(ULIB)
$(OBJDUMP) -S $U/_sh > $U/sh.asm
$(OBJDUMP) -t $U/_sh | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $U/sh.sym
# Link _psh including psh_accessories.o
$U/_psh: $U/psh.o $U/psh_accessories.o $(ULIB)
$(LD) $(LDFLAGS) -T $U/user.ld -o $U/_psh $U/psh.o $U/psh_accessories.o $(ULIB)
$(OBJDUMP) -S $U/_psh > $U/psh.asm
$(OBJDUMP) -t $U/_psh | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $U/psh.sym

mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h
gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c

Expand All @@ -125,6 +140,9 @@ UPROGS=\
$U/_ln\
$U/_ls\
$U/_mkdir\
$U/_psh\
$U/_pv\
$U/_pv_tests\
$U/_rm\
$U/_sh\
$U/_stressfs\
Expand All @@ -133,8 +151,8 @@ UPROGS=\
$U/_wc\
$U/_zombie\

fs.img: mkfs/mkfs README.md $(UPROGS)
mkfs/mkfs fs.img README.md $(UPROGS)
fs.img: mkfs/mkfs README.md time-machine.txt $(UPROGS)
mkfs/mkfs fs.img README.md time-machine.txt $(UPROGS)

-include kernel/*.d user/*.d

Expand Down
500 changes: 500 additions & 0 deletions time-machine.txt

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions user/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ main(void)
dup(0); // stdout
dup(0); // stderr

printf(" __________________\n");
printf("< Welcome to FogOS >\n");
printf(" ------------------\n");
printf(" \\ ^__^\n");
printf(" \\ (**)\\_______\n");
printf(" (__)\\ )\\/\\\n");
printf(" U ||----w |\n");
printf(" || ||\n");
// create /tmp for psh line_count storage
if (open("/tmp", O_RDONLY) < 0) {
if (mkdir("/tmp") < 0) {
printf("init: failed to create /tmp\n");
}
}


// create line_count store for psh
int psh_fd = open("/tmp/line_color", O_WRONLY | O_CREATE);
if (psh_fd >= 0) {
write(psh_fd, 0, 1);
close(psh_fd);
} else {
printf("init: failed to create /tmp/line_color\n");
}

for(;;){
printf("init: starting sh\n");
Expand Down
72 changes: 72 additions & 0 deletions user/psh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "kernel/types.h"
#include "kernel/stat.h"
#include "kernel/fs.h"
#include "user/user.h"
#include "kernel/fcntl.h"
#include "user/psh.h"

/**
* psh (pride shell) executable toggle
* run `psh` to toggle
*/

#define OPEN_MSG "🌈 psh enabled! happy pride! 🌈"

int main (int argc, char *argv) {

char *filename = "/tmp/psh_toggle";
int fd;
char buf[2];

fd = open(filename, O_RDWR);

if (fd < 0) {
fd = open(filename, O_CREATE | O_RDWR);
if (fd < 0) {
printf("Error: failed to create psh_toggle file.\n");
exit(1);
}
buf[0] = '1';
buf[1] = '\0';
write(fd, buf, 1);

printf("%s\n", OPEN_MSG);
set_color();

} else {
read(fd, buf, 1);
buf[1] = '\0';

close(fd);

// i wanted to do some bitwise stuff here (i was feeling special)
// it just does an XOR to either turn it on or off
// (if the number in the toggle file is 1 (on), it changes to 0 (off), and vice versa)

int toggle = buf[0] - '0';

toggle = toggle ^ 1;

fd = open(filename, O_WRONLY);
if (fd < 0) {
printf("Error: failed to reopen psh_toggle\n");
exit(1);
}

buf[0] = toggle + '0';
write(fd, buf, 1);

if (toggle == 1) {
printf("%s\n", OPEN_MSG);
set_color();
} else {
printf("\033[0mpsh disabled. you really afraid of rainbows? :(\n", buf[0]);
}


}

close(fd);
exit(0);

}
17 changes: 17 additions & 0 deletions user/psh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check which line to determine color, rets line number
int read_line_count();

// updates line num for color
void save_line_count(int line_count);

// checks if psh is enabled, rets 1 for true, 0 for false
int is_psh_enabled();

// resets color to white
void reset_color();

// updates color
void increment_color();

// sets the color
void set_color();
126 changes: 126 additions & 0 deletions user/psh_accessories.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include "kernel/types.h"
#include "kernel/stat.h"
#include "kernel/fs.h"
#include "user/user.h"
#include "kernel/fcntl.h"
#include "user/psh.h"

//
// psh accessory functions for sh.c (keeps things clean)
//


// 8-Bit color array
char *colors_256[] = {

"\033[38;5;196m", // Red
"\033[38;5;202m", // Light Red/Orange
"\033[38;5;208m", // Orange
"\033[38;5;214m", // Light Orange
"\033[38;5;226m", // Yellow
"\033[38;5;190m", // Light Yellow/Green
"\033[38;5;46m", // Green
"\033[38;5;83m", // Light Green
"\033[38;5;51m", // Cyan
"\033[38;5;81m", // Light Cyan
"\033[38;5;111m", // Sky Blue (Lighter Blue)
"\033[38;5;69m", // Teal/Light Blue
"\033[38;5;33m", // Dark Blue
"\033[38;5;201m", // Magenta
"\033[38;5;207m", // Light Magenta

};


/*
*
* read_line_count() -> returns the current line number for color choice
*
*/
int
read_line_count()
{
int fd, line_count = 0;
fd = open("/tmp/line_count", O_RDONLY);
if (fd >= 0) {
read(fd, &line_count, sizeof(line_count));
close(fd);
}
return line_count;
}

/*
*
* save_line_count(int line_count) -> takes the next line count and saves it to the counter file
*
*/
void
save_line_count(int line_count)
{
int fd = open("/tmp/line_count", O_WRONLY | O_CREATE);
write(fd, &line_count, sizeof(line_count));
close(fd);
}

/*
*
* is_psh_enabled() -> checks if psh is enabled (by calling `psh`), returns 1 if enabled, 0 if not
*
*/

int
is_psh_enabled()
{
int fd;
char buf[2];

fd = open("/tmp/psh_toggle", O_RDONLY);

if (fd < 0) {
return 0;
}

read(fd, buf, 1);
buf[1] = '\0';

close(fd);

return (buf[0] == '1') ? 1 : 0;
}


/*
*
* reset_color() -> resets the terminal color to white
*
*/

void
reset_color()
{
printf("\033[0m");
}



/*
*
* set_next_color() -> moves color to next in `colors_256[]`, updates current line number
*
*/
void increment_color() {
if (is_psh_enabled()) {
set_color();
} else {
reset_color();
}
}

void set_color() {
int line_count = read_line_count();
printf("%s", colors_256[line_count % (sizeof(colors_256) / sizeof(colors_256[0]) - 1)]);
line_count++;
save_line_count(line_count);
}


69 changes: 69 additions & 0 deletions user/pv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Implementation of pipe viewer (pv) for xv6
*
* This program reads data from standard input and writes it to standard output,
* while displaying progress information (bytes transferred and transfer rate)
* on standard error.
*/
#include "kernel/types.h"
#include "kernel/stat.h"
#include "kernel/fs.h"
#include "user/user.h"

#define BUFFER_SIZE 512

/**
* Main function for the pipe viewer
*
* Reads data from standard input in chunks, writes it to standard output,
* and displays progress information on standard error.
*
* @param argc Number of command-line arguments
* @param argv Array of command-line argument strings
* @return 0 on success, 1 on error
*/
int
main(int argc, char *argv[])
{
char buffer[BUFFER_SIZE];
int bytes_read;
unsigned int total_bytes = 0;
int start_time = uptime();
struct stat st;


if (fstat(0, &st) >= 0 && st.type == T_DEVICE) {
fprintf(2, "pv: no input piped\n");
exit(1);
}


while ((bytes_read = read(0, buffer, sizeof(buffer))) > 0) {
if (write(1, buffer, bytes_read) != bytes_read) {
fprintf(2, "pv: write error\n");
exit(1);
}

total_bytes += bytes_read;

int elapsed_ticks = uptime() - start_time;

if (elapsed_ticks == 0) {
elapsed_ticks = 1;
}

int rate = total_bytes / elapsed_ticks;

fprintf(2, "\r%d bytes transferred, %d bytes/tick", total_bytes, rate);

}

if (bytes_read < 0) {
fprintf(2, "pv: read error\n");
exit(1);
}

fprintf(2, "\n");
exit(0);

}
Loading