This source file includes following definitions.
- ubifs_authenticated
- ubifs_hash_get_desc
- ubifs_shash_init
- ubifs_shash_update
- ubifs_shash_final
- ubifs_node_calc_hash
- ubifs_check_hash
- ubifs_check_hmac
- ubifs_node_check_hash
- ubifs_exit_authentication
- ubifs_branch_hash
- ubifs_copy_hash
- ubifs_node_insert_hmac
- ubifs_node_verify_hmac
- ubifs_auth_node_sz
- ubifs_shash_copy_state
- ubifs_evict_xattr_inode
- ubifs_purge_xattrs
- ubifs_init_security
- ubifs_encrypt
- ubifs_decrypt
- ubifs_crypt_is_encrypted
1
2
3
4
5
6
7
8
9
10
11 #ifndef __UBIFS_H__
12 #define __UBIFS_H__
13
14 #include <asm/div64.h>
15 #include <linux/statfs.h>
16 #include <linux/fs.h>
17 #include <linux/err.h>
18 #include <linux/sched.h>
19 #include <linux/slab.h>
20 #include <linux/vmalloc.h>
21 #include <linux/spinlock.h>
22 #include <linux/mutex.h>
23 #include <linux/rwsem.h>
24 #include <linux/mtd/ubi.h>
25 #include <linux/pagemap.h>
26 #include <linux/backing-dev.h>
27 #include <linux/security.h>
28 #include <linux/xattr.h>
29 #include <linux/random.h>
30 #include <crypto/hash_info.h>
31 #include <crypto/hash.h>
32 #include <crypto/algapi.h>
33
34 #include <linux/fscrypt.h>
35
36 #include "ubifs-media.h"
37
38
39 #define UBIFS_VERSION 1
40
41
42 #define UBIFS_SUPER_MAGIC 0x24051905
43
44
45 #define UBIFS_BLOCKS_PER_PAGE (PAGE_SIZE / UBIFS_BLOCK_SIZE)
46 #define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_SHIFT - UBIFS_BLOCK_SHIFT)
47
48
49 #define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
50 #define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL
51
52
53
54
55
56
57
58 #define MIN_INDEX_LEBS 2
59
60
61 #define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
62
63
64
65
66
67
68
69 #define INUM_WARN_WATERMARK 0xFFF00000
70 #define INUM_WATERMARK 0xFFFFFF00
71
72
73 #define LPT_HEAP_SZ 256
74
75
76
77
78
79 #define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
80
81
82 #define MAX_INUM 0xFFFFFFFF
83
84
85 #define NONDATA_JHEADS_CNT 2
86
87
88 #define GCHD UBIFS_GC_HEAD
89 #define BASEHD UBIFS_BASE_HEAD
90 #define DATAHD UBIFS_DATA_HEAD
91
92
93 #define LPROPS_NC 0x80000001
94
95
96
97
98
99
100
101
102
103
104 #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT
105 #define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT
106
107
108
109
110
111 #define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
112
113
114 #define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
115
116
117
118
119
120
121
122 #define OLD_ZNODE_AGE 20
123 #define YOUNG_ZNODE_AGE 5
124
125
126
127
128
129
130 #define WORST_COMPR_FACTOR 2
131
132 #ifdef CONFIG_FS_ENCRYPTION
133 #define UBIFS_CIPHER_BLOCK_SIZE FS_CRYPTO_BLOCK_SIZE
134 #else
135 #define UBIFS_CIPHER_BLOCK_SIZE 0
136 #endif
137
138
139
140
141 #define COMPRESSED_DATA_NODE_BUF_SZ \
142 (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR)
143
144
145 #define BOTTOM_UP_HEIGHT 64
146
147
148 #define UBIFS_MAX_BULK_READ 32
149
150 #ifdef CONFIG_UBIFS_FS_AUTHENTICATION
151 #define UBIFS_HASH_ARR_SZ UBIFS_MAX_HASH_LEN
152 #define UBIFS_HMAC_ARR_SZ UBIFS_MAX_HMAC_LEN
153 #else
154 #define UBIFS_HASH_ARR_SZ 0
155 #define UBIFS_HMAC_ARR_SZ 0
156 #endif
157
158
159
160
161 enum {
162 WB_MUTEX_1 = 0,
163 WB_MUTEX_2 = 1,
164 WB_MUTEX_3 = 2,
165 WB_MUTEX_4 = 3,
166 };
167
168
169
170
171
172
173
174
175
176
177
178 enum {
179 DIRTY_ZNODE = 0,
180 COW_ZNODE = 1,
181 OBSOLETE_ZNODE = 2,
182 };
183
184
185
186
187
188
189
190
191
192
193
194 enum {
195 COMMIT_RESTING = 0,
196 COMMIT_BACKGROUND,
197 COMMIT_REQUIRED,
198 COMMIT_RUNNING_BACKGROUND,
199 COMMIT_RUNNING_REQUIRED,
200 COMMIT_BROKEN,
201 };
202
203
204
205
206
207
208
209
210
211
212
213
214 enum {
215 SCANNED_GARBAGE = 0,
216 SCANNED_EMPTY_SPACE = -1,
217 SCANNED_A_NODE = -2,
218 SCANNED_A_CORRUPT_NODE = -3,
219 SCANNED_A_BAD_PAD_NODE = -4,
220 };
221
222
223
224
225
226
227
228
229
230 enum {
231 DIRTY_CNODE = 0,
232 OBSOLETE_CNODE = 1,
233 COW_CNODE = 2,
234 };
235
236
237
238
239
240
241
242 enum {
243 LTAB_DIRTY = 1,
244 LSAVE_DIRTY = 2,
245 };
246
247
248
249
250
251
252
253 enum {
254 LEB_FREED,
255 LEB_FREED_IDX,
256 LEB_RETAINED,
257 };
258
259
260
261
262
263
264
265 enum {
266 ASSACT_REPORT = 0,
267 ASSACT_RO,
268 ASSACT_PANIC,
269 };
270
271
272
273
274
275
276
277 struct ubifs_old_idx {
278 struct rb_node rb;
279 int lnum;
280 int offs;
281 };
282
283
284 union ubifs_key {
285 uint8_t u8[UBIFS_SK_LEN];
286 uint32_t u32[UBIFS_SK_LEN/4];
287 uint64_t u64[UBIFS_SK_LEN/8];
288 __le32 j32[UBIFS_SK_LEN/4];
289 };
290
291
292
293
294
295
296
297
298
299
300
301 struct ubifs_scan_node {
302 struct list_head list;
303 union ubifs_key key;
304 unsigned long long sqnum;
305 int type;
306 int offs;
307 int len;
308 void *node;
309 };
310
311
312
313
314
315
316
317
318
319 struct ubifs_scan_leb {
320 int lnum;
321 int nodes_cnt;
322 struct list_head nodes;
323 int endpt;
324 void *buf;
325 };
326
327
328
329
330
331
332
333
334
335
336
337 struct ubifs_gced_idx_leb {
338 struct list_head list;
339 int lnum;
340 int unmap;
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 struct ubifs_inode {
401 struct inode vfs_inode;
402 unsigned long long creat_sqnum;
403 unsigned long long del_cmtno;
404 unsigned int xattr_size;
405 unsigned int xattr_cnt;
406 unsigned int xattr_names;
407 unsigned int dirty:1;
408 unsigned int xattr:1;
409 unsigned int bulk_read:1;
410 unsigned int compr_type:2;
411 struct mutex ui_mutex;
412 spinlock_t ui_lock;
413 loff_t synced_i_size;
414 loff_t ui_size;
415 int flags;
416 pgoff_t last_page_read;
417 pgoff_t read_in_a_row;
418 int data_len;
419 void *data;
420 };
421
422
423
424
425
426
427
428
429
430
431
432 struct ubifs_unclean_leb {
433 struct list_head list;
434 int lnum;
435 int endpt;
436 };
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453 enum {
454 LPROPS_UNCAT = 0,
455 LPROPS_DIRTY = 1,
456 LPROPS_DIRTY_IDX = 2,
457 LPROPS_FREE = 3,
458 LPROPS_HEAP_CNT = 3,
459 LPROPS_EMPTY = 4,
460 LPROPS_FREEABLE = 5,
461 LPROPS_FRDI_IDX = 6,
462 LPROPS_CAT_MASK = 15,
463 LPROPS_TAKEN = 16,
464 LPROPS_INDEX = 32,
465 };
466
467
468
469
470
471
472
473
474
475
476 struct ubifs_lprops {
477 int free;
478 int dirty;
479 int flags;
480 int lnum;
481 union {
482 struct list_head list;
483 int hpos;
484 };
485 };
486
487
488
489
490
491
492
493
494 struct ubifs_lpt_lprops {
495 int free;
496 int dirty;
497 unsigned tgc:1;
498 unsigned cmt:1;
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 struct ubifs_lp_stats {
528 int empty_lebs;
529 int taken_empty_lebs;
530 int idx_lebs;
531 long long total_free;
532 long long total_dirty;
533 long long total_used;
534 long long total_dead;
535 long long total_dark;
536 };
537
538 struct ubifs_nnode;
539
540
541
542
543
544
545
546
547
548
549 struct ubifs_cnode {
550 struct ubifs_nnode *parent;
551 struct ubifs_cnode *cnext;
552 unsigned long flags;
553 int iip;
554 int level;
555 int num;
556 };
557
558
559
560
561
562
563
564
565
566
567
568 struct ubifs_pnode {
569 struct ubifs_nnode *parent;
570 struct ubifs_cnode *cnext;
571 unsigned long flags;
572 int iip;
573 int level;
574 int num;
575 struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
576 };
577
578
579
580
581
582
583
584
585
586 struct ubifs_nbranch {
587 int lnum;
588 int offs;
589 union {
590 struct ubifs_nnode *nnode;
591 struct ubifs_pnode *pnode;
592 struct ubifs_cnode *cnode;
593 };
594 };
595
596
597
598
599
600
601
602
603
604
605
606 struct ubifs_nnode {
607 struct ubifs_nnode *parent;
608 struct ubifs_cnode *cnext;
609 unsigned long flags;
610 int iip;
611 int level;
612 int num;
613 struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
614 };
615
616
617
618
619
620
621
622
623
624 struct ubifs_lpt_heap {
625 struct ubifs_lprops **arr;
626 int cnt;
627 int max_cnt;
628 };
629
630
631
632
633
634
635
636
637 enum {
638 LPT_SCAN_CONTINUE = 0,
639 LPT_SCAN_ADD = 1,
640 LPT_SCAN_STOP = 2,
641 };
642
643 struct ubifs_info;
644
645
646 typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
647 const struct ubifs_lprops *lprops,
648 int in_tree, void *data);
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 struct ubifs_wbuf {
682 struct ubifs_info *c;
683 void *buf;
684 int lnum;
685 int offs;
686 int avail;
687 int used;
688 int size;
689 int jhead;
690 int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
691 struct mutex io_mutex;
692 spinlock_t lock;
693 struct hrtimer timer;
694 unsigned int no_timer:1;
695 unsigned int need_sync:1;
696 int next_ino;
697 ino_t *inodes;
698 };
699
700
701
702
703
704
705
706
707
708
709 struct ubifs_bud {
710 int lnum;
711 int start;
712 int jhead;
713 struct list_head list;
714 struct rb_node rb;
715 struct shash_desc *log_hash;
716 };
717
718
719
720
721
722
723
724
725
726
727 struct ubifs_jhead {
728 struct ubifs_wbuf wbuf;
729 struct list_head buds_list;
730 unsigned int grouped:1;
731 struct shash_desc *log_hash;
732 };
733
734
735
736
737
738
739
740
741
742
743 struct ubifs_zbranch {
744 union ubifs_key key;
745 union {
746 struct ubifs_znode *znode;
747 void *leaf;
748 };
749 int lnum;
750 int offs;
751 int len;
752 u8 hash[UBIFS_HASH_ARR_SZ];
753 };
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775 struct ubifs_znode {
776 struct ubifs_znode *parent;
777 struct ubifs_znode *cnext;
778 struct ubifs_znode *cparent;
779 int ciip;
780 unsigned long flags;
781 time64_t time;
782 int level;
783 int child_cnt;
784 int iip;
785 int alt;
786 int lnum;
787 int offs;
788 int len;
789 struct ubifs_zbranch zbranch[];
790 };
791
792
793
794
795
796
797
798
799
800
801
802
803 struct bu_info {
804 union ubifs_key key;
805 struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
806 void *buf;
807 int buf_len;
808 int gc_seq;
809 int cnt;
810 int blk_cnt;
811 int eof;
812 };
813
814
815
816
817
818
819
820
821
822 struct ubifs_node_range {
823 union {
824 int len;
825 int min_len;
826 };
827 int max_len;
828 };
829
830
831
832
833
834
835
836
837
838
839 struct ubifs_compressor {
840 int compr_type;
841 struct crypto_comp *cc;
842 struct mutex *comp_mutex;
843 struct mutex *decomp_mutex;
844 const char *name;
845 const char *capi_name;
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 struct ubifs_budget_req {
883 unsigned int fast:1;
884 unsigned int recalculate:1;
885 #ifndef UBIFS_DEBUG
886 unsigned int new_page:1;
887 unsigned int dirtied_page:1;
888 unsigned int new_dent:1;
889 unsigned int mod_dent:1;
890 unsigned int new_ino:1;
891 unsigned int new_ino_d:13;
892 unsigned int dirtied_ino:4;
893 unsigned int dirtied_ino_d:15;
894 #else
895
896 unsigned int new_page;
897 unsigned int dirtied_page;
898 unsigned int new_dent;
899 unsigned int mod_dent;
900 unsigned int new_ino;
901 unsigned int new_ino_d;
902 unsigned int dirtied_ino;
903 unsigned int dirtied_ino_d;
904 #endif
905 int idx_growth;
906 int data_growth;
907 int dd_growth;
908 };
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924 struct ubifs_orphan {
925 struct rb_node rb;
926 struct list_head list;
927 struct list_head new_list;
928 struct list_head child_list;
929 struct ubifs_orphan *cnext;
930 struct ubifs_orphan *dnext;
931 ino_t inum;
932 unsigned new:1;
933 unsigned cmt:1;
934 unsigned del:1;
935 };
936
937
938
939
940
941
942
943
944
945
946
947
948
949 struct ubifs_mount_opts {
950 unsigned int unmount_mode:2;
951 unsigned int bulk_read:2;
952 unsigned int chk_data_crc:2;
953 unsigned int override_compr:1;
954 unsigned int compr_type:2;
955 };
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977 struct ubifs_budg_info {
978 long long idx_growth;
979 long long data_growth;
980 long long dd_growth;
981 long long uncommitted_idx;
982 unsigned long long old_idx_sz;
983 int min_idx_lebs;
984 unsigned int nospace:1;
985 unsigned int nospace_rp:1;
986 int page_budget;
987 int inode_budget;
988 int dent_budget;
989 };
990
991 struct ubifs_debug_info;
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253 struct ubifs_info {
1254 struct super_block *vfs_sb;
1255 struct ubifs_sb_node *sup_node;
1256
1257 ino_t highest_inum;
1258 unsigned long long max_sqnum;
1259 unsigned long long cmt_no;
1260 spinlock_t cnt_lock;
1261 int fmt_version;
1262 int ro_compat_version;
1263 unsigned char uuid[16];
1264
1265 int lhead_lnum;
1266 int lhead_offs;
1267 int ltail_lnum;
1268 struct mutex log_mutex;
1269 int min_log_bytes;
1270 long long cmt_bud_bytes;
1271
1272 struct rb_root buds;
1273 long long bud_bytes;
1274 spinlock_t buds_lock;
1275 int jhead_cnt;
1276 struct ubifs_jhead *jheads;
1277 long long max_bud_bytes;
1278 long long bg_bud_bytes;
1279 struct list_head old_buds;
1280 int max_bud_cnt;
1281
1282 struct rw_semaphore commit_sem;
1283 int cmt_state;
1284 spinlock_t cs_lock;
1285 wait_queue_head_t cmt_wq;
1286
1287 unsigned int big_lpt:1;
1288 unsigned int space_fixup:1;
1289 unsigned int double_hash:1;
1290 unsigned int encrypted:1;
1291 unsigned int no_chk_data_crc:1;
1292 unsigned int bulk_read:1;
1293 unsigned int default_compr:2;
1294 unsigned int rw_incompat:1;
1295 unsigned int assert_action:2;
1296 unsigned int authenticated:1;
1297 unsigned int superblock_need_write:1;
1298
1299 struct mutex tnc_mutex;
1300 struct ubifs_zbranch zroot;
1301 struct ubifs_znode *cnext;
1302 struct ubifs_znode *enext;
1303 int *gap_lebs;
1304 void *cbuf;
1305 void *ileb_buf;
1306 int ileb_len;
1307 int ihead_lnum;
1308 int ihead_offs;
1309 int *ilebs;
1310 int ileb_cnt;
1311 int ileb_nxt;
1312 struct rb_root old_idx;
1313 int *bottom_up_buf;
1314
1315 struct ubifs_mst_node *mst_node;
1316 int mst_offs;
1317
1318 int max_bu_buf_len;
1319 struct mutex bu_mutex;
1320 struct bu_info bu;
1321
1322 struct mutex write_reserve_mutex;
1323 void *write_reserve_buf;
1324
1325 int log_lebs;
1326 long long log_bytes;
1327 int log_last;
1328 int lpt_lebs;
1329 int lpt_first;
1330 int lpt_last;
1331 int orph_lebs;
1332 int orph_first;
1333 int orph_last;
1334 int main_lebs;
1335 int main_first;
1336 long long main_bytes;
1337
1338 uint8_t key_hash_type;
1339 uint32_t (*key_hash)(const char *str, int len);
1340 int key_fmt;
1341 int key_len;
1342 int hash_len;
1343 int fanout;
1344
1345 int min_io_size;
1346 int min_io_shift;
1347 int max_write_size;
1348 int max_write_shift;
1349 int leb_size;
1350 int leb_start;
1351 int half_leb_size;
1352 int idx_leb_size;
1353 int leb_cnt;
1354 int max_leb_cnt;
1355 unsigned int ro_media:1;
1356 unsigned int ro_mount:1;
1357 unsigned int ro_error:1;
1358
1359 atomic_long_t dirty_pg_cnt;
1360 atomic_long_t dirty_zn_cnt;
1361 atomic_long_t clean_zn_cnt;
1362
1363 spinlock_t space_lock;
1364 struct ubifs_lp_stats lst;
1365 struct ubifs_budg_info bi;
1366 unsigned long long calc_idx_sz;
1367
1368 int ref_node_alsz;
1369 int mst_node_alsz;
1370 int min_idx_node_sz;
1371 int max_idx_node_sz;
1372 long long max_inode_sz;
1373 int max_znode_sz;
1374
1375 int leb_overhead;
1376 int dead_wm;
1377 int dark_wm;
1378 int block_cnt;
1379
1380 struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
1381 struct ubi_volume_desc *ubi;
1382 struct ubi_device_info di;
1383 struct ubi_volume_info vi;
1384
1385 struct rb_root orph_tree;
1386 struct list_head orph_list;
1387 struct list_head orph_new;
1388 struct ubifs_orphan *orph_cnext;
1389 struct ubifs_orphan *orph_dnext;
1390 spinlock_t orphan_lock;
1391 void *orph_buf;
1392 int new_orphans;
1393 int cmt_orphans;
1394 int tot_orphans;
1395 int max_orphans;
1396 int ohead_lnum;
1397 int ohead_offs;
1398 int no_orphs;
1399
1400 struct task_struct *bgt;
1401 char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
1402 int need_bgt;
1403 int need_wbuf_sync;
1404
1405 int gc_lnum;
1406 void *sbuf;
1407 struct list_head idx_gc;
1408 int idx_gc_cnt;
1409 int gc_seq;
1410 int gced_lnum;
1411
1412 struct list_head infos_list;
1413 struct mutex umount_mutex;
1414 unsigned int shrinker_run_no;
1415
1416 int space_bits;
1417 int lpt_lnum_bits;
1418 int lpt_offs_bits;
1419 int lpt_spc_bits;
1420 int pcnt_bits;
1421 int lnum_bits;
1422 int nnode_sz;
1423 int pnode_sz;
1424 int ltab_sz;
1425 int lsave_sz;
1426 int pnode_cnt;
1427 int nnode_cnt;
1428 int lpt_hght;
1429 int pnodes_have;
1430
1431 struct mutex lp_mutex;
1432 int lpt_lnum;
1433 int lpt_offs;
1434 int nhead_lnum;
1435 int nhead_offs;
1436 int lpt_drty_flgs;
1437 int dirty_nn_cnt;
1438 int dirty_pn_cnt;
1439 int check_lpt_free;
1440 long long lpt_sz;
1441 void *lpt_nod_buf;
1442 void *lpt_buf;
1443 struct ubifs_nnode *nroot;
1444 struct ubifs_cnode *lpt_cnext;
1445 struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
1446 struct ubifs_lpt_heap dirty_idx;
1447 struct list_head uncat_list;
1448 struct list_head empty_list;
1449 struct list_head freeable_list;
1450 struct list_head frdi_idx_list;
1451 int freeable_cnt;
1452 int in_a_category_cnt;
1453
1454 int ltab_lnum;
1455 int ltab_offs;
1456 struct ubifs_lpt_lprops *ltab;
1457 struct ubifs_lpt_lprops *ltab_cmt;
1458 int lsave_cnt;
1459 int lsave_lnum;
1460 int lsave_offs;
1461 int *lsave;
1462 int lscan_lnum;
1463
1464 long long rp_size;
1465 long long report_rp_size;
1466 kuid_t rp_uid;
1467 kgid_t rp_gid;
1468
1469 struct crypto_shash *hash_tfm;
1470 struct crypto_shash *hmac_tfm;
1471 int hmac_desc_len;
1472 char *auth_key_name;
1473 char *auth_hash_name;
1474 enum hash_algo auth_hash_algo;
1475
1476 struct shash_desc *log_hash;
1477
1478
1479 unsigned int empty:1;
1480 unsigned int need_recovery:1;
1481 unsigned int replaying:1;
1482 unsigned int mounting:1;
1483 unsigned int remounting_rw:1;
1484 unsigned int probing:1;
1485 struct list_head replay_list;
1486 struct list_head replay_buds;
1487 unsigned long long cs_sqnum;
1488 struct list_head unclean_leb_list;
1489 struct ubifs_mst_node *rcvrd_mst_node;
1490 struct rb_root size_tree;
1491 struct ubifs_mount_opts mount_opts;
1492
1493 struct ubifs_debug_info *dbg;
1494 };
1495
1496 extern struct list_head ubifs_infos;
1497 extern spinlock_t ubifs_infos_lock;
1498 extern atomic_long_t ubifs_clean_zn_cnt;
1499 extern const struct super_operations ubifs_super_operations;
1500 extern const struct address_space_operations ubifs_file_address_operations;
1501 extern const struct file_operations ubifs_file_operations;
1502 extern const struct inode_operations ubifs_file_inode_operations;
1503 extern const struct file_operations ubifs_dir_operations;
1504 extern const struct inode_operations ubifs_dir_inode_operations;
1505 extern const struct inode_operations ubifs_symlink_inode_operations;
1506 extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
1507
1508
1509 static inline int ubifs_authenticated(const struct ubifs_info *c)
1510 {
1511 return (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) && c->authenticated;
1512 }
1513
1514 struct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c);
1515 static inline struct shash_desc *ubifs_hash_get_desc(const struct ubifs_info *c)
1516 {
1517 return ubifs_authenticated(c) ? __ubifs_hash_get_desc(c) : NULL;
1518 }
1519
1520 static inline int ubifs_shash_init(const struct ubifs_info *c,
1521 struct shash_desc *desc)
1522 {
1523 if (ubifs_authenticated(c))
1524 return crypto_shash_init(desc);
1525 else
1526 return 0;
1527 }
1528
1529 static inline int ubifs_shash_update(const struct ubifs_info *c,
1530 struct shash_desc *desc, const void *buf,
1531 unsigned int len)
1532 {
1533 int err = 0;
1534
1535 if (ubifs_authenticated(c)) {
1536 err = crypto_shash_update(desc, buf, len);
1537 if (err < 0)
1538 return err;
1539 }
1540
1541 return 0;
1542 }
1543
1544 static inline int ubifs_shash_final(const struct ubifs_info *c,
1545 struct shash_desc *desc, u8 *out)
1546 {
1547 return ubifs_authenticated(c) ? crypto_shash_final(desc, out) : 0;
1548 }
1549
1550 int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *buf,
1551 u8 *hash);
1552 static inline int ubifs_node_calc_hash(const struct ubifs_info *c,
1553 const void *buf, u8 *hash)
1554 {
1555 if (ubifs_authenticated(c))
1556 return __ubifs_node_calc_hash(c, buf, hash);
1557 else
1558 return 0;
1559 }
1560
1561 int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
1562 struct shash_desc *inhash);
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573 static inline int ubifs_check_hash(const struct ubifs_info *c,
1574 const u8 *expected, const u8 *got)
1575 {
1576 return crypto_memneq(expected, got, c->hash_len);
1577 }
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588 static inline int ubifs_check_hmac(const struct ubifs_info *c,
1589 const u8 *expected, const u8 *got)
1590 {
1591 return crypto_memneq(expected, got, c->hmac_desc_len);
1592 }
1593
1594 void ubifs_bad_hash(const struct ubifs_info *c, const void *node,
1595 const u8 *hash, int lnum, int offs);
1596
1597 int __ubifs_node_check_hash(const struct ubifs_info *c, const void *buf,
1598 const u8 *expected);
1599 static inline int ubifs_node_check_hash(const struct ubifs_info *c,
1600 const void *buf, const u8 *expected)
1601 {
1602 if (ubifs_authenticated(c))
1603 return __ubifs_node_check_hash(c, buf, expected);
1604 else
1605 return 0;
1606 }
1607
1608 int ubifs_init_authentication(struct ubifs_info *c);
1609 void __ubifs_exit_authentication(struct ubifs_info *c);
1610 static inline void ubifs_exit_authentication(struct ubifs_info *c)
1611 {
1612 if (ubifs_authenticated(c))
1613 __ubifs_exit_authentication(c);
1614 }
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624 static inline u8 *ubifs_branch_hash(struct ubifs_info *c,
1625 struct ubifs_branch *br)
1626 {
1627 return (void *)br + sizeof(*br) + c->key_len;
1628 }
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638 static inline void ubifs_copy_hash(const struct ubifs_info *c, const u8 *from,
1639 u8 *to)
1640 {
1641 if (ubifs_authenticated(c))
1642 memcpy(to, from, c->hash_len);
1643 }
1644
1645 int __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
1646 int len, int ofs_hmac);
1647 static inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
1648 int len, int ofs_hmac)
1649 {
1650 if (ubifs_authenticated(c))
1651 return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac);
1652 else
1653 return 0;
1654 }
1655
1656 int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf,
1657 int len, int ofs_hmac);
1658 static inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
1659 const void *buf, int len, int ofs_hmac)
1660 {
1661 if (ubifs_authenticated(c))
1662 return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac);
1663 else
1664 return 0;
1665 }
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675 static inline int ubifs_auth_node_sz(const struct ubifs_info *c)
1676 {
1677 if (ubifs_authenticated(c))
1678 return sizeof(struct ubifs_auth_node) + c->hmac_desc_len;
1679 else
1680 return 0;
1681 }
1682 int ubifs_sb_verify_signature(struct ubifs_info *c,
1683 const struct ubifs_sb_node *sup);
1684 bool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac);
1685
1686 int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac);
1687
1688 int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
1689 struct shash_desc *target);
1690 static inline int ubifs_shash_copy_state(const struct ubifs_info *c,
1691 struct shash_desc *src,
1692 struct shash_desc *target)
1693 {
1694 if (ubifs_authenticated(c))
1695 return __ubifs_shash_copy_state(c, src, target);
1696 else
1697 return 0;
1698 }
1699
1700
1701 void ubifs_ro_mode(struct ubifs_info *c, int err);
1702 int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
1703 int len, int even_ebadmsg);
1704 int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
1705 int len);
1706 int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
1707 int ubifs_leb_unmap(struct ubifs_info *c, int lnum);
1708 int ubifs_leb_map(struct ubifs_info *c, int lnum);
1709 int ubifs_is_mapped(const struct ubifs_info *c, int lnum);
1710 int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
1711 int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
1712 int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
1713 int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
1714 int lnum, int offs);
1715 int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
1716 int lnum, int offs);
1717 int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
1718 int offs);
1719 int ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum,
1720 int offs, int hmac_offs);
1721 int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
1722 int offs, int quiet, int must_chk_crc);
1723 void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad);
1724 void ubifs_crc_node(struct ubifs_info *c, void *buf, int len);
1725 void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
1726 int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
1727 int hmac_offs, int pad);
1728 void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
1729 int ubifs_io_init(struct ubifs_info *c);
1730 void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
1731 int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
1732 int ubifs_bg_wbufs_sync(struct ubifs_info *c);
1733 void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
1734 int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
1735
1736
1737 struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
1738 int offs, void *sbuf, int quiet);
1739 void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
1740 int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
1741 int offs, int quiet);
1742 struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
1743 int offs, void *sbuf);
1744 void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1745 int lnum, int offs);
1746 int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1747 void *buf, int offs);
1748 void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
1749 void *buf);
1750
1751
1752 void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
1753 void ubifs_create_buds_lists(struct ubifs_info *c);
1754 int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
1755 struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
1756 struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
1757 int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
1758 int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
1759 int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
1760 int ubifs_consolidate_log(struct ubifs_info *c);
1761
1762
1763 int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
1764 const struct fscrypt_name *nm, const struct inode *inode,
1765 int deletion, int xent);
1766 int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
1767 const union ubifs_key *key, const void *buf, int len);
1768 int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
1769 int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
1770 int ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir,
1771 const struct inode *fst_inode,
1772 const struct fscrypt_name *fst_nm,
1773 const struct inode *snd_dir,
1774 const struct inode *snd_inode,
1775 const struct fscrypt_name *snd_nm, int sync);
1776 int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
1777 const struct inode *old_inode,
1778 const struct fscrypt_name *old_nm,
1779 const struct inode *new_dir,
1780 const struct inode *new_inode,
1781 const struct fscrypt_name *new_nm,
1782 const struct inode *whiteout, int sync);
1783 int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
1784 loff_t old_size, loff_t new_size);
1785 int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
1786 const struct inode *inode, const struct fscrypt_name *nm);
1787 int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
1788 const struct inode *inode2);
1789
1790
1791 int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
1792 void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
1793 void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
1794 struct ubifs_inode *ui);
1795 int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
1796 struct ubifs_budget_req *req);
1797 void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
1798 struct ubifs_budget_req *req);
1799 void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
1800 struct ubifs_budget_req *req);
1801 long long ubifs_get_free_space(struct ubifs_info *c);
1802 long long ubifs_get_free_space_nolock(struct ubifs_info *c);
1803 int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
1804 void ubifs_convert_page_budget(struct ubifs_info *c);
1805 long long ubifs_reported_space(const struct ubifs_info *c, long long free);
1806 long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
1807
1808
1809 int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
1810 int squeeze);
1811 int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
1812 int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
1813 int min_space, int pick_free);
1814 int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
1815 int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
1816
1817
1818 int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
1819 struct ubifs_znode **zn, int *n);
1820 int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
1821 void *node, const struct fscrypt_name *nm);
1822 int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,
1823 void *node, uint32_t secondary_hash);
1824 int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
1825 void *node, int *lnum, int *offs);
1826 int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
1827 int offs, int len, const u8 *hash);
1828 int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
1829 int old_lnum, int old_offs, int lnum, int offs, int len);
1830 int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
1831 int lnum, int offs, int len, const u8 *hash,
1832 const struct fscrypt_name *nm);
1833 int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
1834 int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
1835 const struct fscrypt_name *nm);
1836 int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key,
1837 uint32_t cookie);
1838 int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
1839 union ubifs_key *to_key);
1840 int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
1841 struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
1842 union ubifs_key *key,
1843 const struct fscrypt_name *nm);
1844 void ubifs_tnc_close(struct ubifs_info *c);
1845 int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
1846 int lnum, int offs, int is_idx);
1847 int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
1848 int lnum, int offs);
1849
1850 void destroy_old_idx(struct ubifs_info *c);
1851 int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
1852 int lnum, int offs);
1853 int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
1854 int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
1855 int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
1856
1857
1858 struct ubifs_znode *ubifs_tnc_levelorder_next(const struct ubifs_info *c,
1859 struct ubifs_znode *zr,
1860 struct ubifs_znode *znode);
1861 int ubifs_search_zbranch(const struct ubifs_info *c,
1862 const struct ubifs_znode *znode,
1863 const union ubifs_key *key, int *n);
1864 struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
1865 struct ubifs_znode *ubifs_tnc_postorder_next(const struct ubifs_info *c,
1866 struct ubifs_znode *znode);
1867 long ubifs_destroy_tnc_subtree(const struct ubifs_info *c,
1868 struct ubifs_znode *zr);
1869 struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
1870 struct ubifs_zbranch *zbr,
1871 struct ubifs_znode *parent, int iip);
1872 int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
1873 void *node);
1874
1875
1876 int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
1877 int ubifs_tnc_end_commit(struct ubifs_info *c);
1878
1879
1880 unsigned long ubifs_shrink_scan(struct shrinker *shrink,
1881 struct shrink_control *sc);
1882 unsigned long ubifs_shrink_count(struct shrinker *shrink,
1883 struct shrink_control *sc);
1884
1885
1886 int ubifs_bg_thread(void *info);
1887 void ubifs_commit_required(struct ubifs_info *c);
1888 void ubifs_request_bg_commit(struct ubifs_info *c);
1889 int ubifs_run_commit(struct ubifs_info *c);
1890 void ubifs_recovery_commit(struct ubifs_info *c);
1891 int ubifs_gc_should_commit(struct ubifs_info *c);
1892 void ubifs_wait_for_commit(struct ubifs_info *c);
1893
1894
1895 int ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2);
1896 int ubifs_read_master(struct ubifs_info *c);
1897 int ubifs_write_master(struct ubifs_info *c);
1898
1899
1900 int ubifs_read_superblock(struct ubifs_info *c);
1901 int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
1902 int ubifs_fixup_free_space(struct ubifs_info *c);
1903 int ubifs_enable_encryption(struct ubifs_info *c);
1904
1905
1906 int ubifs_validate_entry(struct ubifs_info *c,
1907 const struct ubifs_dent_node *dent);
1908 int ubifs_replay_journal(struct ubifs_info *c);
1909
1910
1911 int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
1912 int ubifs_gc_start_commit(struct ubifs_info *c);
1913 int ubifs_gc_end_commit(struct ubifs_info *c);
1914 void ubifs_destroy_idx_gc(struct ubifs_info *c);
1915 int ubifs_get_idx_gc_leb(struct ubifs_info *c);
1916 int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
1917
1918
1919 int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
1920 void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
1921 int ubifs_orphan_start_commit(struct ubifs_info *c);
1922 int ubifs_orphan_end_commit(struct ubifs_info *c);
1923 int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
1924 int ubifs_clear_orphans(struct ubifs_info *c);
1925
1926
1927 int ubifs_calc_lpt_geom(struct ubifs_info *c);
1928 int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
1929 int *lpt_lebs, int *big_lpt, u8 *hash);
1930 int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
1931 struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
1932 struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
1933 int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
1934 ubifs_lpt_scan_callback scan_cb, void *data);
1935
1936
1937 void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
1938 void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
1939 struct ubifs_lpt_lprops *ltab);
1940 void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
1941 struct ubifs_pnode *pnode);
1942 void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
1943 struct ubifs_nnode *nnode);
1944 struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
1945 struct ubifs_nnode *parent, int iip);
1946 struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
1947 struct ubifs_nnode *parent, int iip);
1948 struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i);
1949 int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
1950 void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
1951 void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
1952 uint32_t ubifs_unpack_bits(const struct ubifs_info *c, uint8_t **addr, int *pos, int nrbits);
1953 struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
1954
1955 int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1956 struct ubifs_nnode *nnode);
1957 int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash);
1958
1959
1960 int ubifs_lpt_start_commit(struct ubifs_info *c);
1961 int ubifs_lpt_end_commit(struct ubifs_info *c);
1962 int ubifs_lpt_post_commit(struct ubifs_info *c);
1963 void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
1964
1965
1966 const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
1967 const struct ubifs_lprops *lp,
1968 int free, int dirty, int flags,
1969 int idx_gc_cnt);
1970 void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
1971 void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
1972 int cat);
1973 void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
1974 struct ubifs_lprops *new_lprops);
1975 void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
1976 int ubifs_categorize_lprops(const struct ubifs_info *c,
1977 const struct ubifs_lprops *lprops);
1978 int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1979 int flags_set, int flags_clean, int idx_gc_cnt);
1980 int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1981 int flags_set, int flags_clean);
1982 int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
1983 const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
1984 const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
1985 const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
1986 const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
1987 int ubifs_calc_dark(const struct ubifs_info *c, int spc);
1988
1989
1990 int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
1991 int ubifs_setattr(struct dentry *dentry, struct iattr *attr);
1992 int ubifs_update_time(struct inode *inode, struct timespec64 *time, int flags);
1993
1994
1995 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
1996 umode_t mode);
1997 int ubifs_getattr(const struct path *path, struct kstat *stat,
1998 u32 request_mask, unsigned int flags);
1999 int ubifs_check_dir_empty(struct inode *dir);
2000
2001
2002 extern const struct xattr_handler *ubifs_xattr_handlers[];
2003 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
2004 int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
2005 size_t size, int flags, bool check_lock);
2006 ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
2007 size_t size);
2008
2009 #ifdef CONFIG_UBIFS_FS_XATTR
2010 void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum);
2011 int ubifs_purge_xattrs(struct inode *host);
2012 #else
2013 static inline void ubifs_evict_xattr_inode(struct ubifs_info *c,
2014 ino_t xattr_inum) { }
2015 static inline int ubifs_purge_xattrs(struct inode *host)
2016 {
2017 return 0;
2018 }
2019 #endif
2020
2021 #ifdef CONFIG_UBIFS_FS_SECURITY
2022 extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
2023 const struct qstr *qstr);
2024 #else
2025 static inline int ubifs_init_security(struct inode *dentry,
2026 struct inode *inode, const struct qstr *qstr)
2027 {
2028 return 0;
2029 }
2030 #endif
2031
2032
2033
2034 struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
2035
2036
2037 int ubifs_recover_master_node(struct ubifs_info *c);
2038 int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
2039 struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
2040 int offs, void *sbuf, int jhead);
2041 struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
2042 int offs, void *sbuf);
2043 int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
2044 int ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
2045 int ubifs_rcvry_gc_commit(struct ubifs_info *c);
2046 int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
2047 int deletion, loff_t new_size);
2048 int ubifs_recover_size(struct ubifs_info *c, bool in_place);
2049 void ubifs_destroy_size_tree(struct ubifs_info *c);
2050
2051
2052 long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2053 void ubifs_set_inode_flags(struct inode *inode);
2054 #ifdef CONFIG_COMPAT
2055 long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2056 #endif
2057
2058
2059 int __init ubifs_compressors_init(void);
2060 void ubifs_compressors_exit(void);
2061 void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
2062 void *out_buf, int *out_len, int *compr_type);
2063 int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
2064 void *out, int *out_len, int compr_type);
2065
2066 #include "debug.h"
2067 #include "misc.h"
2068 #include "key.h"
2069
2070 #ifndef CONFIG_FS_ENCRYPTION
2071 static inline int ubifs_encrypt(const struct inode *inode,
2072 struct ubifs_data_node *dn,
2073 unsigned int in_len, unsigned int *out_len,
2074 int block)
2075 {
2076 struct ubifs_info *c = inode->i_sb->s_fs_info;
2077 ubifs_assert(c, 0);
2078 return -EOPNOTSUPP;
2079 }
2080 static inline int ubifs_decrypt(const struct inode *inode,
2081 struct ubifs_data_node *dn,
2082 unsigned int *out_len, int block)
2083 {
2084 struct ubifs_info *c = inode->i_sb->s_fs_info;
2085 ubifs_assert(c, 0);
2086 return -EOPNOTSUPP;
2087 }
2088 #else
2089
2090 int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
2091 unsigned int in_len, unsigned int *out_len, int block);
2092 int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
2093 unsigned int *out_len, int block);
2094 #endif
2095
2096 extern const struct fscrypt_operations ubifs_crypt_operations;
2097
2098 static inline bool ubifs_crypt_is_encrypted(const struct inode *inode)
2099 {
2100 const struct ubifs_inode *ui = ubifs_inode(inode);
2101
2102 return ui->flags & UBIFS_CRYPT_FL;
2103 }
2104
2105
2106 __printf(2, 3)
2107 void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
2108 __printf(2, 3)
2109 void ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
2110 __printf(2, 3)
2111 void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
2112
2113
2114
2115
2116 #define ubifs_errc(c, fmt, ...) \
2117 do { \
2118 if (!(c)->probing) \
2119 ubifs_err(c, fmt, ##__VA_ARGS__); \
2120 } while (0)
2121
2122 #endif