Basic Solution File System - BSFS
Loading...
Searching...
No Matches
bspan_queue_bsfs.c File Reference

Implementation of dynamic queue operations for BSpan allocation. More...

Functions

void init_bspan_queue (bspan_queue_t *queue)
 Initializes a bspan queue.
int enqueue_bspan (bspan_queue_t *queue, uint32_t file_blk, uint32_t disk_blk, uint16_t length)
 Enqueues a bspan into the queue.
bspan_t dequeue_bspan (bspan_queue_t *queue)
 Dequeues and returns the bspan from the front of the queue.
bspan_queue_tcopy_bspan_queue (bspan_queue_t *original)
 Copies a bspan queue.
int is_bspan_queue_empty (bspan_queue_t *queue)
 Checks if the bspan queue is empty.
void free_bspan_queue (bspan_queue_t *queue)
 Frees all elements of the bspan queue.

Detailed Description

Implementation of dynamic queue operations for BSpan allocation.

This file provides the implementation of a FIFO queue used to manage sequences of block spans (bspan_t) in the BSFS file system. These queues are used during block allocation to track contiguous ranges of blocks available for file storage.

Core operations include:

  • Initializing an empty queue
  • Enqueuing and dequeuing bspans
  • Copying a queue
  • Freeing all queue elements
  • Checking if the queue is empty

This abstraction simplifies memory management and ordering of block span assignments during file writing or preallocation.

Function Documentation

◆ copy_bspan_queue()

bspan_queue_t * copy_bspan_queue ( bspan_queue_t * original)

Copies a bspan queue.

This function creates a new queue and copies all the elements from the original queue into the new queue. The new queue is returned.

Parameters
originalPointer to the bspan queue to be copied.
Returns
Pointer to the new copied bspan queue.

◆ dequeue_bspan()

bspan_t dequeue_bspan ( bspan_queue_t * queue)

Dequeues and returns the bspan from the front of the queue.

This function removes the first bspan from the queue and returns it. If the queue is empty, the program exits with an error.

Parameters
queuePointer to the bspan queue from which the bspan will be dequeued.
Returns
The bspan removed from the front of the queue.

◆ enqueue_bspan()

int enqueue_bspan ( bspan_queue_t * queue,
uint32_t file_blk,
uint32_t disk_blk,
uint16_t length )

Enqueues a bspan into the queue.

This function creates a new node to store the bspan and adds it to the end of the queue. If the queue is empty, the new node becomes both the front and the rear of the queue.

Parameters
queuePointer to the bspan queue where the bspan will be added.
file_blkThe file block associated with the bspan.
disk_blkThe disk block associated with the bspan.
lengthThe length of the bspan.
Returns
0 on success, -1 if memory allocation fails.

◆ free_bspan_queue()

void free_bspan_queue ( bspan_queue_t * queue)

Frees all elements of the bspan queue.

This function removes all elements from the queue, freeing the memory allocated for each node.

Parameters
queuePointer to the bspan queue to be freed.

◆ init_bspan_queue()

void init_bspan_queue ( bspan_queue_t * queue)

Initializes a bspan queue.

The function sets the front and rear pointers of the queue to NULL, indicating that the queue is empty.

Parameters
queuePointer to the bspan queue to be initialized.

◆ is_bspan_queue_empty()

int is_bspan_queue_empty ( bspan_queue_t * queue)

Checks if the bspan queue is empty.

This function returns 1 if the queue is empty, and 0 otherwise.

Parameters
queuePointer to the bspan queue to be checked.
Returns
1 if the queue is empty, 0 otherwise.