Skip to content

Commit f6310df

Browse files
committed
Updated xfs-interface
1 parent 571067f commit f6310df

23 files changed

+1984
-2147
lines changed

.gitignore

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ disk.xfs
88
*.txt
99
*.tmp
1010
*.dSYM
11+
*.vscode/
12+
.DS_Store
1113
temp*
1214
test
1315
inodetable.txt

AUTHORS

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Current Maintainers
22
----------------------------------
3-
K Muralikrishnan [email protected]
3+
K Muralikrishnan [email protected]
44
55
6-
Vivek Anand T Kallampally [email protected]
6+
Vivek Anand T Kallampally [email protected]
77

88

99
Contributors
@@ -14,7 +14,7 @@
1414
Deepak Goyal
1515
Jeril K Goerge
1616
K Dinesh
17-
K Muralikrishnan
17+
K Muralikrishnan
1818
Mathew Kumpalamthanam
1919
Naseem Iqbal
2020
Nitish Kumar

LICENSE

100644100755
File mode changed.

Makefile

100644100755
-22
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
1-
#Our compiler.
21
CC = gcc
32
CFLAGS = -g
43
LDFLAGS = -lreadline
5-
#Default rule.
64

75
default: xfs-interface
86

97
xfs-interface: *.c *.h
108
$(CC) $(CFLAGS) *.c -o xfs-interface $(LDFLAGS)
11-
#xfs-interface: labels.o diskUtility.o inode.o interface.o fileSystem.o exception.o
12-
# $(CC) $(CFLAGS) -o xfs-interface labels.o diskUtility.o inode.o interface.o fileSystem.o exception.o $(LDFLAGS)
13-
14-
#diskUtility.o: diskUtility.c diskUtility.h exception.h
15-
# $(CC) $(CFLAGS) -c diskUtility.c
16-
17-
#exception.o: exception.c exception.h
18-
# $(CC) $(CFLAGS) -c exception.c
19-
20-
#fileSystem.o: fileSystem.c fileSystem.h memOrg.h inode.h diskUtility.h constants.h
21-
# $(CC) $(CFLAGS) -c fileSystem.c
22-
23-
#inode.o: inode.c inode.h
24-
# $(CC) $(CFLAGS) -c inode.c
25-
26-
#interface.o: interface.c interface.h inode.h diskUtility.h fileSystem.h
27-
# $(CC) $(CFLAGS) -c interface.c
28-
29-
#labels.o: labels.c labels.h
30-
# $(CC) $(CFLAGS) -c labels.c
319

3210
clean:
3311
$(RM) xfs-interface *.o disk.xfs rootfile.txt inodeusertable.txt

README

-23
This file was deleted.

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
XFS Interface
2+
=============
3+
4+
**Introduction** : XFS (eXperimental File System) Interface is an external interface to access the file system of the eXpOS. The filesystem is simulated on a binary file called ”disk.xfs”. The interface can format the disk, load/remove files, list files and copy blocks to a UNIX file.
5+
6+
Prerequisites :
7+
-------------
8+
• GCC (GNU project C and C++ compiler)
9+
• libreadline-dev (readline library for command completion)
10+
11+
Compiling and Running :
12+
---------------------
13+
Run the following commands to compile and run the XFS interface:
14+
1. `make`
15+
2. `./xfs-interface`
16+
17+
Commands :
18+
--------
19+
Type `help` in the interface to display the list of commands.

constants.h

100644100755
+4-23
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
#ifndef _XSM_CONSTANTS_H
1+
#ifndef XFS_CONSTANTS_H
22

3-
#define _XSM_CONSTANTS_H
3+
#define XFS_CONSTANTS_H
44

55
#include <stdbool.h>
66

77
#define XSM_WORD_SIZE 16
88
#define XSM_MEMORY_NUMPAGES 128
99
#define XSM_PAGE_SIZE 512
1010

11-
#define XSM_REGSIZE XSM_WORD_SIZE
12-
#define XSM_NUM_REG 33
13-
14-
#define XSM_ILLINSTR -1
15-
16-
#define XSM_SUCCESS 1
17-
#define XSM_FAILURE 0
11+
#define XFS_SUCCESS 0
12+
#define XFS_FAILURE -1
1813

1914
#define XSM_INSTRUCTION_SIZE 2
2015

21-
/* Disk states. */
22-
#define XSM_DISK_IDLE 0
23-
#define XSM_DISK_BUSY 1
24-
25-
/* Console states. */
26-
#define XSM_CONSOLE_IDLE 0
27-
#define XSM_CONSOLE_BUSY 1
28-
2916
#ifndef TRUE
3017
#define TRUE 1
3118
#endif
@@ -34,10 +21,4 @@
3421
#define FALSE 0
3522
#endif
3623

37-
/* Interrupts */
38-
#define XSM_INTERRUPT_EXCEPTION 0
39-
#define XSM_INTERRUPT_TIMER 1
40-
#define XSM_INTERRUPT_DISK 2
41-
#define XSM_INTERRUPT_CONSOLE 3
42-
4324
#endif

disk.c

100644100755
+45-53
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,69 @@
1+
/*
2+
Interface to access disk file.
3+
*/
4+
15
#include "disk.h"
2-
#include "exception.h"
6+
37
#include <fcntl.h>
48
#include <stdlib.h>
59
#include <unistd.h>
610
#include <sys/types.h>
711

8-
BLOCK* disk;
12+
BLOCK *disk;
913

