-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 317903b
Showing
36 changed files
with
1,969 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CC = gcc | ||
OPTIONS = -Wall -Wextra -Werror | ||
|
||
all: generate_students kernel request_generator_admin request_generator_manager request_generator_member server | ||
|
||
clear: | ||
rm disk generate_students kernel server request_generator_admin requests.txt log.txt requests | ||
|
||
generate_students: generate_students.c | ||
$(CC) -Wall -g generate_students.c -o generate_students | ||
|
||
kernel: | ||
$(CC) -Wall -g kernel.c -o kernel | ||
|
||
request_generator_admin: request_generator_admin.c | ||
$(CC) -Wall -g request_generator_admin.c -o request_generator_admin | ||
|
||
request_generator_manager: request_generator_manager.c | ||
$(CC) -Wall -g request_generator_manager.c -o request_generator_manager | ||
|
||
request_generator_member: request_generator_member.c | ||
$(CC) -Wall -g request_generator_member.c -o request_generator_member | ||
|
||
server: server.c | ||
$(CC) -Wall -g server.c -o server | ||
# build: | ||
# @$(CC) -Wall -g $(MODULE).c -o bin/$(MODULE) | ||
# @./bin/$(MODULE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
OS PROJECT: Student Management Program | ||
|
||
Name: Roll No: | ||
Cecily Ambooken IIB2022003 | ||
Rakim Middya IIT2022255 | ||
Rishab Bohra IIB2022004 | ||
Veerathu Sindhu IIB2022006 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#ifndef GENERATE | ||
#define GENERATE | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
#include <sys/time.h> | ||
#include <sys/stat.h> | ||
#include <assert.h> | ||
|
||
#include "student.h" | ||
|
||
// Function to load names from a file into an array | ||
|
||
|
||
unsigned int randval() | ||
{ | ||
unsigned int randval; | ||
FILE *f; | ||
f = fopen("/dev/random", "r"); | ||
fread(&randval, sizeof(randval), 1, f); | ||
fclose(f); | ||
return randval; | ||
} | ||
|
||
void loadNamesFromFile(char* filename, char array[][MAX_STRING_LEN], int numNames) | ||
{ | ||
FILE *file = fopen(filename, "r"); | ||
for (int i = 0; i < 20; i++) | ||
{ | ||
char ch = fgetc(file); | ||
int j = 0; | ||
while (ch != EOF) | ||
{ | ||
//printf("%c", ch); | ||
if (ch == '\n') | ||
{ | ||
array[i][j] = '\0'; | ||
break; | ||
} | ||
array[i][j] = ch; | ||
ch = fgetc(file); | ||
j++; | ||
} | ||
// fgets(array[i], MAX_NAME_LEN, file); | ||
} | ||
for (int i = 0; i < numNames-1; i++) | ||
{ | ||
array[i][strlen(array[i]) - 1] = '\0'; | ||
} | ||
fclose(file); | ||
} | ||
|
||
char* generateFullName(char first_names[20][MAX_STRING_LEN], char last_names[20][MAX_STRING_LEN]) | ||
{ | ||
srand(time(NULL)); | ||
int i = randval()%20; | ||
int j = randval()%20; | ||
char *name = malloc(sizeof(char)*105); | ||
sprintf(name, "%s %s", first_names[i], last_names[j]); | ||
//printf("%s", name); | ||
return name; | ||
} | ||
|
||
char* getRandomString(char names[][MAX_STRING_LEN], int range) | ||
{ | ||
srand(time(NULL)); | ||
int num = randval() % range; | ||
return names[num]; | ||
} | ||
|
||
struct Student generateStudent(int id) | ||
{ | ||
struct Student student; | ||
|
||
char firstNames[20][MAX_STRING_LEN]; | ||
char lastNames[20][MAX_STRING_LEN]; | ||
char hostelNames[5][MAX_STRING_LEN]; | ||
char courses[5][MAX_STRING_LEN]; | ||
|
||
loadNamesFromFile("names/firstname.txt", firstNames, 20); | ||
loadNamesFromFile("names/lastname.txt", lastNames, 20); | ||
loadNamesFromFile("names/hostelnames.txt", hostelNames, 5); | ||
loadNamesFromFile("names/coursenames.txt", courses, 5); | ||
|
||
srand(time(NULL)); | ||
student.id = id; | ||
strcpy(student.name, generateFullName(firstNames, lastNames)); | ||
strcpy(student.hostel, getRandomString(hostelNames, 5)); | ||
strcpy(student.course, getRandomString(courses, 5)); | ||
student.roomNumber = randval() % 400 + 101; | ||
sprintf(student.dob, "%d/%d/%d", randval() % 28 + 1, randval() % 12 + 1, randval() % 16 + 1985); | ||
student.yearOfStudy = randval() % 5 + 1; | ||
|
||
return student; | ||
} | ||
|
||
void registration(struct Student student) | ||
{ | ||
FILE *file = fopen("disk", "a"); | ||
if (file == NULL) | ||
{ | ||
perror("Error opening database file"); | ||
exit(0); | ||
} | ||
|
||
fwrite(&student, 1, sizeof(struct Student), file); | ||
fclose(file); | ||
} | ||
|
||
double GetTime() | ||
{ | ||
struct timeval t; | ||
int rc = gettimeofday(&t, NULL); | ||
assert(rc == 0); | ||
return (double) t.tv_sec + (double) t.tv_usec/1e6; | ||
} | ||
|
||
void Spin(int howlong) | ||
{ | ||
double t = GetTime(); | ||
while ((GetTime() - t) < (double) howlong); // do nothing in loop | ||
} | ||
|
||
|
||
void generate() | ||
{ | ||
FILE *file = fopen("disk", "a"); | ||
if (file == NULL) | ||
{ | ||
perror("Error opening database file"); | ||
exit(0); | ||
} | ||
fseek(file, -sizeof(struct Student), SEEK_CUR); | ||
struct Student temp; | ||
fread(&temp, 1, sizeof(struct Student), file); | ||
if (temp.id >= 100) | ||
{ | ||
// printf("Registration complete for 100 students.\n"); | ||
fclose(file); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
struct Student student = generateStudent(i+1); | ||
//Spin(1); | ||
registration(student); | ||
} | ||
|
||
// printf("Registration complete for 100 students.\n"); | ||
fclose(file); | ||
} | ||
|
||
int main() | ||
{ | ||
generate(); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#ifndef KERNCALL | ||
#define KERNCALL | ||
|
||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
#include "student.h" | ||
#include "log.c" | ||
|
||
struct kerncall { | ||
char ch; // 'u' = updateFile 's' = searchFile; | ||
int id; // id to update/search | ||
int newRoomNo; // room number to update | ||
}; | ||
|
||
|
||
void writeToPipe(int fd, char ch, int id, int newRoomNo) | ||
{ | ||
struct kerncall k = {0}; | ||
k.ch = ch; | ||
k.id = id; | ||
k.newRoomNo = newRoomNo; | ||
write(fd, &k, sizeof(k)); | ||
} | ||
|
||
struct Student searchFile(int id, int flag) | ||
{ | ||
FILE* db = fopen("disk", "r"); | ||
if (db == NULL) | ||
{ | ||
perror("Error opening database file"); | ||
exit(0); | ||
} | ||
struct Student temp; | ||
while(fread(&temp, 1, sizeof(struct Student), db) && sizeof(temp) == sizeof(struct Student)) | ||
{ | ||
if (temp.id == id) | ||
{ | ||
if (flag == 0) | ||
{ | ||
// printf("%d, %s, %s, %s, %d, %s, Year %d\n", temp.id, temp.name, | ||
// temp.hostel, temp.course, temp.roomNumber, temp.dob, temp.yearOfStudy); | ||
} | ||
fclose(db); | ||
return temp; | ||
} | ||
} | ||
|
||
// printf("NOT FOUND!!\n"); | ||
fclose(db); | ||
temp.id = -1; | ||
return temp; | ||
} | ||
|
||
// Update the file. | ||
void updateFile(int id, int newRoomNumber) | ||
{ | ||
/* | ||
* | ||
* Implement the logic for updating here. | ||
* First search file, but instead of returning a number, get the file pointer. | ||
* Use fseek to reposition the file pointer. The number of bytes will be similar. | ||
* And write the new struct there. | ||
* | ||
*/ | ||
FILE* db = fopen("disk", "r+"); | ||
if (db == NULL) | ||
{ | ||
perror("Error opening database file"); | ||
exit(0); | ||
} | ||
|
||
struct Student temp; | ||
|
||
while(fread(&temp, 1, sizeof(struct Student), db) && sizeof(temp) == sizeof(struct Student)) | ||
{ | ||
if (temp.id == id) | ||
{ | ||
temp.roomNumber = newRoomNumber; | ||
fseek(db, -sizeof(struct Student), SEEK_CUR); | ||
fwrite(&temp, 1, sizeof(struct Student), db); | ||
fclose(db); | ||
return; | ||
} | ||
} | ||
|
||
fclose(db); | ||
return; | ||
} | ||
#endif |
Binary file not shown.
Oops, something went wrong.