2005-04-21 16:53:53 +02:00
|
|
|
/* This file is the counterpart of "read.c". It contains the code for writing
|
2010-02-09 09:12:37 +01:00
|
|
|
* insofar as this is not contained in fs_readwrite().
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* The entry points into this file are
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
* write_map: write a new zone into an inode
|
2005-04-21 16:53:53 +02:00
|
|
|
* clear_zone: erase a zone in the middle of a file
|
|
|
|
* new_block: acquire a new block
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
* zero_block: overwrite a block with zeroes
|
2008-02-06 16:05:57 +01:00
|
|
|
*
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <string.h>
|
2013-03-16 03:29:32 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/param.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "buf.h"
|
|
|
|
#include "inode.h"
|
|
|
|
#include "super.h"
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void wr_indir(struct buf *bp, int index, zone_t zone);
|
|
|
|
static int empty_indir(struct buf *, struct super_block *);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* write_map *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int write_map(rip, position, new_zone, op)
|
2006-01-11 18:14:51 +01:00
|
|
|
struct inode *rip; /* pointer to inode to be changed */
|
2005-04-21 16:53:53 +02:00
|
|
|
off_t position; /* file address to be mapped */
|
|
|
|
zone_t new_zone; /* zone # to be inserted */
|
2006-01-11 18:14:51 +01:00
|
|
|
int op; /* special actions */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2006-01-11 18:14:51 +01:00
|
|
|
/* Write a new zone into an inode.
|
|
|
|
*
|
|
|
|
* If op includes WMAP_FREE, free the data zone corresponding to that position
|
|
|
|
* in the inode ('new_zone' is ignored then). Also free the indirect block
|
|
|
|
* if that was the last entry in the indirect block.
|
|
|
|
* Also free the double indirect block if that was the last entry in the
|
|
|
|
* double indirect block.
|
|
|
|
*/
|
2006-10-25 15:40:36 +02:00
|
|
|
int scale, ind_ex = 0, new_ind, new_dbl,
|
|
|
|
zones, nr_indirects, single, zindex, ex;
|
2006-01-11 18:14:51 +01:00
|
|
|
zone_t z, z1, z2 = NO_ZONE, old_zone;
|
2005-04-21 16:53:53 +02:00
|
|
|
register block_t b;
|
|
|
|
long excess, zone;
|
2010-05-10 15:26:00 +02:00
|
|
|
struct buf *bp_dindir = NULL, *bp = NULL;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-12-22 01:29:27 +01:00
|
|
|
IN_MARKDIRTY(rip);
|
2005-04-21 16:53:53 +02:00
|
|
|
scale = rip->i_sp->s_log_zone_size; /* for zone-block conversion */
|
2005-08-29 18:47:18 +02:00
|
|
|
/* relative zone # to insert */
|
|
|
|
zone = (position/rip->i_sp->s_block_size) >> scale;
|
2005-04-21 16:53:53 +02:00
|
|
|
zones = rip->i_ndzones; /* # direct zones in the inode */
|
|
|
|
nr_indirects = rip->i_nindirs;/* # indirect zones per indirect block */
|
|
|
|
|
|
|
|
/* Is 'position' to be found in the inode itself? */
|
|
|
|
if (zone < zones) {
|
|
|
|
zindex = (int) zone; /* we need an integer here */
|
2006-01-11 18:14:51 +01:00
|
|
|
if(rip->i_zone[zindex] != NO_ZONE && (op & WMAP_FREE)) {
|
|
|
|
free_zone(rip->i_dev, rip->i_zone[zindex]);
|
|
|
|
rip->i_zone[zindex] = NO_ZONE;
|
|
|
|
} else {
|
|
|
|
rip->i_zone[zindex] = new_zone;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It is not in the inode, so it must be single or double indirect. */
|
|
|
|
excess = zone - zones; /* first Vx_NR_DZONES don't count */
|
|
|
|
new_ind = FALSE;
|
|
|
|
new_dbl = FALSE;
|
|
|
|
|
|
|
|
if (excess < nr_indirects) {
|
|
|
|
/* 'position' can be located via the single indirect block. */
|
|
|
|
z1 = rip->i_zone[zones]; /* single indirect zone */
|
|
|
|
single = TRUE;
|
|
|
|
} else {
|
|
|
|
/* 'position' can be located via the double indirect block. */
|
2006-01-11 18:14:51 +01:00
|
|
|
if ( (z2 = z = rip->i_zone[zones+1]) == NO_ZONE &&
|
|
|
|
!(op & WMAP_FREE)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Create the double indirect block. */
|
|
|
|
if ( (z = alloc_zone(rip->i_dev, rip->i_zone[0])) == NO_ZONE)
|
|
|
|
return(err_code);
|
|
|
|
rip->i_zone[zones+1] = z;
|
|
|
|
new_dbl = TRUE; /* set flag for later */
|
|
|
|
}
|
|
|
|
|
2006-01-11 18:14:51 +01:00
|
|
|
/* 'z' is zone number for double indirect block, either old
|
|
|
|
* or newly created.
|
|
|
|
* If there wasn't one and WMAP_FREE is set, 'z' is NO_ZONE.
|
|
|
|
*/
|
2005-04-21 16:53:53 +02:00
|
|
|
excess -= nr_indirects; /* single indirect doesn't count */
|
|
|
|
ind_ex = (int) (excess / nr_indirects);
|
|
|
|
excess = excess % nr_indirects;
|
|
|
|
if (ind_ex >= nr_indirects) return(EFBIG);
|
2006-01-11 18:14:51 +01:00
|
|
|
|
2011-08-10 22:46:33 +02:00
|
|
|
if(z == NO_ZONE && (op & WMAP_FREE)) {
|
2006-01-11 18:14:51 +01:00
|
|
|
/* WMAP_FREE and no double indirect block - then no
|
|
|
|
* single indirect block either.
|
|
|
|
*/
|
|
|
|
z1 = NO_ZONE;
|
|
|
|
} else {
|
|
|
|
b = (block_t) z << scale;
|
2013-03-16 03:29:32 +01:00
|
|
|
bp_dindir = get_block(rip->i_dev, b,
|
|
|
|
(new_dbl?NO_READ:NORMAL));
|
2006-01-11 18:14:51 +01:00
|
|
|
if (new_dbl) zero_block(bp_dindir);
|
|
|
|
z1 = rd_indir(bp_dindir, ind_ex);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
single = FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-11 18:14:51 +01:00
|
|
|
/* z1 is now single indirect zone, or NO_ZONE; 'excess' is index.
|
|
|
|
* We have to create the indirect zone if it's NO_ZONE. Unless
|
|
|
|
* we're freeing (WMAP_FREE).
|
|
|
|
*/
|
|
|
|
if (z1 == NO_ZONE && !(op & WMAP_FREE)) {
|
2005-04-21 16:53:53 +02:00
|
|
|
z1 = alloc_zone(rip->i_dev, rip->i_zone[0]);
|
|
|
|
if (single)
|
2006-01-11 18:14:51 +01:00
|
|
|
rip->i_zone[zones] = z1; /* update inode w. single indirect */
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2006-01-11 18:14:51 +01:00
|
|
|
wr_indir(bp_dindir, ind_ex, z1); /* update dbl indir */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
new_ind = TRUE;
|
2006-01-11 18:14:51 +01:00
|
|
|
/* If double ind, it is dirty. */
|
2011-12-22 01:29:27 +01:00
|
|
|
if (bp_dindir != NULL) MARKDIRTY(bp_dindir);
|
2005-04-21 16:53:53 +02:00
|
|
|
if (z1 == NO_ZONE) {
|
2006-01-11 18:14:51 +01:00
|
|
|
/* Release dbl indirect blk. */
|
|
|
|
put_block(bp_dindir, INDIRECT_BLOCK);
|
2005-04-21 16:53:53 +02:00
|
|
|
return(err_code); /* couldn't create single ind */
|
|
|
|
}
|
|
|
|
}
|
2006-01-11 18:14:51 +01:00
|
|
|
|
|
|
|
/* z1 is indirect block's zone number (unless it's NO_ZONE when we're
|
|
|
|
* freeing).
|
|
|
|
*/
|
|
|
|
if(z1 != NO_ZONE) {
|
|
|
|
ex = (int) excess; /* we need an int here */
|
|
|
|
b = (block_t) z1 << scale;
|
|
|
|
bp = get_block(rip->i_dev, b, (new_ind ? NO_READ : NORMAL) );
|
|
|
|
if (new_ind) zero_block(bp);
|
|
|
|
if(op & WMAP_FREE) {
|
|
|
|
if((old_zone = rd_indir(bp, ex)) != NO_ZONE) {
|
|
|
|
free_zone(rip->i_dev, old_zone);
|
|
|
|
wr_indir(bp, ex, NO_ZONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Last reference in the indirect block gone? Then
|
2010-02-09 09:12:37 +01:00
|
|
|
* free the indirect block.
|
2006-01-11 18:14:51 +01:00
|
|
|
*/
|
|
|
|
if(empty_indir(bp, rip->i_sp)) {
|
|
|
|
free_zone(rip->i_dev, z1);
|
|
|
|
z1 = NO_ZONE;
|
|
|
|
/* Update the reference to the indirect block to
|
|
|
|
* NO_ZONE - in the double indirect block if there
|
|
|
|
* is one, otherwise in the inode directly.
|
|
|
|
*/
|
|
|
|
if(single) {
|
|
|
|
rip->i_zone[zones] = z1;
|
|
|
|
} else {
|
|
|
|
wr_indir(bp_dindir, ind_ex, z1);
|
2011-12-22 01:29:27 +01:00
|
|
|
MARKDIRTY(bp_dindir);
|
2006-01-11 18:14:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
wr_indir(bp, ex, new_zone);
|
|
|
|
}
|
2010-02-09 09:12:37 +01:00
|
|
|
/* z1 equals NO_ZONE only when we are freeing up the indirect block. */
|
2011-12-22 01:29:27 +01:00
|
|
|
if(z1 == NO_ZONE) { MARKCLEAN(bp); } else { MARKDIRTY(bp); }
|
2006-01-11 18:14:51 +01:00
|
|
|
put_block(bp, INDIRECT_BLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the single indirect block isn't there (or was just freed),
|
2009-12-25 00:43:16 +01:00
|
|
|
* see if we have to keep the double indirect block, if any.
|
2010-02-09 09:12:37 +01:00
|
|
|
* If we don't have to keep it, don't bother writing it out.
|
2006-01-11 18:14:51 +01:00
|
|
|
*/
|
2009-12-25 00:43:16 +01:00
|
|
|
if(z1 == NO_ZONE && !single && z2 != NO_ZONE &&
|
|
|
|
empty_indir(bp_dindir, rip->i_sp)) {
|
2011-12-22 01:29:27 +01:00
|
|
|
MARKCLEAN(bp_dindir);
|
2006-01-11 18:14:51 +01:00
|
|
|
free_zone(rip->i_dev, z2);
|
|
|
|
rip->i_zone[zones+1] = NO_ZONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
put_block(bp_dindir, INDIRECT_BLOCK); /* release double indirect blk */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* wr_indir *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void wr_indir(bp, index, zone)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct buf *bp; /* pointer to indirect block */
|
|
|
|
int index; /* index into *bp */
|
|
|
|
zone_t zone; /* zone to write */
|
|
|
|
{
|
|
|
|
/* Given a pointer to an indirect block, write one entry. */
|
|
|
|
|
|
|
|
struct super_block *sp;
|
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
if(bp == NULL)
|
|
|
|
panic("wr_indir() on NULL");
|
2006-01-11 18:14:51 +01:00
|
|
|
|
2012-10-16 17:40:39 +02:00
|
|
|
sp = get_super(lmfs_dev(bp)); /* need super block to find file sys type */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* write a zone into an indirect block */
|
2013-09-16 22:52:36 +02:00
|
|
|
assert(sp->s_version == V3);
|
|
|
|
b_v2_ind(bp)[index] = (zone_t) conv4(sp->s_native, (long) zone);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2006-01-11 18:14:51 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* empty_indir *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int empty_indir(bp, sb)
|
2006-01-11 18:14:51 +01:00
|
|
|
struct buf *bp; /* pointer to indirect block */
|
|
|
|
struct super_block *sb; /* superblock of device block resides on */
|
|
|
|
{
|
|
|
|
/* Return nonzero if the indirect block pointed to by bp contains
|
|
|
|
* only NO_ZONE entries.
|
|
|
|
*/
|
2010-06-01 14:35:33 +02:00
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < V2_INDIRECTS(sb->s_block_size); i++)
|
2012-10-16 17:40:39 +02:00
|
|
|
if( b_v2_ind(bp)[i] != NO_ZONE)
|
2010-06-01 14:35:33 +02:00
|
|
|
return(0);
|
2006-01-11 18:14:51 +01:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(1);
|
2006-01-11 18:14:51 +01:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* clear_zone *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void clear_zone(rip, pos, flag)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct inode *rip; /* inode to clear */
|
|
|
|
off_t pos; /* points to block to clear */
|
2010-02-09 09:12:37 +01:00
|
|
|
int flag; /* 1 if called by new_block, 0 otherwise */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Zero a zone, possibly starting in the middle. The parameter 'pos' gives
|
|
|
|
* a byte in the first block to be zeroed. Clearzone() is called from
|
2010-02-09 09:12:37 +01:00
|
|
|
* fs_readwrite(), truncate_inode(), and new_block().
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2013-03-16 03:29:32 +01:00
|
|
|
int scale;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* If the block size and zone size are the same, clear_zone() not needed. */
|
|
|
|
scale = rip->i_sp->s_log_zone_size;
|
2013-03-16 03:29:32 +01:00
|
|
|
assert(scale == 0);
|
|
|
|
return;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* new_block *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
struct buf *new_block(rip, position)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct inode *rip; /* pointer to inode */
|
|
|
|
off_t position; /* file pointer */
|
|
|
|
{
|
|
|
|
/* Acquire a new block and return a pointer to it. Doing so may require
|
|
|
|
* allocating a complete zone, and then returning the initial block.
|
|
|
|
* On the other hand, the current zone may still have some unused blocks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
register struct buf *bp;
|
|
|
|
block_t b, base_block;
|
|
|
|
zone_t z;
|
|
|
|
zone_t zone_size;
|
|
|
|
int scale, r;
|
|
|
|
|
|
|
|
/* Is another block available in the current zone? */
|
2013-03-16 03:29:32 +01:00
|
|
|
if ( (b = read_map(rip, position, 0)) == NO_BLOCK) {
|
2008-02-06 16:05:57 +01:00
|
|
|
if (rip->i_zsearch == NO_ZONE) {
|
|
|
|
/* First search for this file. Start looking from
|
|
|
|
* the file's first data zone to prevent fragmentation
|
|
|
|
*/
|
2010-06-01 14:35:33 +02:00
|
|
|
if ( (z = rip->i_zone[0]) == NO_ZONE) {
|
|
|
|
/* No first zone for file either, let alloc_zone
|
|
|
|
* decide. */
|
|
|
|
z = (zone_t) rip->i_sp->s_firstdatazone;
|
2008-02-06 16:05:57 +01:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
} else {
|
2008-02-06 16:05:57 +01:00
|
|
|
/* searched before, start from last find */
|
|
|
|
z = rip->i_zsearch;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2010-05-10 15:26:00 +02:00
|
|
|
if ( (z = alloc_zone(rip->i_dev, z)) == NO_ZONE) return(NULL);
|
2008-02-06 16:05:57 +01:00
|
|
|
rip->i_zsearch = z; /* store for next lookup */
|
2006-01-11 18:14:51 +01:00
|
|
|
if ( (r = write_map(rip, position, z, 0)) != OK) {
|
2005-04-21 16:53:53 +02:00
|
|
|
free_zone(rip->i_dev, z);
|
|
|
|
err_code = r;
|
2010-05-10 15:26:00 +02:00
|
|
|
return(NULL);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are not writing at EOF, clear the zone, just to be safe. */
|
|
|
|
if ( position != rip->i_size) clear_zone(rip, position, 1);
|
|
|
|
scale = rip->i_sp->s_log_zone_size;
|
|
|
|
base_block = (block_t) z << scale;
|
|
|
|
zone_size = (zone_t) rip->i_sp->s_block_size << scale;
|
|
|
|
b = base_block + (block_t)((position % zone_size)/rip->i_sp->s_block_size);
|
|
|
|
}
|
|
|
|
|
2013-03-16 03:29:32 +01:00
|
|
|
bp = lmfs_get_block_ino(rip->i_dev, b, NO_READ, rip->i_num,
|
|
|
|
rounddown(position, rip->i_sp->s_block_size));
|
2005-04-21 16:53:53 +02:00
|
|
|
zero_block(bp);
|
|
|
|
return(bp);
|
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* zero_block *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void zero_block(bp)
|
2005-04-21 16:53:53 +02:00
|
|
|
register struct buf *bp; /* pointer to buffer to zero */
|
|
|
|
{
|
|
|
|
/* Zero a block. */
|
2012-10-16 17:40:39 +02:00
|
|
|
ASSERT(lmfs_bytes(bp) > 0);
|
|
|
|
ASSERT(bp->data);
|
|
|
|
memset(b_data(bp), 0, (size_t) lmfs_bytes(bp));
|
2011-12-22 01:29:27 +01:00
|
|
|
MARKDIRTY(bp);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|