@@ -273,12 +273,24 @@ free_anon_mapping(struct address_space *as)
273
273
vm_object_deallocate (as );
274
274
}
275
275
276
+ static int shm_file_mmap (struct linux_file * filp , struct vm_area_struct * vma )
277
+ {
278
+ vma -> vm_file = get_file (filp );
279
+ return 0 ;
280
+ }
281
+
282
+
283
+ struct file_operations linux_shm_fops = {
284
+ .mmap = shm_file_mmap
285
+ };
286
+
276
287
struct linux_file *
277
288
shmem_file_setup (char * name , loff_t size , unsigned long flags )
278
289
{
279
290
struct fileobj {
280
291
struct linux_file file __aligned (sizeof (void * ));
281
292
struct vnode vnode __aligned (sizeof (void * ));
293
+ __typeof ( * ((struct file * )0 )-> _file ) pseudo_file __aligned (sizeof (void * ));
282
294
};
283
295
struct fileobj * fileobj ;
284
296
struct linux_file * filp ;
@@ -291,14 +303,20 @@ shmem_file_setup(char *name, loff_t size, unsigned long flags)
291
303
goto err_0 ;
292
304
}
293
305
filp = & fileobj -> file ;
306
+ filp -> _file = & fileobj -> pseudo_file ;
294
307
vp = & fileobj -> vnode ;
308
+ refcount_init (& filp -> _file -> f_count , 1 );
309
+
310
+
295
311
296
312
filp -> f_dentry = & filp -> f_dentry_store ;
297
313
filp -> f_vnode = vp ;
298
314
filp -> f_mapping = file_inode (filp )-> i_mapping =
299
315
vm_pager_allocate (OBJT_DEFAULT , NULL , size ,
300
316
VM_PROT_READ | VM_PROT_WRITE , 0 , curthread -> td_ucred );
301
-
317
+
318
+ filp -> f_op = & linux_shm_fops ;
319
+
302
320
if (file_inode (filp )-> i_mapping == NULL ) {
303
321
error = - ENOMEM ;
304
322
goto err_1 ;
442
460
linux_file_free (struct linux_file * filp )
443
461
{
444
462
445
- if (filp -> _file == NULL ) {
463
+ if (filp -> f_op == & linux_shm_fops ) {
446
464
struct vnode * vp = filp -> f_vnode ;
447
465
if (vp != NULL && vp -> i_mapping != NULL )
448
466
vm_object_deallocate (vp -> i_mapping );
0 commit comments