--- linux/fs/minix/namei.c 2018/04/24 18:10:47 1.1.1.5 +++ linux/fs/minix/namei.c 2018/04/24 18:14:30 1.1.1.7 @@ -1,7 +1,7 @@ /* * linux/fs/minix/namei.c * - * (C) 1991 Linus Torvalds + * Copyright (C) 1991, 1992 Linus Torvalds */ #include @@ -10,10 +10,9 @@ #include #include #include -#include +#include -#include -#include +#include /* * comment out this line if you want names > MINIX_NAME_LEN chars to be @@ -59,8 +58,7 @@ static int minix_match(int len,const cha static struct buffer_head * minix_find_entry(struct inode * dir, const char * name, int namelen, struct minix_dir_entry ** res_dir) { - int entries; - int block,i; + int entries, i; struct buffer_head * bh; struct minix_dir_entry * de; @@ -75,18 +73,16 @@ static struct buffer_head * minix_find_e namelen = MINIX_NAME_LEN; #endif entries = dir->i_size / (sizeof (struct minix_dir_entry)); - if (!(block = dir->i_data[0])) - return NULL; - if (!(bh = bread(dir->i_dev,block))) + bh = minix_bread(dir,0,0); + if (!bh) return NULL; i = 0; de = (struct minix_dir_entry *) bh->b_data; while (i < entries) { if ((char *)de >= BLOCK_SIZE+bh->b_data) { brelse(bh); - bh = NULL; - if (!(block = minix_bmap(dir,i/MINIX_DIR_ENTRIES_PER_BLOCK)) || - !(bh = bread(dir->i_dev,block))) { + bh = minix_bread(dir,i/MINIX_DIR_ENTRIES_PER_BLOCK,0); + if (!bh) { i += MINIX_DIR_ENTRIES_PER_BLOCK; continue; } @@ -144,7 +140,7 @@ int minix_lookup(struct inode * dir,cons static struct buffer_head * minix_add_entry(struct inode * dir, const char * name, int namelen, struct minix_dir_entry ** res_dir) { - int block,i; + int i; struct buffer_head * bh; struct minix_dir_entry * de; @@ -160,23 +156,17 @@ static struct buffer_head * minix_add_en #endif if (!namelen) return NULL; - if (!(block = dir->i_data[0])) - return NULL; - if (!(bh = bread(dir->i_dev,block))) + bh = minix_bread(dir,0,0); + if (!bh) return NULL; i = 0; de = (struct minix_dir_entry *) bh->b_data; while (1) { if ((char *)de >= BLOCK_SIZE+bh->b_data) { brelse(bh); - bh = NULL; - block = minix_create_block(dir,i/MINIX_DIR_ENTRIES_PER_BLOCK); - if (!block) + bh = minix_bread(dir,i/MINIX_DIR_ENTRIES_PER_BLOCK,1); + if (!bh) return NULL; - if (!(bh = bread(dir->i_dev,block))) { - i += MINIX_DIR_ENTRIES_PER_BLOCK; - continue; - } de = (struct minix_dir_entry *) bh->b_data; } if (i*sizeof(struct minix_dir_entry) >= dir->i_size) { @@ -268,9 +258,10 @@ int minix_mknod(struct inode * dir, cons inode->i_op = &minix_blkdev_inode_operations; else if (S_ISFIFO(inode->i_mode)) { inode->i_op = &minix_fifo_inode_operations; - inode->i_size = 0; inode->i_pipe = 1; + PIPE_BASE(*inode) = NULL; PIPE_HEAD(*inode) = PIPE_TAIL(*inode) = 0; + PIPE_READ_WAIT(*inode) = PIPE_WRITE_WAIT(*inode) = NULL; PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0; } if (S_ISBLK(mode) || S_ISCHR(mode)) @@ -313,21 +304,14 @@ int minix_mkdir(struct inode * dir, cons inode->i_op = &minix_dir_inode_operations; inode->i_size = 2 * sizeof (struct minix_dir_entry); inode->i_mtime = inode->i_atime = CURRENT_TIME; - if (!(inode->i_data[0] = minix_new_block(inode->i_dev))) { + dir_block = minix_bread(inode,0,1); + if (!dir_block) { iput(dir); inode->i_nlink--; inode->i_dirt = 1; iput(inode); return -ENOSPC; } - inode->i_dirt = 1; - if (!(dir_block = bread(inode->i_dev,inode->i_data[0]))) { - iput(dir); - inode->i_nlink--; - inode->i_dirt = 1; - iput(inode); - return -EIO; - } de = (struct minix_dir_entry *) dir_block->b_data; de->inode=inode->i_ino; strcpy(de->name,"."); @@ -337,7 +321,7 @@ int minix_mkdir(struct inode * dir, cons inode->i_nlink = 2; dir_block->b_dirt = 1; brelse(dir_block); - inode->i_mode = I_DIRECTORY | (mode & 0777 & ~current->umask); + inode->i_mode = S_IFDIR | (mode & 0777 & ~current->umask); inode->i_dirt = 1; bh = minix_add_entry(dir,name,len,&de); if (!bh) { @@ -361,35 +345,31 @@ int minix_mkdir(struct inode * dir, cons */ static int empty_dir(struct inode * inode) { - int nr,block; - int len; + int nr, len; struct buffer_head * bh; struct minix_dir_entry * de; len = inode->i_size / sizeof (struct minix_dir_entry); - if (len<2 || !inode->i_data[0] || - !(bh=bread(inode->i_dev,inode->i_data[0]))) { + if (len<2 || !(bh = minix_bread(inode,0,0))) { printk("warning - bad directory on dev %04x\n",inode->i_dev); - return 0; + return 1; } de = (struct minix_dir_entry *) bh->b_data; if (de[0].inode != inode->i_ino || !de[1].inode || strcmp(".",de[0].name) || strcmp("..",de[1].name)) { printk("warning - bad directory on dev %04x\n",inode->i_dev); - return 0; + return 1; } nr = 2; de += 2; while (nr= (void *) (bh->b_data+BLOCK_SIZE)) { brelse(bh); - block = minix_bmap(inode,nr/MINIX_DIR_ENTRIES_PER_BLOCK); - if (!block) { + bh = minix_bread(inode,nr/MINIX_DIR_ENTRIES_PER_BLOCK,0); + if (!bh) { nr += MINIX_DIR_ENTRIES_PER_BLOCK; continue; } - if (!(bh=bread(inode->i_dev,block))) - return 0; de = (struct minix_dir_entry *) bh->b_data; } if (de->inode) { @@ -507,21 +487,14 @@ int minix_symlink(struct inode * dir, co } inode->i_mode = S_IFLNK | 0777; inode->i_op = &minix_symlink_inode_operations; - if (!(inode->i_data[0] = minix_new_block(inode->i_dev))) { + name_block = minix_bread(inode,0,1); + if (!name_block) { iput(dir); inode->i_nlink--; inode->i_dirt = 1; iput(inode); return -ENOSPC; } - inode->i_dirt = 1; - if (!(name_block = bread(inode->i_dev,inode->i_data[0]))) { - iput(dir); - inode->i_nlink--; - inode->i_dirt = 1; - iput(inode); - return -EIO; - } i = 0; while (i < 1023 && (c=get_fs_byte(symname++))) name_block->b_data[i++] = c; @@ -676,6 +649,10 @@ start_up: retval = 0; goto end_rename; } + if (S_ISDIR(new_inode->i_mode)) { + retval = -EEXIST; + goto end_rename; + } if (S_ISDIR(old_inode->i_mode)) { retval = -EEXIST; if (new_bh) @@ -687,9 +664,8 @@ start_up: if (subdir(new_dir, old_inode)) goto end_rename; retval = -EIO; - if (!old_inode->i_data[0]) - goto end_rename; - if (!(dir_bh = bread(old_inode->i_dev, old_inode->i_data[0]))) + dir_bh = minix_bread(old_inode,0,0); + if (!dir_bh) goto end_rename; if (PARENT_INO(dir_bh->b_data) != old_dir->i_ino) goto end_rename; @@ -747,7 +723,7 @@ end_rename: int minix_rename(struct inode * old_dir, const char * old_name, int old_len, struct inode * new_dir, const char * new_name, int new_len) { - static struct task_struct * wait = NULL; + static struct wait_queue * wait = NULL; static int lock = 0; int result;