-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmfs.h
More file actions
80 lines (67 loc) · 2.79 KB
/
mfs.h
File metadata and controls
80 lines (67 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _MFS_H
#define _MFS_H
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include "b_io.h"
#include "fsInit.h"
#include <dirent.h>
#define FT_REGFILE DT_REG
#define FT_DIRECTORY DT_DIR
#define FT_LINK DT_LNK
#ifndef uint64_t
typedef u_int64_t uint64_t;
#endif
#ifndef uint32_t
typedef u_int32_t uint32_t;
#endif
// This structure is returned by fs_readdir to provide the caller with information
// about each file as it iterates through a directory
struct fs_diriteminfo
{
unsigned short d_reclen; /* length of this record */
unsigned char fileType;
char d_name[256]; /* filename max filename is 255 characters */
};
// This is a private structure used only by fs_opendir, fs_readdir, and fs_closedir
// Think of this like a file descriptor but for a directory - one can only read
// from a directory. This structure helps you (the file system) keep track of
// which directory entry you are currently processing so that everytime the caller
// calls the function readdir, you give the next entry in the directory
typedef struct
{
unsigned short d_reclen; /* length of this record */
unsigned short dirEntryPosition; /* which directory entry position, like file pos */
directoryEntry* directory; /* Pointer to the loaded directory you want to iterate */
struct fs_diriteminfo * di; /* Pointer to the structure you return from read */
} fdDir;
// Key directory functions
int fs_mkdir(const char *pathname, mode_t mode);
int fs_rmdir(const char *pathname);
int fs_mvitem(const char *source, const char *destination);
// Directory iteration functions
fdDir * fs_opendir(const char *pathname);
struct fs_diriteminfo *fs_readdir(fdDir *dirp);
int fs_closedir(fdDir *dirp);
// Misc directory functions
directoryEntry* getCwd(); //helper function for external call (fsPath)
int setCwd(directoryEntry* directory); //helper function for external call (fsInit)
int setCwdString(char* CwdString); //helper function for external call (fsInit)
int freeDir(directoryEntry* directory); //helper function for external call (b_io)
char * fs_getcwd(char *pathname, size_t size);
int fs_setcwd(char *pathname); //linux chdir
int fs_isFile(char * filename); //return 1 if file, 0 otherwise
int fs_isDir(char * pathname); //return 1 if directory, 0 otherwise
int fs_delete(char* filename); //removes a file
// This is the strucutre that is filled in from a call to fs_stat
struct fs_stat
{
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_accesstime; /* time of last access */
time_t st_modtime; /* time of last modification */
time_t st_createtime; /* time of last status change */
};
int fs_stat(const char *path, struct fs_stat *buf);
#endif