Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos_forked_resit
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s2-alsaloumi
Pintos_forked_resit
Commits
e9a0ca4d
Commit
e9a0ca4d
authored
1 year ago
by
h2-addad
Browse files
Options
Downloads
Patches
Plain Diff
Update
parent
d10583e8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/filesys/filesys.c
+103
-0
103 additions, 0 deletions
src/filesys/filesys.c
with
103 additions
and
0 deletions
src/filesys/filesys.c
0 → 100644
+
103
−
0
View file @
e9a0ca4d
#include
"filesys/filesys.h"
#include
<debug.h>
#include
<stdio.h>
#include
<string.h>
#include
"filesys/file.h"
#include
"filesys/free-map.h"
#include
"filesys/inode.h"
#include
"filesys/directory.h"
/* Partition that contains the file system. */
struct
block
*
fs_device
;
static
void
do_format
(
void
);
/* Initializes the file system module.
If FORMAT is true, reformats the file system. */
void
filesys_init
(
bool
format
)
{
fs_device
=
block_get_role
(
BLOCK_FILESYS
);
if
(
fs_device
==
NULL
)
PANIC
(
"No file system device found, can't initialize file system."
);
inode_init
();
free_map_init
();
if
(
format
)
do_format
();
free_map_open
();
}
/* Shuts down the file system module, writing any unwritten data
to disk. */
void
filesys_done
(
void
)
{
free_map_close
();
}
/* Creates a file named NAME with the given INITIAL_SIZE.
Returns true if successful, false otherwise.
Fails if a file named NAME already exists,
or if internal memory allocation fails. */
bool
filesys_create
(
const
char
*
name
,
off_t
initial_size
)
{
block_sector_t
inode_sector
=
0
;
struct
dir
*
dir
=
dir_open_root
();
bool
success
=
(
dir
!=
NULL
&&
free_map_allocate
(
1
,
&
inode_sector
)
&&
inode_create
(
inode_sector
,
initial_size
)
&&
dir_add
(
dir
,
name
,
inode_sector
));
if
(
!
success
&&
inode_sector
!=
0
)
free_map_release
(
inode_sector
,
1
);
dir_close
(
dir
);
return
success
;
}
/* Opens the file with the given NAME.
Returns the new file if successful or a null pointer
otherwise.
Fails if no file named NAME exists,
or if an internal memory allocation fails. */
struct
file
*
filesys_open
(
const
char
*
name
)
{
struct
dir
*
dir
=
dir_open_root
();
struct
inode
*
inode
=
NULL
;
if
(
dir
!=
NULL
)
dir_lookup
(
dir
,
name
,
&
inode
);
dir_close
(
dir
);
return
file_open
(
inode
);
}
/* Deletes the file named NAME.
Returns true if successful, false on failure.
Fails if no file named NAME exists,
or if an internal memory allocation fails. */
bool
filesys_remove
(
const
char
*
name
)
{
struct
dir
*
dir
=
dir_open_root
();
bool
success
=
dir
!=
NULL
&&
dir_remove
(
dir
,
name
);
dir_close
(
dir
);
return
success
;
}
/* Formats the file system. */
static
void
do_format
(
void
)
{
printf
(
"Formatting file system..."
);
free_map_create
();
if
(
!
dir_create
(
ROOT_DIR_SECTOR
,
16
))
PANIC
(
"root directory creation failed"
);
free_map_close
();
printf
(
"done.
\n
"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment