?? inode.c
字號:
inode->i_ctime = attr->ia_ctime; if (attr->ia_valid & ATTR_MODE) { inode->i_mode = attr->ia_mode; if (!fsuser() && !in_group_p(inode->i_gid)) inode->i_mode &= ~S_ISGID; } inode->i_dirt = 1;}/* * notify_change is called for inode-changing operations such as * chown, chmod, utime, and truncate. It is guaranteed (unlike * write_inode) to be called from the context of the user requesting * the change. */int notify_change(struct inode * inode, struct iattr *attr){ int retval; attr->ia_ctime = CURRENT_TIME; if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME)) { if (!(attr->ia_valid & ATTR_ATIME_SET)) attr->ia_atime = attr->ia_ctime; if (!(attr->ia_valid & ATTR_MTIME_SET)) attr->ia_mtime = attr->ia_ctime; } if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->notify_change) return inode->i_sb->s_op->notify_change(inode, attr); if ((retval = inode_change_ok(inode, attr)) != 0) return retval; inode_setattr(inode, attr); return 0;}/* * bmap is needed for demand-loading and paging: if this function * doesn't exist for a filesystem, then those things are impossible: * executables cannot be run from the filesystem etc... * * This isn't as bad as it sounds: the read-routines might still work, * so the filesystem would be otherwise ok (for example, you might have * a DOS filesystem, which doesn't lend itself to bmap very well, but * you could still transfer files to/from the filesystem) */int bmap(struct inode * inode, int block){ if (inode->i_op && inode->i_op->bmap) return inode->i_op->bmap(inode,block); return 0;}void invalidate_inodes(kdev_t dev){ struct inode * inode, * next; int i; next = first_inode; for(i = nr_inodes ; i > 0 ; i--) { inode = next; next = inode->i_next; /* clear_inode() changes the queues.. */ if (inode->i_dev != dev) continue; if (inode->i_count || inode->i_dirt || inode->i_lock) { printk("VFS: inode busy on removed device %s\n", kdevname(dev)); continue; } clear_inode(inode); }}void sync_inodes(kdev_t dev){ int i; struct inode * inode; inode = first_inode; for(i = 0; i < nr_inodes*2; i++, inode = inode->i_next) { if (dev && inode->i_dev != dev) continue; wait_on_inode(inode); if (inode->i_dirt) write_inode(inode); }}void iput(struct inode * inode){ if (!inode) return; wait_on_inode(inode); if (!inode->i_count) { printk("VFS: iput: trying to free free inode\n"); printk("VFS: device %s, inode %lu, mode=0%07o\n", kdevname(inode->i_rdev), inode->i_ino, inode->i_mode); return; } if (inode->i_pipe) wake_up_interruptible(&PIPE_WAIT(*inode));repeat: if (inode->i_count>1) { inode->i_count--; return; } wake_up(&inode_wait); if (inode->i_pipe) { unsigned long page = (unsigned long) PIPE_BASE(*inode); PIPE_BASE(*inode) = NULL; free_page(page); } if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->put_inode) { inode->i_sb->s_op->put_inode(inode); if (!inode->i_nlink) return; } if (inode->i_dirt) { write_inode(inode); /* we can sleep - so do again */ wait_on_inode(inode); goto repeat; } if (IS_WRITABLE(inode)) { if (inode->i_sb && inode->i_sb->dq_op) { /* Here we can sleep also. Let's do it again * Dmitry Gorodchanin 02/11/96 */ inode->i_lock = 1; inode->i_sb->dq_op->drop(inode); unlock_inode(inode); goto repeat; } } inode->i_count--; if (inode->i_count) /* * Huoh, we were supposed to be the last user, but someone has * grabbed it while we were sleeping. Dont destroy inode VM * mappings, it might cause a memory leak. */ return;#ifndef NO_MM if (inode->i_mmap) { printk("iput: inode %lu on device %s still has mappings.\n", inode->i_ino, kdevname(inode->i_dev)); inode->i_mmap = NULL; }#endif nr_free_inodes++; return;}struct inode * get_empty_inode(void){ static int ino = 0; struct inode * inode, * best; unsigned long badness; int i; if (nr_inodes < max_inodes && nr_free_inodes < (nr_inodes >> 1)) grow_inodes();repeat: inode = first_inode; best = NULL; badness = 1000; for (i = nr_inodes/2; i > 0; i--,inode = inode->i_next) { if (!inode->i_count) { unsigned long i = 999; if (!(inode->i_lock || inode->i_dirt)) i = inode->i_nrpages; if (i < badness) { best = inode; if (!i) goto found_good; badness = i; } } } if (nr_inodes < max_inodes) { if (grow_inodes() == 0) goto repeat; best = NULL; } if (!best) { printk("VFS: No free inodes - contact Linus\n"); sleep_on(&inode_wait); goto repeat; } if (best->i_lock) { wait_on_inode(best); goto repeat; } if (best->i_dirt) { write_inode(best); goto repeat; } if (best->i_count) goto repeat;found_good: clear_inode(best); best->i_count = 1; best->i_nlink = 1; best->i_version = ++event; best->i_sem.count = 1; best->i_ino = ++ino; best->i_dev = 0; nr_free_inodes--; if (nr_free_inodes < 0) { printk ("VFS: get_empty_inode: bad free inode count.\n"); nr_free_inodes = 0; } return best;}struct inode * get_pipe_inode(void){ struct inode * inode; extern struct inode_operations pipe_inode_operations; if (!(inode = get_empty_inode())) return NULL; if (!(PIPE_BASE(*inode) = (char*) __get_free_page(GFP_USER))) { iput(inode); return NULL; } inode->i_op = &pipe_inode_operations; inode->i_count = 2; /* sum of readers/writers */ PIPE_WAIT(*inode) = NULL; PIPE_START(*inode) = PIPE_LEN(*inode) = 0; PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0; PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 1; PIPE_LOCK(*inode) = 0; inode->i_pipe = 1; inode->i_mode |= S_IFIFO | S_IRUSR | S_IWUSR; inode->i_uid = current->fsuid; inode->i_gid = current->fsgid; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_blksize = PAGE_SIZE; return inode;}struct inode *__iget(struct super_block * sb, int nr, int crossmntp){ static struct wait_queue * update_wait = NULL; struct inode_hash_entry * h; struct inode * inode; struct inode * empty = NULL; if (!sb) panic("VFS: iget with sb==NULL"); h = hash(sb->s_dev, nr);repeat: for (inode = h->inode; inode ; inode = inode->i_hash_next) if (inode->i_dev == sb->s_dev && inode->i_ino == nr) goto found_it; if (!empty) { /* * If we sleep here before we have found an inode * we need to make sure nobody does anything bad * to the inode while we sleep, because otherwise * we may return an inode that is not valid any * more when we wake up.. */ h->updating++; empty = get_empty_inode(); if (!--h->updating) wake_up(&update_wait); if (empty) goto repeat; return (NULL); } inode = empty; inode->i_sb = sb; inode->i_dev = sb->s_dev; inode->i_ino = nr; inode->i_flags = sb->s_flags; put_last_free(inode); insert_inode_hash(inode); read_inode(inode); goto return_it;found_it: /* * The inode may currently be being pulled down by * clear_inode(). Avoid it if so. If we get past this, then * the increment of i_count will prevent the inode's reuse. */ if (inode->i_condemned) { sleep_on(&inode->i_wait); goto repeat; } if (!inode->i_count) nr_free_inodes--; inode->i_count++; wait_on_inode(inode); if (inode->i_dev != sb->s_dev || inode->i_ino != nr) { printk("Whee.. inode changed from under us. Tell Linus\n"); iput(inode); goto repeat; } if (crossmntp && inode->i_mount) { struct inode * tmp = inode->i_mount; tmp->i_count++; iput(inode); inode = tmp; wait_on_inode(inode); } if (empty) iput(empty);return_it: while (h->updating) sleep_on(&update_wait); return inode;}/* * The "new" scheduling primitives (new as of 0.97 or so) allow this to * be done without disabling interrupts (other than in the actual queue * updating things: only a couple of 386 instructions). This should be * much better for interrupt latency. */static void __wait_on_inode(struct inode * inode){ struct wait_queue wait = { current, NULL }; add_wait_queue(&inode->i_wait, &wait);repeat: current->state = TASK_UNINTERRUPTIBLE; if (inode->i_lock) { schedule(); goto repeat; } remove_wait_queue(&inode->i_wait, &wait); current->state = TASK_RUNNING;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -