#include "../../servers/mfs/super.h"
_PROTOTYPE(int main, (int argc, char **argv));
-_PROTOTYPE(void rw_super, (int flag));
_PROTOTYPE(void get_super, (void));
-_PROTOTYPE(void put_super, (void));
_PROTOTYPE(void rw_inode, (struct stat * stat_ptr, int rw_mode));
_PROTOTYPE(void get_inode, (struct stat * stat_ptr));
_PROTOTYPE(void put_inode, (struct stat * stat_ptr));
#define V_SMALLER V1_NR_DZONES
#endif
-#if 0
-struct super_block {
- ino_t s_ninodes; /* # usable inodes on the minor device */
- zone1_t s_nzones; /* total device size, including bit maps etc */
- short s_imap_blocks; /* # of blocks used by inode bit map */
- short s_zmap_blocks; /* # of blocks used by zone bit map */
- zone1_t s_firstdatazone; /* number of first data zone */
- short s_log_zone_size; /* log2 of blocks/zone */
- off_t s_max_size; /* maximum file size on this device */
- short s_magic; /* magic number to recognize super-blocks */
- short s_pad; /* try to avoid compiler-dependent padding */
- zone_t s_zones; /* number of zones (replaces s_nzones in V2) */
-} super_block;
-#endif
/* ====== globals ======= */
/* ====== super block routines ======= */
-void rw_super(flag)
-int flag;
-{ /* read or write a superblock */
- int rwd;
+void get_super()
+ /* Get super_block. global pointer sp is used */
+{
+ int rd;
- lseek(fd, 0L, SEEK_SET); /* rewind */
lseek(fd, (long) BLOCK_SIZE, SEEK_SET); /* seek */
- if (flag == READ)
- rwd = read(fd, (char *) sp, SUPER_SIZE);
- else
- rwd = write(fd, (char *) sp, SUPER_SIZE);
- if (rwd != SUPER_SIZE) { /* ok ? */
- printf("Bad %s in get_super() (should be %u is %d)\n",
- flag == READ ? "read" : "write",
- (unsigned) SUPER_SIZE, rwd);
+ rd = read(fd, (char *) sp, SUPER_SIZE);
+ if (rd != SUPER_SIZE) { /* ok ? */
+ printf("Bad read in get_super() (should be %u is %d)\n",
+ (unsigned) SUPER_SIZE, rd);
done(DIR_CREATED);
}
-}
-
-void get_super()
- /* Get super_block. global pointer sp is used */
-{
- rw_super(READ);
if (sp->s_magic == SUPER_MAGIC) {
/* This is a V1 file system. */
}
-void put_super()
-{
- rw_super(WRITE);
-}
-
/* ========== inode routines =========== */
void rw_inode(stat_ptr, rw_mode)
offset = (block_t) ((i_num - 1) % inodes_per_block);
offset *= (block_t) (inode_size); /* and this offset */
- lseek(fd, (off_t) 0, SEEK_SET); /* rewind */
lseek(fd, (off_t) (blk + offset), SEEK_SET); /* seek */
/* Pointer is at the inode */
}
put_inode(&stat_buf); /* save the inode on disk */
- put_super(); /* bit_maps too */
}
blk_offset += (block_t) (words * SIZE_OF_INT); /* offset */
- lseek(fd, (off_t) 0, SEEK_SET); /* rewind */
lseek(fd, (off_t) blk_offset, SEEK_SET); /* set pointer at word */
rd = read(fd, (char *) &tst_word, SIZE_OF_INT);
blk_offset += (long) (words * SIZE_OF_INT);
- lseek(fd, (off_t) 0, SEEK_SET); /* rewind */
lseek(fd, (off_t) blk_offset, SEEK_SET);
rwd = read(fd, (char *) &tst_word, SIZE_OF_INT);
}
bit = offset % INT_BITS;
if (((tst_word >> bit) & 01) == 0) { /* free */
- lseek(fd, 0L, SEEK_SET);/* rewind */
lseek(fd, (off_t) blk_offset, SEEK_SET);
tst_word |= (1 << bit); /* not free anymore */
rwd = write(fd, (char *) &tst_word, SIZE_OF_INT);
/* Authors: Andy Tanenbaum, Paul Ogilvie, Frans Meulenbroeks, Bruce Evans
*
- * This program can make both version 1 and version 2 file systems, as follows:
- * mkfs /dev/fd0 1200 # Version 2 (default)
+ * This program can make version 1, 2 and 3 file systems, as follows:
+ * mkfs /dev/fd0 1200 # Version 3 (default)
* mkfs -1 /dev/fd0 360 # Version 1
*
+ * Note that the version 1 and 2 file systems produced by this program are not
+ * compatible with the original version 1 and 2 file system layout.
*/
#include <sys/types.h>
default: usage();
}
+ if (argc == optind) usage();
+
if(fs_version == 3) {
if(!block_size) block_size = _MAX_BLOCK_SIZE; /* V3 default block size */
if(block_size%SECTOR_SIZE || block_size < _MIN_BLOCK_SIZE) {
int inodeblks;
int initblks;
u32_t nb;
-
- zone_t initzones, nrzones, v1sq, v2sq;
+ zone_t v1sq, v2sq;
zone_t zo;
struct super_block *sup;
char *buf, *cp;
sup->s_ninodes = inodes;
if (fs_version == 1) {
sup->s_nzones = zones;
+ if (sup->s_nzones != zones) pexit("too many zones");
} else {
sup->s_nzones = 0; /* not used in V2 - 0 forces errors early */
sup->s_zones = zones;
inode_offset = sup->s_imap_blocks + sup->s_zmap_blocks + 2;
inodeblks = (inodes + inodes_per_block - 1) / inodes_per_block;
initblks = inode_offset + inodeblks;
- initzones = (initblks + (1 << zone_shift) - 1) >> zone_shift;
- nrzones = nrblocks >> zone_shift;
sup->s_firstdatazone = nb = (initblks + (1 << zone_shift) - 1) >> zone_shift;
+ if(nb >= zones) pexit("bit maps too large");
if(nb != sup->s_firstdatazone) {
fprintf(stderr, "mkfs: too much bitmap and inode data.\n" BIGGERBLOCKS);
exit(1);