Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tddb68
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Elise Lång
tddb68
Commits
21fb86c9
Commit
21fb86c9
authored
6 years ago
by
oskan107
Browse files
Options
Downloads
Patches
Plain Diff
Shouldn't be much difference
parent
c74a3952
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pintos/src/filesys/file.c
+17
-17
17 additions, 17 deletions
pintos/src/filesys/file.c
with
17 additions
and
17 deletions
pintos/src/filesys/file.c
+
17
−
17
View file @
21fb86c9
...
...
@@ -4,7 +4,7 @@
#include
"threads/malloc.h"
/* An open file. */
struct
file
struct
file
{
struct
inode
*
inode
;
/* File's inode. */
off_t
pos
;
/* Current position. */
...
...
@@ -15,7 +15,7 @@ struct file
and returns the new file. Returns a null pointer if an
allocation fails or if INODE is null. */
struct
file
*
file_open
(
struct
inode
*
inode
)
file_open
(
struct
inode
*
inode
)
{
struct
file
*
file
=
calloc
(
1
,
sizeof
*
file
);
if
(
inode
!=
NULL
&&
file
!=
NULL
)
...
...
@@ -29,33 +29,33 @@ file_open (struct inode *inode)
{
inode_close
(
inode
);
free
(
file
);
return
NULL
;
return
NULL
;
}
}
/* Opens and returns a new file for the same inode as FILE.
Returns a null pointer if unsuccessful. */
struct
file
*
file_reopen
(
struct
file
*
file
)
file_reopen
(
struct
file
*
file
)
{
return
file_open
(
inode_reopen
(
file
->
inode
));
}
/* Closes FILE. */
void
file_close
(
struct
file
*
file
)
file_close
(
struct
file
*
file
)
{
if
(
file
!=
NULL
)
{
file_allow_write
(
file
);
inode_close
(
file
->
inode
);
free
(
file
);
free
(
file
);
}
}
/* Returns the inode encapsulated by FILE. */
struct
inode
*
file_get_inode
(
struct
file
*
file
)
file_get_inode
(
struct
file
*
file
)
{
return
file
->
inode
;
}
...
...
@@ -66,7 +66,7 @@ file_get_inode (struct file *file)
which may be less than SIZE if end of file is reached.
Advances FILE's position by the number of bytes read. */
off_t
file_read
(
struct
file
*
file
,
void
*
buffer
,
off_t
size
)
file_read
(
struct
file
*
file
,
void
*
buffer
,
off_t
size
)
{
off_t
bytes_read
=
inode_read_at
(
file
->
inode
,
buffer
,
size
,
file
->
pos
);
file
->
pos
+=
bytes_read
;
...
...
@@ -79,7 +79,7 @@ file_read (struct file *file, void *buffer, off_t size)
which may be less than SIZE if end of file is reached.
The file's current position is unaffected. */
off_t
file_read_at
(
struct
file
*
file
,
void
*
buffer
,
off_t
size
,
off_t
file_ofs
)
file_read_at
(
struct
file
*
file
,
void
*
buffer
,
off_t
size
,
off_t
file_ofs
)
{
return
inode_read_at
(
file
->
inode
,
buffer
,
size
,
file_ofs
);
}
...
...
@@ -92,7 +92,7 @@ file_read_at (struct file *file, void *buffer, off_t size, off_t file_ofs)
not yet implemented.)
Advances FILE's position by the number of bytes read. */
off_t
file_write
(
struct
file
*
file
,
const
void
*
buffer
,
off_t
size
)
file_write
(
struct
file
*
file
,
const
void
*
buffer
,
off_t
size
)
{
off_t
bytes_written
=
inode_write_at
(
file
->
inode
,
buffer
,
size
,
file
->
pos
);
file
->
pos
+=
bytes_written
;
...
...
@@ -108,7 +108,7 @@ file_write (struct file *file, const void *buffer, off_t size)
The file's current position is unaffected. */
off_t
file_write_at
(
struct
file
*
file
,
const
void
*
buffer
,
off_t
size
,
off_t
file_ofs
)
off_t
file_ofs
)
{
return
inode_write_at
(
file
->
inode
,
buffer
,
size
,
file_ofs
);
}
...
...
@@ -116,10 +116,10 @@ file_write_at (struct file *file, const void *buffer, off_t size,
/* Prevents write operations on FILE's underlying inode
until file_allow_write() is called or FILE is closed. */
void
file_deny_write
(
struct
file
*
file
)
file_deny_write
(
struct
file
*
file
)
{
ASSERT
(
file
!=
NULL
);
if
(
!
file
->
deny_write
)
if
(
!
file
->
deny_write
)
{
file
->
deny_write
=
true
;
inode_deny_write
(
file
->
inode
);
...
...
@@ -130,10 +130,10 @@ file_deny_write (struct file *file)
(Writes might still be denied by some other file that has the
same inode open.) */
void
file_allow_write
(
struct
file
*
file
)
file_allow_write
(
struct
file
*
file
)
{
ASSERT
(
file
!=
NULL
);
if
(
file
->
deny_write
)
if
(
file
->
deny_write
)
{
file
->
deny_write
=
false
;
inode_allow_write
(
file
->
inode
);
...
...
@@ -142,7 +142,7 @@ file_allow_write (struct file *file)
/* Returns the size of FILE in bytes. */
off_t
file_length
(
struct
file
*
file
)
file_length
(
struct
file
*
file
)
{
ASSERT
(
file
!=
NULL
);
return
inode_length
(
file
->
inode
);
...
...
@@ -161,7 +161,7 @@ file_seek (struct file *file, off_t new_pos)
/* Returns the current position in FILE as a byte offset from the
start of the file. */
off_t
file_tell
(
struct
file
*
file
)
file_tell
(
struct
file
*
file
)
{
ASSERT
(
file
!=
NULL
);
return
file
->
pos
;
...
...
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