Skip to content

Commit

Permalink
Merge pull request #154 from hangpark/iss/153
Browse files Browse the repository at this point in the history
[#153] Implement file extension
  • Loading branch information
hangpark authored Jun 12, 2017
2 parents 28429c3 + 62065f0 commit a1f0994
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 28 deletions.
49 changes: 49 additions & 0 deletions src/filesys/free-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,52 @@ free_map_create (void)
if (!bitmap_write (free_map, free_map_file))
PANIC ("can't write free map");
}

/* Allocates consecutive sectors from the free map. This can be
used for recursive jobs.
Desired number of sectors to allocate from now is set by *CNTP.
But, kernel may not be able to allocate *CNTP consecutive sectors.
Then it decreases SIZE by half until (decreased) SIZE consecutive
sectors becomes available to be allocated.
After allocating n consecutive sectors, this method decrease
*CNTP by n so that desired number of sector reduced which can be
allocated in the next loop.
This returns the number of consecutive allocated sectors.
Example usage:
size_t cnt = 100; // Number of sectors to allocate.
size_t size = cnt;
while (cnt > 0)
{
size = free_map_allocate_r (&cnt, size, &sector);
if (size == 0)
goto fail; // Cannot allocate.
// Do whatever with size and sector.
}
*/
size_t
free_map_allocate_r (size_t *cntp, size_t size, disk_sector_t *sectorp)
{
ASSERT (cntp != NULL);
ASSERT (sectorp != NULL);

if (size > *cntp)
size = *cntp;

while (size > 0)
{
if (free_map_allocate (size, sectorp))
break;
size = size >> 1;
}

*cntp -= size;

return size;
}
2 changes: 2 additions & 0 deletions src/filesys/free-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ void free_map_close (void);
bool free_map_allocate (size_t, disk_sector_t *);
void free_map_release (disk_sector_t, size_t);

size_t free_map_allocate_r (size_t *, size_t, disk_sector_t *);

#endif /* filesys/free-map.h */
Loading

0 comments on commit a1f0994

Please sign in to comment.