10-
/*
11-
This function reads an entire BLOCK from the address specified from fileBlockNumber on the disk file to virtBlockNumber on the memory copy of the disk.
12-
*/
13-
int readFromDisk(int virtBlockNumber, int fileBlockNumber) {
14-
int fd;
15-
fd = openDiskFile(O_RDONLY);
16-
lseek(fd,sizeof (BLOCK)*fileBlockNumber,SEEK_SET);
17-
read(fd,&disk[virtBlockNumber],sizeof (BLOCK));
18-
close(fd);
19-
return 0;
14+
/* Reads an entire block from fileBlockNumber on the disk to virtBlockNumber on the memory copy of the disk */
15+
int readFromDisk(int virtBlockNumber, int fileBlockNumber)
16+
{
17+
int fd = openDiskFile(O_RDONLY);
18+
19+
lseek(fd, sizeof(BLOCK) * fileBlockNumber, SEEK_SET);
20+
read(fd, &disk[virtBlockNumber], sizeof(BLOCK));
21+
close(fd);
22+
23+
return XFS_SUCCESS;
2024
}
2125

26+
/* Writes an entire block to fileBlocknumber on the disk from virtBlockNumber on the memory copy of the disk */
27+
int writeToDisk(int virtBlockNumber, int fileBlockNumber)
28+
{
29+
int fd = openDiskFile(O_WRONLY);
2230

23-
/*
24-
This function writes an entire block to fileBlocknumber on the disk file from virtBlockNumber on the memory copy of the disk.
25-
*/
26-
int writeToDisk(int virtBlockNumber, int fileBlockNumber) {
27-
int fd;
28-
fd = openDiskFile(O_WRONLY);
29-
lseek(fd,0,SEEK_SET);
30-
lseek(fd,sizeof (BLOCK)*fileBlockNumber,SEEK_CUR);
31-
write(fd,&disk[virtBlockNumber],sizeof (BLOCK));
32-
close(fd);
33-
return 0;
31+
lseek(fd, 0, SEEK_SET);
32+
lseek(fd, sizeof(BLOCK) * fileBlockNumber, SEEK_CUR);
33+
write(fd, &disk[virtBlockNumber], sizeof(BLOCK));
34+
close(fd);
35+
36+
return XFS_SUCCESS;
3437
}
3538

36-
/*
37-
Opens the disk file returns the file descriptor
38-
if it fails, throws an exception and transfers control to the interface
39-
*/
39+
/* Opens the disk file and returns the file descriptor */
4040
int openDiskFile(int access)
4141
{
42-
int fd;
43-
fd = open(DISK_NAME, access, 0666);
44-
if(fd < 0){
45-
exception_throwException(EXCEPTION_CANT_OPEN_DISK);
46-
}
47-
return fd;
42+
int fd = open(DISK_NAME, access, 0666);
43+
if (fd < 0)
44+
exception_throwException(EXCEPTION_CANT_OPEN_DISK);
45+
46+
return fd;
4847
}
4948

50-
/*
51-
Creates the disk file
52-
Arguments: format) disk is formatted if its value is DISK_FORMAT
53-
if it fails, throws an exception and transfers control to the interface
54-
*/
49+
/* Creates the disk file */
5550
void createDiskFile(int format)
5651
{
57-
int fd;
52+
int fd;
53+
54+
if (format == DISK_FORMAT)
55+
fd = open(DISK_NAME, O_CREAT | O_TRUNC | O_SYNC, 0666);
56+
else
57+
fd = open(DISK_NAME, O_CREAT, 0666);
5858

59-
if(format==DISK_FORMAT)
60-
fd = open(DISK_NAME, O_CREAT | O_TRUNC | O_SYNC, 0666);
61-
else
62-
fd = open(DISK_NAME, O_CREAT, 0666);
59+
if (fd < 0)
60+
exception_throwException(EXCEPTION_CANT_CREATE_DISK);
6361

64-
if(fd < 0){
65-
exception_throwException(EXCEPTION_CANT_CREATE_DISK);
66-
}
67-
close(fd);
62+
close(fd);
6863
}
6964

70-
/*
71-
Tries to open the disk file, throws an exception if it fails.
72-
An exception returns the control to the jmppoint set in interface.c
73-
*/
65+
/* Tries to open the disk */
7466
void diskCheckFileExists()
7567
{
76-
close(openDiskFile(O_RDONLY));
77-
}
68+
close(openDiskFile(O_RDONLY));
69+
}

disk.h

100644100755
+9-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
#ifndef DISK_H
2-
#define DISK_H
1+
#ifndef XFS_DISK_H
2+
3+
#define XFS_DISK_H
34

45
#include "fileSystem.h"
6+
#include "exception.h"
57

6-
#define DISK_NAME "disk.xfs"
7-
#define BOOT_BLOCK 0
8+
#define DISK_NAME "disk.xfs"
89

910
#define DISK_NO_FORMAT 0
1011
#define DISK_FORMAT 1
1112

12-
typedef struct{
13-
char word[BLOCK_SIZE][WORD_SIZE];
14-
}BLOCK;
13+
typedef struct
14+
{
15+
char word[BLOCK_SIZE][WORD_SIZE];
16+
} BLOCK;
1517

1618
int readFromDisk(int virtBlockNumber, int fileBlockNumber);
1719
int writeToDisk(int virtBlockNumber, int fileBlockNumber);

0 commit comments

Comments
 (0)