The next commit will make mode_t 32-bits, ino_t 64-bits, nlink_t 32-bits, and off_t 64-bits. However, in the protocol there is no room for that. When analyzing the usage of these data types we can see that of mode_t we currently use 15 bits and that future flags (if copied from NetBSD) are only of importance to VFS and not to the actual file system on disk. Therefore we can get away with keeping the protocol version of mode_t (pmode_t) 16 bits. At this point it is unlikely that MINIX will support file systems that can hold more than 2^32 files. Keeping the protocol version of ino_t (pino_t) 32-bits and exposing it as 64-bits to the rest of the system is fine. uid_t and gid_t are already 32-bits, but in behind the scenes they're 16-bits. This is sufficient since we don't support uid/gids larger than 2^16-1. off_t will become 64-bits, but the protocol had room reserved for that since it was revised years ago. So to make the difference clear between what the protocol supports and what is exposed to the system, we define protocol version of these data types. Change-Id: Ifb883aafb222142e69d6dcc3049a47170b78b3ee
104 lines
2.4 KiB
C
104 lines
2.4 KiB
C
#include "fs.h"
|
|
#include "buf.h"
|
|
#include "inode.h"
|
|
#include <sys/types.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static struct buf *new_block(dev_t dev, pino_t inum);
|
|
|
|
/*===========================================================================*
|
|
* buf_pool *
|
|
*===========================================================================*/
|
|
void buf_pool(void)
|
|
{
|
|
/* Initialize the buffer pool. */
|
|
|
|
front = NULL;
|
|
rear = NULL;
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
* get_block *
|
|
*===========================================================================*/
|
|
struct buf *get_block(dev_t dev, pino_t inum)
|
|
{
|
|
struct buf *bp = front;
|
|
|
|
while(bp != NULL) {
|
|
if (bp->b_dev == dev && bp->b_num == inum) {
|
|
bp->b_count++;
|
|
return(bp);
|
|
}
|
|
bp = bp->b_next;
|
|
}
|
|
|
|
/* Buffer was not found. Try to allocate a new one */
|
|
return new_block(dev, inum);
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* new_block *
|
|
*===========================================================================*/
|
|
static struct buf *new_block(dev_t dev, pino_t inum)
|
|
{
|
|
/* Allocate a new buffer and add it to the double linked buffer list */
|
|
struct buf *bp;
|
|
|
|
bp = malloc(sizeof(struct buf));
|
|
if (bp == NULL) {
|
|
err_code = ENOSPC;
|
|
return(NULL);
|
|
}
|
|
bp->b_num = inum;
|
|
bp->b_dev = dev;
|
|
bp->b_bytes = 0;
|
|
bp->b_count = 1;
|
|
memset(bp->b_data, 0 , PIPE_BUF);
|
|
|
|
/* Add at the end of the buffer */
|
|
if (front == NULL) { /* Empty list? */
|
|
front = bp;
|
|
bp->b_prev = NULL;
|
|
} else {
|
|
rear->b_next = bp;
|
|
bp->b_prev = rear;
|
|
}
|
|
bp->b_next = NULL;
|
|
rear = bp;
|
|
|
|
return(bp);
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* put_block *
|
|
*===========================================================================*/
|
|
void put_block(dev_t dev, pino_t inum)
|
|
{
|
|
struct buf *bp;
|
|
|
|
bp = get_block(dev, inum);
|
|
if (bp == NULL) return; /* We didn't find the block. Nothing to put. */
|
|
|
|
bp->b_count--; /* Compensate for above 'get_block'. */
|
|
if (--bp->b_count > 0) return;
|
|
|
|
/* Cut bp out of the loop */
|
|
if (bp->b_prev == NULL)
|
|
front = bp->b_next;
|
|
else
|
|
bp->b_prev->b_next = bp->b_next;
|
|
|
|
if (bp->b_next == NULL)
|
|
rear = bp->b_prev;
|
|
else
|
|
bp->b_next->b_prev = bp->b_prev;
|
|
|
|
/* Buffer administration is done. Now it's safe to free up bp. */
|
|
free(bp);
|
|
}
|