13
13
#include <linux/memblock.h>
14
14
#include <linux/namei.h>
15
15
16
- static ssize_t __init xwrite (int fd , const char * p , size_t count )
16
+ static ssize_t __init xwrite (struct file * file , const char * p , size_t count ,
17
+ loff_t * pos )
17
18
{
18
19
ssize_t out = 0 ;
19
20
20
21
/* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
21
22
while (count ) {
22
- ssize_t rv = ksys_write ( fd , p , count );
23
+ ssize_t rv = kernel_write ( file , p , count , pos );
23
24
24
25
if (rv < 0 ) {
25
26
if (rv == - EINTR || rv == - EAGAIN )
@@ -317,7 +318,8 @@ static int __init maybe_link(void)
317
318
return 0 ;
318
319
}
319
320
320
- static __initdata int wfd ;
321
+ static __initdata struct file * wfile ;
322
+ static __initdata loff_t wfile_pos ;
321
323
322
324
static int __init do_name (void )
323
325
{
@@ -334,16 +336,17 @@ static int __init do_name(void)
334
336
int openflags = O_WRONLY |O_CREAT ;
335
337
if (ml != 1 )
336
338
openflags |= O_TRUNC ;
337
- wfd = ksys_open (collected , openflags , mode );
338
-
339
- if (wfd >= 0 ) {
340
- ksys_fchown (wfd , uid , gid );
341
- ksys_fchmod (wfd , mode );
342
- if (body_len )
343
- ksys_ftruncate (wfd , body_len );
344
- vcollected = kstrdup (collected , GFP_KERNEL );
345
- state = CopyFile ;
346
- }
339
+ wfile = filp_open (collected , openflags , mode );
340
+ if (IS_ERR (wfile ))
341
+ return 0 ;
342
+ wfile_pos = 0 ;
343
+
344
+ vfs_fchown (wfile , uid , gid );
345
+ vfs_fchmod (wfile , mode );
346
+ if (body_len )
347
+ vfs_truncate (& wfile -> f_path , body_len );
348
+ vcollected = kstrdup (collected , GFP_KERNEL );
349
+ state = CopyFile ;
347
350
}
348
351
} else if (S_ISDIR (mode )) {
349
352
ksys_mkdir (collected , mode );
@@ -365,16 +368,16 @@ static int __init do_name(void)
365
368
static int __init do_copy (void )
366
369
{
367
370
if (byte_count >= body_len ) {
368
- if (xwrite (wfd , victim , body_len ) != body_len )
371
+ if (xwrite (wfile , victim , body_len , & wfile_pos ) != body_len )
369
372
error ("write error" );
370
- ksys_close ( wfd );
373
+ fput ( wfile );
371
374
do_utime (vcollected , mtime );
372
375
kfree (vcollected );
373
376
eat (body_len );
374
377
state = SkipIt ;
375
378
return 0 ;
376
379
} else {
377
- if (xwrite (wfd , victim , byte_count ) != byte_count )
380
+ if (xwrite (wfile , victim , byte_count , & wfile_pos ) != byte_count )
378
381
error ("write error" );
379
382
body_len -= byte_count ;
380
383
eat (byte_count );
@@ -576,21 +579,23 @@ static inline bool kexec_free_initrd(void)
576
579
static void __init populate_initrd_image (char * err )
577
580
{
578
581
ssize_t written ;
579
- int fd ;
582
+ struct file * file ;
583
+ loff_t pos = 0 ;
580
584
581
585
unpack_to_rootfs (__initramfs_start , __initramfs_size );
582
586
583
587
printk (KERN_INFO "rootfs image is not initramfs (%s); looks like an initrd\n" ,
584
588
err );
585
- fd = ksys_open ("/initrd.image" , O_WRONLY | O_CREAT , 0700 );
586
- if (fd < 0 )
589
+ file = filp_open ("/initrd.image" , O_WRONLY | O_CREAT , 0700 );
590
+ if (IS_ERR ( file ) )
587
591
return ;
588
592
589
- written = xwrite (fd , (char * )initrd_start , initrd_end - initrd_start );
593
+ written = xwrite (file , (char * )initrd_start , initrd_end - initrd_start ,
594
+ & pos );
590
595
if (written != initrd_end - initrd_start )
591
596
pr_err ("/initrd.image: incomplete write (%zd != %ld)\n" ,
592
597
written , initrd_end - initrd_start );
593
- ksys_close ( fd );
598
+ fput ( file );
594
599
}
595
600
#endif /* CONFIG_BLK_DEV_RAM */
596
601
0 commit comments