Clean up PFS

This commit is contained in:
Thomas Veerman 2010-05-28 09:39:18 +00:00
parent 8d06457241
commit 5d78cefaf2
22 changed files with 97 additions and 177 deletions

View File

@ -157,6 +157,7 @@
#define NO_ENTRY ((ino_t) 0) /* absence of a dir entry */ #define NO_ENTRY ((ino_t) 0) /* absence of a dir entry */
#define NO_ZONE ((zone_t) 0) /* absence of a zone number */ #define NO_ZONE ((zone_t) 0) /* absence of a zone number */
#define NO_DEV ((dev_t) 0) /* absence of a device numb */ #define NO_DEV ((dev_t) 0) /* absence of a device numb */
#define NO_LINK ((nlink_t) 0) /* absence of incoming links */
#define SERVARNAME "cttyline" #define SERVARNAME "cttyline"

View File

@ -14,7 +14,7 @@ struct stat {
dev_t st_dev; /* major/minor device number */ dev_t st_dev; /* major/minor device number */
ino_t st_ino; /* i-node number */ ino_t st_ino; /* i-node number */
mode_t st_mode; /* file mode, protection bits, etc. */ mode_t st_mode; /* file mode, protection bits, etc. */
short int st_nlink; /* # links; TEMPORARY HACK: should be nlink_t*/ nlink_t st_nlink; /* # links; */
uid_t st_uid; /* uid of the file's owner */ uid_t st_uid; /* uid of the file's owner */
short int st_gid; /* gid; TEMPORARY HACK: should be gid_t */ short int st_gid; /* gid; TEMPORARY HACK: should be gid_t */
dev_t st_rdev; dev_t st_rdev;

View File

@ -11,7 +11,4 @@ MAN=
BINDIR?= /usr/sbin BINDIR?= /usr/sbin
INSTALLFLAGS+= -S 128k INSTALLFLAGS+= -S 128k
NR_BUFS= 256
CPPFLAGS+= -DNR_BUFS=${NR_BUFS}
.include <minix.prog.mk> .include <minix.prog.mk>

View File

@ -1,3 +1,6 @@
#ifndef __PFS_BUF_H__
#define __PFS_BUF_H__
/* Buffer (block) cache. /* Buffer (block) cache.
*/ */
@ -17,9 +20,7 @@ struct buf {
/* A block is free if b_dev == NO_DEV. */ /* A block is free if b_dev == NO_DEV. */
#define BUFHASH(b) ((b) % NR_BUFS)
EXTERN struct buf *front; /* points to least recently used free block */ EXTERN struct buf *front; /* points to least recently used free block */
EXTERN struct buf *rear; /* points to most recently used free block */ EXTERN struct buf *rear; /* points to most recently used free block */
EXTERN int bufs_in_use; /* # bufs currently in use (not on free list)*/
#endif

View File

@ -3,9 +3,9 @@
#include "inode.h" #include "inode.h"
#include <sys/types.h> #include <sys/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <alloca.h>
#include <string.h> #include <string.h>
FORWARD _PROTOTYPE( struct buf *new_block, (dev_t dev, ino_t inum) );
/*===========================================================================* /*===========================================================================*
* buf_pool * * buf_pool *
@ -43,7 +43,7 @@ PUBLIC struct buf *get_block(dev_t dev, ino_t inum)
/*===========================================================================* /*===========================================================================*
* new_block * * new_block *
*===========================================================================*/ *===========================================================================*/
PUBLIC struct buf *new_block(dev_t dev, ino_t inum) PRIVATE struct buf *new_block(dev_t dev, ino_t inum)
{ {
/* Allocate a new buffer and add it to the double linked buffer list */ /* Allocate a new buffer and add it to the double linked buffer list */
struct buf *bp; struct buf *bp;

View File

@ -1,16 +1,11 @@
/* Tables sizes */ #ifndef __PFS_CONST_H__
#define V1_NR_DZONES 7 /* # direct zone numbers in a V1 inode */ #define __PFS_CONST_H__
#define V1_NR_TZONES 9 /* total # zone numbers in a V1 inode */
#define V2_NR_DZONES 7 /* # direct zone numbers in a V2 inode */
#define V2_NR_TZONES 10 /* total # zone numbers in a V2 inode */
#define NR_INODES 256 /* # slots in "in core" inode table */ #define NR_INODES 256 /* # slots in "in core" inode table */
#define GETDENTS_BUFSIZ 257
#define INODE_HASH_LOG2 7 /* 2 based logarithm of the inode hash size */ #define INODE_HASH_LOG2 7 /* 2 based logarithm of the inode hash size */
#define INODE_HASH_SIZE ((unsigned long)1<<INODE_HASH_LOG2) #define INODE_HASH_SIZE ((unsigned long)1<<INODE_HASH_LOG2)
#define INODE_HASH_MASK (((unsigned long)1<<INODE_HASH_LOG2)-1) #define INODE_HASH_MASK (((unsigned long)1<<INODE_HASH_LOG2)-1)
#define INODE_MAP_SIZE INODE_HASH_LOG2
/* The type of sizeof may be (unsigned) long. Use the following macro for /* The type of sizeof may be (unsigned) long. Use the following macro for
@ -19,79 +14,22 @@
*/ */
#define usizeof(t) ((unsigned) sizeof(t)) #define usizeof(t) ((unsigned) sizeof(t))
/* File system types. */
#define SUPER_MAGIC 0x137F /* magic number contained in super-block */
#define SUPER_REV 0x7F13 /* magic # when 68000 disk read on PC or vv */
#define SUPER_V2 0x2468 /* magic # for V2 file systems */
#define SUPER_V2_REV 0x6824 /* V2 magic written on PC, read on 68K or vv */
#define SUPER_V3 0x4d5a /* magic # for V3 file systems */
#define V1 1 /* version number of V1 file systems */
#define V2 2 /* version number of V2 file systems */
#define V3 3 /* version number of V3 file systems */
/* Miscellaneous constants */ /* Miscellaneous constants */
#define SU_UID ((uid_t) 0) /* super_user's uid_t */ #define INVAL_UID ((uid_t) -1) /* Invalid user ID */
#define SYS_UID ((uid_t) 0) /* uid_t for processes MM and INIT */ #define INVAL_GID ((gid_t) -1) /* Invalid group ID */
#define SYS_GID ((gid_t) 0) /* gid_t for processes MM and INIT */
#define NORMAL 0 /* forces get_block to do disk read */ #define NORMAL 0 /* forces get_block to do disk read */
#define NO_READ 1 /* prevents get_block from doing disk read */ #define NO_READ 1 /* prevents get_block from doing disk read */
#define PREFETCH 2 /* tells get_block not to read or mark dev */ #define PREFETCH 2 /* tells get_block not to read or mark dev */
#define NO_BIT ((bit_t) 0) /* returned by alloc_bit() to signal failure */ #define NO_BIT ((bit_t) 0) /* returned by alloc_bit() to signal failure */
/* write_map() args */
#define WMAP_FREE (1 << 0)
#define IGN_PERM 0
#define CHK_PERM 1
#define CLEAN 0 /* disk and memory copies identical */
#define DIRTY 1 /* disk and memory copies differ */
#define ATIME 002 /* set if atime field needs updating */ #define ATIME 002 /* set if atime field needs updating */
#define CTIME 004 /* set if ctime field needs updating */ #define CTIME 004 /* set if ctime field needs updating */
#define MTIME 010 /* set if mtime field needs updating */ #define MTIME 010 /* set if mtime field needs updating */
#define BYTE_SWAP 0 /* tells conv2/conv4 to swap bytes */
#define END_OF_FILE (-104) /* eof detected */
#define ROOT_INODE 1 /* inode number for root directory */
#define BOOT_BLOCK ((block_t) 0) /* block number of boot block */
#define SUPER_BLOCK_BYTES (1024) /* bytes offset */
#define START_BLOCK 2 /* first block of FS (not counting SB) */
#define DIR_ENTRY_SIZE usizeof (struct direct) /* # bytes/dir entry */
#define NR_DIR_ENTRIES(b) ((b)/DIR_ENTRY_SIZE) /* # dir entries/blk */
#define SUPER_SIZE usizeof (struct super_block) /* super_block size */
#define PIPE_SIZE(b) (V1_NR_DZONES*(b)) /* pipe size in bytes */
#define FS_BITMAP_CHUNKS(b) ((b)/usizeof (bitchunk_t))/* # map chunks/blk */ #define FS_BITMAP_CHUNKS(b) ((b)/usizeof (bitchunk_t))/* # map chunks/blk */
#define FS_BITCHUNK_BITS (usizeof(bitchunk_t) * CHAR_BIT) #define FS_BITCHUNK_BITS (usizeof(bitchunk_t) * CHAR_BIT)
#define FS_BITS_PER_BLOCK(b) (FS_BITMAP_CHUNKS(b) * FS_BITCHUNK_BITS) #define FS_BITS_PER_BLOCK(b) (FS_BITMAP_CHUNKS(b) * FS_BITCHUNK_BITS)
/* Derived sizes pertaining to the V1 file system. */ #endif
#define V1_ZONE_NUM_SIZE usizeof (zone1_t) /* # bytes in V1 zone */
#define V1_INODE_SIZE usizeof (d1_inode) /* bytes in V1 dsk ino */
/* # zones/indir block */
#define V1_INDIRECTS (_STATIC_BLOCK_SIZE/V1_ZONE_NUM_SIZE)
/* # V1 dsk inodes/blk */
#define V1_INODES_PER_BLOCK (_STATIC_BLOCK_SIZE/V1_INODE_SIZE)
/* Derived sizes pertaining to the V2 file system. */
#define V2_ZONE_NUM_SIZE usizeof (zone_t) /* # bytes in V2 zone */
#define V2_INODE_SIZE usizeof (d2_inode) /* bytes in V2 dsk ino */
#define V2_INDIRECTS(b) ((b)/V2_ZONE_NUM_SIZE) /* # zones/indir block */
#define V2_INODES_PER_BLOCK(b) ((b)/V2_INODE_SIZE)/* # V2 dsk inodes/blk */
#define PFS_MIN(a,b) pfs_min_f(__FILE__,__LINE__,(a), (b))
#define PFS_NUL(str,l,m) pfs_nul_f(__FILE__,__LINE__,(str), (l), (m))
/* Args to dev_bio/dev_io */
#define PFS_DEV_READ 10001
#define PFS_DEV_WRITE 10002
#define PFS_DEV_SCATTER 10003
#define PFS_DEV_GATHER 10004

View File

@ -1,9 +0,0 @@
/* Driver endpoints for major devices. Only the block devices
* are mapped here, it's a subset of the mapping in the VFS */
EXTERN struct driver_endpoints {
endpoint_t driver_e;
} driver_endpoints[NR_DEVICES];

View File

@ -1,3 +1,6 @@
#ifndef __PFS_FS_H__
#define __PFS_FS_H__
/* This is the master header for pfs. It includes some other files /* This is the master header for pfs. It includes some other files
* and defines the principal constants. * and defines the principal constants.
*/ */
@ -5,8 +8,6 @@
#define _MINIX 1 /* tell headers to include MINIX stuff */ #define _MINIX 1 /* tell headers to include MINIX stuff */
#define _SYSTEM 1 /* tell headers that this is the kernel */ #define _SYSTEM 1 /* tell headers that this is the kernel */
#define VERBOSE 0 /* show messages during initialization? */
/* The following are so basic, all the *.c files get them automatically. */ /* The following are so basic, all the *.c files get them automatically. */
#include <minix/config.h> /* MUST be first */ #include <minix/config.h> /* MUST be first */
#include <ansi.h> /* MUST be second */ #include <ansi.h> /* MUST be second */
@ -25,3 +26,5 @@
#include "const.h" #include "const.h"
#include "proto.h" #include "proto.h"
#include "glo.h" #include "glo.h"
#endif

View File

@ -1,3 +1,6 @@
#ifndef __PFS_GLO_H__
#define __PFS_GLO_H__
/* EXTERN should be extern except for the table file */ /* EXTERN should be extern except for the table file */
#ifdef _TABLE #ifdef _TABLE
#undef EXTERN #undef EXTERN
@ -9,9 +12,7 @@
/* The following variables are used for returning results to the caller. */ /* The following variables are used for returning results to the caller. */
EXTERN int err_code; /* temporary storage for error number */ EXTERN int err_code; /* temporary storage for error number */
EXTERN int cch[NR_INODES]; EXTERN _PROTOTYPE (int (*fs_call_vec[]), (void) ); /* fs call table */
extern _PROTOTYPE (int (*fs_call_vec[]), (void) ); /* fs call table */
EXTERN message fs_m_in; EXTERN message fs_m_in;
EXTERN message fs_m_out; EXTERN message fs_m_out;
@ -25,3 +26,5 @@ EXTERN int busy;
/* Inode map. */ /* Inode map. */
EXTERN bitchunk_t inodemap[FS_BITMAP_CHUNKS(NR_INODES)]; EXTERN bitchunk_t inodemap[FS_BITMAP_CHUNKS(NR_INODES)];
#endif

View File

@ -19,8 +19,8 @@
#include "inode.h" #include "inode.h"
#include <minix/vfsif.h> #include <minix/vfsif.h>
FORWARD _PROTOTYPE( int addhash_inode, (struct inode *node) ); FORWARD _PROTOTYPE( void addhash_inode, (struct inode * const node) );
FORWARD _PROTOTYPE( int unhash_inode, (struct inode *node) ); FORWARD _PROTOTYPE( void unhash_inode, (struct inode * const node) );
/*===========================================================================* /*===========================================================================*
@ -35,11 +35,11 @@ PUBLIC int fs_putnode()
dev_t dev; dev_t dev;
ino_t inum; ino_t inum;
rip = find_inode(fs_m_in.REQ_INODE_NR); rip = find_inode( (ino_t) fs_m_in.REQ_INODE_NR);
if(!rip) { if(!rip) {
printf("%s:%d put_inode: inode #%d dev: %d not found\n", __FILE__, printf("%s:%d put_inode: inode #%ld dev: %d not found\n", __FILE__,
__LINE__, fs_m_in.REQ_INODE_NR, fs_m_in.REQ_DEV); __LINE__, fs_m_in.REQ_INODE_NR, (dev_t) fs_m_in.REQ_DEV);
panic("fs_putnode failed"); panic("fs_putnode failed");
} }
@ -82,7 +82,7 @@ PUBLIC void init_inode_cache()
/* add free inodes to unused/free list */ /* add free inodes to unused/free list */
for (rip = &inode[0]; rip < &inode[NR_INODES]; ++rip) { for (rip = &inode[0]; rip < &inode[NR_INODES]; ++rip) {
rip->i_num = 0; rip->i_num = NO_ENTRY;
TAILQ_INSERT_HEAD(&unused_inodes, rip, i_unused); TAILQ_INSERT_HEAD(&unused_inodes, rip, i_unused);
} }
@ -95,24 +95,22 @@ PUBLIC void init_inode_cache()
/*===========================================================================* /*===========================================================================*
* addhash_inode * * addhash_inode *
*===========================================================================*/ *===========================================================================*/
PRIVATE int addhash_inode(struct inode *node) PRIVATE void addhash_inode(struct inode * const node)
{ {
int hashi = node->i_num & INODE_HASH_MASK; int hashi = (int) (node->i_num & INODE_HASH_MASK);
/* insert into hash table */ /* insert into hash table */
LIST_INSERT_HEAD(&hash_inodes[hashi], node, i_hash); LIST_INSERT_HEAD(&hash_inodes[hashi], node, i_hash);
return(OK);
} }
/*===========================================================================* /*===========================================================================*
* unhash_inode * * unhash_inode *
*===========================================================================*/ *===========================================================================*/
PRIVATE int unhash_inode(struct inode *node) PRIVATE void unhash_inode(struct inode * const node)
{ {
/* remove from hash table */ /* remove from hash table */
LIST_REMOVE(node, i_hash); LIST_REMOVE(node, i_hash);
return(OK);
} }
@ -121,7 +119,7 @@ PRIVATE int unhash_inode(struct inode *node)
*===========================================================================*/ *===========================================================================*/
PUBLIC struct inode *get_inode( PUBLIC struct inode *get_inode(
dev_t dev, /* device on which inode resides */ dev_t dev, /* device on which inode resides */
int numb /* inode number (ANSI: may not be unshort) */ ino_t numb /* inode number */
) )
{ {
/* Find the inode in the hash table. If it is not there, get a free inode /* Find the inode in the hash table. If it is not there, get a free inode
@ -130,7 +128,7 @@ PUBLIC struct inode *get_inode(
register struct inode *rip; register struct inode *rip;
int hashi; int hashi;
hashi = numb & INODE_HASH_MASK; hashi = (int) (numb & INODE_HASH_MASK);
/* Search inode in the hash table */ /* Search inode in the hash table */
LIST_FOREACH(rip, &hash_inodes[hashi], i_hash) { LIST_FOREACH(rip, &hash_inodes[hashi], i_hash) {
@ -153,7 +151,7 @@ PUBLIC struct inode *get_inode(
rip = TAILQ_FIRST(&unused_inodes); rip = TAILQ_FIRST(&unused_inodes);
/* If not free unhash it */ /* If not free unhash it */
if (rip->i_num != 0) unhash_inode(rip); if (rip->i_num != NO_ENTRY) unhash_inode(rip);
/* Inode is not unused any more */ /* Inode is not unused any more */
TAILQ_REMOVE(&unused_inodes, rip, i_unused); TAILQ_REMOVE(&unused_inodes, rip, i_unused);
@ -176,14 +174,14 @@ PUBLIC struct inode *get_inode(
* find_inode * * find_inode *
*===========================================================================*/ *===========================================================================*/
PUBLIC struct inode *find_inode(numb) PUBLIC struct inode *find_inode(numb)
int numb; /* inode number (ANSI: may not be unshort) */ ino_t numb; /* inode number */
{ {
/* Find the inode specified by the inode and device number. /* Find the inode specified by the inode and device number.
*/ */
struct inode *rip; struct inode *rip;
int hashi; int hashi;
hashi = numb & INODE_HASH_MASK; hashi = (int) (numb & INODE_HASH_MASK);
/* Search inode in the hash table */ /* Search inode in the hash table */
LIST_FOREACH(rip, &hash_inodes[hashi], i_hash) { LIST_FOREACH(rip, &hash_inodes[hashi], i_hash) {
@ -200,7 +198,7 @@ int numb; /* inode number (ANSI: may not be unshort) */
* put_inode * * put_inode *
*===========================================================================*/ *===========================================================================*/
PUBLIC void put_inode(rip) PUBLIC void put_inode(rip)
register struct inode *rip; /* pointer to inode to be released */ struct inode *rip; /* pointer to inode to be released */
{ {
/* The caller is no longer using this inode. If no one else is using it either /* The caller is no longer using this inode. If no one else is using it either
* write it back to the disk immediately. If it has no links, truncate it and * write it back to the disk immediately. If it has no links, truncate it and
@ -213,19 +211,19 @@ register struct inode *rip; /* pointer to inode to be released */
panic("put_inode: i_count already below 1: %d", rip->i_count); panic("put_inode: i_count already below 1: %d", rip->i_count);
if (--rip->i_count == 0) { /* i_count == 0 means no one is using it now */ if (--rip->i_count == 0) { /* i_count == 0 means no one is using it now */
if (rip->i_nlinks == 0) { if (rip->i_nlinks == NO_LINK) { /* Are there links to this file? */
/* i_nlinks == 0 means free the inode. */ /* no links, free the inode. */
truncate_inode(rip, 0); /* return all the disk blocks */ truncate_inode(rip, 0); /* return all the disk blocks */
rip->i_mode = I_NOT_ALLOC; /* clear I_TYPE field */ rip->i_mode = I_NOT_ALLOC; /* clear I_TYPE field */
free_inode(rip); free_inode(rip);
} else { } else {
truncate_inode(rip, 0); truncate_inode(rip, (off_t) 0);
} }
if (rip->i_nlinks == 0) { if (rip->i_nlinks == NO_LINK) {
/* free, put at the front of the LRU list */ /* free, put at the front of the LRU list */
unhash_inode(rip); unhash_inode(rip);
rip->i_num = 0; rip->i_num = NO_ENTRY;
rip->i_dev = NO_DEV; rip->i_dev = NO_DEV;
rip->i_rdev = NO_DEV; rip->i_rdev = NO_DEV;
TAILQ_INSERT_HEAD(&unused_inodes, rip, i_unused); TAILQ_INSERT_HEAD(&unused_inodes, rip, i_unused);
@ -265,7 +263,7 @@ PUBLIC struct inode *alloc_inode(dev_t dev, mode_t bits)
/* An inode slot is available. */ /* An inode slot is available. */
rip->i_mode = bits; /* set up RWX bits */ rip->i_mode = bits; /* set up RWX bits */
rip->i_nlinks = 0; /* initial no links */ rip->i_nlinks = NO_LINK; /* initial no links */
rip->i_uid = caller_uid; /* file's uid is owner's */ rip->i_uid = caller_uid; /* file's uid is owner's */
rip->i_gid = caller_gid; /* ditto group id */ rip->i_gid = caller_gid; /* ditto group id */
@ -285,7 +283,7 @@ PUBLIC struct inode *alloc_inode(dev_t dev, mode_t bits)
* wipe_inode * * wipe_inode *
*===========================================================================*/ *===========================================================================*/
PUBLIC void wipe_inode(rip) PUBLIC void wipe_inode(rip)
register struct inode *rip; /* the inode to be erased */ struct inode *rip; /* the inode to be erased */
{ {
/* Erase some fields in the inode. This function is called from alloc_inode() /* Erase some fields in the inode. This function is called from alloc_inode()
* when a new inode is to be allocated, and from truncate(), when an existing * when a new inode is to be allocated, and from truncate(), when an existing
@ -307,8 +305,8 @@ struct inode *rip;
bit_t b; bit_t b;
if (rip->i_num <= 0 || rip->i_num >= NR_INODES) return; if (rip->i_num <= (ino_t) 0 || rip->i_num >= (ino_t) NR_INODES) return;
b = rip->i_num; b = (bit_t) rip->i_num;
free_bit(b); free_bit(b);
} }
@ -317,7 +315,7 @@ struct inode *rip;
* update_times * * update_times *
*===========================================================================*/ *===========================================================================*/
PUBLIC void update_times(rip) PUBLIC void update_times(rip)
register struct inode *rip; /* pointer to inode to be read/written */ struct inode *rip; /* pointer to inode to be read/written */
{ {
/* Various system calls are required by the standard to update atime, ctime, /* Various system calls are required by the standard to update atime, ctime,
* or mtime. Since updating a time requires sending a message to the clock * or mtime. Since updating a time requires sending a message to the clock

View File

@ -1,3 +1,6 @@
#ifndef __PFS_INODE_H__
#define __PFS_INODE_H__
/* Inode table. This table holds inodes that are currently in use. /* Inode table. This table holds inodes that are currently in use.
*/ */
@ -33,3 +36,4 @@ EXTERN TAILQ_HEAD(unused_inodes_t, inode) unused_inodes;
EXTERN LIST_HEAD(inodelist, inode) hash_inodes[INODE_HASH_SIZE]; EXTERN LIST_HEAD(inodelist, inode) hash_inodes[INODE_HASH_SIZE];
#endif

View File

@ -1,5 +1,4 @@
#include "fs.h" #include "fs.h"
#include <string.h>
#include "buf.h" #include "buf.h"
#include "inode.h" #include "inode.h"
#include <minix/vfsif.h> #include <minix/vfsif.h>
@ -13,7 +12,7 @@ PUBLIC int fs_ftrunc(void)
off_t start, end; off_t start, end;
ino_t inumb; ino_t inumb;
inumb = fs_m_in.REQ_INODE_NR; inumb = (ino_t) fs_m_in.REQ_INODE_NR;
if( (rip = find_inode(inumb)) == NULL) return(EINVAL); if( (rip = find_inode(inumb)) == NULL) return(EINVAL);

View File

@ -6,7 +6,6 @@
#include <minix/vfsif.h> #include <minix/vfsif.h>
#include "buf.h" #include "buf.h"
#include "inode.h" #include "inode.h"
#include "drivers.h"
FORWARD _PROTOTYPE(void get_work, (message *m_in) ); FORWARD _PROTOTYPE(void get_work, (message *m_in) );
@ -38,19 +37,19 @@ PUBLIC int main(int argc, char *argv[])
src = fs_m_in.m_source; src = fs_m_in.m_source;
error = OK; error = OK;
caller_uid = -1; /* To trap errors */ caller_uid = INVAL_UID; /* To trap errors */
caller_gid = -1; caller_gid = INVAL_GID;
req_nr = fs_m_in.m_type; req_nr = fs_m_in.m_type;
if (req_nr < VFS_BASE) { if (req_nr < VFS_BASE) {
fs_m_in.m_type += VFS_BASE; fs_m_in.m_type += VFS_BASE;
req_nr = fs_m_in.m_type; req_nr = fs_m_in.m_type;
printf("PFS: bad request (no VFS_BASE) %d\n", req_nr);
} }
ind = req_nr - VFS_BASE; ind = req_nr - VFS_BASE;
if (ind < 0 || ind >= NREQS) { if (ind < 0 || ind >= NREQS) {
printf("pfs: bad request %d\n", req_nr); printf("pfs: bad request %d\n", req_nr);
printf("ind = %d\n", ind);
error = EINVAL; error = EINVAL;
} else { } else {
error = (*fs_call_vec[ind])(); error = (*fs_call_vec[ind])();
@ -96,15 +95,10 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
/* Init inode table */ /* Init inode table */
for (i = 0; i < NR_INODES; ++i) { for (i = 0; i < NR_INODES; ++i) {
inode[i].i_count = 0; inode[i].i_count = 0;
cch[i] = 0;
} }
init_inode_cache(); init_inode_cache();
/* Init driver mapping */
for (i = 0; i < NR_DEVICES; ++i)
driver_endpoints[i].driver_e = NONE;
SELF_E = getprocnr(); SELF_E = getprocnr();
buf_pool(); buf_pool();
@ -148,7 +142,7 @@ message *m_in; /* pointer to message */
* reply * * reply *
*===========================================================================*/ *===========================================================================*/
PUBLIC void reply(who, m_out) PUBLIC void reply(who, m_out)
int who; endpoint_t who;
message *m_out; /* report result */ message *m_out; /* report result */
{ {
if (OK != send(who, m_out)) /* send the message */ if (OK != send(who, m_out)) /* send the message */

View File

@ -1,8 +1,4 @@
#include "fs.h" #include "fs.h"
#include <fcntl.h>
#include <minix/vfsif.h>
#include "buf.h"
#include "inode.h"
/*===========================================================================* /*===========================================================================*

View File

@ -1,8 +1,5 @@
#include "fs.h" #include "fs.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <minix/callnr.h>
#include <minix/com.h>
#include "buf.h" #include "buf.h"
#include "inode.h" #include "inode.h"
#include <minix/vfsif.h> #include <minix/vfsif.h>
@ -18,10 +15,10 @@ PUBLIC int fs_newnode()
struct inode *rip; struct inode *rip;
dev_t dev; dev_t dev;
caller_uid = fs_m_in.REQ_UID; caller_uid = (uid_t) fs_m_in.REQ_UID;
caller_gid = fs_m_in.REQ_GID; caller_gid = (gid_t) fs_m_in.REQ_GID;
bits = fs_m_in.REQ_MODE; bits = (mode_t) fs_m_in.REQ_MODE;
dev = fs_m_in.REQ_DEV; dev = (dev_t) fs_m_in.REQ_DEV;
/* Try to allocate the inode */ /* Try to allocate the inode */
if( (rip = alloc_inode(dev, bits) ) == NULL) return(err_code); if( (rip = alloc_inode(dev, bits) ) == NULL) return(err_code);

View File

@ -1,13 +1,14 @@
#ifndef __PFS_PROTO_H__
#define __PFS_PROTO_H__
/* Function prototypes. */ /* Function prototypes. */
/* Structs used in prototypes must be declared as such first. */ /* Structs used in prototypes must be declared as such first. */
struct buf; struct buf;
struct filp;
struct inode; struct inode;
/* buffer.c */ /* buffer.c */
_PROTOTYPE( struct buf *get_block, (dev_t dev, ino_t inum) ); _PROTOTYPE( struct buf *get_block, (dev_t dev, ino_t inum) );
_PROTOTYPE( struct buf *new_block, (dev_t dev, ino_t inum) );
_PROTOTYPE( void put_block, (dev_t dev, ino_t inum) ); _PROTOTYPE( void put_block, (dev_t dev, ino_t inum) );
/* cache.c */ /* cache.c */
@ -16,11 +17,11 @@ _PROTOTYPE( void buf_pool, (void) );
/* inode.c */ /* inode.c */
_PROTOTYPE( struct inode *alloc_inode, (dev_t dev, mode_t mode) ); _PROTOTYPE( struct inode *alloc_inode, (dev_t dev, mode_t mode) );
_PROTOTYPE( void dup_inode, (struct inode *ip) ); _PROTOTYPE( void dup_inode, (struct inode *ip) );
_PROTOTYPE( struct inode *find_inode, (int numb) ); _PROTOTYPE( struct inode *find_inode, (ino_t numb) );
_PROTOTYPE( void free_inode, (struct inode *rip) ); _PROTOTYPE( void free_inode, (struct inode *rip) );
_PROTOTYPE( int fs_putnode, (void) ); _PROTOTYPE( int fs_putnode, (void) );
_PROTOTYPE( void init_inode_cache, (void) ); _PROTOTYPE( void init_inode_cache, (void) );
_PROTOTYPE( struct inode *get_inode, (dev_t dev, int numb) ); _PROTOTYPE( struct inode *get_inode, (dev_t dev, ino_t numb) );
_PROTOTYPE( void put_inode, (struct inode *rip) ); _PROTOTYPE( void put_inode, (struct inode *rip) );
_PROTOTYPE( void update_times, (struct inode *rip) ); _PROTOTYPE( void update_times, (struct inode *rip) );
_PROTOTYPE( void wipe_inode, (struct inode *rip) ); _PROTOTYPE( void wipe_inode, (struct inode *rip) );
@ -31,7 +32,7 @@ _PROTOTYPE( int truncate_inode, (struct inode *rip, off_t newsize) );
/* main.c */ /* main.c */
_PROTOTYPE( void reply, (int who, message *m_out) ); _PROTOTYPE( void reply, (endpoint_t who, message *m_out) );
/* misc.c */ /* misc.c */
_PROTOTYPE( int fs_sync, (void) ); _PROTOTYPE( int fs_sync, (void) );
@ -41,8 +42,6 @@ _PROTOTYPE( int fs_newnode, (void) );
/* read.c */ /* read.c */
_PROTOTYPE( int fs_readwrite, (void) ); _PROTOTYPE( int fs_readwrite, (void) );
_PROTOTYPE( block_t read_map, (struct inode *rip, off_t pos) );
_PROTOTYPE( int read_write, (int rw_flag) );
/* utility.c */ /* utility.c */
_PROTOTYPE( time_t clock_time, (void) ); _PROTOTYPE( time_t clock_time, (void) );
@ -54,3 +53,5 @@ _PROTOTYPE( int fs_stat, (void) );
/* super.c */ /* super.c */
_PROTOTYPE( bit_t alloc_bit, (void) ); _PROTOTYPE( bit_t alloc_bit, (void) );
_PROTOTYPE( void free_bit, (bit_t bit_returned) ); _PROTOTYPE( void free_bit, (bit_t bit_returned) );
#endif

View File

@ -1,8 +1,6 @@
#include "fs.h" #include "fs.h"
#include "buf.h" #include "buf.h"
#include <minix/com.h> #include <minix/com.h>
#include <string.h>
#include <minix/u64.h>
#include "inode.h" #include "inode.h"
@ -22,8 +20,7 @@ PUBLIC int fs_readwrite(void)
r = OK; r = OK;
cum_io = 0; cum_io = 0;
inumb = fs_m_in.REQ_INODE_NR; inumb = (ino_t) fs_m_in.REQ_INODE_NR;
rw_flag = (fs_m_in.m_type == REQ_READ ? READING : WRITING);
/* Find the inode referred */ /* Find the inode referred */
if ((rip = find_inode(inumb)) == NULL) return(EINVAL); if ((rip = find_inode(inumb)) == NULL) return(EINVAL);
@ -34,13 +31,18 @@ PUBLIC int fs_readwrite(void)
/* Get the values from the request message */ /* Get the values from the request message */
rw_flag = (fs_m_in.m_type == REQ_READ ? READING : WRITING); rw_flag = (fs_m_in.m_type == REQ_READ ? READING : WRITING);
gid = fs_m_in.REQ_GRANT; gid = (cp_grant_id_t) fs_m_in.REQ_GRANT;
position = fs_m_in.REQ_SEEK_POS_LO; position = fs_m_in.REQ_SEEK_POS_LO;
nrbytes = (unsigned) fs_m_in.REQ_NBYTES; nrbytes = (unsigned) fs_m_in.REQ_NBYTES;
/* We can't read beyond the max file position */
if (nrbytes > MAX_FILE_POS) return(EFBIG);
if (rw_flag == WRITING) { if (rw_flag == WRITING) {
/* Check in advance to see if file will grow too big. */ /* Check in advance to see if file will grow too big. */
if (position > PIPE_BUF - nrbytes) return(EFBIG); /* Casting nrbytes to signed is safe, because it's guaranteed not to
be beyond max signed value (i.e., MAX_FILE_POS). */
if (position > PIPE_BUF - (signed) nrbytes) return(EFBIG);
} }
/* Mark inode in use */ /* Mark inode in use */
@ -49,16 +51,16 @@ PUBLIC int fs_readwrite(void)
if (rw_flag == READING) { if (rw_flag == READING) {
/* Copy a chunk from the block buffer to user space. */ /* Copy a chunk from the block buffer to user space. */
r = sys_safecopyto(FS_PROC_NR, gid, 0, r = sys_safecopyto(FS_PROC_NR, gid, (vir_bytes) 0,
(vir_bytes) (bp->b_data+position), (phys_bytes) nrbytes, D); (vir_bytes) (bp->b_data+position), (size_t) nrbytes, D);
} else { } else {
/* Copy a chunk from user space to the block buffer. */ /* Copy a chunk from user space to the block buffer. */
r = sys_safecopyfrom(FS_PROC_NR, gid, 0, r = sys_safecopyfrom(FS_PROC_NR, gid, (vir_bytes) 0,
(vir_bytes) (bp->b_data+position), (phys_bytes) nrbytes, D); (vir_bytes) (bp->b_data+position), (size_t) nrbytes, D);
} }
if (r == OK) { if (r == OK) {
position += nrbytes; /* Update position */ position += (signed) nrbytes; /* Update position */
cum_io += nrbytes; cum_io += nrbytes;
} }
@ -79,7 +81,7 @@ PUBLIC int fs_readwrite(void)
bp->b_bytes = position; bp->b_bytes = position;
if (rw_flag == READING) rip->i_update |= ATIME; if (rw_flag == READING) rip->i_update |= ATIME;
if (rw_flag == WRITING) rip->i_update |= CTIME | MTIME; if (rw_flag == WRITING) rip->i_update |= CTIME | MTIME;
fs_m_out.RES_NBYTES = cum_io; fs_m_out.RES_NBYTES = (size_t) cum_io;
put_inode(rip); put_inode(rip);
put_block(rip->i_dev, rip->i_num); put_block(rip->i_dev, rip->i_num);

View File

@ -28,7 +28,7 @@ PRIVATE int stat_inode(
statbuf.st_mode = rip->i_mode; statbuf.st_mode = rip->i_mode;
statbuf.st_nlink = rip->i_nlinks; statbuf.st_nlink = rip->i_nlinks;
statbuf.st_uid = rip->i_uid; statbuf.st_uid = rip->i_uid;
statbuf.st_gid = rip->i_gid; statbuf.st_gid = (short int) rip->i_gid;
statbuf.st_rdev = (dev_t) (s ? rip->i_rdev : NO_DEV); statbuf.st_rdev = (dev_t) (s ? rip->i_rdev : NO_DEV);
statbuf.st_size = rip->i_size; statbuf.st_size = rip->i_size;
if (!s) statbuf.st_mode &= ~I_REGULAR;/* wipe out I_REGULAR bit for pipes */ if (!s) statbuf.st_mode &= ~I_REGULAR;/* wipe out I_REGULAR bit for pipes */
@ -37,8 +37,8 @@ PRIVATE int stat_inode(
statbuf.st_ctime = rip->i_ctime; statbuf.st_ctime = rip->i_ctime;
/* Copy the struct to user space. */ /* Copy the struct to user space. */
r = sys_safecopyto(who_e, gid, 0, (vir_bytes) &statbuf, r = sys_safecopyto(who_e, gid, (vir_bytes) 0, (vir_bytes) &statbuf,
(phys_bytes) sizeof(statbuf), D); (size_t) sizeof(statbuf), D);
return(r); return(r);
} }
@ -54,7 +54,7 @@ PUBLIC int fs_stat()
if( (rip = find_inode(fs_m_in.REQ_INODE_NR)) == NULL) return(EINVAL); if( (rip = find_inode(fs_m_in.REQ_INODE_NR)) == NULL) return(EINVAL);
get_inode(rip->i_dev, rip->i_num); /* mark inode in use */ get_inode(rip->i_dev, rip->i_num); /* mark inode in use */
r = stat_inode(rip, fs_m_in.m_source, fs_m_in.REQ_GRANT); r = stat_inode(rip, fs_m_in.m_source, (cp_grant_id_t) fs_m_in.REQ_GRANT);
put_inode(rip); /* release the inode */ put_inode(rip); /* release the inode */
return(r); return(r);
} }

View File

@ -9,9 +9,6 @@
*/ */
#include "fs.h" #include "fs.h"
#include <string.h>
#include <minix/com.h>
#include <minix/u64.h>
#include "buf.h" #include "buf.h"
#include "inode.h" #include "inode.h"
#include "const.h" #include "const.h"
@ -25,7 +22,7 @@ PUBLIC bit_t alloc_bit(void)
/* Allocate a bit from a bit map and return its bit number. */ /* Allocate a bit from a bit map and return its bit number. */
bitchunk_t *wptr, *wlim; bitchunk_t *wptr, *wlim;
bit_t b; bit_t b;
int i, bcount; unsigned int i, bcount;
bcount = FS_BITMAP_CHUNKS(NR_INODES); /* Inode map has this many chunks. */ bcount = FS_BITMAP_CHUNKS(NR_INODES); /* Inode map has this many chunks. */
wlim = &inodemap[bcount]; /* Point to last chunk in inodemap. */ wlim = &inodemap[bcount]; /* Point to last chunk in inodemap. */
@ -38,7 +35,7 @@ PUBLIC bit_t alloc_bit(void)
for (i = 0; (*wptr & (1 << i)) != 0; ++i) {} for (i = 0; (*wptr & (1 << i)) != 0; ++i) {}
/* Get inode number */ /* Get inode number */
b = (wptr - &inodemap[0]) * FS_BITCHUNK_BITS + i; b = (bit_t) ((wptr - &inodemap[0]) * FS_BITCHUNK_BITS + i);
/* Don't allocate bits beyond end of map. */ /* Don't allocate bits beyond end of map. */
if (b >= NR_INODES) break; if (b >= NR_INODES) break;
@ -66,12 +63,12 @@ bit_t bit_returned; /* number of bit to insert into the inode map*/
unsigned word; unsigned word;
/* Get word offset and bit within offset */ /* Get word offset and bit within offset */
word = bit_returned / FS_BITCHUNK_BITS; word = (unsigned) (bit_returned / (bit_t) FS_BITCHUNK_BITS);
bit = bit_returned % FS_BITCHUNK_BITS; bit = bit_returned % (bit_t) FS_BITCHUNK_BITS;
/* Unset bit */ /* Unset bit */
k = &inodemap[word]; k = &inodemap[word];
mask = 1 << bit; mask = (unsigned) 1 << bit;
*k &= ~mask; *k &= ~mask;
busy--; /* One inode less in use. */ busy--; /* One inode less in use. */

View File

@ -6,11 +6,8 @@
#define _TABLE #define _TABLE
#include "fs.h" #include "fs.h"
#include <minix/callnr.h>
#include <minix/com.h>
#include "inode.h" #include "inode.h"
#include "buf.h" #include "buf.h"
#include "drivers.h"
PUBLIC _PROTOTYPE (int (*fs_call_vec[]), (void) ) = { PUBLIC _PROTOTYPE (int (*fs_call_vec[]), (void) ) = {
no_sys, /* 0 not used */ no_sys, /* 0 not used */

View File

@ -23,9 +23,10 @@ PUBLIC time_t clock_time()
*/ */
int r; int r;
clock_t uptime, boottime; clock_t uptime; /* Uptime in ticks */
time_t boottime;
if ((r = getuptime2(&uptime,&boottime)) != OK) if ((r = getuptime2(&uptime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", r); panic("clock_time: getuptme2 failed: %d", r);
return( (time_t) (boottime + (uptime/sys_hz()))); return( (time_t) (boottime + (uptime/sys_hz())));