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
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
![](https://img.shields.io/badge/Difficulty-Hard-informational?style=flat&color=2bbc8a)
![](https://img.shields.io/tokei/lines/github/eastonco/CS360)
# CPTS 360
Taken Fall 2020 @ WSU

# CPTS 360

Taken Fall 2020 @ WSU

[Spring 2022]: Refactored and improved!

## Dependencies

* `gcc <= 11.2`
* `make <= 4.3`
* `gcc-multilib`
* `e2fslibs-dev` **note: Linux/ext2_fs.h is depreciated**

## Instructions
Navigate into a folder and follow the README inside to get started. As always, This repo is not for cheating/copying and should be used for education purposes only.

## P.S.
If this repo has helped you out at all, please give it a star, I'm desperate.
Navigate into a folder and follow the README inside to get started. As always, This repo is not for cheating or copying and should be used for education purposes only.

## P.S

If this repo has helped you out at all, please give it a star, I'm desperate.
15 changes: 7 additions & 8 deletions lab1/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# CS360 Lab 2
Partition Table, myprintf Function

## Dependencies
* gcc
* make
Partition Table, myprintf Function

## Running the Program
To get started, first compile the project by running `make`. This will compile the programs into the bin directory.

From there, `cd` into the bin directory and run `part1.bin` or `part2.bin`. Part1 prints the contents of vdisk including extended partitions. Part2 prints the contents of env[].
Compile the project by running `make`. This compiles the programs into the `bin` directory.

Next, `cd` into the `bin` directory and run `./part1.bin` or `./part2.bin`. Part1 prints the contents of vdisk including the extended partitions. Part2 prints the contents of env[].

## Authors

## Authors
* **Connor Easton** - [Eastonco](https://github.com/Eastonco)
* **KC Wang** - [KC Wang](https://school.eecs.wsu.edu/faculty/profile/?nid=kwang)
* **KC Wang** - [KC Wang](https://school.eecs.wsu.edu/faculty/profile/?nid=kwang)
3 changes: 2 additions & 1 deletion lab1/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GCC = gcc
CFLAGS = -g -m32
CFLAGS = -g -m32 -fcommon
RM = rm -rf
BINDIR = bin
SRCDIR = src
Expand All @@ -12,6 +12,7 @@ build: $(SRCDIR)/lab1_part1.c $(SRCDIR)/lab1_part2.c
mkdir -p $(BINDIR)
$(GCC) $(CFLAGS) -o $(BINDIR)/part1.bin $(SRCDIR)/lab1_part1.c
$(GCC) $(CFLAGS) -o $(BINDIR)/part2.bin $(SRCDIR)/lab1_part2.c
cp vdisk $(BINDIR)/vdisk

clean veryclean:
$(RM) $(BINDIR)
80 changes: 44 additions & 36 deletions lab1/src/lab1_part1.c
Original file line number Diff line number Diff line change
@@ -1,80 +1,87 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>

typedef unsigned char u8;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned int u32;

typedef struct partition {
u8 drive; /* drive number FD=0, HD=0x80, etc. */
u8 drive; /* drive number FD=0, HD=0x80, etc. */

u8 head; /* starting head */
u8 sector; /* starting sector */
u8 cylinder; /* starting cylinder */
u8 head; /* starting head */
u8 sector; /* starting sector */
u8 cylinder; /* starting cylinder */

u8 sys_type; /* partition type: NTFS, LINUX, etc. */
u8 sys_type; /* partition type: NTFS, LINUX, etc. */

u8 end_head; /* end head */
u8 end_sector; /* end sector */
u8 end_cylinder; /* end cylinder */
u8 end_head; /* end head */
u8 end_sector; /* end sector */
u8 end_cylinder; /* end cylinder */

u32 start_sector; /* starting sector counting from 0 */
u32 nr_sectors; /* number of of sectors in partition */
}Partition;
u32 start_sector; /* starting sector counting from 0 */
u32 nr_sectors; /* number of of sectors in partition */
} Partition;

int MBR = 0x1BE;
int MBR = 0x1BE; /* Master Boot Record offset */

void main(int argc, char* argv[]){
void printPartition(Partition *p, int disk);
void printExtendedPartition(Partition *p, int disk);
int calculateEndAddress(Partition *p, int offset);
void read_sector(int disk, int sector, char *buf);

void main(int argc, char *argv[])
{
int disk;
char buf[512];
Partition *p;

disk = open("vdisk", O_RDONLY);
if (disk == -1){
printf("ERROR: failed to open disk, Aborting...\n");
disk = open("vdisk", O_RDONLY);

if (disk == -1) {
printf("ERROR: failed to open disk, Aborting...\n\n");
return;
}
printf("Disk opened successfully\nReading...\n");
printf("Disk opened successfully\nReading...\n\n");
read_sector(disk, 0, buf);


p = (Partition *) &buf[MBR];
p = (Partition *)&buf[MBR];
printPartition(p, disk);
p += 3;
printExtendedPartition(p, disk);

close(disk);

};

void printPartition(Partition *p, int disk){
printf("\e[1mDevice\tBoot Start\tEnd\tSectors\tId\n\e[0m");
void printPartition(Partition *p, int disk)
{
printf("\e[4mDevice\tBoot Start\tEnd\tSectors\tId\n\e[0m");

for(int i = 0; i<4; i++){
printf("vdisk%d\t", i+1);
for (int i = 0; i < 4; i++) {
printf("vdisk%d\t", i + 1);
printf("%d\t\t", p->start_sector);
printf("%d\t", calculateEndAddress(p,0));
printf("%d\t", calculateEndAddress(p, 0));
printf("%d\t", p->nr_sectors);
printf("%d\n", p->sys_type);
p++;
}
}

void printExtendedPartition(Partition *p, int disk){
void printExtendedPartition(Partition *p, int disk)
{
char buf[512];
int p4StartSector = p->start_sector;
int partitionCount = 5;
int offset = p4StartSector;

while(p->nr_sectors != 0){
while (p->nr_sectors != 0) {
read_sector(disk, offset, buf);
p = (Partition *)&buf[MBR];
p = (Partition *)&buf[MBR];
printf("vdisk%d\t", partitionCount);
printf("%d\t\t", p->start_sector + offset);
printf("%d\t", calculateEndAddress(p,offset));
printf("%d\t", calculateEndAddress(p, offset));
printf("%d\t", p->nr_sectors);
printf("%d\n", p->sys_type);
partitionCount++;
Expand All @@ -83,12 +90,13 @@ void printExtendedPartition(Partition *p, int disk){
}
}

int calculateEndAddress(Partition *p, int offset){
int calculateEndAddress(Partition *p, int offset)
{
return p->start_sector + p->nr_sectors - 1 + offset;
}


void read_sector(int disk, int sector, char *buf){
lseek(disk, sector*512, SEEK_SET);
void read_sector(int disk, int sector, char *buf)
{
lseek(disk, sector * 512, SEEK_SET);
read(disk, buf, 512);
};
Loading