1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#ifndef __UBIFS_H__
24#define __UBIFS_H__
25
26#include <asm/div64.h>
27#include <linux/statfs.h>
28#include <linux/fs.h>
29#include <linux/err.h>
30#include <linux/sched.h>
31#include <linux/slab.h>
32#include <linux/vmalloc.h>
33#include <linux/spinlock.h>
34#include <linux/mutex.h>
35#include <linux/rwsem.h>
36#include <linux/mtd/ubi.h>
37#include <linux/pagemap.h>
38#include <linux/backing-dev.h>
39#include <linux/security.h>
40#include "ubifs-media.h"
41
42
43#define UBIFS_VERSION 1
44
45
46#define UBIFS_SUPER_MAGIC 0x24051905
47
48
49#define UBIFS_BLOCKS_PER_PAGE (PAGE_SIZE / UBIFS_BLOCK_SIZE)
50#define UBIFS_BLOCKS_PER_PAGE_SHIFT (PAGE_SHIFT - UBIFS_BLOCK_SHIFT)
51
52
53#define SQNUM_WARN_WATERMARK 0xFFFFFFFF00000000ULL
54#define SQNUM_WATERMARK 0xFFFFFFFFFF000000ULL
55
56
57
58
59
60
61
62#define MIN_INDEX_LEBS 2
63
64
65#define MIN_WRITE_SZ (UBIFS_DATA_NODE_SZ + 8)
66
67
68
69
70
71
72
73#define INUM_WARN_WATERMARK 0xFFF00000
74#define INUM_WATERMARK 0xFFFFFF00
75
76
77#define LPT_HEAP_SZ 256
78
79
80
81
82
83#define BGT_NAME_PATTERN "ubifs_bgt%d_%d"
84
85
86#define WBUF_TIMEOUT_SOFTLIMIT 3
87#define WBUF_TIMEOUT_HARDLIMIT 5
88
89
90#define MAX_INUM 0xFFFFFFFF
91
92
93#define NONDATA_JHEADS_CNT 2
94
95
96#define GCHD UBIFS_GC_HEAD
97#define BASEHD UBIFS_BASE_HEAD
98#define DATAHD UBIFS_DATA_HEAD
99
100
101#define LPROPS_NC 0x80000001
102
103
104
105
106
107
108
109
110
111
112#define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT
113#define UBIFS_INVALID_KEY UBIFS_KEY_TYPES_CNT
114
115
116
117
118
119#define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8)
120
121
122#define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8)
123
124
125
126
127
128
129
130#define OLD_ZNODE_AGE 20
131#define YOUNG_ZNODE_AGE 5
132
133
134
135
136
137
138#define WORST_COMPR_FACTOR 2
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
153
154
155enum {
156 WB_MUTEX_1 = 0,
157 WB_MUTEX_2 = 1,
158 WB_MUTEX_3 = 2,
159};
160
161
162
163
164
165
166
167
168
169
170
171enum {
172 DIRTY_ZNODE = 0,
173 COW_ZNODE = 1,
174 OBSOLETE_ZNODE = 2,
175};
176
177
178
179
180
181
182
183
184
185
186
187enum {
188 COMMIT_RESTING = 0,
189 COMMIT_BACKGROUND,
190 COMMIT_REQUIRED,
191 COMMIT_RUNNING_BACKGROUND,
192 COMMIT_RUNNING_REQUIRED,
193 COMMIT_BROKEN,
194};
195
196
197
198
199
200
201
202
203
204
205
206
207enum {
208 SCANNED_GARBAGE = 0,
209 SCANNED_EMPTY_SPACE = -1,
210 SCANNED_A_NODE = -2,
211 SCANNED_A_CORRUPT_NODE = -3,
212 SCANNED_A_BAD_PAD_NODE = -4,
213};
214
215
216
217
218
219
220
221
222
223enum {
224 DIRTY_CNODE = 0,
225 OBSOLETE_CNODE = 1,
226 COW_CNODE = 2,
227};
228
229
230
231
232
233
234
235enum {
236 LTAB_DIRTY = 1,
237 LSAVE_DIRTY = 2,
238};
239
240
241
242
243
244
245
246enum {
247 LEB_FREED,
248 LEB_FREED_IDX,
249 LEB_RETAINED,
250};
251
252
253
254
255
256
257
258struct ubifs_old_idx {
259 struct rb_node rb;
260 int lnum;
261 int offs;
262};
263
264
265union ubifs_key {
266 uint8_t u8[UBIFS_SK_LEN];
267 uint32_t u32[UBIFS_SK_LEN/4];
268 uint64_t u64[UBIFS_SK_LEN/8];
269 __le32 j32[UBIFS_SK_LEN/4];
270};
271
272
273
274
275
276
277
278
279
280
281
282struct ubifs_scan_node {
283 struct list_head list;
284 union ubifs_key key;
285 unsigned long long sqnum;
286 int type;
287 int offs;
288 int len;
289 void *node;
290};
291
292
293
294
295
296
297
298
299
300struct ubifs_scan_leb {
301 int lnum;
302 int nodes_cnt;
303 struct list_head nodes;
304 int endpt;
305 void *buf;
306};
307
308
309
310
311
312
313
314
315
316
317
318struct ubifs_gced_idx_leb {
319 struct list_head list;
320 int lnum;
321 int unmap;
322};
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381struct ubifs_inode {
382 struct inode vfs_inode;
383 unsigned long long creat_sqnum;
384 unsigned long long del_cmtno;
385 unsigned int xattr_size;
386 unsigned int xattr_cnt;
387 unsigned int xattr_names;
388 unsigned int dirty:1;
389 unsigned int xattr:1;
390 unsigned int bulk_read:1;
391 unsigned int compr_type:2;
392 struct mutex ui_mutex;
393 spinlock_t ui_lock;
394 loff_t synced_i_size;
395 loff_t ui_size;
396 int flags;
397 pgoff_t last_page_read;
398 pgoff_t read_in_a_row;
399 int data_len;
400 void *data;
401};
402
403
404
405
406
407
408
409
410
411
412
413struct ubifs_unclean_leb {
414 struct list_head list;
415 int lnum;
416 int endpt;
417};
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434enum {
435 LPROPS_UNCAT = 0,
436 LPROPS_DIRTY = 1,
437 LPROPS_DIRTY_IDX = 2,
438 LPROPS_FREE = 3,
439 LPROPS_HEAP_CNT = 3,
440 LPROPS_EMPTY = 4,
441 LPROPS_FREEABLE = 5,
442 LPROPS_FRDI_IDX = 6,
443 LPROPS_CAT_MASK = 15,
444 LPROPS_TAKEN = 16,
445 LPROPS_INDEX = 32,
446};
447
448
449
450
451
452
453
454
455
456
457struct ubifs_lprops {
458 int free;
459 int dirty;
460 int flags;
461 int lnum;
462 union {
463 struct list_head list;
464 int hpos;
465 };
466};
467
468
469
470
471
472
473
474
475struct ubifs_lpt_lprops {
476 int free;
477 int dirty;
478 unsigned tgc:1;
479 unsigned cmt:1;
480};
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508struct ubifs_lp_stats {
509 int empty_lebs;
510 int taken_empty_lebs;
511 int idx_lebs;
512 long long total_free;
513 long long total_dirty;
514 long long total_used;
515 long long total_dead;
516 long long total_dark;
517};
518
519struct ubifs_nnode;
520
521
522
523
524
525
526
527
528
529
530struct ubifs_cnode {
531 struct ubifs_nnode *parent;
532 struct ubifs_cnode *cnext;
533 unsigned long flags;
534 int iip;
535 int level;
536 int num;
537};
538
539
540
541
542
543
544
545
546
547
548
549struct ubifs_pnode {
550 struct ubifs_nnode *parent;
551 struct ubifs_cnode *cnext;
552 unsigned long flags;
553 int iip;
554 int level;
555 int num;
556 struct ubifs_lprops lprops[UBIFS_LPT_FANOUT];
557};
558
559
560
561
562
563
564
565
566
567struct ubifs_nbranch {
568 int lnum;
569 int offs;
570 union {
571 struct ubifs_nnode *nnode;
572 struct ubifs_pnode *pnode;
573 struct ubifs_cnode *cnode;
574 };
575};
576
577
578
579
580
581
582
583
584
585
586
587struct ubifs_nnode {
588 struct ubifs_nnode *parent;
589 struct ubifs_cnode *cnext;
590 unsigned long flags;
591 int iip;
592 int level;
593 int num;
594 struct ubifs_nbranch nbranch[UBIFS_LPT_FANOUT];
595};
596
597
598
599
600
601
602
603
604
605struct ubifs_lpt_heap {
606 struct ubifs_lprops **arr;
607 int cnt;
608 int max_cnt;
609};
610
611
612
613
614
615
616
617
618enum {
619 LPT_SCAN_CONTINUE = 0,
620 LPT_SCAN_ADD = 1,
621 LPT_SCAN_STOP = 2,
622};
623
624struct ubifs_info;
625
626
627typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,
628 const struct ubifs_lprops *lprops,
629 int in_tree, void *data);
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665struct ubifs_wbuf {
666 struct ubifs_info *c;
667 void *buf;
668 int lnum;
669 int offs;
670 int avail;
671 int used;
672 int size;
673 int jhead;
674 int (*sync_callback)(struct ubifs_info *c, int lnum, int free, int pad);
675 struct mutex io_mutex;
676 spinlock_t lock;
677 ktime_t softlimit;
678 unsigned long long delta;
679 struct hrtimer timer;
680 unsigned int no_timer:1;
681 unsigned int need_sync:1;
682 int next_ino;
683 ino_t *inodes;
684};
685
686
687
688
689
690
691
692
693
694struct ubifs_bud {
695 int lnum;
696 int start;
697 int jhead;
698 struct list_head list;
699 struct rb_node rb;
700};
701
702
703
704
705
706
707
708
709
710struct ubifs_jhead {
711 struct ubifs_wbuf wbuf;
712 struct list_head buds_list;
713 unsigned int grouped:1;
714};
715
716
717
718
719
720
721
722
723
724struct ubifs_zbranch {
725 union ubifs_key key;
726 union {
727 struct ubifs_znode *znode;
728 void *leaf;
729 };
730 int lnum;
731 int offs;
732 int len;
733};
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753struct ubifs_znode {
754 struct ubifs_znode *parent;
755 struct ubifs_znode *cnext;
756 unsigned long flags;
757 unsigned long time;
758 int level;
759 int child_cnt;
760 int iip;
761 int alt;
762 int lnum;
763 int offs;
764 int len;
765 struct ubifs_zbranch zbranch[];
766};
767
768
769
770
771
772
773
774
775
776
777
778
779struct bu_info {
780 union ubifs_key key;
781 struct ubifs_zbranch zbranch[UBIFS_MAX_BULK_READ];
782 void *buf;
783 int buf_len;
784 int gc_seq;
785 int cnt;
786 int blk_cnt;
787 int eof;
788};
789
790
791
792
793
794
795
796
797
798struct ubifs_node_range {
799 union {
800 int len;
801 int min_len;
802 };
803 int max_len;
804};
805
806
807
808
809
810
811
812
813
814
815struct ubifs_compressor {
816 int compr_type;
817 struct crypto_comp *cc;
818 struct mutex *comp_mutex;
819 struct mutex *decomp_mutex;
820 const char *name;
821 const char *capi_name;
822};
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858struct ubifs_budget_req {
859 unsigned int fast:1;
860 unsigned int recalculate:1;
861#ifndef UBIFS_DEBUG
862 unsigned int new_page:1;
863 unsigned int dirtied_page:1;
864 unsigned int new_dent:1;
865 unsigned int mod_dent:1;
866 unsigned int new_ino:1;
867 unsigned int new_ino_d:13;
868 unsigned int dirtied_ino:4;
869 unsigned int dirtied_ino_d:15;
870#else
871
872 unsigned int new_page;
873 unsigned int dirtied_page;
874 unsigned int new_dent;
875 unsigned int mod_dent;
876 unsigned int new_ino;
877 unsigned int new_ino_d;
878 unsigned int dirtied_ino;
879 unsigned int dirtied_ino_d;
880#endif
881 int idx_growth;
882 int data_growth;
883 int dd_growth;
884};
885
886
887
888
889
890
891
892
893
894
895
896
897
898struct ubifs_orphan {
899 struct rb_node rb;
900 struct list_head list;
901 struct list_head new_list;
902 struct ubifs_orphan *cnext;
903 struct ubifs_orphan *dnext;
904 ino_t inum;
905 unsigned new:1;
906 unsigned cmt:1;
907 unsigned del:1;
908};
909
910
911
912
913
914
915
916
917
918
919
920
921
922struct ubifs_mount_opts {
923 unsigned int unmount_mode:2;
924 unsigned int bulk_read:2;
925 unsigned int chk_data_crc:2;
926 unsigned int override_compr:1;
927 unsigned int compr_type:2;
928};
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950struct ubifs_budg_info {
951 long long idx_growth;
952 long long data_growth;
953 long long dd_growth;
954 long long uncommitted_idx;
955 unsigned long long old_idx_sz;
956 int min_idx_lebs;
957 unsigned int nospace:1;
958 unsigned int nospace_rp:1;
959 int page_budget;
960 int inode_budget;
961 int dent_budget;
962};
963
964struct ubifs_debug_info;
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
1214struct ubifs_info {
1215 struct super_block *vfs_sb;
1216 struct backing_dev_info bdi;
1217
1218 ino_t highest_inum;
1219 unsigned long long max_sqnum;
1220 unsigned long long cmt_no;
1221 spinlock_t cnt_lock;
1222 int fmt_version;
1223 int ro_compat_version;
1224 unsigned char uuid[16];
1225
1226 int lhead_lnum;
1227 int lhead_offs;
1228 int ltail_lnum;
1229 struct mutex log_mutex;
1230 int min_log_bytes;
1231 long long cmt_bud_bytes;
1232
1233 struct rb_root buds;
1234 long long bud_bytes;
1235 spinlock_t buds_lock;
1236 int jhead_cnt;
1237 struct ubifs_jhead *jheads;
1238 long long max_bud_bytes;
1239 long long bg_bud_bytes;
1240 struct list_head old_buds;
1241 int max_bud_cnt;
1242
1243 struct rw_semaphore commit_sem;
1244 int cmt_state;
1245 spinlock_t cs_lock;
1246 wait_queue_head_t cmt_wq;
1247
1248 unsigned int big_lpt:1;
1249 unsigned int space_fixup:1;
1250 unsigned int no_chk_data_crc:1;
1251 unsigned int bulk_read:1;
1252 unsigned int default_compr:2;
1253 unsigned int rw_incompat:1;
1254
1255 struct mutex tnc_mutex;
1256 struct ubifs_zbranch zroot;
1257 struct ubifs_znode *cnext;
1258 struct ubifs_znode *enext;
1259 int *gap_lebs;
1260 void *cbuf;
1261 void *ileb_buf;
1262 int ileb_len;
1263 int ihead_lnum;
1264 int ihead_offs;
1265 int *ilebs;
1266 int ileb_cnt;
1267 int ileb_nxt;
1268 struct rb_root old_idx;
1269 int *bottom_up_buf;
1270
1271 struct ubifs_mst_node *mst_node;
1272 int mst_offs;
1273
1274 int max_bu_buf_len;
1275 struct mutex bu_mutex;
1276 struct bu_info bu;
1277
1278 struct mutex write_reserve_mutex;
1279 void *write_reserve_buf;
1280
1281 int log_lebs;
1282 long long log_bytes;
1283 int log_last;
1284 int lpt_lebs;
1285 int lpt_first;
1286 int lpt_last;
1287 int orph_lebs;
1288 int orph_first;
1289 int orph_last;
1290 int main_lebs;
1291 int main_first;
1292 long long main_bytes;
1293
1294 uint8_t key_hash_type;
1295 uint32_t (*key_hash)(const char *str, int len);
1296 int key_fmt;
1297 int key_len;
1298 int fanout;
1299
1300 int min_io_size;
1301 int min_io_shift;
1302 int max_write_size;
1303 int max_write_shift;
1304 int leb_size;
1305 int leb_start;
1306 int half_leb_size;
1307 int idx_leb_size;
1308 int leb_cnt;
1309 int max_leb_cnt;
1310 int old_leb_cnt;
1311 unsigned int ro_media:1;
1312 unsigned int ro_mount:1;
1313 unsigned int ro_error:1;
1314
1315 atomic_long_t dirty_pg_cnt;
1316 atomic_long_t dirty_zn_cnt;
1317 atomic_long_t clean_zn_cnt;
1318
1319 spinlock_t space_lock;
1320 struct ubifs_lp_stats lst;
1321 struct ubifs_budg_info bi;
1322 unsigned long long calc_idx_sz;
1323
1324 int ref_node_alsz;
1325 int mst_node_alsz;
1326 int min_idx_node_sz;
1327 int max_idx_node_sz;
1328 long long max_inode_sz;
1329 int max_znode_sz;
1330
1331 int leb_overhead;
1332 int dead_wm;
1333 int dark_wm;
1334 int block_cnt;
1335
1336 struct ubifs_node_range ranges[UBIFS_NODE_TYPES_CNT];
1337 struct ubi_volume_desc *ubi;
1338 struct ubi_device_info di;
1339 struct ubi_volume_info vi;
1340
1341 struct rb_root orph_tree;
1342 struct list_head orph_list;
1343 struct list_head orph_new;
1344 struct ubifs_orphan *orph_cnext;
1345 struct ubifs_orphan *orph_dnext;
1346 spinlock_t orphan_lock;
1347 void *orph_buf;
1348 int new_orphans;
1349 int cmt_orphans;
1350 int tot_orphans;
1351 int max_orphans;
1352 int ohead_lnum;
1353 int ohead_offs;
1354 int no_orphs;
1355
1356 struct task_struct *bgt;
1357 char bgt_name[sizeof(BGT_NAME_PATTERN) + 9];
1358 int need_bgt;
1359 int need_wbuf_sync;
1360
1361 int gc_lnum;
1362 void *sbuf;
1363 struct list_head idx_gc;
1364 int idx_gc_cnt;
1365 int gc_seq;
1366 int gced_lnum;
1367
1368 struct list_head infos_list;
1369 struct mutex umount_mutex;
1370 unsigned int shrinker_run_no;
1371
1372 int space_bits;
1373 int lpt_lnum_bits;
1374 int lpt_offs_bits;
1375 int lpt_spc_bits;
1376 int pcnt_bits;
1377 int lnum_bits;
1378 int nnode_sz;
1379 int pnode_sz;
1380 int ltab_sz;
1381 int lsave_sz;
1382 int pnode_cnt;
1383 int nnode_cnt;
1384 int lpt_hght;
1385 int pnodes_have;
1386
1387 struct mutex lp_mutex;
1388 int lpt_lnum;
1389 int lpt_offs;
1390 int nhead_lnum;
1391 int nhead_offs;
1392 int lpt_drty_flgs;
1393 int dirty_nn_cnt;
1394 int dirty_pn_cnt;
1395 int check_lpt_free;
1396 long long lpt_sz;
1397 void *lpt_nod_buf;
1398 void *lpt_buf;
1399 struct ubifs_nnode *nroot;
1400 struct ubifs_cnode *lpt_cnext;
1401 struct ubifs_lpt_heap lpt_heap[LPROPS_HEAP_CNT];
1402 struct ubifs_lpt_heap dirty_idx;
1403 struct list_head uncat_list;
1404 struct list_head empty_list;
1405 struct list_head freeable_list;
1406 struct list_head frdi_idx_list;
1407 int freeable_cnt;
1408 int in_a_category_cnt;
1409
1410 int ltab_lnum;
1411 int ltab_offs;
1412 struct ubifs_lpt_lprops *ltab;
1413 struct ubifs_lpt_lprops *ltab_cmt;
1414 int lsave_cnt;
1415 int lsave_lnum;
1416 int lsave_offs;
1417 int *lsave;
1418 int lscan_lnum;
1419
1420 long long rp_size;
1421 long long report_rp_size;
1422 kuid_t rp_uid;
1423 kgid_t rp_gid;
1424
1425
1426 unsigned int empty:1;
1427 unsigned int need_recovery:1;
1428 unsigned int replaying:1;
1429 unsigned int mounting:1;
1430 unsigned int remounting_rw:1;
1431 unsigned int probing:1;
1432 struct list_head replay_list;
1433 struct list_head replay_buds;
1434 unsigned long long cs_sqnum;
1435 unsigned long long replay_sqnum;
1436 struct list_head unclean_leb_list;
1437 struct ubifs_mst_node *rcvrd_mst_node;
1438 struct rb_root size_tree;
1439 struct ubifs_mount_opts mount_opts;
1440
1441 struct ubifs_debug_info *dbg;
1442};
1443
1444extern struct list_head ubifs_infos;
1445extern spinlock_t ubifs_infos_lock;
1446extern atomic_long_t ubifs_clean_zn_cnt;
1447extern struct kmem_cache *ubifs_inode_slab;
1448extern const struct super_operations ubifs_super_operations;
1449extern const struct address_space_operations ubifs_file_address_operations;
1450extern const struct file_operations ubifs_file_operations;
1451extern const struct inode_operations ubifs_file_inode_operations;
1452extern const struct file_operations ubifs_dir_operations;
1453extern const struct inode_operations ubifs_dir_inode_operations;
1454extern const struct inode_operations ubifs_symlink_inode_operations;
1455extern struct backing_dev_info ubifs_backing_dev_info;
1456extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
1457
1458
1459void ubifs_ro_mode(struct ubifs_info *c, int err);
1460int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
1461 int len, int even_ebadmsg);
1462int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
1463 int len);
1464int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
1465int ubifs_leb_unmap(struct ubifs_info *c, int lnum);
1466int ubifs_leb_map(struct ubifs_info *c, int lnum);
1467int ubifs_is_mapped(const struct ubifs_info *c, int lnum);
1468int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len);
1469int ubifs_wbuf_seek_nolock(struct ubifs_wbuf *wbuf, int lnum, int offs);
1470int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf);
1471int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
1472 int lnum, int offs);
1473int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
1474 int lnum, int offs);
1475int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
1476 int offs);
1477int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
1478 int offs, int quiet, int must_chk_crc);
1479void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
1480void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
1481int ubifs_io_init(struct ubifs_info *c);
1482void ubifs_pad(const struct ubifs_info *c, void *buf, int pad);
1483int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf);
1484int ubifs_bg_wbufs_sync(struct ubifs_info *c);
1485void ubifs_wbuf_add_ino_nolock(struct ubifs_wbuf *wbuf, ino_t inum);
1486int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
1487
1488
1489struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
1490 int offs, void *sbuf, int quiet);
1491void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
1492int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
1493 int offs, int quiet);
1494struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
1495 int offs, void *sbuf);
1496void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1497 int lnum, int offs);
1498int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
1499 void *buf, int offs);
1500void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
1501 void *buf);
1502
1503
1504void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud);
1505void ubifs_create_buds_lists(struct ubifs_info *c);
1506int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs);
1507struct ubifs_bud *ubifs_search_bud(struct ubifs_info *c, int lnum);
1508struct ubifs_wbuf *ubifs_get_wbuf(struct ubifs_info *c, int lnum);
1509int ubifs_log_start_commit(struct ubifs_info *c, int *ltail_lnum);
1510int ubifs_log_end_commit(struct ubifs_info *c, int new_ltail_lnum);
1511int ubifs_log_post_commit(struct ubifs_info *c, int old_ltail_lnum);
1512int ubifs_consolidate_log(struct ubifs_info *c);
1513
1514
1515int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
1516 const struct qstr *nm, const struct inode *inode,
1517 int deletion, int xent);
1518int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
1519 const union ubifs_key *key, const void *buf, int len);
1520int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode);
1521int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode);
1522int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
1523 const struct dentry *old_dentry,
1524 const struct inode *new_dir,
1525 const struct dentry *new_dentry, int sync);
1526int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
1527 loff_t old_size, loff_t new_size);
1528int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
1529 const struct inode *inode, const struct qstr *nm);
1530int ubifs_jnl_change_xattr(struct ubifs_info *c, const struct inode *inode1,
1531 const struct inode *inode2);
1532
1533
1534int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req);
1535void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req);
1536void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
1537 struct ubifs_inode *ui);
1538int ubifs_budget_inode_op(struct ubifs_info *c, struct inode *inode,
1539 struct ubifs_budget_req *req);
1540void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode,
1541 struct ubifs_budget_req *req);
1542void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
1543 struct ubifs_budget_req *req);
1544long long ubifs_get_free_space(struct ubifs_info *c);
1545long long ubifs_get_free_space_nolock(struct ubifs_info *c);
1546int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
1547void ubifs_convert_page_budget(struct ubifs_info *c);
1548long long ubifs_reported_space(const struct ubifs_info *c, long long free);
1549long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
1550
1551
1552int ubifs_find_free_space(struct ubifs_info *c, int min_space, int *offs,
1553 int squeeze);
1554int ubifs_find_free_leb_for_idx(struct ubifs_info *c);
1555int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
1556 int min_space, int pick_free);
1557int ubifs_find_dirty_idx_leb(struct ubifs_info *c);
1558int ubifs_save_dirty_idx_lnums(struct ubifs_info *c);
1559
1560
1561int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
1562 struct ubifs_znode **zn, int *n);
1563int ubifs_tnc_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
1564 void *node, const struct qstr *nm);
1565int ubifs_tnc_locate(struct ubifs_info *c, const union ubifs_key *key,
1566 void *node, int *lnum, int *offs);
1567int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
1568 int offs, int len);
1569int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
1570 int old_lnum, int old_offs, int lnum, int offs, int len);
1571int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
1572 int lnum, int offs, int len, const struct qstr *nm);
1573int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key);
1574int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
1575 const struct qstr *nm);
1576int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
1577 union ubifs_key *to_key);
1578int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum);
1579struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
1580 union ubifs_key *key,
1581 const struct qstr *nm);
1582void ubifs_tnc_close(struct ubifs_info *c);
1583int ubifs_tnc_has_node(struct ubifs_info *c, union ubifs_key *key, int level,
1584 int lnum, int offs, int is_idx);
1585int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
1586 int lnum, int offs);
1587
1588void destroy_old_idx(struct ubifs_info *c);
1589int is_idx_node_in_tnc(struct ubifs_info *c, union ubifs_key *key, int level,
1590 int lnum, int offs);
1591int insert_old_idx_znode(struct ubifs_info *c, struct ubifs_znode *znode);
1592int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu);
1593int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu);
1594
1595
1596struct ubifs_znode *ubifs_tnc_levelorder_next(struct ubifs_znode *zr,
1597 struct ubifs_znode *znode);
1598int ubifs_search_zbranch(const struct ubifs_info *c,
1599 const struct ubifs_znode *znode,
1600 const union ubifs_key *key, int *n);
1601struct ubifs_znode *ubifs_tnc_postorder_first(struct ubifs_znode *znode);
1602struct ubifs_znode *ubifs_tnc_postorder_next(struct ubifs_znode *znode);
1603long ubifs_destroy_tnc_subtree(struct ubifs_znode *zr);
1604struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
1605 struct ubifs_zbranch *zbr,
1606 struct ubifs_znode *parent, int iip);
1607int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
1608 void *node);
1609
1610
1611int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot);
1612int ubifs_tnc_end_commit(struct ubifs_info *c);
1613
1614
1615unsigned long ubifs_shrink_scan(struct shrinker *shrink,
1616 struct shrink_control *sc);
1617unsigned long ubifs_shrink_count(struct shrinker *shrink,
1618 struct shrink_control *sc);
1619
1620
1621int ubifs_bg_thread(void *info);
1622void ubifs_commit_required(struct ubifs_info *c);
1623void ubifs_request_bg_commit(struct ubifs_info *c);
1624int ubifs_run_commit(struct ubifs_info *c);
1625void ubifs_recovery_commit(struct ubifs_info *c);
1626int ubifs_gc_should_commit(struct ubifs_info *c);
1627void ubifs_wait_for_commit(struct ubifs_info *c);
1628
1629
1630int ubifs_read_master(struct ubifs_info *c);
1631int ubifs_write_master(struct ubifs_info *c);
1632
1633
1634int ubifs_read_superblock(struct ubifs_info *c);
1635struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c);
1636int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup);
1637int ubifs_fixup_free_space(struct ubifs_info *c);
1638
1639
1640int ubifs_validate_entry(struct ubifs_info *c,
1641 const struct ubifs_dent_node *dent);
1642int ubifs_replay_journal(struct ubifs_info *c);
1643
1644
1645int ubifs_garbage_collect(struct ubifs_info *c, int anyway);
1646int ubifs_gc_start_commit(struct ubifs_info *c);
1647int ubifs_gc_end_commit(struct ubifs_info *c);
1648void ubifs_destroy_idx_gc(struct ubifs_info *c);
1649int ubifs_get_idx_gc_leb(struct ubifs_info *c);
1650int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp);
1651
1652
1653int ubifs_add_orphan(struct ubifs_info *c, ino_t inum);
1654void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum);
1655int ubifs_orphan_start_commit(struct ubifs_info *c);
1656int ubifs_orphan_end_commit(struct ubifs_info *c);
1657int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only);
1658int ubifs_clear_orphans(struct ubifs_info *c);
1659
1660
1661int ubifs_calc_lpt_geom(struct ubifs_info *c);
1662int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
1663 int *lpt_lebs, int *big_lpt);
1664int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
1665struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
1666struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
1667int ubifs_lpt_scan_nolock(struct ubifs_info *c, int start_lnum, int end_lnum,
1668 ubifs_lpt_scan_callback scan_cb, void *data);
1669
1670
1671void ubifs_pack_lsave(struct ubifs_info *c, void *buf, int *lsave);
1672void ubifs_pack_ltab(struct ubifs_info *c, void *buf,
1673 struct ubifs_lpt_lprops *ltab);
1674void ubifs_pack_pnode(struct ubifs_info *c, void *buf,
1675 struct ubifs_pnode *pnode);
1676void ubifs_pack_nnode(struct ubifs_info *c, void *buf,
1677 struct ubifs_nnode *nnode);
1678struct ubifs_pnode *ubifs_get_pnode(struct ubifs_info *c,
1679 struct ubifs_nnode *parent, int iip);
1680struct ubifs_nnode *ubifs_get_nnode(struct ubifs_info *c,
1681 struct ubifs_nnode *parent, int iip);
1682int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip);
1683void ubifs_add_lpt_dirt(struct ubifs_info *c, int lnum, int dirty);
1684void ubifs_add_nnode_dirt(struct ubifs_info *c, struct ubifs_nnode *nnode);
1685uint32_t ubifs_unpack_bits(uint8_t **addr, int *pos, int nrbits);
1686struct ubifs_nnode *ubifs_first_nnode(struct ubifs_info *c, int *hght);
1687
1688int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1689 struct ubifs_nnode *nnode);
1690
1691
1692int ubifs_lpt_start_commit(struct ubifs_info *c);
1693int ubifs_lpt_end_commit(struct ubifs_info *c);
1694int ubifs_lpt_post_commit(struct ubifs_info *c);
1695void ubifs_lpt_free(struct ubifs_info *c, int wr_only);
1696
1697
1698const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c,
1699 const struct ubifs_lprops *lp,
1700 int free, int dirty, int flags,
1701 int idx_gc_cnt);
1702void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst);
1703void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops,
1704 int cat);
1705void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops,
1706 struct ubifs_lprops *new_lprops);
1707void ubifs_ensure_cat(struct ubifs_info *c, struct ubifs_lprops *lprops);
1708int ubifs_categorize_lprops(const struct ubifs_info *c,
1709 const struct ubifs_lprops *lprops);
1710int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1711 int flags_set, int flags_clean, int idx_gc_cnt);
1712int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
1713 int flags_set, int flags_clean);
1714int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp);
1715const struct ubifs_lprops *ubifs_fast_find_free(struct ubifs_info *c);
1716const struct ubifs_lprops *ubifs_fast_find_empty(struct ubifs_info *c);
1717const struct ubifs_lprops *ubifs_fast_find_freeable(struct ubifs_info *c);
1718const struct ubifs_lprops *ubifs_fast_find_frdi_idx(struct ubifs_info *c);
1719int ubifs_calc_dark(const struct ubifs_info *c, int spc);
1720
1721
1722int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync);
1723int ubifs_setattr(struct dentry *dentry, struct iattr *attr);
1724#ifdef CONFIG_UBIFS_ATIME_SUPPORT
1725int ubifs_update_time(struct inode *inode, struct timespec *time, int flags);
1726#endif
1727
1728
1729struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir,
1730 umode_t mode);
1731int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1732 struct kstat *stat);
1733
1734
1735int ubifs_setxattr(struct dentry *dentry, const char *name,
1736 const void *value, size_t size, int flags);
1737ssize_t ubifs_getxattr(struct dentry *dentry, const char *name, void *buf,
1738 size_t size);
1739ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
1740int ubifs_removexattr(struct dentry *dentry, const char *name);
1741int ubifs_init_security(struct inode *dentry, struct inode *inode,
1742 const struct qstr *qstr);
1743
1744
1745struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
1746
1747
1748int ubifs_recover_master_node(struct ubifs_info *c);
1749int ubifs_write_rcvrd_mst_node(struct ubifs_info *c);
1750struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
1751 int offs, void *sbuf, int jhead);
1752struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
1753 int offs, void *sbuf);
1754int ubifs_recover_inl_heads(struct ubifs_info *c, void *sbuf);
1755int ubifs_clean_lebs(struct ubifs_info *c, void *sbuf);
1756int ubifs_rcvry_gc_commit(struct ubifs_info *c);
1757int ubifs_recover_size_accum(struct ubifs_info *c, union ubifs_key *key,
1758 int deletion, loff_t new_size);
1759int ubifs_recover_size(struct ubifs_info *c);
1760void ubifs_destroy_size_tree(struct ubifs_info *c);
1761
1762
1763long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1764void ubifs_set_inode_flags(struct inode *inode);
1765#ifdef CONFIG_COMPAT
1766long ubifs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1767#endif
1768
1769
1770int __init ubifs_compressors_init(void);
1771void ubifs_compressors_exit(void);
1772void ubifs_compress(const struct ubifs_info *c, const void *in_buf, int in_len,
1773 void *out_buf, int *out_len, int *compr_type);
1774int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
1775 void *out, int *out_len, int compr_type);
1776
1777#include "debug.h"
1778#include "misc.h"
1779#include "key.h"
1780
1781
1782__printf(2, 3)
1783void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
1784__printf(2, 3)
1785void ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
1786__printf(2, 3)
1787void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
1788
1789
1790
1791
1792#define ubifs_errc(c, fmt, ...) \
1793do { \
1794 if (!(c)->probing) \
1795 ubifs_err(c, fmt, ##__VA_ARGS__); \
1796} while (0)
1797
1798#endif
1799