@@ -2902,6 +2902,61 @@ static int do_last(struct nameidata *nd, struct path *path,
29022902 goto retry_lookup ;
29032903}
29042904
2905+ static int do_tmpfile (int dfd , struct filename * pathname ,
2906+ struct nameidata * nd , int flags ,
2907+ const struct open_flags * op ,
2908+ struct file * file , int * opened )
2909+ {
2910+ static const struct qstr name = QSTR_INIT ("/" , 1 );
2911+ struct dentry * dentry , * child ;
2912+ struct inode * dir ;
2913+ int error = path_lookupat (dfd , pathname -> name ,
2914+ flags | LOOKUP_DIRECTORY , nd );
2915+ if (unlikely (error ))
2916+ return error ;
2917+ error = mnt_want_write (nd -> path .mnt );
2918+ if (unlikely (error ))
2919+ goto out ;
2920+ /* we want directory to be writable */
2921+ error = inode_permission (nd -> inode , MAY_WRITE | MAY_EXEC );
2922+ if (error )
2923+ goto out2 ;
2924+ dentry = nd -> path .dentry ;
2925+ dir = dentry -> d_inode ;
2926+ if (!dir -> i_op -> tmpfile ) {
2927+ error = - EOPNOTSUPP ;
2928+ goto out2 ;
2929+ }
2930+ child = d_alloc (dentry , & name );
2931+ if (unlikely (!child )) {
2932+ error = - ENOMEM ;
2933+ goto out2 ;
2934+ }
2935+ nd -> flags &= ~LOOKUP_DIRECTORY ;
2936+ nd -> flags |= op -> intent ;
2937+ dput (nd -> path .dentry );
2938+ nd -> path .dentry = child ;
2939+ error = dir -> i_op -> tmpfile (dir , nd -> path .dentry , op -> mode );
2940+ if (error )
2941+ goto out2 ;
2942+ audit_inode (pathname , nd -> path .dentry , 0 );
2943+ error = may_open (& nd -> path , op -> acc_mode , op -> open_flag );
2944+ if (error )
2945+ goto out2 ;
2946+ file -> f_path .mnt = nd -> path .mnt ;
2947+ error = finish_open (file , nd -> path .dentry , NULL , opened );
2948+ if (error )
2949+ goto out2 ;
2950+ error = open_check_o_direct (file );
2951+ if (error )
2952+ fput (file );
2953+ out2 :
2954+ mnt_drop_write (nd -> path .mnt );
2955+ out :
2956+ path_put (& nd -> path );
2957+ return error ;
2958+ }
2959+
29052960static struct file * path_openat (int dfd , struct filename * pathname ,
29062961 struct nameidata * nd , const struct open_flags * op , int flags )
29072962{
@@ -2917,6 +2972,11 @@ static struct file *path_openat(int dfd, struct filename *pathname,
29172972
29182973 file -> f_flags = op -> open_flag ;
29192974
2975+ if (unlikely (file -> f_flags & O_TMPFILE )) {
2976+ error = do_tmpfile (dfd , pathname , nd , flags , op , file , & opened );
2977+ goto out ;
2978+ }
2979+
29202980 error = path_init (dfd , pathname -> name , flags | LOOKUP_PARENT , nd , & base );
29212981 if (unlikely (error ))
29222982 goto out ;
0 commit comments