Do tmpfile

Retired DISLab
김건우 (토론 | 기여) 사용자의 2014년 4월 30일 (수) 02:38 버전
(비교) ← 이전 판 | 현재 판 (비교) | 다음 판 → (비교)
이동: 둘러보기, 찾기

http://lxr.free-electrons.com/source/fs/namei.c#L3091

3091 static int do_tmpfile(int dfd, struct filename *pathname,
3092                 struct nameidata *nd, int flags,
3093                 const struct open_flags *op,
3094                 struct file *file, int *opened)
3095 {
3096         static const struct qstr name = QSTR_INIT("/", 1);
3097         struct dentry *dentry, *child;
3098         struct inode *dir;
3099         int error = path_lookupat(dfd, pathname->name,
3100                                   flags | LOOKUP_DIRECTORY, nd);
3101         if (unlikely(error))
3102                 return error;
3103         error = mnt_want_write(nd->path.mnt);
3104         if (unlikely(error))
3105                 goto out;
3106         /* we want directory to be writable */
3107         error = inode_permission(nd->inode, MAY_WRITE | MAY_EXEC);
3108         if (error)
3109                 goto out2;
3110         dentry = nd->path.dentry;
3111         dir = dentry->d_inode;
3112         if (!dir->i_op->tmpfile) {
3113                 error = -EOPNOTSUPP;
3114                 goto out2;
3115         }
3116         child = d_alloc(dentry, &name);
3117         if (unlikely(!child)) {
3118                 error = -ENOMEM;
3119                 goto out2;
3120         }
3121         nd->flags &= ~LOOKUP_DIRECTORY;
3122         nd->flags |= op->intent;
3123         dput(nd->path.dentry);
3124         nd->path.dentry = child;
3125         error = dir->i_op->tmpfile(dir, nd->path.dentry, op->mode);
3126         if (error)
3127                 goto out2;
3128         audit_inode(pathname, nd->path.dentry, 0);
3129         error = may_open(&nd->path, op->acc_mode, op->open_flag);
3130         if (error)
3131                 goto out2;
3132         file->f_path.mnt = nd->path.mnt;
3133         error = finish_open(file, nd->path.dentry, NULL, opened);
3134         if (error)
3135                 goto out2;
3136         error = open_check_o_direct(file);
3137         if (error) {
3138                 fput(file);
3139         } else if (!(op->open_flag & O_EXCL)) {
3140                 struct inode *inode = file_inode(file);
3141                 spin_lock(&inode->i_lock);
3142                 inode->i_state |= I_LINKABLE;
3143                 spin_unlock(&inode->i_lock);
3144         }
3145 out2:
3146         mnt_drop_write(nd->path.mnt);
3147 out:
3148         path_put(&nd->path);
3149         return error;
3150 }
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기