forked from Ninals-GitHub/Learning-Ext2-Filesystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathme2fs_inode.c
2892 lines (2534 loc) · 78.7 KB
/
me2fs_inode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************************
File : me2fs_inode.c
Description : inode operations for my ext2 file system
*********************************************************************************/
#include <linux/buffer_head.h>
#include <linux/writeback.h>
#include <linux/mpage.h>
#include <linux/namei.h>
#include <linux/aio.h>
#include <linux/slab.h>
#include "me2fs.h"
#include "me2fs_util.h"
#include "me2fs_block.h"
#include "me2fs_inode.h"
#include "me2fs_dir.h"
#include "me2fs_namei.h"
#include "me2fs_file.h"
#include "me2fs_symlink.h"
#include "me2fs_ialloc.h"
#include "me2fs_namei.h"
#include "me2fs_super.h"
/*
==================================================================================
DEFINES
==================================================================================
*/
typedef struct
{
__le32 *p;
__le32 key;
struct buffer_head *bh;
} Indirect;
/*
==================================================================================
Prototype Statement
==================================================================================
*/
/*
----------------------------------------------------------------------------------
Address Space Operations for Ext2 Inode
----------------------------------------------------------------------------------
*/
static int me2fsReadPage( struct file *filp, struct page *page );
static int me2fsReadPages( struct file *filp,
struct address_space *mapping,
struct list_head *pages,
unsigned nr_pages );
static int me2fsWritePage( struct page *page, struct writeback_control *wbc );
static int me2fsWriteBegin( struct file *file,
struct address_space *mapping,
loff_t pos,
unsigned len,
unsigned flags,
struct page **pagep,
void **fsdata );
static int me2fsWriteEnd( struct file *file,
struct address_space *mapping,
loff_t pos,
unsigned len,
unsigned copied,
struct page *page,
void *fsdata );
static int me2fsWritePages( struct address_space *mapping,
struct writeback_control *wbc );
static sector_t me2fsBmap( struct address_space *mapping, sector_t block );
static ssize_t
me2fsDirectIO( int rw,
struct kiocb *iocb,
struct iov_iter *iter,
loff_t offset );
/*
----------------------------------------------------------------------------------
Helper Functions for Inode
----------------------------------------------------------------------------------
*/
static struct ext2_inode*
me2fsGetExt2Inode( struct super_block *sb,
unsigned long ino,
struct buffer_head **bhp );
static int
me2fsBlockToPath( struct inode *inode,
unsigned long i_block,
int offsets[ 4 ],
int *boundary );
static Indirect*
me2fsGetBranch( struct inode *inode,
int depth,
int *offsets,
Indirect chain[ 4 ],
int *err );
static inline int
verifyIndirectChain( Indirect *from, Indirect *to );
static int me2fsGetBlocks( struct inode *inode,
sector_t iblock,
unsigned long maxblocks,
struct buffer_head *bh_result,
int create );
static inline void addChain( Indirect *p, struct buffer_head *bh, __le32 *v );
static int
__me2fsWriteInode( struct inode *inode, int do_sync );
static int allocBranch( struct inode *inode,
int indirect_blks,
int *blks,
unsigned long goal,
int *offsets,
Indirect *branch );
static void spliceBranch( struct inode *inode,
long block,
Indirect *where,
int num,
int blks );
static unsigned long
findNear( struct inode *inode, Indirect *ind );
static inline unsigned long
findGoal( struct inode *inode, long block, Indirect *partial );
static inline int
isInodeFastSymlink( struct inode *inode );
static void truncateBlocks( struct inode *inode, loff_t offset );
static void __truncateBlocks( struct inode *inode, loff_t offset );
static inline void
freeData( struct inode *inode, __le32 *blocks, __le32 *end_block );
static Indirect*
findShared( struct inode *inode,
int depth,
int offsets[ 4 ],
Indirect chain[ 4 ],
__le32 *top );
static inline int
searchFirstNonZero( __le32 *cur, __le32 *end );
static void
freeBranches( struct inode *inode,
__le32 *cur,
__le32 *end,
int depth );
static int setInodeSize( struct inode *inode, loff_t newsize );
static void writeFailed( struct address_space *mapping, loff_t size );
static unsigned long
blocksToAllocate( Indirect *branch,
int k,
unsigned long blks,
int blocks_to_boundary );
static int allocBlocks( struct inode *inode,
unsigned long goal,
int indirect_blks,
int blks,
unsigned long new_blocks[ 4 ],
int *err );
/*
==================================================================================
Management
==================================================================================
*/
//static int me2fsReadPage( struct file *file, struct page *page )
//{ DBGPRINT( "<ME2FS>AOPS:readpage!\n" ); return 0; }
//static int me2fsReadPages( struct file *filp, struct address_space *mapping,
// struct list_head *pages, unsigned nr_pages )
//{ DBGPRINT( "<ME2FS>AOPS:readpages 2!\n" ); return 0; }
#if 0
static int me2fsWritePage( struct page *page, struct writeback_control *wbc )
{ DBGPRINT( "<ME2FS>AOPS:writepage!\n" ); return 0; }
static int me2fsWriteBegin( struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata )
{ DBGPRINT( "<ME2FS>AOPS:write_begin!\n" ); return 0; }
static int me2fsWriteEnd( struct file *file, struct address_space *mapping,
loff_t pos, unsigned len,
unsigned copied, struct page *page, void *fsdata )
{ DBGPRINT( "<ME2FS>AOPS:write_end!\n" ); return 0; }
#endif
//static sector_t me2fsBmap( struct address_space *mapping, sector_t sec )
//{ DBGPRINT( "<ME2FS>AOPS:bmap!\n" ); return 0; }
#if 0
static int me2fsWritePages( struct address_space *mapping,
struct writeback_control *wbc )
{ DBGPRINT( "<ME2FS>AOPS:writepages 2!\n" ); return 0; }
#endif
/*
---------------------------------------------------------------------------------
Address Space Operations
---------------------------------------------------------------------------------
*/
const struct address_space_operations me2fs_aops =
{
.readpage = me2fsReadPage,
.readpages = me2fsReadPages,
.writepage = me2fsWritePage,
.write_begin = me2fsWriteBegin,
.write_end = me2fsWriteEnd,
.bmap = me2fsBmap,
.direct_IO = me2fsDirectIO,
.writepages = me2fsWritePages,
.migratepage = buffer_migrate_page,
.is_partially_uptodate = block_is_partially_uptodate,
.error_remove_page = generic_error_remove_page,
};
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< Open Functions >
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsGetVfsInode
Input :struct super_block *sb
< vfs super block >
unsigned int ino
< inode number for allocating new inode >
Output :void
Return :struct inode *inode
< vfs inode >
Description :allocate me2fs inode info, get locked vfs inode, read ext2 inode
from a disk and fill them
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
struct inode *me2fsGetVfsInode( struct super_block *sb, unsigned int ino )
{
struct inode *inode;
struct me2fs_inode_info *mei;
struct ext2_inode *ext2_inode;
struct buffer_head *bh;
uid_t i_uid;
gid_t i_gid;
int i;
/* ------------------------------------------------------------------------ */
/* find an inode cache or allocate inode and lock it */
/* ------------------------------------------------------------------------ */
inode = iget_locked( sb, ino );
if( !inode )
{
return( ERR_PTR( -ENOMEM ) );
}
/* ------------------------------------------------------------------------ */
/* get an inode which has already existed */
/* ------------------------------------------------------------------------ */
if( !( inode->i_state & I_NEW ) )
{
return( inode );
}
/* ------------------------------------------------------------------------ */
/* read ext2 inode */
/* ------------------------------------------------------------------------ */
mei = ME2FS_I( inode );
mei->i_block_alloc_info = NULL;
ext2_inode = me2fsGetExt2Inode( inode->i_sb, ino, &bh );
if( IS_ERR( ext2_inode ) )
{
iget_failed( inode );
return( ( struct inode* )( ext2_inode ) );
}
dbgPrintExt2InodeInfo( ext2_inode );
/* ------------------------------------------------------------------------ */
/* set up vfs inode */
/* ------------------------------------------------------------------------ */
inode->i_mode = le16_to_cpu( ext2_inode->i_mode );
i_uid = ( uid_t )le16_to_cpu( ext2_inode->i_uid ); // low bytes
i_gid = ( gid_t )le16_to_cpu( ext2_inode->i_gid ); // low bytes
if( ME2FS_SB( sb )->s_mount_opt & EXT2_MOUNT_NO_UID32 )
{
/* do nothing */
}
else
{
i_uid |= le16_to_cpu( ext2_inode->osd2.linux2.l_i_uid_high ) << 16;
i_gid |= le16_to_cpu( ext2_inode->osd2.linux2.l_i_gid_high ) << 16;
}
i_uid_write( inode, i_uid );
i_gid_write( inode, i_gid );
set_nlink( inode, le16_to_cpu( ext2_inode->i_links_count ) );
inode->i_size = le32_to_cpu( ext2_inode->i_size );
inode->i_atime.tv_sec = ( signed int )le32_to_cpu( ext2_inode->i_atime );
inode->i_ctime.tv_sec = ( signed int )le32_to_cpu( ext2_inode->i_ctime );
inode->i_mtime.tv_sec = ( signed int )le32_to_cpu( ext2_inode->i_mtime );
inode->i_atime.tv_nsec = 0;
inode->i_ctime.tv_nsec = 0;
inode->i_mtime.tv_nsec = 0;
mei->i_dtime = le32_to_cpu( ext2_inode->i_dtime );
if( ( inode->i_nlink == 0 ) &&
( ( inode->i_mode == 0 ) || ( mei->i_dtime ) ) )
{
brelse( bh );
iget_failed( inode );
return( ERR_PTR( -ESTALE ) );
}
inode->i_blocks = le32_to_cpu( ext2_inode->i_blocks );
mei->i_flags = le32_to_cpu( ext2_inode->i_flags );
mei->i_faddr = le32_to_cpu( ext2_inode->i_faddr );
mei->i_frag_no = ext2_inode->osd2.linux2.l_i_frag;
mei->i_frag_size = ext2_inode->osd2.linux2.l_i_fsize;
mei->i_file_acl = le32_to_cpu( ext2_inode->i_file_acl );
mei->i_dir_acl = 0;
DBGPRINT( "[1]vfs i_size = %lu\n", ( unsigned long )inode->i_size );
if( S_ISREG( inode->i_mode ) )
{
/* use i_dir_acl higher 32 byte of file size */
inode->i_size |= ( ( __u64 )le32_to_cpu( ext2_inode->i_dir_acl ) )
<< 32;
}
else
{
mei->i_dir_acl = le32_to_cpu( ext2_inode->i_dir_acl );
}
DBGPRINT( "[2]vfs i_size = %lu\n", ( unsigned long )inode->i_size );
mei->i_dtime = 0;
inode->i_generation = le32_to_cpu( ext2_inode->i_generation );
mei->i_state = 0;
mei->i_block_group = ( ino - 1 ) / ME2FS_SB( sb )->s_inodes_per_group;
mei->i_dir_start_lookup = 0;
for( i = 0 ; i < ME2FS_NR_BLOCKS ; i++ )
{
mei->i_data[ i ] = ext2_inode->i_block[ i ];
}
if( S_ISREG( inode->i_mode ) )
{
inode->i_fop = &me2fs_file_operations;
inode->i_op = &me2fs_file_inode_operations;
inode->i_mapping->a_ops = &me2fs_aops;
}
else if( S_ISDIR( inode->i_mode ) )
{
DBGPRINT( "<ME2FS>get directory inode!\n" );
inode->i_fop = &me2fs_dir_operations;
inode->i_op = &me2fs_dir_inode_operations;
inode->i_mapping->a_ops = &me2fs_aops;
}
else if( S_ISLNK( inode->i_mode ) )
{
if( isInodeFastSymlink( inode ) )
{
inode->i_op = &me2fs_fast_symlink_inode_operations;
nd_terminate_link( mei->i_data,
inode->i_size,
sizeof( mei->i_data ) - 1 );
}
else
{
inode->i_op = &me2fs_symlink_inode_operations;
inode->i_mapping->a_ops = &me2fs_aops;
}
}
else
{
inode->i_op = &me2fs_special_inode_operations;
if( ext2_inode->i_block[ 0 ] )
{
init_special_inode( inode,
inode->i_mode,
old_decode_dev(
le32_to_cpu( ext2_inode->i_block[ 0 ] )
) );
}
else
{
init_special_inode( inode,
inode->i_mode,
new_decode_dev(
le32_to_cpu( ext2_inode->i_block[ 1 ] )
) );
}
}
brelse( bh );
me2fsSetVfsInodeFlags( inode );
//dbgPrintMe2fsInodeInfo( mei );
//dbgPrintVfsInode( inode );
unlock_new_inode( inode );
DBGPRINT( "[3]vfs i_size = %lu\n", ( unsigned long )inode->i_size );
return( inode );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsSetVfsInodeFlags
Input :struct inode *inode
< target vfs inode >
Output :struct inode *inode
< written to inode->i_flags >
Return :void
Description :write ext2 inode flags to vfs inode flags
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
void me2fsSetVfsInodeFlags( struct inode *inode )
{
unsigned int flags;
flags = ME2FS_I( inode )->i_flags;
inode->i_flags &= ~( S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC );
if( flags & EXT2_SYNC_FL )
{
inode->i_flags |= S_SYNC;
}
if( flags & EXT2_APPEND_FL )
{
inode->i_flags |= S_APPEND;
}
if( flags & EXT2_IMMUTABLE_FL )
{
inode->i_flags |= S_IMMUTABLE;
}
if( flags & EXT2_NOATIME_FL )
{
inode->i_flags |= S_NOATIME;
}
if( flags & EXT2_DIRSYNC_FL )
{
inode->i_flags |= S_DIRSYNC;
}
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsSetMe2fsInodeFlags
Input :struct me2fs_inode_info *mei
< me2fs inode information >
Output :struct me2fs_inode_info *mei
< written to i_flags >
Return :void
Description :write vfs inode flags to ext2 inode flags
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
void me2fsSetMe2fsInodeFlags( struct me2fs_inode_info *mei )
{
unsigned int flags;
flags = mei->vfs_inode.i_flags;
mei->i_flags &= ~( EXT2_SYNC_FL | EXT2_APPEND_FL | EXT2_IMMUTABLE_FL |
EXT2_NOATIME_FL | EXT2_DIRSYNC_FL );
if( flags & S_SYNC )
{
mei->i_flags |= EXT2_SYNC_FL;
}
if( flags & S_APPEND )
{
mei->i_flags |= EXT2_APPEND_FL;
}
if( flags & S_IMMUTABLE )
{
mei->i_flags |= EXT2_IMMUTABLE_FL;
}
if( flags & S_NOATIME )
{
mei->i_flags |= EXT2_NOATIME_FL;
}
if( flags & S_DIRSYNC )
{
mei->i_flags |= EXT2_DIRSYNC_FL;
}
}
/*
----------------------------------------------------------------------------------
Superblock Operations
----------------------------------------------------------------------------------
*/
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsWriteInode
Input :struct inode *inode
< vfs inode >
struct writeback_control *wbc
< write back information >
Output :void
Return :int
< result >
Description :commit writing an inode
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
int me2fsWriteInode( struct inode *inode, struct writeback_control *wbc )
{
DBGPRINT( "<ME2FS>%s:ino=%lu\n", __func__, ( unsigned long )inode->i_ino );
return( __me2fsWriteInode( inode, wbc->sync_mode == WB_SYNC_ALL ) );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsEvictInode
Input :struct inode *inode
Output :void
Return :void
Description :evict inode
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
void me2fsEvictInode( struct inode *inode )
{
struct ext2_block_alloc_info *rsv;
int want_delete;
if( !inode->i_nlink && !is_bad_inode( inode ) )
{
want_delete = 1;
}
else
{
want_delete = 0;
}
DBGPRINT( "<ME2FS>%s:info:evict inode [%lu]\n",
__func__, ( unsigned long )inode->i_ino );
/* ------------------------------------------------------------------------ */
/* truncate page cache */
/* ------------------------------------------------------------------------ */
truncate_inode_pages( &inode->i_data, 0 );
//DBGPRINT( "<ME2FS>%s:info:end truncate_inode_pages\n", __func__ );
//DBGPRINT( "<ME2FS>%s:info:want_delete(%d)\n", __func__, want_delete );
if( want_delete )
{
/* -------------------------------------------------------------------- */
/* wait until super block is unfreezed */
/* -------------------------------------------------------------------- */
sb_start_intwrite( inode->i_sb );
ME2FS_I( inode )->i_dtime = get_seconds( );
mark_inode_dirty( inode );
/* if IS_SYNC or IS_DIRSYNC, then needs sync */
__me2fsWriteInode( inode, inode_needs_sync( inode ) );
/* truncate to 0 */
inode->i_size = 0;
if( inode->i_blocks )
{
//DBGPRINT( "<ME2FS>%s:info:start truncateBlocks\n", __func__ );
/* ---------------------------------------------------------------- */
/* truncate blocks of disk */
/* ---------------------------------------------------------------- */
truncateBlocks( inode, 0 );
//DBGPRINT( "<ME2FS>%s:info:end truncateBlocks\n", __func__ );
}
}
invalidate_inode_buffers( inode );
clear_inode( inode );
me2fsDiscardReservation( inode );
rsv = ME2FS_I( inode )->i_block_alloc_info;
ME2FS_I( inode )->i_block_alloc_info = NULL;
if( unlikely( rsv ) )
{
kfree( rsv );
}
if( want_delete )
{
//DBGPRINT( "<ME2FS>%s:info:start me2fsFreeInode\n", __func__ );
me2fsFreeInode( inode );
//DBGPRINT( "<ME2FS>%s:info:end me2fsFreeInode\n", __func__ );
sb_end_intwrite( inode->i_sb );
}
}
/*
----------------------------------------------------------------------------------
Inode Operations for Ext2 Inode
----------------------------------------------------------------------------------
*/
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsFiemap
Input :struct inode *inode
< vfs inode >
struct fiemap_extent_info *fieinfo
< file exent information >
u64 start
< initial block to map >
u64 len
< length of the extent to attempt to map >
Output :void
Return :int
< result >
Description :get file extent information
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
int me2fsFiemap( struct inode*inode,
struct fiemap_extent_info *fieinfo,
u64 start,
u64 len )
{
return( generic_block_fiemap( inode, fieinfo, start, len, me2fsGetBlock ) );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsSetAttr
Input :struct dentry *dentry
< vfs dentry >
iattr *iattr
< attribute of inode >
Output :void
Return :void
Description :set attribute to inode
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
int me2fsSetAttr( struct dentry *dentry, struct iattr *iattr )
{
struct inode *inode;
int error;
inode = dentry->d_inode;
DBGPRINT( "<ME2FS>%s:set attribute : name = %s, ino = %lu\n",
__func__, dentry->d_name.name, ( unsigned long )inode->i_ino );
if( ( error = inode_change_ok( inode, iattr ) ) )
{
return( error );
}
/* as for now, quota is not implemented */
if( ( iattr->ia_valid & ATTR_SIZE ) &&
( iattr->ia_size != inode->i_size ) )
{
if( ( error = setInodeSize( inode, iattr->ia_size ) ) )
{
return( error );
}
}
setattr_copy( inode, iattr );
/* as for now, acl is not implemented */
mark_inode_dirty( inode );
return( error );
}
/*
----------------------------------------------------------------------------------
Helper Functions
----------------------------------------------------------------------------------
*/
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :dbgPrintVfsInode
Input :struct inode *inode
< vfs inode >
Output :void
Return :void
Description :print vfs inode debug information
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
void dbgPrintVfsInode( struct inode *inode )
{
DBGPRINT( "<ME2FS>[vfs inode information]\n" );
DBGPRINT( "<ME2FS>i_no = %lu\n", ( unsigned long )inode->i_ino );
DBGPRINT( "<ME2FS>i_mode = %4X\n", inode->i_mode );
DBGPRINT( "<ME2FS>i_opflags = %u\n", inode->i_opflags );
DBGPRINT( "<ME2FS>i_uid = %u\n", __kuid_val( inode->i_uid ) );
DBGPRINT( "<ME2FS>i_gid = %u\n", __kgid_val( inode->i_gid ) );
DBGPRINT( "<ME2FS>i_flags = %u\n", inode->i_flags );
DBGPRINT( "<ME2FS>i_nlink = %u\n", inode->i_nlink );
DBGPRINT( "<ME2FS>i_rdev = %u\n", inode->i_rdev );
DBGPRINT( "<ME2FS>i_size = %llu\n", inode->i_size );
DBGPRINT( "<ME2FS>i_atime.tv_sec = %lu\n", inode->i_atime.tv_sec );
DBGPRINT( "<ME2FS>i_atime.tv_nsec = %lu\n", inode->i_atime.tv_nsec );
DBGPRINT( "<ME2FS>i_mtime.tv_sec = %lu\n", inode->i_mtime.tv_sec );
DBGPRINT( "<ME2FS>i_mtime.tv_nsec = %lu\n", inode->i_mtime.tv_nsec );
DBGPRINT( "<ME2FS>i_ctime.tv_sec = %lu\n", inode->i_ctime.tv_sec );
DBGPRINT( "<ME2FS>i_ctime.tv_nsec = %lu\n", inode->i_ctime.tv_nsec );
DBGPRINT( "<ME2FS>i_bytes = %u\n", inode->i_bytes );
DBGPRINT( "<ME2FS>i_blkbits = %u\n", inode->i_blkbits );
DBGPRINT( "<ME2FS>i_blocks = %lu\n", inode->i_blocks );
DBGPRINT( "<ME2FS>i_state = %lu\n", inode->i_state );
DBGPRINT( "<ME2FS>dirtied_when = %lu\n", inode->dirtied_when );
DBGPRINT( "<ME2FS>i_version = %llu\n", inode->i_version );
DBGPRINT( "<ME2FS>i_count = %d\n", atomic_read( &inode->i_count ) );
DBGPRINT( "<ME2FS>i_dio_count = %d\n", atomic_read( &inode->i_dio_count ) );
DBGPRINT( "<ME2FS>i_writecount = %d\n", atomic_read( &inode->i_writecount ) );
DBGPRINT( "<ME2FS>i_generation = %u\n", inode->i_generation );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :dbgPrintMe2fsInodeInfo
Input :struct me2fs_inode_info *mei
< me2fs ext2 inode information >
Output :void
Return :void
Description :print me2fs inode information
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
void dbgPrintMe2fsInodeInfo( struct me2fs_inode_info *mei )
{
int i;
unsigned int value;
DBGPRINT( "<ME2FS>[me2fs inode information]\n" );
DBGPRINT( "<ME2FS>i_no = %lu\n", ( unsigned long )mei->vfs_inode.i_ino );
DBGPRINT( "<ME2FS>i_data:\n" );
for( i = 0 ; i < ME2FS_NR_BLOCKS ; i++ )
{
value = le32_to_cpu( mei->i_data[ i ] );
DBGPRINT( "<ME2FS>i_data[%d] = %u\n", i, value );
}
DBGPRINT( "<ME2FS>i_flags = %u\n", mei->i_flags );
DBGPRINT( "<ME2FS>i_faddr = %u\n", mei->i_faddr );
DBGPRINT( "<ME2FS>i_frag_no = %u\n", ( unsigned int )mei->i_frag_no );
DBGPRINT( "<ME2FS>i_frag_size = %u\n", ( unsigned int )mei->i_frag_size );
DBGPRINT( "<ME2FS>i_state = %u\n", mei->i_state );
DBGPRINT( "<ME2FS>i_file_acl = %u\n", mei->i_file_acl );
DBGPRINT( "<ME2FS>i_dir_cl = %u\n", mei->i_dir_acl );
DBGPRINT( "<ME2FS>i_dtime = %u\n", mei->i_dtime );
DBGPRINT( "<ME2FS>i_block_group = %u\n", mei->i_block_group );
DBGPRINT( "<ME2FS>i_dir_start_lookup = %u\n", mei->i_dir_start_lookup );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :dbgPrintExt2InodeInfo
Input :struct ext2_inode *ei
< ext2 inode >
Output :void
Return :void
Description :print ext2 inode debug information
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
void dbgPrintExt2InodeInfo( struct ext2_inode *ei )
{
int i;
unsigned int value;
DBGPRINT( "<ME2FS>[ext2 inode information]\n" );
value = le16_to_cpu( ei->i_mode );
DBGPRINT( "<ME2FS>i_mode = %4X\n", value );
value = le16_to_cpu( ei->i_uid );
DBGPRINT( "<ME2FS>i_uid = %u\n", value );
value = le32_to_cpu( ei->i_size );
DBGPRINT( "<ME2FS>i_size = %u\n", value );
value = le32_to_cpu( ei->i_atime );
DBGPRINT( "<ME2FS>i_atime = %u\n", value );
value = le32_to_cpu( ei->i_ctime );
DBGPRINT( "<ME2FS>i_ctime = %u\n", value );
value = le32_to_cpu( ei->i_mtime );
DBGPRINT( "<ME2FS>i_mtime = %u\n", value );
value = le32_to_cpu( ei->i_dtime );
DBGPRINT( "<ME2FS>i_dtime = %u\n", value );
value = le16_to_cpu( ei->i_gid );
DBGPRINT( "<ME2FS>i_gid = %u\n", value );
value = le16_to_cpu( ei->i_links_count );
DBGPRINT( "<ME2FS>i_links_count = %u\n", value );
value = le32_to_cpu( ei->i_blocks );
DBGPRINT( "<ME2FS>i_blocks = %u\n", value );
value = le32_to_cpu( ei->i_flags );
DBGPRINT( "<ME2FS>i_flags = %u\n", value );
DBGPRINT( "<ME2FS>i_block:\n" );
for( i = 0 ; i < ME2FS_NR_BLOCKS ; i++ )
{
value = le32_to_cpu( ei->i_block[ i ] );
DBGPRINT( "<ME2FS>i_block[ %d ] = %u\n", i, value );
}
value = le32_to_cpu( ei->i_generation );
DBGPRINT( "<ME2FS>i_generation = %u\n", value );
value = le32_to_cpu( ei->i_file_acl );
DBGPRINT( "<ME2FS>i_file_acl = %u\n", value );
value = le32_to_cpu( ei->i_dir_acl );
DBGPRINT( "<ME2FS>i_dir_acl = %u\n", value );
value = le32_to_cpu( ei->i_faddr );
DBGPRINT( "<ME2FS>i_faddr = %u\n", value );
DBGPRINT( "<ME2FS>l_i_frag = %u\n",
( unsigned int )ei->osd2.linux2.l_i_frag );
DBGPRINT( "<ME2FS>l_i_fsize = %u\n",
( unsigned int )ei->osd2.linux2.l_i_fsize );
value = le16_to_cpu( ei->osd2.linux2.l_i_uid_high );
DBGPRINT( "<ME2FS>l_i_uid_high = %u\n", value );
value = le16_to_cpu( ei->osd2.linux2.l_i_gid_high );
DBGPRINT( "<ME2FS>l_i_gid_high = %u\n", value );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :me2fsGetBlock
Input :struct inode *inode
< vfs inode >
sector_t iblock
< block number in file >
struct buffer_head *bh_result
< buffer cache for the block >
int create
< 0 : plain lookup, 1 : creation >
Output :struct buffer_head *bh_result
< buffer cache for the block >
Return :int
< result >
Description :get block in file or allocate block for file
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
int me2fsGetBlock( struct inode *inode,
sector_t iblock,
struct buffer_head *bh_result,
int create )
{
unsigned long maxblocks;
int ret;
if( !inode )
{
ME2FS_ERROR( "<ME2FS>%s:inode is null!\n", __func__ );
return( 0 );
}
//DBGPRINT( "<ME2FS>%s:inode info:\n", __func__ );
//DBGPRINT( "<ME2FS>ino=%lu iblock=%lu\n",
// inode->i_ino, ( unsigned long )iblock );
maxblocks = bh_result->b_size >> inode->i_blkbits;
ret = me2fsGetBlocks( inode, iblock, maxblocks, bh_result, create );
if( 0 < ret )
{
bh_result->b_size = ( ret << inode->i_blkbits );
ret = 0;
}
return( ret );
}
/*
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Function :void
Input :void
Output :void
Return :void
Description :
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*/
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< Local Functions >
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
/*
----------------------------------------------------------------------------------
Address Space Operations for Ext2 Inode
----------------------------------------------------------------------------------
*/
/*
==================================================================================
Function :me2fsReadPage
Input :struct file *filp
< vfs file object >
struct page *page
< information of page to be filled with data >
Output :void
Return :int
< result >
Description : make read request and fill data to buffer cache
==================================================================================
*/
static int me2fsReadPage( struct file *filp, struct page *page )
{
DBGPRINT( "<ME2FS>read page\n" );
return( mpage_readpage( page, me2fsGetBlock ) );
}
/*
==================================================================================
Function :me2fsReadPages
Input :struct file *filp
< vfs file object >
struct address_space *mapping >
< address space associated with the file >
struct list_head *pages
< information of pages to be filled with read data >
unsigned nr_pages
< number of pages >
Output :void
Return :void
Description :make multiple read requests and fill data to buffer cache
==================================================================================
*/
static int me2fsReadPages( struct file *filp,
struct address_space *mapping,
struct list_head *pages,
unsigned nr_pages )
{
DBGPRINT( "<ME2FS>read page[s]\n" );
DBGPRINT( "vfs i_size = %lu\n", ( unsigned long )filp->f_inode->i_size );
return( mpage_readpages( mapping, pages, nr_pages, me2fsGetBlock ) );
}
/*
==================================================================================
Function :me2fsWritePage
Input :struct page *page
< page cache >
struct writeback_control *wbc
< writeback control information >
Output :void
Return :int
< result >
Description :make a write back request of a page cache
==================================================================================
*/
static int me2fsWritePage( struct page *page, struct writeback_control *wbc )
{
DBGPRINT( "<ME2FS>write page\n" );
return( block_write_full_page( page, me2fsGetBlock, wbc ) );
}
/*
==================================================================================
Function :me2fsWriteBegin
Input :struct file *file
< vfs file object >
struct address_space *mapping
< address space asociated with the file >
loff_t pos
< position in a file >
unsigned len
< write size >
unsigned flags
< write flags >
struct page **pagep
< pages to be initialized >
void **fsdata
< file system specific data >
Output :void
Return :int
< result >
Description :prepare pages to write back
==================================================================================
*/
static int me2fsWriteBegin( struct file *file,
struct address_space *mapping,
loff_t pos,