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