mfs fix by tveerman from trunk.

This commit is contained in:
Ben Gras 2010-06-07 15:46:26 +00:00
parent 255ad2ab37
commit 6677a8c8e0
4 changed files with 28 additions and 23 deletions

View File

@ -150,7 +150,7 @@
/* Some limits. */
#define MAX_INODE_NR ((ino_t) 037777777777) /* largest inode number */
#define MAX_FILE_POS ((off_t) 0x7FFFFFFF) /* largest legal file offset */
#define UMAX_FILE_POS ((unsigned) 0x7FFFFFF) /* largest legal file offset */
#define UMAX_FILE_POS ((unsigned) 0x7FFFFFFF) /* largest legal file offset */
#define MAX_SYM_LOOPS 8 /* how many symbolic links are recursed */

View File

@ -226,7 +226,11 @@ register struct inode *rip; /* pointer to inode to be released */
if (rip->i_nlinks == NO_LINK) {
/* i_nlinks == NO_LINK means free the inode. */
/* return all the disk blocks */
if (truncate_inode(rip, (off_t) 0) != OK) return;
/* Ignore errors by truncate_inode in case inode is a block
* special or character special file.
*/
(void) truncate_inode(rip, (off_t) 0);
rip->i_mode = I_NOT_ALLOC; /* clear I_TYPE field */
rip->i_dirt = DIRTY;
free_inode(rip->i_dev, rip->i_num);
@ -257,8 +261,9 @@ PUBLIC struct inode *alloc_inode(dev_t dev, mode_t bits)
register struct inode *rip;
register struct super_block *sp;
int major, minor, inumb;
int major, minor;
bit_t b;
ino_t inumb;
sp = get_super(dev); /* get pointer to super_block */
if (sp->s_rd_only) { /* can't allocate an inode on a read only device. */
@ -276,7 +281,7 @@ PUBLIC struct inode *alloc_inode(dev_t dev, mode_t bits)
return(NULL);
}
sp->s_isearch = b; /* next time start here */
inumb = (int) b; /* be careful not to pass unshort as param */
inumb = (ino_t) b; /* be careful not to pass unshort as param */
/* Try to acquire a slot in the inode table. */
if ((rip = get_inode(NO_DEV, inumb)) == NULL) {
@ -339,7 +344,7 @@ PRIVATE void free_inode(
/* Locate the appropriate super_block. */
sp = get_super(dev);
if (inumb > sp->s_ninodes) return;
if (inumb == 0 || inumb > sp->s_ninodes) return;
b = (bit_t) inumb;
free_bit(sp, IMAP, b);
if (b < sp->s_isearch) sp->s_isearch = b;

View File

@ -245,14 +245,14 @@ char file_name[NAME_MAX]; /* name of file to be removed */
{
/* Unlink 'file_name'; rip must be the inode of 'file_name' or NULL. */
ino_t numb; /* inode number */
ino_t inumb; /* inode number */
int r;
/* If rip is not NULL, it is used to get faster access to the inode. */
if (rip == NULL) {
/* Search for file in directory and try to get its inode. */
err_code = search_dir(dirp, file_name, &numb, LOOK_UP, IGN_PERM);
if (err_code == OK) rip = get_inode(dirp->i_dev, (int) numb);
err_code = search_dir(dirp, file_name, &inumb, LOOK_UP, IGN_PERM);
if (err_code == OK) rip = get_inode(dirp->i_dev, inumb);
if (err_code != OK || rip == NULL) return(err_code);
} else {
dup_inode(rip); /* inode will be returned with put_inode */
@ -284,7 +284,7 @@ PUBLIC int fs_rename()
int odir, ndir; /* TRUE iff {old|new} file is dir */
int same_pdir; /* TRUE iff parent dirs are the same */
char old_name[NAME_MAX], new_name[NAME_MAX];
ino_t numb;
ino_t inumb;
phys_bytes len;
/* Copy the last component of the old name */
@ -423,16 +423,16 @@ PUBLIC int fs_rename()
* otherwise first try to create the new name entry to make sure
* the rename will succeed.
*/
numb = old_ip->i_num; /* inode number of old file */
inumb = old_ip->i_num; /* inode number of old file */
if(same_pdir) {
r = search_dir(old_dirp, old_name, NULL, DELETE, IGN_PERM);
/* shouldn't go wrong. */
if(r == OK)
(void) search_dir(old_dirp, new_name, &numb, ENTER,
(void) search_dir(old_dirp, new_name, &inumb, ENTER,
IGN_PERM);
} else {
r = search_dir(new_dirp, new_name, &numb, ENTER, IGN_PERM);
r = search_dir(new_dirp, new_name, &inumb, ENTER, IGN_PERM);
if(r == OK)
(void) search_dir(old_dirp, old_name, NULL, DELETE,
IGN_PERM);
@ -443,9 +443,9 @@ PUBLIC int fs_rename()
if(r == OK && odir && !same_pdir) {
/* Update the .. entry in the directory (still points to old_dirp).*/
numb = new_dirp->i_num;
inumb = new_dirp->i_num;
(void) unlink_file(old_ip, NULL, dot2);
if(search_dir(old_ip, dot2, &numb, ENTER, IGN_PERM) == OK) {
if(search_dir(old_ip, dot2, &inumb, ENTER, IGN_PERM) == OK) {
/* New link created. */
new_dirp->i_nlinks++;
new_dirp->i_dirt = DIRTY;

View File

@ -363,7 +363,7 @@ int chk_perm; /* check permissions when string is looked up*/
* the directory, find the inode, open it, and return a pointer to its inode
* slot.
*/
ino_t numb;
ino_t inumb;
struct inode *rip;
/* If 'string' is empty, return an error. */
@ -376,12 +376,12 @@ int chk_perm; /* check permissions when string is looked up*/
if (dirp == NULL) return(NULL);
/* If 'string' is not present in the directory, signal error. */
if ( (err_code = search_dir(dirp, string, &numb, LOOK_UP, chk_perm)) != OK) {
if ( (err_code = search_dir(dirp, string, &inumb, LOOK_UP, chk_perm)) != OK) {
return(NULL);
}
/* The component has been found in the directory. Get inode. */
if ( (rip = get_inode(dirp->i_dev, (int) numb)) == NULL) {
if ( (rip = get_inode(dirp->i_dev, inumb)) == NULL) {
return(NULL);
}
@ -468,17 +468,17 @@ char string[NAME_MAX+1]; /* component extracted from 'old_name' */
/*===========================================================================*
* search_dir *
*===========================================================================*/
PUBLIC int search_dir(ldir_ptr, string, numb, flag, check_permissions)
PUBLIC int search_dir(ldir_ptr, string, inumb, flag, check_permissions)
register struct inode *ldir_ptr; /* ptr to inode for dir to search */
char string[NAME_MAX]; /* component to search for */
ino_t *numb; /* pointer to inode number */
ino_t *inumb; /* pointer to inode number */
int flag; /* LOOK_UP, ENTER, DELETE or IS_EMPTY */
int check_permissions; /* check permissions when flag is !IS_EMPTY */
{
/* This function searches the directory whose inode is pointed to by 'ldip':
* if (flag == ENTER) enter 'string' in the directory with inode # '*numb';
* if (flag == ENTER) enter 'string' in the directory with inode # '*inumb';
* if (flag == DELETE) delete 'string' from the directory;
* if (flag == LOOK_UP) search for 'string' and return inode # in 'numb';
* if (flag == LOOK_UP) search for 'string' and return inode # in 'inumb';
* if (flag == IS_EMPTY) return OK if only . and .. in dir else ENOTEMPTY;
*
* if 'string' is dot1 or dot2, no access permissions are checked.
@ -563,7 +563,7 @@ int check_permissions; /* check permissions when flag is !IS_EMPTY */
ldir_ptr->i_dirt = DIRTY;
} else {
sp = ldir_ptr->i_sp; /* 'flag' is LOOK_UP */
*numb = (ino_t) conv4(sp->s_native,
*inumb = (ino_t) conv4(sp->s_native,
(int) dp->d_ino);
}
put_block(bp, DIRECTORY_BLOCK);
@ -603,7 +603,7 @@ int check_permissions; /* check permissions when flag is !IS_EMPTY */
(void) memset(dp->d_name, 0, (size_t) NAME_MAX); /* clear entry */
for (i = 0; i < NAME_MAX && string[i]; i++) dp->d_name[i] = string[i];
sp = ldir_ptr->i_sp;
dp->d_ino = conv4(sp->s_native, (int) *numb);
dp->d_ino = conv4(sp->s_native, (int) *inumb);
bp->b_dirt = DIRTY;
put_block(bp, DIRECTORY_BLOCK);
ldir_ptr->i_update |= CTIME | MTIME; /* mark mtime for update later */