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
161enum {
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
178enum {
179 DIRTY_ZNODE = 0,
180 COW_ZNODE = 1,
181 OBSOLETE_ZNODE = 2,
182};
183
184
185
186
187
188
189
190
191
192
193
194enum {
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
214enum {
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
230enum {
231 DIRTY_CNODE = 0,
232 OBSOLETE_CNODE = 1,
233 COW_CNODE = 2,
234};
235
236
237
238
239
240
241
242enum {
243 LTAB_DIRTY = 1,
244 LSAVE_DIRTY = 2,
245};
246
247
248
249
250
251
252
253enum {
254 LEB_FREED,
255 LEB_FREED_IDX,
256 LEB_RETAINED,
257};
258
259
260
261
262
263
264
265enum {
266 ASSACT_REPORT = 0,
267 ASSACT_RO,
268 ASSACT_PANIC,
269};
270
271
272
273
274
275
276
277struct ubifs_old_idx {
278 struct rb_node rb;
279 int lnum;
280 int offs;
281};
282
283
284union 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
301struct 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
319struct 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
337struct 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
401struct ubifs_inode {
402 struct inode vfs_inode;
403 unsigned long long creat_sqnum;
404 unsigned long long del_cmtno;
405 unsigned int xattr_size;
406 unsigned int xattr_cnt;
407 unsigned int xattr_names;
408 unsigned int dirty:1;
409 unsigned int xattr:1;
410 unsigned int bulk_read:1;
411 unsigned int compr_type:2;
412 struct mutex ui_mutex;
413 struct rw_semaphore xattr_sem;
414 spinlock_t ui_lock;
415 loff_t synced_i_size;
416 loff_t ui_size;
417 int flags;
418 pgoff_t last_page_read;
419 pgoff_t read_in_a_row;
420 int data_len;
421 void *data;
422};
423
424
425
426
427
428
429
430
431
432
433
434struct ubifs_unclean_leb {
435 struct list_head list;
436 int lnum;
437 int endpt;
438};
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455enum {
456 LPROPS_UNCAT = 0,
457 LPROPS_DIRTY = 1,
458 LPROPS_DIRTY_IDX = 2,
459 LPROPS_FREE = 3,
460 LPROPS_HEAP_CNT = 3,
461 LPROPS_EMPTY = 4,
462 LPROPS_FREEABLE = 5,
463 LPROPS_FRDI_IDX = 6,
464 LPROPS_CAT_MASK = 15,
465 LPROPS_TAKEN = 16,
466 LPROPS_INDEX = 32,
467};
468
469
470
471
472
473
474
475
476
477
478struct ubifs_lprops {
479 int free;
480 int dirty;
481 int flags;
482 int lnum;
483 union {
484 struct list_head list;
485 int hpos;
486 };
487};
488
489
490
491
492
493
494
495
496struct ubifs_lpt_lprops {
497 int free;
498 int dirty;
499 unsigned tgc:1;
500 unsigned cmt:1;
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
529struct ubifs_lp_stats {
530 int empty_lebs;
531 int taken_empty_lebs;
532 int idx_lebs;
533 long long total_free;
534 long long total_dirty;
535 long long total_used;
536 long long total_dead;
537 long long total_dark;
538};
539
540struct ubifs_nnode;
541
542
543
544
545
546
547
548
549
550
551struct ubifs_cnode {
552 struct ubifs_nnode *parent;
553 struct ubifs_cnode *cnext;
554 unsigned long flags;
555 int iip;
556 int level;
557 int num;
558};
559
560
561
562
563
564
565
566
567
568
569
570struct ubifs_pnode {
571 struct ubifs_nnode *parent;
572 struct ubifs_cnode *cnext;
573 unsigned long flags;
574 int iip;
575 int level;
576 int num;
577 struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
578};
579
580
581
582
583
584
585
586
587
588struct ubifs_nbranch {
589 int lnum;
590 int offs;
591 union {
592 struct ubifs_nnode *nnode;
593 struct ubifs_pnode *pnode;
594 struct ubifs_cnode *cnode;
595 };
596};
597
598
599
600
601
602
603
604
605
606
607
608struct ubifs_nnode {
609 struct ubifs_nnode *parent;
610 struct ubifs_cnode *cnext;
611 unsigned long flags;
612 int iip;
613 int level;
614 int num;
615 struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
616};
617
618
619
620
621
622
623
624
625
626struct ubifs_lpt_heap {
627 struct ubifs_lprops **arr;
628 int cnt;
629 int max_cnt;
630};
631
632
633
634
635
636
637
638
639enum {
640 LPT_SCAN_CONTINUE = 0,
641 LPT_SCAN_ADD = 1,
642 LPT_SCAN_STOP = 2,
643};
644
645struct ubifs_info;
646
647
648typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
649 const struct ubifs_lprops *lprops,
650 int in_tree, void *data);
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
683struct ubifs_wbuf {
684 struct ubifs_info *c;
685 void *buf;
686 int lnum;
687 int offs;
688 int avail;
689 int used;
690 int size;
691 int jhead;
692 int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
693 struct mutex io_mutex;
694 spinlock_t lock;
695 struct hrtimer timer;
696 unsigned int no_timer:1;
697 unsigned int need_sync:1;
698 int next_ino;
699 ino_t *inodes;
700};
701
702
703
704
705
706
707
708
709
710
711struct ubifs_bud {
712 int lnum;
713 int start;
714 int jhead;
715 struct list_head list;
716 struct rb_node rb;
717 struct shash_desc *log_hash;
718};
719
720
721
722
723
724
725
726
727
728
729struct ubifs_jhead {
730 struct ubifs_wbuf wbuf;
731 struct list_head buds_list;
732 unsigned int grouped:1;
733 struct shash_desc *log_hash;
734};
735
736
737
738
739
740
741
742
743
744
745struct ubifs_zbranch {
746 union ubifs_key key;
747 union {
748 struct ubifs_znode *znode;
749 void *leaf;
750 };
751 int lnum;
752 int offs;
753 int len;
754 u8 hash[UBIFS_HASH_ARR_SZ];
755};
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777struct ubifs_znode {
778 struct ubifs_znode *parent;
779 struct ubifs_znode *cnext;
780 struct ubifs_znode *cparent;
781 int ciip;
782 unsigned long flags;
783 time64_t time;
784 int level;
785 int child_cnt;
786 int iip;
787 int alt;
788 int lnum;
789 int offs;
790 int len;
791 struct ubifs_zbranch zbranch[];
792};
793
794
795
796
797
798
799
800
801
802
803
804
805struct bu_info {
806 union ubifs_key key;
807 struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
808 void *buf;
809 int buf_len;
810 int gc_seq;
811 int cnt;
812 int blk_cnt;
813 int eof;
814};
815
816
817
818
819
820
821
822
823
824struct ubifs_node_range {
825 union {
826 int len;
827 int min_len;
828 };
829 int max_len;
830};
831
832
833
834
835
836
837
838
839
840
841struct ubifs_compressor {
842 int compr_type;
843 struct crypto_comp *cc;
844 struct mutex *comp_mutex;
845 struct mutex *decomp_mutex;
846 const char *name;
847 const char *capi_name;
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
884struct ubifs_budget_req {
885 unsigned int fast:1;
886 unsigned int recalculate:1;
887#ifndef UBIFS_DEBUG
888 unsigned int new_page:1;
889 unsigned int dirtied_page:1;
890 unsigned int new_dent:1;
891 unsigned int mod_dent:1;
892 unsigned int new_ino:1;
893 unsigned int new_ino_d:13;
894 unsigned int dirtied_ino:4;
895 unsigned int dirtied_ino_d:15;
896#else
897
898 unsigned int new_page;
899 unsigned int dirtied_page;
900 unsigned int new_dent;
901 unsigned int mod_dent;
902 unsigned int new_ino;
903 unsigned int new_ino_d;
904 unsigned int dirtied_ino;
905 unsigned int dirtied_ino_d;
906#endif
907 int idx_growth;
908 int data_growth;
909 int dd_growth;
910};
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926struct ubifs_orphan {
927 struct rb_node rb;
928 struct list_head list;
929 struct list_head new_list;
930 struct list_head child_list;
931 struct ubifs_orphan *cnext;
932 struct ubifs_orphan *dnext;
933 ino_t inum;
934 unsigned new:1;
935 unsigned cmt:1;
936 unsigned del:1;
937};
938
939
940
941
942
943
944
945
946
947
948
949
950
951struct ubifs_mount_opts {
952 unsigned int unmount_mode:2;
953 unsigned int bulk_read:2;
954 unsigned int chk_data_crc:2;
955 unsigned int override_compr:1;
956 unsigned int compr_type:2;
957};
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979struct ubifs_budg_info {
980 long long idx_growth;
981 long long data_growth;
982 long long dd_growth;
983 long long uncommitted_idx;
984 unsigned long long old_idx_sz;
985 int min_idx_lebs;
986 unsigned int nospace:1;
987 unsigned int nospace_rp:1;
988 int page_budget;
989 int inode_budget;
990 int dent_budget;
991};
992
993struct ubifs_debug_info;
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
1254
1255struct ubifs_info {
1256 struct super_block *vfs_sb;
1257 struct ubifs_sb_node *sup_node;
1258
1259 ino_t highest_inum;
1260 unsigned long long max_sqnum;
1261 unsigned long long cmt_no;
1262 spinlock_t cnt_lock;
1263 int fmt_version;
1264 int ro_compat_version;
1265 unsigned char uuid[16];
1266
1267 int lhead_lnum;
1268 int lhead_offs;
1269 int ltail_lnum;
1270 struct mutex log_mutex;
1271 int min_log_bytes;
1272 long long cmt_bud_bytes;
1273
1274 struct rb_root buds;
1275 long long bud_bytes;
1276 spinlock_t buds_lock;
1277 int jhead_cnt;
1278 struct ubifs_jhead *jheads;
1279 long long max_bud_bytes;
1280 long long bg_bud_bytes;
1281 struct list_head old_buds;
1282 int max_bud_cnt;
1283
1284 struct rw_semaphore commit_sem;
1285 int cmt_state;
1286 spinlock_t cs_lock;
1287 wait_queue_head_t cmt_wq;
1288
1289 unsigned int big_lpt:1;
1290 unsigned int space_fixup:1;
1291 unsigned int double_hash:1;
1292 unsigned int encrypted:1;
1293 unsigned int no_chk_data_crc:1;
1294 unsigned int bulk_read:1;
1295 unsigned int default_compr:2;
1296 unsigned int rw_incompat:1;
1297 unsigned int assert_action:2;
1298 unsigned int authenticated:1;
1299 unsigned int superblock_need_write:1;
1300
1301 struct mutex tnc_mutex;
1302 struct ubifs_zbranch zroot;
1303 struct ubifs_znode *cnext;
1304 struct ubifs_znode *enext;
1305 int *gap_lebs;
1306 void *cbuf;
1307 void *ileb_buf;
1308 int ileb_len;
1309 int ihead_lnum;
1310 int ihead_offs;
1311 int *ilebs;
1312 int ileb_cnt;
1313 int ileb_nxt;
1314 struct rb_root old_idx;
1315 int *bottom_up_buf;
1316
1317 struct ubifs_mst_node *mst_node;
1318 int mst_offs;
1319
1320 int max_bu_buf_len;
1321 struct mutex bu_mutex;
1322 struct bu_info bu;
1323
1324 struct mutex write_reserve_mutex;
1325 void *write_reserve_buf;
1326
1327 int log_lebs;
1328 long long log_bytes;
1329 int log_last;
1330 int lpt_lebs;
1331 int lpt_first;
1332 int lpt_last;
1333 int orph_lebs;
1334 int orph_first;
1335 int orph_last;
1336 int main_lebs;
1337 int main_first;
1338 long long main_bytes;
1339
1340 uint8_t key_hash_type;
1341 uint32_t (*key_hash)(const char *str, int len);
1342 int key_fmt;
1343 int key_len;
1344 int hash_len;
1345 int fanout;
1346
1347 int min_io_size;
1348 int min_io_shift;
1349 int max_write_size;
1350 int max_write_shift;
1351 int leb_size;
1352 int leb_start;
1353 int half_leb_size;
1354 int idx_leb_size;
1355 int leb_cnt;
1356 int max_leb_cnt;
1357 unsigned int ro_media:1;
1358 unsigned int ro_mount:1;
1359 unsigned int ro_error:1;
1360
1361 atomic_long_t dirty_pg_cnt;
1362 atomic_long_t dirty_zn_cnt;
1363 atomic_long_t clean_zn_cnt;
1364
1365 spinlock_t space_lock;
1366 struct ubifs_lp_stats lst;
1367 struct ubifs_budg_info bi;
1368 unsigned long long calc_idx_sz;
1369
1370 int ref_node_alsz;
1371 int mst_node_alsz;
1372 int min_idx_node_sz;
1373 int max_idx_node_sz;
1374 long long max_inode_sz;
1375 int max_znode_sz;
1376
1377 int leb_overhead;
1378 int dead_wm;
1379 int dark_wm;
1380 int block_cnt;
1381
1382 struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
1383 struct ubi_volume_desc *ubi;
1384 struct ubi_device_info di;
1385 struct ubi_volume_info vi;
1386
1387 struct rb_root orph_tree;
1388 struct list_head orph_list;
1389 struct list_head orph_new;
1390 struct ubifs_orphan *orph_cnext;
1391 struct ubifs_orphan *orph_dnext;
1392 spinlock_t orphan_lock;
1393 void *orph_buf;
1394 int new_orphans;
1395 int cmt_orphans;
1396 int tot_orphans;
1397 int max_orphans;
1398 int ohead_lnum;
1399 int ohead_offs;
1400 int no_orphs;
1401
1402 struct task_struct *bgt;
1403 char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
1404 int need_bgt;
1405 int need_wbuf_sync;
1406
1407 int gc_lnum;
1408 void *sbuf;
1409 struct list_head idx_gc;
1410 int idx_gc_cnt;
1411 int gc_seq;
1412 int gced_lnum;
1413
1414 struct list_head infos_list;
1415 struct mutex umount_mutex;
1416 unsigned int shrinker_run_no;
1417
1418 int space_bits;
1419 int lpt_lnum_bits;
1420 int lpt_offs_bits;
1421 int lpt_spc_bits;
1422 int pcnt_bits;
1423 int lnum_bits;
1424 int nnode_sz;
1425 int pnode_sz;
1426 int ltab_sz;
1427 int lsave_sz;
1428 int pnode_cnt;
1429 int nnode_cnt;
1430 int lpt_hght;
1431 int pnodes_have;
1432
1433 struct mutex lp_mutex;
1434 int lpt_lnum;
1435 int lpt_offs;
1436 int nhead_lnum;
1437 int nhead_offs;
1438 int lpt_drty_flgs;
1439 int dirty_nn_cnt;
1440 int dirty_pn_cnt;
1441 int check_lpt_free;
1442 long long lpt_sz;
1443 void *lpt_nod_buf;
1444 void *lpt_buf;
1445 struct ubifs_nnode *nroot;
1446 struct ubifs_cnode *lpt_cnext;
1447 struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
1448 struct ubifs_lpt_heap dirty_idx;
1449 struct list_head uncat_list;
1450 struct list_head empty_list;
1451 struct list_head freeable_list;
1452 struct list_head frdi_idx_list;
1453 int freeable_cnt;
1454 int in_a_category_cnt;
1455
1456 int ltab_lnum;
1457 int ltab_offs;
1458 struct ubifs_lpt_lprops *ltab;
1459 struct ubifs_lpt_lprops *ltab_cmt;
1460 int lsave_cnt;
1461 int lsave_lnum;
1462 int lsave_offs;
1463 int *lsave;
1464 int lscan_lnum;
1465
1466 long long rp_size;
1467 long long report_rp_size;
1468 kuid_t rp_uid;
1469 kgid_t rp_gid;
1470
1471 struct crypto_shash *hash_tfm;
1472 struct crypto_shash *hmac_tfm;
1473 int hmac_desc_len;
1474 char *auth_key_name;
1475 char *auth_hash_name;
1476 enum hash_algo auth_hash_algo;
1477
1478 struct shash_desc *log_hash;
1479
1480
1481 unsigned int empty:1;
1482 unsigned int need_recovery:1;
1483 unsigned int replaying:1;
1484 unsigned int mounting:1;
1485 unsigned int remounting_rw:1;
1486 unsigned int probing:1;
1487 struct list_head replay_list;
1488 struct list_head replay_buds;
1489 unsigned long long cs_sqnum;
1490 struct list_head unclean_leb_list;
1491 struct ubifs_mst_node *rcvrd_mst_node;
1492 struct rb_root size_tree;
1493 struct ubifs_mount_opts mount_opts;
1494
1495 struct ubifs_debug_info *dbg;
1496};
1497
1498extern struct list_head ubifs_infos;
1499extern spinlock_t ubifs_infos_lock;
1500extern atomic_long_t ubifs_clean_zn_cnt;
1501extern const struct super_operations ubifs_super_operations;
1502extern const struct address_space_operations ubifs_file_address_operations;
1503extern const struct file_operations ubifs_file_operations;
1504extern const struct inode_operations ubifs_file_inode_operations;
1505extern const struct file_operations ubifs_dir_operations;
1506extern const struct inode_operations ubifs_dir_inode_operations;
1507extern const struct inode_operations ubifs_symlink_inode_operations;
1508extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
1509extern int ubifs_default_version;
1510
1511
1512static inline int ubifs_authenticated(const struct ubifs_info *c)
1513{
1514 return (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) && c->authenticated;
1515}
1516
1517struct shash_desc *__ubifs_hash_get_desc(const struct ubifs_info *c);
1518static inline struct shash_desc *ubifs_hash_get_desc(const struct ubifs_info *c)
1519{
1520 return ubifs_authenticated(c) ? __ubifs_hash_get_desc(c) : NULL;
1521}
1522
1523static inline int ubifs_shash_init(const struct ubifs_info *c,
1524 struct shash_desc *desc)
1525{
1526 if (ubifs_authenticated(c))
1527 return crypto_shash_init(desc);
1528 else
1529 return 0;
1530}
1531
1532static inline int ubifs_shash_update(const struct ubifs_info *c,
1533 struct shash_desc *desc, const void *buf,
1534 unsigned int len)
1535{
1536 int err = 0;
1537
1538 if (ubifs_authenticated(c)) {
1539 err = crypto_shash_update(desc, buf, len);
1540 if (err < 0)
1541 return err;
1542 }
1543
1544 return 0;
1545}
1546
1547static inline int ubifs_shash_final(const struct ubifs_info *c,
1548 struct shash_desc *desc, u8 *out)
1549{
1550 return ubifs_authenticated(c) ? crypto_shash_final(desc, out) : 0;
1551}
1552
1553int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *buf,
1554 u8 *hash);
1555static inline int ubifs_node_calc_hash(const struct ubifs_info *c,
1556 const void *buf, u8 *hash)
1557{
1558 if (ubifs_authenticated(c))
1559 return __ubifs_node_calc_hash(c, buf, hash);
1560 else
1561 return 0;
1562}
1563
1564int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
1565 struct shash_desc *inhash);
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576static inline int ubifs_check_hash(const struct ubifs_info *c,
1577 const u8 *expected, const u8 *got)
1578{
1579 return crypto_memneq(expected, got, c->hash_len);
1580}
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591static inline int ubifs_check_hmac(const struct ubifs_info *c,
1592 const u8 *expected, const u8 *got)
1593{
1594 return crypto_memneq(expected, got, c->hmac_desc_len);
1595}
1596
1597void ubifs_bad_hash(const struct ubifs_info *c, const void *node,
1598 const u8 *hash, int lnum, int offs);
1599
1600int __ubifs_node_check_hash(const struct ubifs_info *c, const void *buf,
1601 const u8 *expected);
1602static inline int ubifs_node_check_hash(const struct ubifs_info *c,
1603 const void *buf, const u8 *expected)
1604{
1605 if (ubifs_authenticated(c))
1606 return __ubifs_node_check_hash(c, buf, expected);
1607 else
1608 return 0;
1609}
1610
1611int ubifs_init_authentication(struct ubifs_info *c);
1612void __ubifs_exit_authentication(struct ubifs_info *c);
1613static inline void ubifs_exit_authentication(struct ubifs_info *c)
1614{
1615 if (ubifs_authenticated(c))
1616 __ubifs_exit_authentication(c);
1617}
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627static inline u8 *ubifs_branch_hash(struct ubifs_info *c,
1628 struct ubifs_branch *br)
1629{
1630 return (void *)br + sizeof(*br) + c->key_len;
1631}
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641static inline void ubifs_copy_hash(const struct ubifs_info *c, const u8 *from,
1642 u8 *to)
1643{
1644 if (ubifs_authenticated(c))
1645 memcpy(to, from, c->hash_len);
1646}
1647
1648int __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
1649 int len, int ofs_hmac);
1650static inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
1651 int len, int ofs_hmac)
1652{
1653 if (ubifs_authenticated(c))
1654 return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac);
1655 else
1656 return 0;
1657}
1658
1659int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf,
1660 int len, int ofs_hmac);
1661static inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
1662 const void *buf, int len, int ofs_hmac)
1663{
1664 if (ubifs_authenticated(c))
1665 return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac);
1666 else
1667 return 0;
1668}
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678static inline int ubifs_auth_node_sz(const struct ubifs_info *c)
1679{
1680 if (ubifs_authenticated(c))
1681 return sizeof(struct ubifs_auth_node) + c->hmac_desc_len;
1682 else
1683 return 0;
1684}
1685int ubifs_sb_verify_signature(struct ubifs_info *c,
1686 const struct ubifs_sb_node *sup);
1687bool ubifs_hmac_zero(struct ubifs_info *c, const u8 *hmac);
1688
1689int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac);
1690
1691int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
1692 struct shash_desc *target);
1693static inline int ubifs_shash_copy_state(const struct ubifs_info *c,
1694 struct shash_desc *src,
1695 struct shash_desc *target)
1696{
1697 if (ubifs_authenticated(c))
1698 return __ubifs_shash_copy_state(c, src, target);
1699 else
1700 return 0;
1701}
1702
1703
1704void ubifs_ro_mode(struct ubifs_info *c, int err);
1705int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
1706 int len, int even_ebadmsg);
1707int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
1708 int len);
1709int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
1710int ubifs_leb_unmap(struct ubifs_info *c, int lnum);
1711int ubifs_leb_map(struct ubifs_info *c, int lnum);
1712int ubifs_is_mapped(const struct ubifs_info *c, int lnum);
1713int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
1714int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
1715int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
1716int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
1717 int lnum, int offs);
1718int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
1719 int lnum, int offs);
1720int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
1721 int offs);
1722int ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum,
1723 int offs, int hmac_offs);
1724int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
1725 int lnum, int offs, int quiet, int must_chk_crc);
1726void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad);
1727void ubifs_crc_node(struct ubifs_info *c, void *buf, int len);
1728void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
1729int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
1730 int hmac_offs, int pad);
1731void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
1732int ubifs_io_init(struct ubifs_info *c);
1733void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
1734int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
1735int ubifs_bg_wbufs_sync(struct ubifs_info *c);
1736void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
1737int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
1738
1739
1740struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
1741 int offs, void *sbuf, int quiet);
1742void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
1743int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
1744 int offs, int quiet);
1745struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
1746 int offs, void *sbuf);
1747void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1748 int lnum, int offs);
1749int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1750 void *buf, int offs);
1751void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
1752 void *buf);
1753
1754
1755void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
1756void ubifs_create_buds_lists(struct ubifs_info *c);
1757int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
1758struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
1759struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
1760int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
1761int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
1762int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
1763int ubifs_consolidate_log(struct ubifs_info *c);
1764
1765
1766int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
1767 const struct fscrypt_name *nm, const struct inode *inode,
1768 int deletion, int xent);
1769int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
1770 const union ubifs_key *key, const void *buf, int len);
1771int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
1772int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
1773int ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir,
1774 const struct inode *fst_inode,
1775 const struct fscrypt_name *fst_nm,
1776 const struct inode *snd_dir,
1777 const struct inode *snd_inode,
1778 const struct fscrypt_name *snd_nm, int sync);
1779int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
1780 const struct inode *old_inode,
1781 const struct fscrypt_name *old_nm,
1782 const struct inode *new_dir,
1783 const struct inode *new_inode,
1784 const struct fscrypt_name *new_nm,
1785 const struct inode *whiteout, int sync);
1786int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
1787 loff_t old_size, loff_t new_size);
1788int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
1789 const struct inode *inode, const struct fscrypt_name *nm);
1790int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
1791 const struct inode *inode2);
1792
1793
1794int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
1795void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
1796void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
1797 struct ubifs_inode *ui);
1798int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
1799 struct ubifs_budget_req *req);
1800void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
1801 struct ubifs_budget_req *req);
1802void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
1803 struct ubifs_budget_req *req);
1804long long ubifs_get_free_space(struct ubifs_info *c);
1805long long ubifs_get_free_space_nolock(struct ubifs_info *c);
1806int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
1807void ubifs_convert_page_budget(struct ubifs_info *c);
1808long long ubifs_reported_space(const struct ubifs_info *c, long long free);
1809long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
1810
1811
1812int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
1813 int squeeze);
1814int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
1815int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
1816 int min_space, int pick_free);
1817int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
1818int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
1819
1820
1821int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
1822 struct ubifs_znode **zn, int *n);
1823int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
1824 void *node, const struct fscrypt_name *nm);
1825int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,
1826 void *node, uint32_t secondary_hash);
1827int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
1828 void *node, int *lnum, int *offs);
1829int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
1830 int offs, int len, const u8 *hash);
1831int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
1832 int old_lnum, int old_offs, int lnum, int offs, int len);
1833int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
1834 int lnum, int offs, int len, const u8 *hash,
1835 const struct fscrypt_name *nm);
1836int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
1837int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
1838 const struct fscrypt_name *nm);
1839int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key,
1840 uint32_t cookie);
1841int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
1842 union ubifs_key *to_key);
1843int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
1844struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
1845 union ubifs_key *key,
1846 const struct fscrypt_name *nm);
1847void ubifs_tnc_close(struct ubifs_info *c);
1848int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
1849 int lnum, int offs, int is_idx);
1850int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
1851 int lnum, int offs);
1852
1853void destroy_old_idx(struct ubifs_info *c);
1854int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
1855 int lnum, int offs);
1856int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
1857int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
1858int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
1859
1860
1861struct ubifs_znode *ubifs_tnc_levelorder_next(const struct ubifs_info *c,
1862 struct ubifs_znode *zr,
1863 struct ubifs_znode *znode);
1864int ubifs_search_zbranch(const struct ubifs_info *c,
1865 const struct ubifs_znode *znode,
1866 const union ubifs_key *key, int *n);
1867struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
1868struct ubifs_znode *ubifs_tnc_postorder_next(const struct ubifs_info *c,
1869 struct ubifs_znode *znode);
1870long ubifs_destroy_tnc_subtree(const struct ubifs_info *c,
1871 struct ubifs_znode *zr);
1872struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
1873 struct ubifs_zbranch *zbr,
1874 struct ubifs_znode *parent, int iip);
1875int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
1876 void *node);
1877
1878
1879int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
1880int ubifs_tnc_end_commit(struct ubifs_info *c);
1881
1882
1883unsigned long ubifs_shrink_scan(struct shrinker *shrink,
1884 struct shrink_control *sc);
1885unsigned long ubifs_shrink_count(struct shrinker *shrink,
1886 struct shrink_control *sc);
1887
1888
1889int ubifs_bg_thread(void *info);
1890void ubifs_commit_required(struct ubifs_info *c);
1891void ubifs_request_bg_commit(struct ubifs_info *c);
1892int ubifs_run_commit(struct ubifs_info *c);
1893void ubifs_recovery_commit(struct ubifs_info *c);
1894int ubifs_gc_should_commit(struct ubifs_info *c);
1895void ubifs_wait_for_commit(struct ubifs_info *c);
1896
1897
1898int ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2);
1899int ubifs_read_master(struct ubifs_info *c);
1900int ubifs_write_master(struct ubifs_info *c);
1901
1902
1903int ubifs_read_superblock(struct ubifs_info *c);
1904int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
1905int ubifs_fixup_free_space(struct ubifs_info *c);
1906int ubifs_enable_encryption(struct ubifs_info *c);
1907
1908
1909int ubifs_validate_entry(struct ubifs_info *c,
1910 const struct ubifs_dent_node *dent);
1911int ubifs_replay_journal(struct ubifs_info *c);
1912
1913
1914int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
1915int ubifs_gc_start_commit(struct ubifs_info *c);
1916int ubifs_gc_end_commit(struct ubifs_info *c);
1917void ubifs_destroy_idx_gc(struct ubifs_info *c);
1918int ubifs_get_idx_gc_leb(struct ubifs_info *c);
1919int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
1920
1921
1922int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
1923void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
1924int ubifs_orphan_start_commit(struct ubifs_info *c);
1925int ubifs_orphan_end_commit(struct ubifs_info *c);
1926int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
1927int ubifs_clear_orphans(struct ubifs_info *c);
1928
1929
1930int ubifs_calc_lpt_geom(struct ubifs_info *c);
1931int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
1932 int *lpt_lebs, int *big_lpt, u8 *hash);
1933int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
1934struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
1935struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
1936int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
1937 ubifs_lpt_scan_callback scan_cb, void *data);
1938
1939
1940void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
1941void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
1942 struct ubifs_lpt_lprops *ltab);
1943void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
1944 struct ubifs_pnode *pnode);
1945void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
1946 struct ubifs_nnode *nnode);
1947struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
1948 struct ubifs_nnode *parent, int iip);
1949struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
1950 struct ubifs_nnode *parent, int iip);
1951struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i);
1952int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
1953void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
1954void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
1955uint32_t ubifs_unpack_bits(const struct ubifs_info *c, uint8_t **addr, int *pos, int nrbits);
1956struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
1957
1958int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1959 struct ubifs_nnode *nnode);
1960int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash);
1961
1962
1963int ubifs_lpt_start_commit(struct ubifs_info *c);
1964int ubifs_lpt_end_commit(struct ubifs_info *c);
1965int ubifs_lpt_post_commit(struct ubifs_info *c);
1966void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
1967
1968
1969const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
1970 const struct ubifs_lprops *lp,
1971 int free, int dirty, int flags,
1972 int idx_gc_cnt);
1973void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
1974void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
1975 int cat);
1976void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
1977 struct ubifs_lprops *new_lprops);
1978void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
1979int ubifs_categorize_lprops(const struct ubifs_info *c,
1980 const struct ubifs_lprops *lprops);
1981int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1982 int flags_set, int flags_clean, int idx_gc_cnt);
1983int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1984 int flags_set, int flags_clean);
1985int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
1986const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
1987const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
1988const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
1989const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
1990int ubifs_calc_dark(const struct ubifs_info *c, int spc);
1991
1992
1993int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
1994int ubifs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
1995 struct iattr *attr);
1996int ubifs_update_time(struct inode *inode, struct timespec64 *time, int flags);
1997
1998
1999struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
2000 umode_t mode);
2001int ubifs_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat,
2002 u32 request_mask, unsigned int flags);
2003int ubifs_check_dir_empty(struct inode *dir);
2004
2005
2006int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
2007 size_t size, int flags, bool check_lock);
2008ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
2009 size_t size);
2010
2011#ifdef CONFIG_UBIFS_FS_XATTR
2012extern const struct xattr_handler *ubifs_xattr_handlers[];
2013ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
2014void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum);
2015int ubifs_purge_xattrs(struct inode *host);
2016#else
2017#define ubifs_listxattr NULL
2018#define ubifs_xattr_handlers NULL
2019static inline void ubifs_evict_xattr_inode(struct ubifs_info *c,
2020 ino_t xattr_inum) { }
2021static inline int ubifs_purge_xattrs(struct inode *host)
2022{
2023 return 0;
2024}
2025#endif
2026
2027#ifdef CONFIG_UBIFS_FS_SECURITY
2028extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
2029 const struct qstr *qstr);
2030#else
2031static inline int ubifs_init_security(struct inode *dentry,
2032 struct inode *inode, const struct qstr *qstr)
2033{
2034 return 0;
2035}
2036#endif
2037
2038
2039
2040struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
2041
2042
2043int ubifs_recover_master_node(struct ubifs_info *c);
2044int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
2045struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
2046 int offs, void *sbuf, int jhead);
2047struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
2048 int offs, void *sbuf);
2049int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
2050int ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
2051int ubifs_rcvry_gc_commit(struct ubifs_info *c);
2052int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
2053 int deletion, loff_t new_size);
2054int ubifs_recover_size(struct ubifs_info *c, bool in_place);
2055void ubifs_destroy_size_tree(struct ubifs_info *c);
2056
2057
2058int ubifs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
2059int ubifs_fileattr_set(struct user_namespace *mnt_userns,
2060 struct dentry *dentry, struct fileattr *fa);
2061long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2062void ubifs_set_inode_flags(struct inode *inode);
2063#ifdef CONFIG_COMPAT
2064long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2065#endif
2066
2067
2068int __init ubifs_compressors_init(void);
2069void ubifs_compressors_exit(void);
2070void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
2071 void *out_buf, int *out_len, int *compr_type);
2072int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
2073 void *out, int *out_len, int compr_type);
2074
2075#include "debug.h"
2076#include "misc.h"
2077#include "key.h"
2078
2079#ifndef CONFIG_FS_ENCRYPTION
2080static inline int ubifs_encrypt(const struct inode *inode,
2081 struct ubifs_data_node *dn,
2082 unsigned int in_len, unsigned int *out_len,
2083 int block)
2084{
2085 struct ubifs_info *c = inode->i_sb->s_fs_info;
2086 ubifs_assert(c, 0);
2087 return -EOPNOTSUPP;
2088}
2089static inline int ubifs_decrypt(const struct inode *inode,
2090 struct ubifs_data_node *dn,
2091 unsigned int *out_len, int block)
2092{
2093 struct ubifs_info *c = inode->i_sb->s_fs_info;
2094 ubifs_assert(c, 0);
2095 return -EOPNOTSUPP;
2096}
2097#else
2098
2099int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
2100 unsigned int in_len, unsigned int *out_len, int block);
2101int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
2102 unsigned int *out_len, int block);
2103#endif
2104
2105extern const struct fscrypt_operations ubifs_crypt_operations;
2106
2107
2108__printf(2, 3)
2109void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
2110__printf(2, 3)
2111void ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
2112__printf(2, 3)
2113void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
2114
2115
2116
2117
2118#define ubifs_errc(c, fmt, ...) \
2119do { \
2120 if (!(c)->probing) \
2121 ubifs_err(c, fmt, ##__VA_ARGS__); \
2122} while (0)
2123
2124#endif
2125