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