namei.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:15k
- /*
- * linux/fs/hpfs/namei.c
- *
- * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
- *
- * adding & removing files & directories
- */
- #include <linux/string.h>
- #include "hpfs_fn.h"
- int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
- {
- const char *name = dentry->d_name.name;
- unsigned len = dentry->d_name.len;
- struct quad_buffer_head qbh0;
- struct buffer_head *bh;
- struct hpfs_dirent *de;
- struct fnode *fnode;
- struct dnode *dnode;
- struct inode *result;
- fnode_secno fno;
- dnode_secno dno;
- int r;
- struct hpfs_dirent dee;
- int err;
- if ((err = hpfs_chk_name((char *)name, &len))) return err==-ENOENT ? -EINVAL : err;
- if (!(fnode = hpfs_alloc_fnode(dir->i_sb, dir->i_hpfs_dno, &fno, &bh))) goto bail;
- if (!(dnode = hpfs_alloc_dnode(dir->i_sb, fno, &dno, &qbh0, 1))) goto bail1;
- memset(&dee, 0, sizeof dee);
- dee.directory = 1;
- if (!(mode & 0222)) dee.read_only = 1;
- /*dee.archive = 0;*/
- dee.hidden = name[0] == '.';
- dee.fnode = fno;
- dee.creation_date = dee.write_date = dee.read_date = gmt_to_local(dir->i_sb, CURRENT_TIME);
- hpfs_lock_inode(dir);
- r = hpfs_add_dirent(dir, (char *)name, len, &dee, 0);
- if (r == 1) goto bail2;
- if (r == -1) {
- brelse(bh);
- hpfs_brelse4(&qbh0);
- hpfs_free_sectors(dir->i_sb, fno, 1);
- hpfs_free_dnode(dir->i_sb, dno);
- hpfs_unlock_inode(dir);
- return -EEXIST;
- }
- fnode->len = len;
- memcpy(fnode->name, name, len > 15 ? 15 : len);
- fnode->up = dir->i_ino;
- fnode->dirflag = 1;
- fnode->btree.n_free_nodes = 7;
- fnode->btree.n_used_nodes = 1;
- fnode->btree.first_free = 0x14;
- fnode->u.external[0].disk_secno = dno;
- fnode->u.external[0].file_secno = -1;
- dnode->root_dnode = 1;
- dnode->up = fno;
- de = hpfs_add_de(dir->i_sb, dnode, "