History

Removed nasty tabs.

gkostka committed 13 years ago

Commit ead60f11 parent 14dd31728 files · +600 −605Browse files

Unified · Split

28 files
  1. blockdev/filedev/ext4_filedev.c +36 −36
  2. blockdev/filedev/ext4_filedev.h +5 −5
  3. demos/generic/main.c +103 −103
  4. ext4.h +25 −25
  5. lwext4/ext4.c +25 −25
  6. lwext4/ext4_balloc.c +11 −11
  7. lwext4/ext4_balloc.h +21 −21
  8. lwext4/ext4_bcache.c +6 −6
  9. lwext4/ext4_bcache.h +62 −62
  10. lwext4/ext4_bitmap.h +21 −21
  11. lwext4/ext4_blockdev.c +16 −16
  12. lwext4/ext4_blockdev.h +102 −102
  13. lwext4/ext4_config.h +9 −9
  14. lwext4/ext4_debug.h +20 −20
  15. lwext4/ext4_dir.c +3 −3
  16. lwext4/ext4_dir_idx.c +3 −3
  17. lwext4/ext4_errno.h +35 −35
  18. lwext4/ext4_fs.c +10 −10
  19. lwext4/ext4_hash.h +8 −8
  20. lwext4/ext4_ialloc.c +2 −2
  21. lwext4/ext4_inode.c +5 −5
  22. lwext4/ext4_super.c +4 −4
  23. lwext4/ext4_super.h +2 −2
  24. lwext4/ext4_types.h +39 −39
  25. readme.txt +4 −4
  26. toolchain/bf518.cmake +7 −12
  27. toolchain/cortex-m3.cmake +8 −8
  28. toolchain/cortex-m4.cmake +8 −8
blockdev/filedev/ext4_filedev.c+36−36
@@ -33,14 +33,14 @@ · 32 unmodified lines
33#include <string.h>33#include <string.h>
34#include <fcntl.h>34#include <fcntl.h>
35 35
36/**@brief Default filename.*/36/**@brief Default filename.*/
37static const char *fname = "ext2";37static const char *fname = "ext2";
38 38
39/**@brief Image block size.*/39/**@brief Image block size.*/
40#define EXT4_FILEDEV_BSIZE 51240#define EXT4_FILEDEV_BSIZE 512
41 41
42/**@brief Image file descriptor.*/42/**@brief Image file descriptor.*/
43static FILE *dev_file;43static FILE *dev_file;
44 44
45#define DROP_LINUXCACHE_BUFFERS 145#define DROP_LINUXCACHE_BUFFERS 1
46 46
@@ -48,21 +48,21 @@ static FILE *dev_file; · 1 unmodified line
48/**********************BLOCKDEV INTERFACE**************************************/48/**********************BLOCKDEV INTERFACE**************************************/
49static int filedev_open(struct ext4_blockdev *bdev);49static int filedev_open(struct ext4_blockdev *bdev);
50static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,50static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
51 uint32_t blk_cnt);51 uint32_t blk_cnt);
52static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,52static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf,
53 uint64_t blk_id, uint32_t blk_cnt);53 uint64_t blk_id, uint32_t blk_cnt);
54static int filedev_close(struct ext4_blockdev *bdev);54static int filedev_close(struct ext4_blockdev *bdev);
55 55
56 56
57/******************************************************************************/57/******************************************************************************/
58EXT4_BLOCKDEV_STATIC_INSTANCE(58EXT4_BLOCKDEV_STATIC_INSTANCE(
59 _filedev,59 _filedev,
60 EXT4_FILEDEV_BSIZE,60 EXT4_FILEDEV_BSIZE,
61 0,61 0,
62 filedev_open,62 filedev_open,
63 filedev_bread,63 filedev_bread,
64 filedev_bwrite,64 filedev_bwrite,
65 filedev_close65 filedev_close
66);66);
67 67
68/******************************************************************************/68/******************************************************************************/
@@ -71,34 +71,34 @@ EXT4_BCACHE_STATIC_INSTANCE(__cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024); · 2 unmodified lines
71/******************************************************************************/71/******************************************************************************/
72static int filedev_open(struct ext4_blockdev *bdev)72static int filedev_open(struct ext4_blockdev *bdev)
73{73{
74 dev_file = fopen(fname, "r+b");74 dev_file = fopen(fname, "r+b");
75 75
76 if(!dev_file)76 if(!dev_file)
77 return EIO;77 return EIO;
78 78
79 /*No buffering at file.*/79 /*No buffering at file.*/
80 setbuf(dev_file, 0);80 setbuf(dev_file, 0);
81 81
82 if(fseek(dev_file, 0, SEEK_END))82 if(fseek(dev_file, 0, SEEK_END))
83 return EFAULT;83 return EFAULT;
84 84
85 _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;85 _filedev.ph_bcnt = ftell(dev_file) / _filedev.ph_bsize;
86 86
87 return EOK;87 return EOK;
88}88}
89 89
90/******************************************************************************/90/******************************************************************************/
91 91
92static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,92static int filedev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
93 uint32_t blk_cnt)93 uint32_t blk_cnt)
94{94{
95 if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))95 if(fseek(dev_file, blk_id * bdev->ph_bsize, SEEK_SET))
96 return EIO;96 return EIO;
97 97
98 if(!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))98 if(!fread(buf, bdev->ph_bsize * blk_cnt, 1, dev_file))
99 return EIO;99 return EIO;
100 100
101 return EOK;101 return EOK;
102}102}
103 103
104static void drop_cache(void)104static void drop_cache(void)
@@ -130,26 +130,26 @@ static int filedev_bwrite(struct ext4_blockdev *bdev, const void *buf, · 25 unmodified lines
130/******************************************************************************/130/******************************************************************************/
131static int filedev_close(struct ext4_blockdev *bdev)131static int filedev_close(struct ext4_blockdev *bdev)
132{132{
133 fclose(dev_file);133 fclose(dev_file);
134 return EOK;134 return EOK;
135}135}
136 136
137 137
138/******************************************************************************/138/******************************************************************************/
139 139
140struct ext4_bcache* ext4_filecache_get(void)140struct ext4_bcache* ext4_filecache_get(void)
141{141{
142 return &__cache;142 return &__cache;
143}143}
144/******************************************************************************/144/******************************************************************************/
145struct ext4_blockdev* ext4_filedev_get(void)145struct ext4_blockdev* ext4_filedev_get(void)
146{146{
147 return &_filedev;147 return &_filedev;
148}148}
149/******************************************************************************/149/******************************************************************************/
150void ext4_filedev_filename(const char *n)150void ext4_filedev_filename(const char *n)
151{151{
152 fname = n;152 fname = n;
153}153}
154 154
155/******************************************************************************/155/******************************************************************************/
blockdev/filedev/ext4_filedev.h+5−5
@@ -34,12 +34,12 @@ · 33 unmodified lines
34#include <stdint.h>34#include <stdint.h>
35#include <stdbool.h>35#include <stdbool.h>
36 36
37/**@brief Filecache get.*/37/**@brief Filecache get.*/
38struct ext4_bcache* ext4_filecache_get(void);38struct ext4_bcache* ext4_filecache_get(void);
39 39
40/**@brief File blockdev get.*/40/**@brief File blockdev get.*/
41struct ext4_blockdev* ext4_filedev_get(void);41struct ext4_blockdev* ext4_filedev_get(void);
42 42
43void ext4_filedev_filename(const char *n);43void ext4_filedev_filename(const char *n);
44 44
45#endif /* EXT4_FILEDEV_H_ */45#endif /* EXT4_FILEDEV_H_ */
demos/generic/main.c+103−103
@@ -46,10 +46,10 @@ · 45 unmodified lines
46/**@brief Input stream name.*/46/**@brief Input stream name.*/
47char input_name[128] = "ext2";47char input_name[128] = "ext2";
48 48
49/**@brief Read-write size*/49/**@brief Read-write size*/
50static int rw_szie = 1024 * 1024;50static int rw_szie = 1024 * 1024;
51 51
52/**@brief Read-write size*/52/**@brief Read-write size*/
53static int rw_count = 10;53static int rw_count = 10;
54 54
55/**@brief Directory test count*/55/**@brief Directory test count*/
@@ -70,16 +70,16 @@ static bool sbstat = false; · 14 unmodified lines
70/**@brief Indicates that input is windows partition.*/70/**@brief Indicates that input is windows partition.*/
71static bool winpart = false;71static bool winpart = false;
72 72
73/**@brief File write buffer*/73/**@brief File write buffer*/
74static uint8_t *wr_buff;74static uint8_t *wr_buff;
75 75
76/**@brief File read buffer.*/76/**@brief File read buffer.*/
77static uint8_t *rd_buff;77static uint8_t *rd_buff;
78 78
79/**@brief Block device handle.*/79/**@brief Block device handle.*/
80static struct ext4_blockdev *bd;80static struct ext4_blockdev *bd;
81 81
82/**@brief Block cache handle.*/82/**@brief Block cache handle.*/
83static struct ext4_bcache *bc;83static struct ext4_bcache *bc;
84 84
85static const char *usage = " \n\85static const char *usage = " \n\
@@ -99,52 +99,52 @@ Usage: \n\ · 13 unmodified lines
99 99
100static char* entry_to_str(uint8_t type)100static char* entry_to_str(uint8_t type)
101{101{
102 switch(type){102 switch(type){
103 case EXT4_DIRENTRY_UNKNOWN:103 case EXT4_DIRENTRY_UNKNOWN:
104 return "[UNK] ";104 return "[UNK] ";
105 case EXT4_DIRENTRY_REG_FILE:105 case EXT4_DIRENTRY_REG_FILE:
106 return "[FIL] ";106 return "[FIL] ";
107 case EXT4_DIRENTRY_DIR:107 case EXT4_DIRENTRY_DIR:
108 return "[DIR] ";108 return "[DIR] ";
109 case EXT4_DIRENTRY_CHRDEV:109 case EXT4_DIRENTRY_CHRDEV:
110 return "[CHA] ";110 return "[CHA] ";
111 case EXT4_DIRENTRY_BLKDEV:111 case EXT4_DIRENTRY_BLKDEV:
112 return "[BLK] ";112 return "[BLK] ";
113 case EXT4_DIRENTRY_FIFO:113 case EXT4_DIRENTRY_FIFO:
114 return "[FIF] ";114 return "[FIF] ";
115 case EXT4_DIRENTRY_SOCK:115 case EXT4_DIRENTRY_SOCK:
116 return "[SOC] ";116 return "[SOC] ";
117 case EXT4_DIRENTRY_SYMLINK:117 case EXT4_DIRENTRY_SYMLINK:
118 return "[SYM] ";118 return "[SYM] ";
119 default:119 default:
120 break;120 break;
121 }121 }
122 return "[???]";122 return "[???]";
123}123}
124 124
125static void dir_ls(const char *path)125static void dir_ls(const char *path)
126{126{
127 int j = 0;127 int j = 0;
128 char sss[255];128 char sss[255];
129 ext4_dir d;129 ext4_dir d;
130 ext4_direntry *de;130 ext4_direntry *de;
131 131
132 printf("**********************************************\n");132 printf("**********************************************\n");
133 133
134 ext4_dir_open(&d, path);134 ext4_dir_open(&d, path);
135 de = ext4_dir_entry_get(&d, j++);135 de = ext4_dir_entry_get(&d, j++);
136 printf("ls %s\n", path);136 printf("ls %s\n", path);
137 137
138 while(de){138 while(de){
139 memcpy(sss, de->name, de->name_length);139 memcpy(sss, de->name, de->name_length);
140 sss[de->name_length] = 0;140 sss[de->name_length] = 0;
141 printf("%s", entry_to_str(de->inode_type));141 printf("%s", entry_to_str(de->inode_type));
142 printf("%s", sss);142 printf("%s", sss);
143 printf("\n");143 printf("\n");
144 de = ext4_dir_entry_get(&d, j++);144 de = ext4_dir_entry_get(&d, j++);
145 }145 }
146 printf("**********************************************\n");146 printf("**********************************************\n");
147 ext4_dir_close(&d);147 ext4_dir_close(&d);
148}148}
149 149
150static void mp_stats(void)150static void mp_stats(void)
@@ -397,8 +397,8 @@ static bool mount(void) · 246 unmodified lines
397{397{
398 int r;398 int r;
399 if(winpart){399 if(winpart){
400 if(!open_winpartition())400 if(!open_winpartition())
401 return false;401 return false;
402 }else{402 }else{
403 if(!open_filedev())403 if(!open_filedev())
404 return false;404 return false;
@@ -445,52 +445,52 @@ static bool parse_opt(int argc, char **argv) · 40 unmodified lines
445 int c;445 int c;
446 446
447 static struct option long_options[] =447 static struct option long_options[] =
448 {448 {
449 {"in", required_argument, 0, 'a'},449 {"in", required_argument, 0, 'a'},
450 {"rws", required_argument, 0, 'b'},450 {"rws", required_argument, 0, 'b'},
451 {"rwc", required_argument, 0, 'c'},451 {"rwc", required_argument, 0, 'c'},
452 {"cache", required_argument, 0, 'd'},452 {"cache", required_argument, 0, 'd'},
453 {"dirs", required_argument, 0, 'e'},453 {"dirs", required_argument, 0, 'e'},
454 {"clean", no_argument, 0, 'f'},454 {"clean", no_argument, 0, 'f'},
455 {"bstat", no_argument, 0, 'g'},455 {"bstat", no_argument, 0, 'g'},
456 {"sbstat", no_argument, 0, 'h'},456 {"sbstat", no_argument, 0, 'h'},
457 {"wpart", no_argument, 0, 'i'},457 {"wpart", no_argument, 0, 'i'},
458 {0, 0, 0, 0}458 {0, 0, 0, 0}
459 };459 };
460 460
461 while(-1 != (c = getopt_long (argc, argv, "a:b:c:d:e:fghi", long_options, &option_index))) {461 while(-1 != (c = getopt_long (argc, argv, "a:b:c:d:e:fghi", long_options, &option_index))) {
462 462
463 switch(c){463 switch(c){
464 case 'a':464 case 'a':
465 strcpy(input_name, optarg);465 strcpy(input_name, optarg);
466 break;466 break;
467 case 'b':467 case 'b':
468 rw_szie = atoi(optarg);468 rw_szie = atoi(optarg);
469 break;469 break;
470 case 'c':470 case 'c':
471 rw_count = atoi(optarg);471 rw_count = atoi(optarg);
472 break;472 break;
473 case 'd':473 case 'd':
474 cache_mode = atoi(optarg);474 cache_mode = atoi(optarg);
475 break;475 break;
476 case 'e':476 case 'e':
477 dir_cnt = atoi(optarg);477 dir_cnt = atoi(optarg);
478 break;478 break;
479 case 'f':479 case 'f':
480 cleanup_flag = true;480 cleanup_flag = true;
481 break;481 break;
482 case 'g':482 case 'g':
483 bstat = true;483 bstat = true;
484 break;484 break;
485 case 'h':485 case 'h':
486 sbstat = true;486 sbstat = true;
487 break;487 break;
488 case 'i':488 case 'i':
489 winpart = true;489 winpart = true;
490 break;490 break;
491 default:491 default:
492 printf("%s", usage);492 printf("%s", usage);
493 return false;493 return false;
494 494
495 }495 }
496 }496 }
@@ -520,20 +520,20 @@ int main(int argc, char **argv) · 23 unmodified lines
520 dir_ls("/mp/");520 dir_ls("/mp/");
521 fflush(stdout);521 fflush(stdout);
522 if(!dir_test(dir_cnt))522 if(!dir_test(dir_cnt))
523 return EXIT_FAILURE;523 return EXIT_FAILURE;
524 524
525 fflush(stdout);525 fflush(stdout);
526 if(!file_test())526 if(!file_test())
527 return EXIT_FAILURE;527 return EXIT_FAILURE;
528 528
529 fflush(stdout);529 fflush(stdout);
530 dir_ls("/mp/");530 dir_ls("/mp/");
531 531
532 if(sbstat)532 if(sbstat)
533 mp_stats();533 mp_stats();
534 534
535 if(cleanup_flag)535 if(cleanup_flag)
536 cleanup();536 cleanup();
537 537
538 if(bstat)538 if(bstat)
539 block_stats();539 block_stats();
ext4.h+25−25
@@ -32,7 +32,7 @@ · 31 unmodified lines
32/**32/**
33 * @file ext4.h33 * @file ext4.h
34 * @brief Ext4 high level operations (files, directories, mountpoints...).34 * @brief Ext4 high level operations (files, directories, mountpoints...).
35 * Client has to include only this file.35 * Client has to include only this file.
36 */36 */
37 37
38#ifndef EXT4_H_38#ifndef EXT4_H_
@@ -75,53 +75,53 @@ · 36 unmodified lines
75/********************************FILE SEEK FLAGS*****************************/75/********************************FILE SEEK FLAGS*****************************/
76 76
77#ifndef SEEK_SET77#ifndef SEEK_SET
78#define SEEK_SET 078#define SEEK_SET 0
79#endif79#endif
80 80
81#ifndef SEEK_CUR81#ifndef SEEK_CUR
82#define SEEK_CUR 182#define SEEK_CUR 1
83#endif83#endif
84 84
85#ifndef SEEK_END85#ifndef SEEK_END
86#define SEEK_END 286#define SEEK_END 2
87#endif87#endif
88 88
89/********************************OS LOCK INFERFACE***************************/89/********************************OS LOCK INFERFACE***************************/
90 90
91/**@brief OS dependent lock interface.*/91/**@brief OS dependent lock interface.*/
92struct ext4_lock {92struct ext4_lock {
93 93
94 /**@brief Lock access to mountpoint*/94 /**@brief Lock access to mountpoint*/
95 void (*lock)(void);95 void (*lock)(void);
96 96
97 /**@brief Unlock access to mountpoint*/97 /**@brief Unlock access to mountpoint*/
98 void (*unlock)(void);98 void (*unlock)(void);
99};99};
100 100
101 101
102/********************************FILE DESCRIPTOR*****************************/102/********************************FILE DESCRIPTOR*****************************/
103 103
104/**@brief File descriptor*/104/**@brief File descriptor*/
105typedef struct ext4_file {105typedef struct ext4_file {
106 106
107 /**@brief Pountpoint handle.*/107 /**@brief Pountpoint handle.*/
108 struct ext4_mountpoint *mp;108 struct ext4_mountpoint *mp;
109 109
110 /**@brief File inode id*/110 /**@brief File inode id*/
111 uint32_t inode;111 uint32_t inode;
112 112
113 /**@brief Open flags.*/113 /**@brief Open flags.*/
114 uint32_t flags;114 uint32_t flags;
115 115
116 /**@brief File size.*/116 /**@brief File size.*/
117 uint64_t fsize;117 uint64_t fsize;
118 118
119 /**@brief File position*/119 /**@brief File position*/
120 uint64_t fpos;120 uint64_t fpos;
121}ext4_file;121}ext4_file;
122 122
123/*****************************DIRECTORY DESCRIPTOR***************************/123/*****************************DIRECTORY DESCRIPTOR***************************/
124/**@brief Directory entry types. Copy from ext4_types.h*/124/**@brief Directory entry types. Copy from ext4_types.h*/
125enum {125enum {
126 EXT4_DIRENTRY_UNKNOWN = 0,126 EXT4_DIRENTRY_UNKNOWN = 0,
127 EXT4_DIRENTRY_REG_FILE,127 EXT4_DIRENTRY_REG_FILE,
@@ -146,10 +146,10 @@ typedef struct { · 18 unmodified lines
146}ext4_direntry;146}ext4_direntry;
147 147
148typedef struct {148typedef struct {
149 /**@brief File descriptor*/149 /**@brief File descriptor*/
150 ext4_file f;150 ext4_file f;
151 /**@brief Current direntry.*/151 /**@brief Current direntry.*/
152 ext4_direntry de;152 ext4_direntry de;
153}ext4_dir;153}ext4_dir;
154 154
155/********************************MOUNT OPERATIONS****************************/155/********************************MOUNT OPERATIONS****************************/
@@ -167,8 +167,8 @@ int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc, · 11 unmodified lines
167 const char *dev_name);167 const char *dev_name);
168 168
169/**@brief Mount a block device with EXT4 partition to the mountpoint.169/**@brief Mount a block device with EXT4 partition to the mountpoint.
170 * @param dev_name block device name (@ref ext4_device_register)170 * @param dev_name block device name (@ref ext4_device_register)
171 * @param mount_point pount point, for example171 * @param mount_point pount point, for example
172 * - /172 * - /
173 * - /my_partition/173 * - /my_partition/
174 * - /my_second_partition/174 * - /my_second_partition/
@@ -177,7 +177,7 @@ int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc, · 2 unmodified lines
177int ext4_mount(const char * dev_name, char *mount_point);177int ext4_mount(const char * dev_name, char *mount_point);
178 178
179/**@brief Umount operation.179/**@brief Umount operation.
180 * @param mount_point mount name180 * @param mount_point mount name
181 * @return standard error code */181 * @return standard error code */
182int ext4_umount(char *mount_point);182int ext4_umount(char *mount_point);
183 183
@@ -212,9 +212,9 @@ int ext4_mount_point_stats(const char *mount_point, · 28 unmodified lines
212int ext4_fremove(const char *path);212int ext4_fremove(const char *path);
213 213
214/**@brief File open function.214/**@brief File open function.
215 * @param filename, (has to start from mountpoint)215 * @param filename, (has to start from mountpoint)
216 * /my_partition/my_file216 * /my_partition/my_file
217 * @param flags open file flags217 * @param flags open file flags
218 * |---------------------------------------------------------------|218 * |---------------------------------------------------------------|
219 * | r or rb O_RDONLY |219 * | r or rb O_RDONLY |
220 * |---------------------------------------------------------------|220 * |---------------------------------------------------------------|
@@ -229,7 +229,7 @@ int ext4_fremove(const char *path); · 8 unmodified lines
229 * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |229 * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |
230 * |---------------------------------------------------------------|230 * |---------------------------------------------------------------|
231 *231 *
232 * @return standard error code*/232 * @return standard error code*/
233int ext4_fopen (ext4_file *f, const char *path, const char *flags);233int ext4_fopen (ext4_file *f, const char *path, const char *flags);
234 234
235/**@brief File close function.235/**@brief File close function.
lwext4/ext4.c+25−25
@@ -61,21 +61,21 @@ · 60 unmodified lines
61/**@brief Mount point descrpitor.*/61/**@brief Mount point descrpitor.*/
62struct ext4_mountpoint {62struct ext4_mountpoint {
63 63
64 /**@brief Mount point name (@ref ext4_mount)*/64 /**@brief Mount point name (@ref ext4_mount)*/
65 const char *name;65 const char *name;
66 66
67 /**@brief Os dependent lock/unlock functions.*/67 /**@brief Os dependent lock/unlock functions.*/
68 struct ext4_lock *os_locks;68 struct ext4_lock *os_locks;
69 69
70 /**@brief Ext4 filesystem internals.*/70 /**@brief Ext4 filesystem internals.*/
71 struct ext4_fs fs;71 struct ext4_fs fs;
72 72
73 /**@brief Dynamic alocation cache flag.*/73 /**@brief Dynamic alocation cache flag.*/
74 bool cache_dynamic;74 bool cache_dynamic;
75};75};
76 76
77/**@brief Block devices descriptor.*/77/**@brief Block devices descriptor.*/
78struct _ext4_devices {78struct _ext4_devices {
79 79
80 /**@brief Block device name (@ref ext4_device_register)*/80 /**@brief Block device name (@ref ext4_device_register)*/
81 const char *name;81 const char *name;
@@ -87,11 +87,11 @@ struct _ext4_devices { · 5 unmodified lines
87 struct ext4_bcache *bc;87 struct ext4_bcache *bc;
88};88};
89 89
90/**@brief Block devices.*/90/**@brief Block devices.*/
91struct _ext4_devices _bdevices[CONFIG_EXT4_BLOCKDEVS_COUNT];91struct _ext4_devices _bdevices[CONFIG_EXT4_BLOCKDEVS_COUNT];
92 92
93 93
94/**@brief Mountpoints.*/94/**@brief Mountpoints.*/
95struct ext4_mountpoint _mp[CONFIG_EXT4_MOUNTPOINTS_COUNT];95struct ext4_mountpoint _mp[CONFIG_EXT4_MOUNTPOINTS_COUNT];
96 96
97 97
@@ -105,8 +105,8 @@ int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc, · 7 unmodified lines
105 for (i = 0; i < CONFIG_EXT4_BLOCKDEVS_COUNT; ++i) {105 for (i = 0; i < CONFIG_EXT4_BLOCKDEVS_COUNT; ++i) {
106 if(!_bdevices[i].name){106 if(!_bdevices[i].name){
107 _bdevices[i].name = dev_name;107 _bdevices[i].name = dev_name;
108 _bdevices[i].bd = bd;108 _bdevices[i].bd = bd;
109 _bdevices[i].bc = bc;109 _bdevices[i].bc = bc;
110 return EOK;110 return EOK;
111 }111 }
112 }112 }
@@ -388,11 +388,11 @@ int ext4_mount(const char * dev_name, char *mount_point) · 275 unmodified lines
388}388}
389 389
390 390
391int ext4_umount(char *mount_point)391int ext4_umount(char *mount_point)
392{392{
393 int i;393 int i;
394 int r = EOK;394 int r = EOK;
395 struct ext4_mountpoint *mp = 0;395 struct ext4_mountpoint *mp = 0;
396 396
397 for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {397 for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
398 if(_mp[i].name){398 if(_mp[i].name){
@@ -502,7 +502,7 @@ static bool ext4_parse_flags(const char *flags, uint32_t *file_flags) · 103 unmodified lines
502 }502 }
503 503
504 if(!strcmp(flags, "a") || !strcmp(flags, "ab")){504 if(!strcmp(flags, "a") || !strcmp(flags, "ab")){
505 *file_flags = O_WRONLY | O_CREAT | O_APPEND ;505 *file_flags = O_WRONLY | O_CREAT | O_APPEND;
506 return true;506 return true;
507 }507 }
508 508
@@ -531,10 +531,10 @@ static int ext4_generic_open (ext4_file *f, const char *path, · 22 unmodified lines
531{531{
532 struct ext4_mountpoint *mp = ext4_get_mount(path);532 struct ext4_mountpoint *mp = ext4_get_mount(path);
533 struct ext4_directory_search_result result;533 struct ext4_directory_search_result result;
534 struct ext4_inode_ref ref;534 struct ext4_inode_ref ref;
535 bool is_goal = false;535 bool is_goal = false;
536 uint8_t inode_type = EXT4_DIRECTORY_FILETYPE_DIR;536 uint8_t inode_type = EXT4_DIRECTORY_FILETYPE_DIR;
537 int r = ENOENT;537 int r = ENOENT;
538 uint32_t next_inode;538 uint32_t next_inode;
539 539
540 f->mp = 0;540 f->mp = 0;
@@ -585,7 +585,7 @@ static int ext4_generic_open (ext4_file *f, const char *path, · 44 unmodified lines
585 break;585 break;
586 586
587 /*O_CREAT allows create new entry*/587 /*O_CREAT allows create new entry*/
588 struct ext4_inode_ref child_ref;588 struct ext4_inode_ref child_ref;
589 r = ext4_fs_alloc_inode(&mp->fs, &child_ref, is_goal ? !file_expect : true);589 r = ext4_fs_alloc_inode(&mp->fs, &child_ref, is_goal ? !file_expect : true);
590 if(r != EOK)590 if(r != EOK)
591 break;591 break;
@@ -790,7 +790,7 @@ int ext4_fread(ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt) · 198 unmodified lines
790 uint32_t fblock_start;790 uint32_t fblock_start;
791 uint32_t fblock_cnt;791 uint32_t fblock_cnt;
792 struct ext4_block b;792 struct ext4_block b;
793 uint8_t *u8_buf = buf;793 uint8_t *u8_buf = buf;
794 struct ext4_inode_ref ref;794 struct ext4_inode_ref ref;
795 uint32_t sblock;795 uint32_t sblock;
796 uint32_t sblock_end;796 uint32_t sblock_end;
@@ -821,7 +821,7 @@ int ext4_fread(ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt) · 24 unmodified lines
821 821
822 block_size = ext4_sb_get_block_size(&f->mp->fs.sb);822 block_size = ext4_sb_get_block_size(&f->mp->fs.sb);
823 size = size > (f->fsize - f->fpos) ? (f->fsize - f->fpos) : size;823 size = size > (f->fsize - f->fpos) ? (f->fsize - f->fpos) : size;
824 sblock = (f->fpos) / block_size;824 sblock = (f->fpos) / block_size;
825 sblock_end = (f->fpos + size) / block_size;825 sblock_end = (f->fpos + size) / block_size;
826 u = (f->fpos) % block_size;826 u = (f->fpos) % block_size;
827 827
@@ -916,13 +916,13 @@ int ext4_fread(ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt) · 88 unmodified lines
916 return r;916 return r;
917}917}
918 918
919int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt)919int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt)
920{920{
921 int r = EOK;921 int r = EOK;
922 uint32_t u;922 uint32_t u;
923 uint32_t fblock;923 uint32_t fblock;
924 struct ext4_block b;924 struct ext4_block b;
925 uint8_t *u8_buf = buf;925 uint8_t *u8_buf = buf;
926 struct ext4_inode_ref ref;926 struct ext4_inode_ref ref;
927 uint32_t sblock;927 uint32_t sblock;
928 uint32_t sblock_end;928 uint32_t sblock_end;
@@ -962,7 +962,7 @@ int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt) · 33 unmodified lines
962 if(f->fsize % block_size)962 if(f->fsize % block_size)
963 file_blocks++;963 file_blocks++;
964 964
965 sblock = (f->fpos) / block_size;965 sblock = (f->fpos) / block_size;
966 966
967 u = (f->fpos) % block_size;967 u = (f->fpos) % block_size;
968 968
lwext4/ext4_balloc.c+11−11
@@ -62,12 +62,12 @@ static uint32_t ext4_balloc_get_bgid_of_block(struct ext4_sblock *s, · 61 unmodified lines
62uint32_t ext4_balloc_get_first_data_block_in_group(struct ext4_sblock *s,62uint32_t ext4_balloc_get_first_data_block_in_group(struct ext4_sblock *s,
63 struct ext4_block_group_ref * bg_ref)63 struct ext4_block_group_ref * bg_ref)
64{64{
65 uint32_t block_group_count = ext4_block_group_cnt(s);65 uint32_t block_group_count = ext4_block_group_cnt(s);
66 uint32_t inode_table_first_block =66 uint32_t inode_table_first_block =
67 ext4_bg_get_inode_table_first_block(bg_ref->block_group, s);67 ext4_bg_get_inode_table_first_block(bg_ref->block_group, s);
68 uint32_t block_size = ext4_sb_get_block_size(s);68 uint32_t block_size = ext4_sb_get_block_size(s);
69 69
70 uint16_t inode_size = ext4_get16(s, inode_size);70 uint16_t inode_size = ext4_get16(s, inode_size);
71 uint32_t inodes_per_group = ext4_get32(s, inodes_per_group);71 uint32_t inodes_per_group = ext4_get32(s, inodes_per_group);
72 72
73 uint32_t inode_table_bytes;73 uint32_t inode_table_bytes;
@@ -77,7 +77,7 @@ uint32_t ext4_balloc_get_first_data_block_in_group(struct ext4_sblock *s, · 3 unmodified lines
77 inode_table_bytes = inodes_per_group * inode_size;77 inode_table_bytes = inodes_per_group * inode_size;
78 } else {78 } else {
79 /* Last block group could be smaller */79 /* Last block group could be smaller */
80 uint32_t inodes_count_total = ext4_get32(s, inodes_count);80 uint32_t inodes_count_total = ext4_get32(s, inodes_count);
81 inode_table_bytes =81 inode_table_bytes =
82 (inodes_count_total - ((block_group_count - 1) *82 (inodes_count_total - ((block_group_count - 1) *
83 inodes_per_group)) * inode_size;83 inodes_per_group)) * inode_size;
@@ -93,12 +93,12 @@ uint32_t ext4_balloc_get_first_data_block_in_group(struct ext4_sblock *s, · 9 unmodified lines
93 93
94int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref, uint32_t baddr)94int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref, uint32_t baddr)
95{95{
96 struct ext4_fs *fs = inode_ref->fs;96 struct ext4_fs *fs = inode_ref->fs;
97 struct ext4_sblock *sb = &fs->sb;97 struct ext4_sblock *sb = &fs->sb;
98 98
99 99
100 uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, baddr);100 uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, baddr);
101 uint32_t index_in_group = ext4_fs_baddr2_index_in_group(sb, baddr);101 uint32_t index_in_group = ext4_fs_baddr2_index_in_group(sb, baddr);
102 102
103 /* Load block group reference */103 /* Load block group reference */
104 struct ext4_block_group_ref bg_ref;104 struct ext4_block_group_ref bg_ref;
@@ -110,7 +110,7 @@ int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref, uint32_t baddr) · 5 unmodified lines
110 uint32_t bitmap_block_addr =110 uint32_t bitmap_block_addr =
111 ext4_bg_get_block_bitmap(bg_ref.block_group, sb);111 ext4_bg_get_block_bitmap(bg_ref.block_group, sb);
112 112
113 struct ext4_block bitmap_block;113 struct ext4_block bitmap_block;
114 114
115 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);115 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
116 if (rc != EOK)116 if (rc != EOK)
@@ -187,7 +187,7 @@ int ext4_balloc_free_blocks(struct ext4_inode_ref *inode_ref, uint32_t first, · 70 unmodified lines
187 uint32_t bitmap_block_addr =187 uint32_t bitmap_block_addr =
188 ext4_bg_get_block_bitmap(bg_ref.block_group, sb);188 ext4_bg_get_block_bitmap(bg_ref.block_group, sb);
189 189
190 struct ext4_block bitmap_block;190 struct ext4_block bitmap_block;
191 191
192 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);192 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
193 if (rc != EOK)193 if (rc != EOK)
@@ -315,7 +315,7 @@ int ext4_balloc_alloc_block(struct ext4_inode_ref *inode_ref, · 121 unmodified lines
315 uint32_t bitmap_block_addr;315 uint32_t bitmap_block_addr;
316 uint32_t rel_block_idx = 0;316 uint32_t rel_block_idx = 0;
317 317
318 struct ext4_block bitmap_block;318 struct ext4_block bitmap_block;
319 319
320 /* Find GOAL */320 /* Find GOAL */
321 uint32_t goal = ext4_balloc_find_goal(inode_ref);321 uint32_t goal = ext4_balloc_find_goal(inode_ref);
@@ -550,7 +550,7 @@ int ext4_balloc_try_alloc_block(struct ext4_inode_ref *inode_ref, · 228 unmodified lines
550 ext4_bg_get_block_bitmap(bg_ref.block_group, sb);550 ext4_bg_get_block_bitmap(bg_ref.block_group, sb);
551 551
552 552
553 struct ext4_block bitmap_block;553 struct ext4_block bitmap_block;
554 554
555 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);555 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
556 if (rc != EOK)556 if (rc != EOK)
lwext4/ext4_balloc.h+21−21
@@ -49,39 +49,39 @@ · 48 unmodified lines
49#include <stdbool.h>49#include <stdbool.h>
50 50
51 51
52/**@brief Get first datablock in block group52/**@brief Get first datablock in block group
53 * @param s superblock descriptor53 * @param s superblock descriptor
54 * @param bg_ref block group reference54 * @param bg_ref block group reference
55 * @return block id of the first datablock in block group*/55 * @return block id of the first datablock in block group*/
56uint32_t ext4_balloc_get_first_data_block_in_group(struct ext4_sblock *s,56uint32_t ext4_balloc_get_first_data_block_in_group(struct ext4_sblock *s,
57 struct ext4_block_group_ref * bg_ref);57 struct ext4_block_group_ref * bg_ref);
58 58
59/**@brief Free block from inode.59/**@brief Free block from inode.
60 * @param inode_ref inode reference60 * @param inode_ref inode reference
61 * @param baddr block address61 * @param baddr block address
62 * @return standard error code*/62 * @return standard error code*/
63int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref,63int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref,
64 uint32_t baddr);64 uint32_t baddr);
65 65
66/**@brief Free blocks from inode.66/**@brief Free blocks from inode.
67 * @param inode_ref inode reference67 * @param inode_ref inode reference
68 * @param baddr block address68 * @param baddr block address
69 * @return standard error code*/69 * @return standard error code*/
70int ext4_balloc_free_blocks(struct ext4_inode_ref *inode_ref,70int ext4_balloc_free_blocks(struct ext4_inode_ref *inode_ref,
71 uint32_t first, uint32_t count);71 uint32_t first, uint32_t count);
72 72
73/**@brief Allocate block procedure.73/**@brief Allocate block procedure.
74 * @param inode_ref inode reference74 * @param inode_ref inode reference
75 * @param baddr allocated block address75 * @param baddr allocated block address
76 * @return standard error code*/76 * @return standard error code*/
77int ext4_balloc_alloc_block(struct ext4_inode_ref *inode_ref,77int ext4_balloc_alloc_block(struct ext4_inode_ref *inode_ref,
78 uint32_t *baddr);78 uint32_t *baddr);
79 79
80/**@brief Try allocate selected block.80/**@brief Try allocate selected block.
81 * @param inode_ref inode reference81 * @param inode_ref inode reference
82 * @param baddr block address to allocate82 * @param baddr block address to allocate
83 * @param free if baddr is not allocated83 * @param free if baddr is not allocated
84 * @return standard error code*/84 * @return standard error code*/
85int ext4_balloc_try_alloc_block(struct ext4_inode_ref *inode_ref,85int ext4_balloc_try_alloc_block(struct ext4_inode_ref *inode_ref,
86 uint32_t baddr, bool *free);86 uint32_t baddr, bool *free);
87 87
lwext4/ext4_bcache.c+6−6
@@ -43,7 +43,7 @@ · 42 unmodified lines
43#include <stdlib.h>43#include <stdlib.h>
44 44
45 45
46int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,46int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
47 uint32_t itemsize)47 uint32_t itemsize)
48{48{
49 ext4_assert(bc && cnt && itemsize);49 ext4_assert(bc && cnt && itemsize);
@@ -104,7 +104,7 @@ int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt, · 54 unmodified lines
104 return ENOMEM;104 return ENOMEM;
105}105}
106 106
107int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)107int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)
108{108{
109 if(bc->refctr)109 if(bc->refctr)
110 free(bc->refctr);110 free(bc->refctr);
@@ -195,8 +195,8 @@ int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b, · 84 unmodified lines
195 195
196 if(cache_id != bc->cnt){196 if(cache_id != bc->cnt){
197 /*There was unreferenced block*/197 /*There was unreferenced block*/
198 bc->lba[cache_id] = b->lb_id;198 bc->lba[cache_id] = b->lb_id;
199 bc->refctr[cache_id] = 1;199 bc->refctr[cache_id] = 1;
200 bc->lru_id[cache_id] = ++bc->lru_ctr;200 bc->lru_id[cache_id] = ++bc->lru_ctr;
201 201
202 /*Set valid cache data and id*/202 /*Set valid cache data and id*/
@@ -245,8 +245,8 @@ int ext4_bcache_free (struct ext4_bcache *bc, struct ext4_block *b, · 42 unmodified lines
245 if(!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])245 if(!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])
246 bc->ref_blocks--;246 bc->ref_blocks--;
247 247
248 b->lb_id = 0;248 b->lb_id = 0;
249 b->data = 0;249 b->data = 0;
250 b->cache_id = 0;250 b->cache_id = 0;
251 251
252 return EOK;252 return EOK;
lwext4/ext4_bcache.h+62−62
@@ -42,110 +42,110 @@ · 41 unmodified lines
42#include <stdint.h>42#include <stdint.h>
43#include <stdbool.h>43#include <stdbool.h>
44 44
45/**@brief Single block descriptor.*/45/**@brief Single block descriptor.*/
46struct ext4_block {46struct ext4_block {
47 /**@brief Dirty flag.*/47 /**@brief Dirty flag.*/
48 bool dirty;48 bool dirty;
49 49
50 /**@brief Logical block ID*/50 /**@brief Logical block ID*/
51 uint64_t lb_id;51 uint64_t lb_id;
52 52
53 /**@brief Cache id*/53 /**@brief Cache id*/
54 uint32_t cache_id;54 uint32_t cache_id;
55 55
56 /**@brief Data buffer.*/56 /**@brief Data buffer.*/
57 uint8_t *data;57 uint8_t *data;
58};58};
59 59
60 60
61/**@brief Block cache descriptor.*/61/**@brief Block cache descriptor.*/
62struct ext4_bcache {62struct ext4_bcache {
63 63
64 /**@brief Item count in block cache*/64 /**@brief Item count in block cache*/
65 uint32_t cnt;65 uint32_t cnt;
66 66
67 /**@brief Item size in block cache*/67 /**@brief Item size in block cache*/
68 uint32_t itemsize;68 uint32_t itemsize;
69 69
70 /**@brief Last recently used counter.*/70 /**@brief Last recently used counter.*/
71 uint32_t lru_ctr;71 uint32_t lru_ctr;
72 72
73 /**@brief Reference count table (cnt).*/73 /**@brief Reference count table (cnt).*/
74 uint32_t *refctr;74 uint32_t *refctr;
75 75
76 /**@brief Last recently used ID table (cnt)*/76 /**@brief Last recently used ID table (cnt)*/
77 uint32_t *lru_id;77 uint32_t *lru_id;
78 78
79 /**@brief Free delay mode table (cnt)*/79 /**@brief Free delay mode table (cnt)*/
80 uint8_t *free_delay;80 uint8_t *free_delay;
81 81
82 /**@brief Logical block table (cnt).*/82 /**@brief Logical block table (cnt).*/
83 uint64_t *lba;83 uint64_t *lba;
84 84
85 /**@brief Cache data buffers (cnt * itemsize)*/85 /**@brief Cache data buffers (cnt * itemsize)*/
86 uint8_t *data;86 uint8_t *data;
87 87
88 /**@brief Currently referenced datablocks*/88 /**@brief Currently referenced datablocks*/
89 uint32_t ref_blocks;89 uint32_t ref_blocks;
90 90
91 /**@brief Maximum referenced datablocks*/91 /**@brief Maximum referenced datablocks*/
92 uint32_t max_ref_blocks;92 uint32_t max_ref_blocks;
93 93
94};94};
95 95
96/**@brief Static initializer of block cache structure.*/96/**@brief Static initializer of block cache structure.*/
97#define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize) \97#define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize) \
98 static uint32_t __name##_refctr[(__cnt)]; \98 static uint32_t __name##_refctr[(__cnt)]; \
99 static uint32_t __name##_lru_id[(__cnt)]; \99 static uint32_t __name##_lru_id[(__cnt)]; \
100 static uint8_t __name##_free_delay[(__cnt)]; \100 static uint8_t __name##_free_delay[(__cnt)]; \
101 static uint64_t __name##_lba[(__cnt)]; \101 static uint64_t __name##_lba[(__cnt)]; \
102 static uint8_t __name##_data[(__cnt) * (__itemsize)]; \102 static uint8_t __name##_data[(__cnt) * (__itemsize)]; \
103 static struct ext4_bcache __name = { \103 static struct ext4_bcache __name = { \
104 .cnt = __cnt, \104 .cnt = __cnt, \
105 .itemsize = __itemsize, \105 .itemsize = __itemsize, \
106 .lru_ctr = 0, \106 .lru_ctr = 0, \
107 .refctr = __name##_refctr, \107 .refctr = __name##_refctr, \
108 .lru_id = __name##_lru_id, \108 .lru_id = __name##_lru_id, \
109 .lba = __name##_lba, \109 .lba = __name##_lba, \
110 .free_delay= __name##_free_delay, \110 .free_delay= __name##_free_delay, \
111 .data = __name##_data, \111 .data = __name##_data, \
112 }112 }
113 113
114 114
115/**@brief Dynamic initialization of block cache.115/**@brief Dynamic initialization of block cache.
116 * @param bc block cache descriptor116 * @param bc block cache descriptor
117 * @param cnt items count in block cache117 * @param cnt items count in block cache
118 * @param itemsize single item size (in bytes)118 * @param itemsize single item size (in bytes)
119 * @return standard error code*/119 * @return standard error code*/
120int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,120int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
121 uint32_t itemsize);121 uint32_t itemsize);
122 122
123/**@brief Dynamic de-initialization of block cache.123/**@brief Dynamic de-initialization of block cache.
124 * @param bc block cache descriptor124 * @param bc block cache descriptor
125 * @return standard error code*/125 * @return standard error code*/
126int ext4_bcache_fini_dynamic(struct ext4_bcache *bc);126int ext4_bcache_fini_dynamic(struct ext4_bcache *bc);
127 127
128/**@brief Allocate block from block cache memory.128/**@brief Allocate block from block cache memory.
129 * Unreferenced block allocation is based on LRU129 * Unreferenced block allocation is based on LRU
130 * (Last Recently Used) algorithm.130 * (Last Recently Used) algorithm.
131 * @param bc block cache descriptor131 * @param bc block cache descriptor
132 * @param b block to alloc132 * @param b block to alloc
133 * @param is_new block is new (needs to be read)133 * @param is_new block is new (needs to be read)
134 * @return standard error code*/134 * @return standard error code*/
135int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,135int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
136 bool *is_new);136 bool *is_new);
137 137
138/**@brief Free block from cache memory (decrement reference counter).138/**@brief Free block from cache memory (decrement reference counter).
139 * @param bc block cache descriptor139 * @param bc block cache descriptor
140 * @param b block to free140 * @param b block to free
141 * @return standard error code*/141 * @return standard error code*/
142int ext4_bcache_free (struct ext4_bcache *bc, struct ext4_block *b,142int ext4_bcache_free (struct ext4_bcache *bc, struct ext4_block *b,
143 uint8_t free_delay);143 uint8_t free_delay);
144 144
145 145
146/**@brief Return a full status of block cache.146/**@brief Return a full status of block cache.
147 * @param bc block cache descriptor147 * @param bc block cache descriptor
148 * @return full status*/148 * @return full status*/
149bool ext4_bcache_is_full(struct ext4_bcache *bc);149bool ext4_bcache_is_full(struct ext4_bcache *bc);
150 150
151#endif /* EXT4_BCACHE_H_ */151#endif /* EXT4_BCACHE_H_ */
lwext4/ext4_bitmap.h+21−21
@@ -42,50 +42,50 @@ · 41 unmodified lines
42#include <stdint.h>42#include <stdint.h>
43#include <stdbool.h>43#include <stdbool.h>
44 44
45/**@brief Set bitmap bit.45/**@brief Set bitmap bit.
46 * @param bmap bitmap46 * @param bmap bitmap
47 * @param bit bit to set*/47 * @param bit bit to set*/
48static inline void ext4_bmap_bit_set(uint8_t *bmap, uint32_t bit)48static inline void ext4_bmap_bit_set(uint8_t *bmap, uint32_t bit)
49{49{
50 *(bmap + (bit >> 3)) |= (1 << (bit & 7));50 *(bmap + (bit >> 3)) |= (1 << (bit & 7));
51}51}
52 52
53/**@brief Clear bitmap bit.53/**@brief Clear bitmap bit.
54 * @param bmap bitmap buffer54 * @param bmap bitmap buffer
55 * @param bit bit to clear*/55 * @param bit bit to clear*/
56static inline void ext4_bmap_bit_clr(uint8_t *bmap, uint32_t bit)56static inline void ext4_bmap_bit_clr(uint8_t *bmap, uint32_t bit)
57{57{
58 *(bmap + (bit >> 3)) &= ~(1 << (bit & 7));58 *(bmap + (bit >> 3)) &= ~(1 << (bit & 7));
59}59}
60 60
61 61
62/**@brief Check if the bitmap bit is set.62/**@brief Check if the bitmap bit is set.
63 * @param bmap bitmap buffer63 * @param bmap bitmap buffer
64 * @param bit bit to check*/64 * @param bit bit to check*/
65static inline bool ext4_bmap_is_bit_set(uint8_t *bmap, uint32_t bit)65static inline bool ext4_bmap_is_bit_set(uint8_t *bmap, uint32_t bit)
66{66{
67 return (*(bmap + (bit >> 3)) & (1 << (bit & 7)));67 return (*(bmap + (bit >> 3)) & (1 << (bit & 7)));
68}68}
69 69
70/**@brief Check if the bitmap bit is clear.70/**@brief Check if the bitmap bit is clear.
71 * @param bmap bitmap buffer71 * @param bmap bitmap buffer
72 * @param bit bit to check*/72 * @param bit bit to check*/
73static inline bool ext4_bmap_is_bit_clr(uint8_t *bmap, uint32_t bit)73static inline bool ext4_bmap_is_bit_clr(uint8_t *bmap, uint32_t bit)
74{74{
75 return !ext4_bmap_is_bit_set(bmap, bit);75 return !ext4_bmap_is_bit_set(bmap, bit);
76}76}
77 77
78/**@brief Free range of bits in bitmap.78/**@brief Free range of bits in bitmap.
79 * @param bmap bitmap buffer79 * @param bmap bitmap buffer
80 * @param sbit start bit80 * @param sbit start bit
81 * @param bcnt bit count*/81 * @param bcnt bit count*/
82void ext4_bmap_bits_free(uint8_t *bmap, uint32_t sbit, uint32_t bcnt);82void ext4_bmap_bits_free(uint8_t *bmap, uint32_t sbit, uint32_t bcnt);
83 83
84/**@brief Find first clear bit in bitmap.84/**@brief Find first clear bit in bitmap.
85 * @param sbit start bit of search85 * @param sbit start bit of search
86 * @param ebit end bit of search86 * @param ebit end bit of search
87 * @param bit_id output parameter (first free bit)87 * @param bit_id output parameter (first free bit)
88 * @return standard error code*/88 * @return standard error code*/
89int ext4_bmap_bit_find_clr(uint8_t *bmap, uint32_t sbit, uint32_t ebit,89int ext4_bmap_bit_find_clr(uint8_t *bmap, uint32_t sbit, uint32_t ebit,
90 uint32_t *bit_id);90 uint32_t *bit_id);
91 91
lwext4/ext4_blockdev.c+16−16
@@ -44,7 +44,7 @@ · 43 unmodified lines
44 44
45 45
46 46
47int ext4_block_init(struct ext4_blockdev *bdev)47int ext4_block_init(struct ext4_blockdev *bdev)
48{48{
49 int rc;49 int rc;
50 ext4_assert(bdev);50 ext4_assert(bdev);
@@ -58,7 +58,7 @@ int ext4_block_init(struct ext4_blockdev *bdev) · 7 unmodified lines
58 58
59 bdev->flags |= EXT4_BDEV_INITIALIZED;59 bdev->flags |= EXT4_BDEV_INITIALIZED;
60 60
61 return EOK;61 return EOK;
62}62}
63 63
64int ext4_block_bind_bcache(struct ext4_blockdev *bdev, struct ext4_bcache *bc)64int ext4_block_bind_bcache(struct ext4_blockdev *bdev, struct ext4_bcache *bc)
@@ -68,7 +68,7 @@ int ext4_block_bind_bcache(struct ext4_blockdev *bdev, struct ext4_bcache *bc) · 3 unmodified lines
68 return EOK;68 return EOK;
69}69}
70 70
71void ext4_block_set_lb_size(struct ext4_blockdev *bdev, uint64_t lb_bsize)71void ext4_block_set_lb_size(struct ext4_blockdev *bdev, uint64_t lb_bsize)
72{72{
73 /*Logical block size has to be multiply of physical */73 /*Logical block size has to be multiply of physical */
74 ext4_assert(!(lb_bsize % bdev->ph_bsize));74 ext4_assert(!(lb_bsize % bdev->ph_bsize));
@@ -78,7 +78,7 @@ void ext4_block_set_lb_size(struct ext4_blockdev *bdev, uint64_t lb_bsize) · 3 unmodified lines
78 78
79}79}
80 80
81int ext4_block_fini(struct ext4_blockdev *bdev)81int ext4_block_fini(struct ext4_blockdev *bdev)
82{82{
83 ext4_assert(bdev);83 ext4_assert(bdev);
84 84
@@ -89,7 +89,7 @@ int ext4_block_fini(struct ext4_blockdev *bdev) · 4 unmodified lines
89}89}
90 90
91 91
92int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,92int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,
93 uint64_t lba)93 uint64_t lba)
94{94{
95 uint64_t pba;95 uint64_t pba;
@@ -164,7 +164,7 @@ int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b, · 68 unmodified lines
164 return EOK;164 return EOK;
165}165}
166 166
167int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b)167int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b)
168{168{
169 uint64_t pba;169 uint64_t pba;
170 uint32_t pb_cnt;170 uint32_t pb_cnt;
@@ -206,7 +206,7 @@ int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b) · 35 unmodified lines
206 return EOK;206 return EOK;
207}207}
208 208
209int ext4_blocks_get_direct(struct ext4_blockdev *bdev, void *buf,209int ext4_blocks_get_direct(struct ext4_blockdev *bdev, void *buf,
210 uint64_t lba, uint32_t cnt)210 uint64_t lba, uint32_t cnt)
211{211{
212 uint64_t pba;212 uint64_t pba;
@@ -221,7 +221,7 @@ int ext4_blocks_get_direct(struct ext4_blockdev *bdev, void *buf, · 8 unmodified lines
221 return bdev->bread(bdev, buf, pba, pb_cnt * cnt);221 return bdev->bread(bdev, buf, pba, pb_cnt * cnt);
222}222}
223 223
224int ext4_blocks_set_direct(struct ext4_blockdev *bdev, const void *buf,224int ext4_blocks_set_direct(struct ext4_blockdev *bdev, const void *buf,
225 uint64_t lba, uint32_t cnt)225 uint64_t lba, uint32_t cnt)
226{226{
227 uint64_t pba;227 uint64_t pba;
@@ -238,7 +238,7 @@ int ext4_blocks_set_direct(struct ext4_blockdev *bdev, const void *buf, · 10 unmodified lines
238}238}
239 239
240 240
241int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off,241int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off,
242 const void *buf, uint32_t len)242 const void *buf, uint32_t len)
243{243{
244 uint64_t block_idx;244 uint64_t block_idx;
@@ -247,7 +247,7 @@ int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off, · 2 unmodified lines
247 uint32_t unalg;247 uint32_t unalg;
248 int r = EOK;248 int r = EOK;
249 249
250 const uint8_t *p = (void *)buf;250 const uint8_t *p = (void *)buf;
251 251
252 ext4_assert(bdev && buf);252 ext4_assert(bdev && buf);
253 253
@@ -258,7 +258,7 @@ int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off, · 4 unmodified lines
258 block_end = block_idx + len / bdev->ph_bsize;258 block_end = block_idx + len / bdev->ph_bsize;
259 259
260 if(!(block_end < bdev->ph_bcnt))260 if(!(block_end < bdev->ph_bcnt))
261 return EINVAL; /*Ups. Out of range operation*/261 return EINVAL; /*Ups. Out of range operation*/
262 262
263 /*OK lets deal with the first possible unaligned block*/263 /*OK lets deal with the first possible unaligned block*/
264 unalg = (off & (bdev->ph_bsize - 1));264 unalg = (off & (bdev->ph_bsize - 1));
@@ -317,7 +317,7 @@ int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off, · 52 unmodified lines
317 317
318 318
319 319
320int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf,320int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf,
321 uint32_t len)321 uint32_t len)
322{322{
323 uint64_t block_idx;323 uint64_t block_idx;
@@ -326,7 +326,7 @@ int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf, · 2 unmodified lines
326 uint32_t unalg;326 uint32_t unalg;
327 int r = EOK;327 int r = EOK;
328 328
329 uint8_t *p = (void *)buf;329 uint8_t *p = (void *)buf;
330 330
331 ext4_assert(bdev && buf);331 ext4_assert(bdev && buf);
332 332
@@ -337,7 +337,7 @@ int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf, · 4 unmodified lines
337 block_end = block_idx + len / bdev->ph_bsize;337 block_end = block_idx + len / bdev->ph_bsize;
338 338
339 if(!(block_end < bdev->ph_bcnt))339 if(!(block_end < bdev->ph_bcnt))
340 return EINVAL; /*Ups. Out of range operation*/340 return EINVAL; /*Ups. Out of range operation*/
341 341
342 /*OK lets deal with the first possible unaligned block*/342 /*OK lets deal with the first possible unaligned block*/
343 unalg = (off & (bdev->ph_bsize - 1));343 unalg = (off & (bdev->ph_bsize - 1));
@@ -365,7 +365,7 @@ int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf, · 21 unmodified lines
365 if(r != EOK)365 if(r != EOK)
366 return r;366 return r;
367 367
368 p += bdev->ph_bsize * blen;368 p += bdev->ph_bsize * blen;
369 len -= bdev->ph_bsize * blen;369 len -= bdev->ph_bsize * blen;
370 370
371 block_idx += blen;371 block_idx += blen;
@@ -383,7 +383,7 @@ int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf, · 11 unmodified lines
383 return r;383 return r;
384}384}
385 385
386int ext4_block_delay_cache_flush(struct ext4_blockdev *bdev,386int ext4_block_delay_cache_flush(struct ext4_blockdev *bdev,
387 uint8_t on_off)387 uint8_t on_off)
388{388{
389 int r;389 int r;
lwext4/ext4_blockdev.h+102−102
@@ -44,73 +44,73 @@ · 43 unmodified lines
44#include <stdbool.h>44#include <stdbool.h>
45#include <stdint.h>45#include <stdint.h>
46 46
47/**@brief Initialization status flag*/47/**@brief Initialization status flag*/
48#define EXT4_BDEV_INITIALIZED (1 << 0)48#define EXT4_BDEV_INITIALIZED (1 << 0)
49 49
50 50
51/**@brief Definiton of the simple block device.*/51/**@brief Definiton of the simple block device.*/
52struct ext4_blockdev {52struct ext4_blockdev {
53 53
54 /**@brief Open device function54 /**@brief Open device function
55 * @param bdev block device.*/55 * @param bdev block device.*/
56 int (*open)(struct ext4_blockdev *bdev);56 int (*open)(struct ext4_blockdev *bdev);
57 57
58 /**@brief Block read function.58 /**@brief Block read function.
59 * @param bdev block device59 * @param bdev block device
60 * @param buf output buffer60 * @param buf output buffer
61 * @param blk_id block id61 * @param blk_id block id
62 * @param blk_cnt block count*/62 * @param blk_cnt block count*/
63 int (*bread)(struct ext4_blockdev *bdev, void *buf,63 int (*bread)(struct ext4_blockdev *bdev, void *buf,
64 uint64_t blk_id, uint32_t blk_cnt);64 uint64_t blk_id, uint32_t blk_cnt);
65 65
66 /**@brief Block write function.66 /**@brief Block write function.
67 * @param buf input buffer67 * @param buf input buffer
68 * @param blk_id block id68 * @param blk_id block id
69 * @param blk_cnt block count*/69 * @param blk_cnt block count*/
70 int (*bwrite)(struct ext4_blockdev *bdev, const void *buf,70 int (*bwrite)(struct ext4_blockdev *bdev, const void *buf,
71 uint64_t blk_id, uint32_t blk_cnt);71 uint64_t blk_id, uint32_t blk_cnt);
72 72
73 /**@brief Close device function.73 /**@brief Close device function.
74 * @param bdev block device.*/74 * @param bdev block device.*/
75 int (*close)(struct ext4_blockdev *bdev);75 int (*close)(struct ext4_blockdev *bdev);
76 76
77 /**@brief Block cache.*/77 /**@brief Block cache.*/
78 struct ext4_bcache *bc;78 struct ext4_bcache *bc;
79 79
80 /**@brief Block size (bytes): physical*/80 /**@brief Block size (bytes): physical*/
81 uint32_t ph_bsize;81 uint32_t ph_bsize;
82 82
83 /**@brief Block count: physical.*/83 /**@brief Block count: physical.*/
84 uint64_t ph_bcnt;84 uint64_t ph_bcnt;
85 85
86 /**@brief Block size buffer: physical.*/86 /**@brief Block size buffer: physical.*/
87 uint8_t *ph_bbuf;87 uint8_t *ph_bbuf;
88 88
89 /**@brief Block size (bytes) logical*/89 /**@brief Block size (bytes) logical*/
90 uint32_t lg_bsize;90 uint32_t lg_bsize;
91 91
92 /**@brief Block count: phisical.*/92 /**@brief Block count: phisical.*/
93 uint64_t lg_bcnt;93 uint64_t lg_bcnt;
94 94
95 /**@brief Flags of te block device.*/95 /**@brief Flags of te block device.*/
96 uint8_t flags;96 uint8_t flags;
97 97
98 /**@brief Cache flush delay mode flag.*/98 /**@brief Cache flush delay mode flag.*/
99 uint8_t cache_flush_delay;99 uint8_t cache_flush_delay;
100 100
101 /**@brief Physical read counter*/101 /**@brief Physical read counter*/
102 uint32_t bread_ctr;102 uint32_t bread_ctr;
103 103
104 /**@brief Physical write counter*/104 /**@brief Physical write counter*/
105 uint32_t bwrite_ctr;105 uint32_t bwrite_ctr;
106};106};
107 107
108 108
109/**@brief Static initialization fo the block device.*/109/**@brief Static initialization fo the block device.*/
110#define EXT4_BLOCKDEV_STATIC_INSTANCE(__name, __bsize, __bcnt, __open, \110#define EXT4_BLOCKDEV_STATIC_INSTANCE(__name, __bsize, __bcnt, __open, \
111 __bread, __bwrite, __close) \111 __bread, __bwrite, __close) \
112 static uint8_t __name##_ph_bbuf[(__bsize)]; \112 static uint8_t __name##_ph_bbuf[(__bsize)]; \
113 static struct ext4_blockdev __name = { \113 static struct ext4_blockdev __name = { \
114 .open = __open, \114 .open = __open, \
115 .bread = __bread, \115 .bread = __bread, \
116 .bwrite = __bwrite, \116 .bwrite = __bwrite, \
@@ -120,93 +120,93 @@ struct ext4_blockdev { · 3 unmodified lines
120 .ph_bbuf = __name##_ph_bbuf, \120 .ph_bbuf = __name##_ph_bbuf, \
121 }121 }
122 122
123/**@brief Block device initialization.123/**@brief Block device initialization.
124 * @param bdev block device descriptor124 * @param bdev block device descriptor
125 * @param bg_bsize logical block size125 * @param bg_bsize logical block size
126 * @param bdev block device descriptor126 * @param bdev block device descriptor
127 * @return standard error code*/127 * @return standard error code*/
128int ext4_block_init(struct ext4_blockdev *bdev);128int ext4_block_init(struct ext4_blockdev *bdev);
129 129
130 130
131/**@brief Binds a bcache to block device.131/**@brief Binds a bcache to block device.
132 * @param bdev block device descriptor132 * @param bdev block device descriptor
133 * @param bc block cache descriptor133 * @param bc block cache descriptor
134 * @return standard error code*/134 * @return standard error code*/
135int ext4_block_bind_bcache(struct ext4_blockdev *bdev,135int ext4_block_bind_bcache(struct ext4_blockdev *bdev,
136 struct ext4_bcache *bc);136 struct ext4_bcache *bc);
137 137
138/**@brief Close block device138/**@brief Close block device
139 * @param bdev block device descriptor139 * @param bdev block device descriptor
140 * @return standard error code*/140 * @return standard error code*/
141int ext4_block_fini(struct ext4_blockdev *bdev);141int ext4_block_fini(struct ext4_blockdev *bdev);
142 142
143 143
144/**@brief Set logical block size in block device.144/**@brief Set logical block size in block device.
145 * @param bdev block device descriptor145 * @param bdev block device descriptor
146 * @param lb_size ligical block size (in bytes)146 * @param lb_size ligical block size (in bytes)
147 * @return standard error code*/147 * @return standard error code*/
148void ext4_block_set_lb_size(struct ext4_blockdev *bdev,148void ext4_block_set_lb_size(struct ext4_blockdev *bdev,
149 uint64_t lb_bsize);149 uint64_t lb_bsize);
150 150
151/**@brief Block get function (through cache).151/**@brief Block get function (through cache).
152 * @param bdev block device descriptor152 * @param bdev block device descriptor
153 * @param b block descriptor153 * @param b block descriptor
154 * @param lba logical block address154 * @param lba logical block address
155 * @return standard error code*/155 * @return standard error code*/
156int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,156int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,
157 uint64_t lba);157 uint64_t lba);
158 158
159/**@brief Block set procedure (through cache).159/**@brief Block set procedure (through cache).
160 * @param bdev block device descriptor160 * @param bdev block device descriptor
161 * @param b block descriptor161 * @param b block descriptor
162 * @return standard error code*/162 * @return standard error code*/
163int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b);163int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b);
164 164
165 165
166/**@brief Block read procedure (without cache)166/**@brief Block read procedure (without cache)
167 * @param bdev block device descriptor167 * @param bdev block device descriptor
168 * @param buf output buffer168 * @param buf output buffer
169 * @param lba logical block adderss169 * @param lba logical block adderss
170 * @return standard error code*/170 * @return standard error code*/
171int ext4_blocks_get_direct(struct ext4_blockdev *bdev, void *buf,171int ext4_blocks_get_direct(struct ext4_blockdev *bdev, void *buf,
172 uint64_t lba, uint32_t cnt);172 uint64_t lba, uint32_t cnt);
173 173
174 174
175/**@brief Block write procedure (without cache)175/**@brief Block write procedure (without cache)
176 * @param bdev block device descriptor176 * @param bdev block device descriptor
177 * @param buf output buffer177 * @param buf output buffer
178 * @param lba logical block address178 * @param lba logical block address
179 * @return standard error code*/179 * @return standard error code*/
180int ext4_blocks_set_direct(struct ext4_blockdev *bdev, const void *buf,180int ext4_blocks_set_direct(struct ext4_blockdev *bdev, const void *buf,
181 uint64_t lba, uint32_t cnt);181 uint64_t lba, uint32_t cnt);
182 182
183/**@brief Write to block device (by direct adress).183/**@brief Write to block device (by direct adress).
184 * @param bdev block device descriptor184 * @param bdev block device descriptor
185 * @param off byte offset in block device185 * @param off byte offset in block device
186 * @param buf input buffer186 * @param buf input buffer
187 * @param len length of the write nuffer187 * @param len length of the write nuffer
188 * @return EOK when sucess*/188 * @return EOK when sucess*/
189int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off,189int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off,
190 const void *buf, uint32_t len);190 const void *buf, uint32_t len);
191 191
192 192
193 193
194/**@brief Read freom block device (by direct adress).194/**@brief Read freom block device (by direct adress).
195 * @param bdev block device descriptor195 * @param bdev block device descriptor
196 * @param off byte offset in block device196 * @param off byte offset in block device
197 * @param buf input buffer197 * @param buf input buffer
198 * @param len length of the write nuffer198 * @param len length of the write nuffer
199 * @return EOK when sucess*/199 * @return EOK when sucess*/
200int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off,200int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off,
201 void *buf, uint32_t len);201 void *buf, uint32_t len);
202 202
203/**@brief Enable/disable delayed cache flush mode.203/**@brief Enable/disable delayed cache flush mode.
204 * @param bdev block device descriptor204 * @param bdev block device descriptor
205 * @param on_off205 * @param on_off
206 * !0 - ENABLE206 * !0 - ENABLE
207 * 0 - DISABLE (all delayed cache buffers will be flushed)207 * 0 - DISABLE (all delayed cache buffers will be flushed)
208 * @return standard error code*/208 * @return standard error code*/
209int ext4_block_delay_cache_flush(struct ext4_blockdev *bdev, uint8_t on_off);209int ext4_block_delay_cache_flush(struct ext4_blockdev *bdev, uint8_t on_off);
210 210
211#endif /* EXT4_BLOCKDEV_H_ */211#endif /* EXT4_BLOCKDEV_H_ */
212 212
lwext4/ext4_config.h+9−9
@@ -42,51 +42,51 @@ · 41 unmodified lines
42#endif42#endif
43 43
44 44
45/**@brief Enable directory indexing feature (EXT3 feature)*/45/**@brief Enable directory indexing feature (EXT3 feature)*/
46#ifndef CONFIG_DIR_INDEX_ENABLE46#ifndef CONFIG_DIR_INDEX_ENABLE
47#define CONFIG_DIR_INDEX_ENABLE 147#define CONFIG_DIR_INDEX_ENABLE 1
48#endif48#endif
49 49
50/**@brief Enable extents feature (EXT4 feature)*/50/**@brief Enable extents feature (EXT4 feature)*/
51#ifndef CONFIG_EXTENT_ENABLE51#ifndef CONFIG_EXTENT_ENABLE
52#define CONFIG_EXTENT_ENABLE 152#define CONFIG_EXTENT_ENABLE 1
53#endif53#endif
54 54
55 55
56 56
57/**@brief Include error codes from ext4_errno or sandard library.*/57/**@brief Include error codes from ext4_errno or sandard library.*/
58#ifndef CONFIG_HAVE_OWN_ERRNO58#ifndef CONFIG_HAVE_OWN_ERRNO
59#define CONFIG_HAVE_OWN_ERRNO 159#define CONFIG_HAVE_OWN_ERRNO 1
60#endif60#endif
61 61
62 62
63/**@brief Debug printf enable (stdout)*/63/**@brief Debug printf enable (stdout)*/
64#ifndef CONFIG_DEBUG_PRINTF64#ifndef CONFIG_DEBUG_PRINTF
65#define CONFIG_DEBUG_PRINTF 165#define CONFIG_DEBUG_PRINTF 1
66#endif66#endif
67 67
68/**@brief Assert printf enable (stdout)*/68/**@brief Assert printf enable (stdout)*/
69#ifndef CONFIG_DEBUG_ASSERT69#ifndef CONFIG_DEBUG_ASSERT
70#define CONFIG_DEBUG_ASSERT 170#define CONFIG_DEBUG_ASSERT 1
71#endif71#endif
72 72
73/**@brief Statistics of block device*/73/**@brief Statistics of block device*/
74#ifndef CONFIG_BLOCK_DEV_ENABLE_STATS74#ifndef CONFIG_BLOCK_DEV_ENABLE_STATS
75#define CONFIG_BLOCK_DEV_ENABLE_STATS 175#define CONFIG_BLOCK_DEV_ENABLE_STATS 1
76#endif76#endif
77 77
78/**@brief Cache size of block device.*/78/**@brief Cache size of block device.*/
79#ifndef CONFIG_BLOCK_DEV_CACHE_SIZE79#ifndef CONFIG_BLOCK_DEV_CACHE_SIZE
80#define CONFIG_BLOCK_DEV_CACHE_SIZE 880#define CONFIG_BLOCK_DEV_CACHE_SIZE 8
81#endif81#endif
82 82
83 83
84/**@brief Ilosc urzadzen blokowych.*/84/**@brief Ilosc urzadzen blokowych.*/
85#ifndef CONFIG_EXT4_BLOCKDEVS_COUNT85#ifndef CONFIG_EXT4_BLOCKDEVS_COUNT
86#define CONFIG_EXT4_BLOCKDEVS_COUNT 286#define CONFIG_EXT4_BLOCKDEVS_COUNT 2
87#endif87#endif
88 88
89/**@brief Ilosc punktow montowania systemu plikow*/89/**@brief Ilosc punktow montowania systemu plikow*/
90#ifndef CONFIG_EXT4_MOUNTPOINTS_COUNT90#ifndef CONFIG_EXT4_MOUNTPOINTS_COUNT
91#define CONFIG_EXT4_MOUNTPOINTS_COUNT 291#define CONFIG_EXT4_MOUNTPOINTS_COUNT 2
92#endif92#endif
lwext4/ext4_debug.h+20−20
@@ -43,67 +43,67 @@ · 42 unmodified lines
43#include <stdio.h>43#include <stdio.h>
44 44
45/**@brief Debug mask: ext4_blockdev.c*/45/**@brief Debug mask: ext4_blockdev.c*/
46#define EXT4_DEBUG_BLOCKDEV (1 << 0)46#define EXT4_DEBUG_BLOCKDEV (1 << 0)
47 47
48/**@brief Debug mask: ext4_fs.c*/48/**@brief Debug mask: ext4_fs.c*/
49#define EXT4_DEBUG_FS (1 << 1)49#define EXT4_DEBUG_FS (1 << 1)
50 50
51/**@brief Debug mask: ext4_balloc.c*/51/**@brief Debug mask: ext4_balloc.c*/
52#define EXT4_DEBUG_BALLOC (1 << 2)52#define EXT4_DEBUG_BALLOC (1 << 2)
53 53
54/**@brief Debug mask: ext4_bitmap.c*/54/**@brief Debug mask: ext4_bitmap.c*/
55#define EXT4_DEBUG_BITMAP (1 << 3)55#define EXT4_DEBUG_BITMAP (1 << 3)
56 56
57/**@brief Debug mask: ext4_dir_idx.c*/57/**@brief Debug mask: ext4_dir_idx.c*/
58#define EXT4_DEBUG_DIR_IDX (1 << 4)58#define EXT4_DEBUG_DIR_IDX (1 << 4)
59 59
60/**@brief Debug mask: ext4_dir.c*/60/**@brief Debug mask: ext4_dir.c*/
61#define EXT4_DEBUG_DIR (1 << 5)61#define EXT4_DEBUG_DIR (1 << 5)
62 62
63/**@brief Debug mask: ext4_ialloc.c*/63/**@brief Debug mask: ext4_ialloc.c*/
64#define EXT4_DEBUG_IALLOC (1 << 6)64#define EXT4_DEBUG_IALLOC (1 << 6)
65 65
66/**@brief Debug mask: ext4_inode.c*/66/**@brief Debug mask: ext4_inode.c*/
67#define EXT4_DEBUG_INODE (1 << 7)67#define EXT4_DEBUG_INODE (1 << 7)
68 68
69/**@brief Debug mask: ext4_super.c*/69/**@brief Debug mask: ext4_super.c*/
70#define EXT4_DEBUG_SUPER (1 << 8)70#define EXT4_DEBUG_SUPER (1 << 8)
71 71
72/**@brief Debug mask: ext4_bcache.c*/72/**@brief Debug mask: ext4_bcache.c*/
73#define EXT4_DEBUG_BCACHE (1 << 9)73#define EXT4_DEBUG_BCACHE (1 << 9)
74 74
75/**@brief Debug mask: ext4_extents.c*/75/**@brief Debug mask: ext4_extents.c*/
76#define EXT4_DEBUG_EXTENTS (1 << 10)76#define EXT4_DEBUG_EXTENTS (1 << 10)
77 77
78 78
79 79
80/**@brief All debug printf enabled.*/80/**@brief All debug printf enabled.*/
81#define EXT4_DEBUG_ALL (0xFFFFFFFF)81#define EXT4_DEBUG_ALL (0xFFFFFFFF)
82 82
83/**@brief Global mask debug settings.83/**@brief Global mask debug settings.
84 * @brief m new debug mask.*/84 * @brief m new debug mask.*/
85void ext4_dmask_set(uint32_t m);85void ext4_dmask_set(uint32_t m);
86 86
87/**@brief Global debug mask get.87/**@brief Global debug mask get.
88 * @return debug mask*/88 * @return debug mask*/
89uint32_t ext4_dmask_get(void);89uint32_t ext4_dmask_get(void);
90 90
91 91
92#if CONFIG_DEBUG_PRINTF92#if CONFIG_DEBUG_PRINTF
93/**@brief Debug printf.*/93/**@brief Debug printf.*/
94#define ext4_dprintf(m, ...) do { \94#define ext4_dprintf(m, ...) do { \
95 (m & ext4_dmask_get()) ? printf(__VA_ARGS__) : (void)0; \95 (m & ext4_dmask_get()) ? printf(__VA_ARGS__) : (void)0; \
96 fflush(stdout); \96 fflush(stdout); \
97}while(0)97}while(0)
98#else98#else
99#define ext4_dprintf(m, ...)99#define ext4_dprintf(m, ...)
100#endif100#endif
101 101
102 102
103 103
104#if CONFIG_DEBUG_ASSERT104#if CONFIG_DEBUG_ASSERT
105/**@brief Debug asseration.*/105/**@brief Debug asseration.*/
106#define ext4_assert(_v) do { \106#define ext4_assert(_v) do { \
107 if(!(_v)){ \107 if(!(_v)){ \
108 printf("Assertion failed:\nmodule: %s\nfunc: %s\nline: %d\n", \108 printf("Assertion failed:\nmodule: %s\nfunc: %s\nline: %d\n", \
109 __FILE__, __FUNCTION__, __LINE__); \109 __FILE__, __FUNCTION__, __LINE__); \
lwext4/ext4_dir.c+3−3
@@ -439,8 +439,8 @@ int ext4_dir_find_entry(struct ext4_directory_search_result *result, · 438 unmodified lines
439 439
440 /* Entry was not found */440 /* Entry was not found */
441 441
442 result->block.lb_id = 0;442 result->block.lb_id = 0;
443 result->dentry = NULL;443 result->dentry = NULL;
444 444
445 return ENOENT;445 return ENOENT;
446}446}
@@ -513,7 +513,7 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb, · 66 unmodified lines
513 513
514 /* Initialize pointers, stop means to upper bound */514 /* Initialize pointers, stop means to upper bound */
515 struct ext4_directory_entry_ll *dentry = (void *)target_block->data;515 struct ext4_directory_entry_ll *dentry = (void *)target_block->data;
516 struct ext4_directory_entry_ll *stop =516 struct ext4_directory_entry_ll *stop =
517 (void *)(target_block->data + block_size);517 (void *)(target_block->data + block_size);
518 518
519 /*519 /*
lwext4/ext4_dir_idx.c+3−3
@@ -89,7 +89,7 @@ uint8_t ext4_dir_dx_root_info_get_indirect_levels( · 88 unmodified lines
89 return root_info->indirect_levels;89 return root_info->indirect_levels;
90}90}
91 91
92void ext4_dir_dx_root_info_set_indirect_levels(92void ext4_dir_dx_root_info_set_indirect_levels(
93 struct ext4_directory_dx_root_info *root_info, uint8_t lvl)93 struct ext4_directory_dx_root_info *root_info, uint8_t lvl)
94{94{
95 root_info->indirect_levels = lvl;95 root_info->indirect_levels = lvl;
@@ -430,7 +430,7 @@ static int ext4_dir_dx_next_block(struct ext4_inode_ref *inode_ref, · 334 unmodified lines
430 430
431 431
432 432
433int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,433int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,
434 struct ext4_inode_ref *inode_ref, size_t name_len, const char *name)434 struct ext4_inode_ref *inode_ref, size_t name_len, const char *name)
435{435{
436 /* Load direct block 0 (index root) */436 /* Load direct block 0 (index root) */
@@ -799,7 +799,7 @@ static int ext4_dir_dx_split_index(struct ext4_inode_ref *inode_ref, · 362 unmodified lines
799 if (rc != EOK)799 if (rc != EOK)
800 return rc;800 return rc;
801 801
802 struct ext4_directory_dx_node *new_node = (void *)new_block.data;802 struct ext4_directory_dx_node *new_node = (void *)new_block.data;
803 struct ext4_directory_dx_entry *new_entries = new_node->entries;803 struct ext4_directory_dx_entry *new_entries = new_node->entries;
804 804
805 memset(&new_node->fake, 0, sizeof(struct ext4_fake_directory_entry));805 memset(&new_node->fake, 0, sizeof(struct ext4_fake_directory_entry));
lwext4/ext4_errno.h+35−35
@@ -41,41 +41,41 @@ · 40 unmodified lines
41#ifndef CONFIG_HAVE_OWN_ERRNO41#ifndef CONFIG_HAVE_OWN_ERRNO
42#include <errno.h>42#include <errno.h>
43#else43#else
44#define EPERM 1 /* Operation not permitted */44#define EPERM 1 /* Operation not permitted */
45#define ENOENT 2 /* No such file or directory */45#define ENOENT 2 /* No such file or directory */
46#define ESRCH 3 /* No such process */46#define ESRCH 3 /* No such process */
47#define EINTR 4 /* Interrupted system call */47#define EINTR 4 /* Interrupted system call */
48#define EIO 5 /* I/O error */48#define EIO 5 /* I/O error */
49#define ENXIO 6 /* No such device or address */49#define ENXIO 6 /* No such device or address */
50#define E2BIG 7 /* Argument list too long */50#define E2BIG 7 /* Argument list too long */
51#define ENOEXEC 8 /* Exec format error */51#define ENOEXEC 8 /* Exec format error */
52#define EBADF 9 /* Bad file number */52#define EBADF 9 /* Bad file number */
53#define ECHILD 10 /* No child processes */53#define ECHILD 10 /* No child processes */
54#define EAGAIN 11 /* Try again */54#define EAGAIN 11 /* Try again */
55#define ENOMEM 12 /* Out of memory */55#define ENOMEM 12 /* Out of memory */
56#define EACCES 13 /* Permission denied */56#define EACCES 13 /* Permission denied */
57#define EFAULT 14 /* Bad address */57#define EFAULT 14 /* Bad address */
58#define ENOTBLK 15 /* Block device required */58#define ENOTBLK 15 /* Block device required */
59#define EBUSY 16 /* Device or resource busy */59#define EBUSY 16 /* Device or resource busy */
60#define EEXIST 17 /* File exists */60#define EEXIST 17 /* File exists */
61#define EXDEV 18 /* Cross-device link */61#define EXDEV 18 /* Cross-device link */
62#define ENODEV 19 /* No such device */62#define ENODEV 19 /* No such device */
63#define ENOTDIR 20 /* Not a directory */63#define ENOTDIR 20 /* Not a directory */
64#define EISDIR 21 /* Is a directory */64#define EISDIR 21 /* Is a directory */
65#define EINVAL 22 /* Invalid argument */65#define EINVAL 22 /* Invalid argument */
66#define ENFILE 23 /* File table overflow */66#define ENFILE 23 /* File table overflow */
67#define EMFILE 24 /* Too many open files */67#define EMFILE 24 /* Too many open files */
68#define ENOTTY 25 /* Not a typewriter */68#define ENOTTY 25 /* Not a typewriter */
69#define ETXTBSY 26 /* Text file busy */69#define ETXTBSY 26 /* Text file busy */
70#define EFBIG 27 /* File too large */70#define EFBIG 27 /* File too large */
71#define ENOSPC 28 /* No space left on device */71#define ENOSPC 28 /* No space left on device */
72#define ESPIPE 29 /* Illegal seek */72#define ESPIPE 29 /* Illegal seek */
73#define EROFS 30 /* Read-only file system */73#define EROFS 30 /* Read-only file system */
74#define EMLINK 31 /* Too many links */74#define EMLINK 31 /* Too many links */
75#define EPIPE 32 /* Broken pipe */75#define EPIPE 32 /* Broken pipe */
76#define EDOM 33 /* Math argument out of domain of func */76#define EDOM 33 /* Math argument out of domain of func */
77#define ERANGE 34 /* Math result not representable */77#define ERANGE 34 /* Math result not representable */
78#define ENOTSUP 95 /* Not supported */78#define ENOTSUP 95 /* Not supported */
79#endif79#endif
80 80
81#ifndef EOK81#ifndef EOK
lwext4/ext4_fs.c+10−10
@@ -384,8 +384,8 @@ static int ext4_fs_init_inode_table(struct ext4_block_group_ref *bg_ref) · 383 unmodified lines
384{384{
385 struct ext4_sblock *sb = &bg_ref->fs->sb;385 struct ext4_sblock *sb = &bg_ref->fs->sb;
386 386
387 uint32_t inode_size = ext4_get32(sb, inode_size);387 uint32_t inode_size = ext4_get32(sb, inode_size);
388 uint32_t block_size = ext4_sb_get_block_size(sb);388 uint32_t block_size = ext4_sb_get_block_size(sb);
389 uint32_t inodes_per_block = block_size / inode_size;389 uint32_t inodes_per_block = block_size / inode_size;
390 uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bg_ref->index);390 uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bg_ref->index);
391 uint32_t table_blocks = inodes_in_group / inodes_per_block;391 uint32_t table_blocks = inodes_in_group / inodes_per_block;
@@ -670,10 +670,10 @@ int ext4_fs_alloc_inode(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref, · 278 unmodified lines
670 ext4_inode_set_uid(inode, 0);670 ext4_inode_set_uid(inode, 0);
671 ext4_inode_set_gid(inode, 0);671 ext4_inode_set_gid(inode, 0);
672 ext4_inode_set_size(inode, 0);672 ext4_inode_set_size(inode, 0);
673 ext4_inode_set_access_time(inode, 0);673 ext4_inode_set_access_time(inode, 0);
674 ext4_inode_set_change_inode_time(inode, 0);674 ext4_inode_set_change_inode_time(inode, 0);
675 ext4_inode_set_modification_time(inode, 0);675 ext4_inode_set_modification_time(inode, 0);
676 ext4_inode_set_deletion_time(inode, 0);676 ext4_inode_set_deletion_time(inode, 0);
677 ext4_inode_set_blocks_count(&fs->sb, inode, 0);677 ext4_inode_set_blocks_count(&fs->sb, inode, 0);
678 ext4_inode_set_flags(inode, 0);678 ext4_inode_set_flags(inode, 0);
679 ext4_inode_set_generation(inode, 0);679 ext4_inode_set_generation(inode, 0);
@@ -737,7 +737,7 @@ int ext4_fs_free_inode(struct ext4_inode_ref *inode_ref) · 57 unmodified lines
737 uint32_t block_size = ext4_sb_get_block_size(&fs->sb);737 uint32_t block_size = ext4_sb_get_block_size(&fs->sb);
738 uint32_t count = block_size / sizeof(uint32_t);738 uint32_t count = block_size / sizeof(uint32_t);
739 739
740 struct ext4_block block;740 struct ext4_block block;
741 741
742 /* 2) Double indirect */742 /* 2) Double indirect */
743 fblock = ext4_inode_get_indirect_block(inode_ref->inode, 1);743 fblock = ext4_inode_get_indirect_block(inode_ref->inode, 1);
@@ -768,7 +768,7 @@ int ext4_fs_free_inode(struct ext4_inode_ref *inode_ref) · 24 unmodified lines
768 }768 }
769 769
770 /* 3) Tripple indirect */770 /* 3) Tripple indirect */
771 struct ext4_block subblock;771 struct ext4_block subblock;
772 fblock = ext4_inode_get_indirect_block(inode_ref->inode, 2);772 fblock = ext4_inode_get_indirect_block(inode_ref->inode, 2);
773 if (fblock != 0) {773 if (fblock != 0) {
774 int rc = ext4_block_get(fs->bdev, &block, fblock);774 int rc = ext4_block_get(fs->bdev, &block, fblock);
@@ -971,7 +971,7 @@ int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref, · 196 unmodified lines
971 return EOK;971 return EOK;
972 }972 }
973 973
974 struct ext4_block block;974 struct ext4_block block;
975 975
976 /*976 /*
977 * Navigate through other levels, until we find the block number977 * Navigate through other levels, until we find the block number
@@ -1065,8 +1065,8 @@ int ext4_fs_set_inode_data_block_index(struct ext4_inode_ref *inode_ref, · 87 unmodified lines
1065 1065
1066 uint32_t new_block_addr;1066 uint32_t new_block_addr;
1067 1067
1068 struct ext4_block block;1068 struct ext4_block block;
1069 struct ext4_block new_block;1069 struct ext4_block new_block;
1070 1070
1071 /* Is needed to allocate indirect block on the i-node level */1071 /* Is needed to allocate indirect block on the i-node level */
1072 if (current_block == 0) {1072 if (current_block == 0) {
@@ -1224,7 +1224,7 @@ int ext4_fs_release_inode_block(struct ext4_inode_ref *inode_ref, · 151 unmodified lines
1224 * Navigate through other levels, until we find the block number1224 * Navigate through other levels, until we find the block number
1225 * or find null reference meaning we are dealing with sparse file1225 * or find null reference meaning we are dealing with sparse file
1226 */1226 */
1227 struct ext4_block block;1227 struct ext4_block block;
1228 1228
1229 while (level > 0) {1229 while (level > 0) {
1230 1230
lwext4/ext4_hash.h+8−8
@@ -41,14 +41,14 @@ · 40 unmodified lines
41 41
42#include <stdint.h>42#include <stdint.h>
43 43
44/**@brief Directory entry name hash function.44/**@brief Directory entry name hash function.
45 * @param name entry name45 * @param name entry name
46 * @param len entry name length46 * @param len entry name length
47 * @param hash_seed (from superblock)47 * @param hash_seed (from superblock)
48 * @param hash version (from superblock)48 * @param hash version (from superblock)
49 * @param hash_minor output value49 * @param hash_minor output value
50 * @param hash_major output value50 * @param hash_major output value
51 * @return standard error code*/51 * @return standard error code*/
52int ext2_htree_hash(const char *name, int len,52int ext2_htree_hash(const char *name, int len,
53 const uint32_t *hash_seed, int hash_version,53 const uint32_t *hash_seed, int hash_version,
54 uint32_t *hash_major, uint32_t *hash_minor);54 uint32_t *hash_major, uint32_t *hash_minor);
lwext4/ext4_ialloc.c+2−2
@@ -86,7 +86,7 @@ int ext4_ialloc_free_inode(struct ext4_fs *fs, uint32_t index, bool is_dir) · 85 unmodified lines
86 uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(86 uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(
87 bg_ref.block_group, sb);87 bg_ref.block_group, sb);
88 88
89 struct ext4_block bitmap_block;89 struct ext4_block bitmap_block;
90 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);90 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
91 if (rc != EOK)91 if (rc != EOK)
92 return rc;92 return rc;
@@ -173,7 +173,7 @@ int ext4_ialloc_alloc_inode(struct ext4_fs *fs, uint32_t *index, bool is_dir) · 80 unmodified lines
173 uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(173 uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(
174 bg_ref.block_group, sb);174 bg_ref.block_group, sb);
175 175
176 struct ext4_block bitmap_block;176 struct ext4_block bitmap_block;
177 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);177 rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
178 if (rc != EOK)178 if (rc != EOK)
179 return rc;179 return rc;
lwext4/ext4_inode.c+5−5
@@ -69,7 +69,7 @@ uint32_t ext4_inode_get_mode(struct ext4_sblock *sb, struct ext4_inode *inode) · 68 unmodified lines
69 return v;69 return v;
70}70}
71 71
72void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,72void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,
73 uint32_t mode)73 uint32_t mode)
74{74{
75 inode->mode = to_le16((mode << 16) >> 16);75 inode->mode = to_le16((mode << 16) >> 16);
@@ -83,7 +83,7 @@ uint32_t ext4_inode_get_uid(struct ext4_inode *inode) · 7 unmodified lines
83 return to_le32(inode->uid);83 return to_le32(inode->uid);
84}84}
85 85
86void ext4_inode_set_uid(struct ext4_inode *inode, uint32_t uid)86void ext4_inode_set_uid(struct ext4_inode *inode, uint32_t uid)
87{87{
88 inode->uid = to_le32(uid);88 inode->uid = to_le32(uid);
89}89}
@@ -154,7 +154,7 @@ uint32_t ext4_inode_get_gid(struct ext4_inode *inode) · 64 unmodified lines
154}154}
155void ext4_inode_set_gid(struct ext4_inode *inode, uint32_t gid)155void ext4_inode_set_gid(struct ext4_inode *inode, uint32_t gid)
156{156{
157 inode->gid = to_le32(gid);157 inode->gid = to_le32(gid);
158}158}
159 159
160uint16_t ext4_inode_get_links_count(struct ext4_inode *inode)160uint16_t ext4_inode_get_links_count(struct ext4_inode *inode)
@@ -234,14 +234,14 @@ uint32_t ext4_inode_get_flags(struct ext4_inode *inode) · 73 unmodified lines
234}234}
235void ext4_inode_set_flags(struct ext4_inode *inode, uint32_t flags)235void ext4_inode_set_flags(struct ext4_inode *inode, uint32_t flags)
236{236{
237 inode->flags = to_le32(flags);237 inode->flags = to_le32(flags);
238}238}
239 239
240uint32_t ext4_inode_get_generation(struct ext4_inode *inode)240uint32_t ext4_inode_get_generation(struct ext4_inode *inode)
241{241{
242 return to_le32(inode->generation);242 return to_le32(inode->generation);
243}243}
244void ext4_inode_set_generation(struct ext4_inode *inode, uint32_t gen)244void ext4_inode_set_generation(struct ext4_inode *inode, uint32_t gen)
245{245{
246 inode->generation = to_le32(gen);246 inode->generation = to_le32(gen);
247}247}
lwext4/ext4_super.c+4−4
@@ -59,8 +59,8 @@ uint32_t ext4_block_group_cnt(struct ext4_sblock *s) · 58 unmodified lines
59uint32_t ext4_blocks_in_group_cnt(struct ext4_sblock *s, uint32_t bgid)59uint32_t ext4_blocks_in_group_cnt(struct ext4_sblock *s, uint32_t bgid)
60{60{
61 uint32_t block_group_count = ext4_block_group_cnt(s);61 uint32_t block_group_count = ext4_block_group_cnt(s);
62 uint32_t blocks_per_group = ext4_get32(s, blocks_per_group);62 uint32_t blocks_per_group = ext4_get32(s, blocks_per_group);
63 uint64_t total_blocks = ext4_sb_get_blocks_cnt(s);63 uint64_t total_blocks = ext4_sb_get_blocks_cnt(s);
64 64
65 if (bgid < block_group_count - 1)65 if (bgid < block_group_count - 1)
66 return blocks_per_group;66 return blocks_per_group;
@@ -82,13 +82,13 @@ uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid) · 15 unmodified lines
82 return (total_inodes - ((block_group_count - 1) * inodes_per_group));82 return (total_inodes - ((block_group_count - 1) * inodes_per_group));
83}83}
84 84
85int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s)85int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s)
86{86{
87 return ext4_block_writebytes(bdev, EXT4_SUPERBLOCK_OFFSET,87 return ext4_block_writebytes(bdev, EXT4_SUPERBLOCK_OFFSET,
88 s, EXT4_SUPERBLOCK_SIZE);88 s, EXT4_SUPERBLOCK_SIZE);
89}89}
90 90
91int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s)91int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s)
92{92{
93 return ext4_block_readbytes(bdev, EXT4_SUPERBLOCK_OFFSET,93 return ext4_block_readbytes(bdev, EXT4_SUPERBLOCK_OFFSET,
94 s, EXT4_SUPERBLOCK_SIZE);94 s, EXT4_SUPERBLOCK_SIZE);
lwext4/ext4_super.h+2−2
@@ -165,13 +165,13 @@ uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid); · 164 unmodified lines
165 * @param bdev block device descriptor.165 * @param bdev block device descriptor.
166 * @param s superblock descruptor166 * @param s superblock descruptor
167 * @return Standard error code */167 * @return Standard error code */
168int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s);168int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s);
169 169
170/**@brief Superblock read.170/**@brief Superblock read.
171 * @param bdev block device descriptor.171 * @param bdev block device descriptor.
172 * @param s superblock descruptor172 * @param s superblock descruptor
173 * @return Standard error code */173 * @return Standard error code */
174int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s);174int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s);
175 175
176/**@brief Superblock simple validation.176/**@brief Superblock simple validation.
177 * @param s superblock dsecriptor177 * @param s superblock dsecriptor
lwext4/ext4_types.h+39−39
@@ -230,8 +230,8 @@ struct ext4_sblock { · 229 unmodified lines
230 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)230 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
231 231
232struct ext4_fs {232struct ext4_fs {
233 struct ext4_blockdev *bdev;233 struct ext4_blockdev*bdev;
234 struct ext4_sblock sb;234 struct ext4_sblock sb;
235 235
236 uint64_t inode_block_limits[4];236 uint64_t inode_block_limits[4];
237 uint64_t inode_blocks_per_level[4];237 uint64_t inode_blocks_per_level[4];
@@ -270,11 +270,11 @@ struct ext4_bgroup { · 32 unmodified lines
270} ;270} ;
271 271
272struct ext4_block_group_ref {272struct ext4_block_group_ref {
273 struct ext4_block block;273 struct ext4_block block;
274 struct ext4_bgroup *block_group;274 struct ext4_bgroup *block_group;
275 struct ext4_fs *fs;275 struct ext4_fs *fs;
276 uint32_t index;276 uint32_t index;
277 bool dirty;277 bool dirty;
278};278};
279 279
280#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32280#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
@@ -384,8 +384,8 @@ struct ext4_inode { · 103 unmodified lines
384#define EXT4_INODE_ROOT_INDEX 2384#define EXT4_INODE_ROOT_INDEX 2
385 385
386struct ext4_inode_ref {386struct ext4_inode_ref {
387 struct ext4_block block;387 struct ext4_block block;
388 struct ext4_inode *inode;388 struct ext4_inode *inode;
389 struct ext4_fs *fs;389 struct ext4_fs *fs;
390 uint32_t index;390 uint32_t index;
391 bool dirty;391 bool dirty;
@@ -420,15 +420,15 @@ struct ext4_directory_entry_ll { · 28 unmodified lines
420} __attribute__((packed)) ;420} __attribute__((packed)) ;
421 421
422struct ext4_directory_iterator {422struct ext4_directory_iterator {
423 struct ext4_inode_ref *inode_ref;423 struct ext4_inode_ref *inode_ref;
424 struct ext4_block current_block;424 struct ext4_block current_block;
425 uint64_t current_offset;425 uint64_t current_offset;
426 struct ext4_directory_entry_ll *current;426 struct ext4_directory_entry_ll *current;
427};427};
428 428
429struct ext4_directory_search_result {429struct ext4_directory_search_result {
430 struct ext4_block block;430 struct ext4_block block;
431 struct ext4_directory_entry_ll *dentry;431 struct ext4_directory_entry_ll *dentry;
432};432};
433 433
434/* Structures for indexed directory */434/* Structures for indexed directory */
@@ -478,7 +478,7 @@ struct ext4_directory_dx_node { · 43 unmodified lines
478};478};
479 479
480struct ext4_directory_dx_block {480struct ext4_directory_dx_block {
481 struct ext4_block block;481 struct ext4_block block;
482 struct ext4_directory_dx_entry *entries;482 struct ext4_directory_dx_entry *entries;
483 struct ext4_directory_dx_entry *position;483 struct ext4_directory_dx_entry *position;
484} ;484} ;
@@ -526,31 +526,31 @@ struct ext4_extent_header { · 41 unmodified lines
526} ;526} ;
527 527
528struct ext4_extent_path {528struct ext4_extent_path {
529 struct ext4_block block;529 struct ext4_block block;
530 uint16_t depth;530 uint16_t depth;
531 struct ext4_extent_header *header;531 struct ext4_extent_header *header;
532 struct ext4_extent_index *index;532 struct ext4_extent_index *index;
533 struct ext4_extent *extent;533 struct ext4_extent *extent;
534} ;534} ;
535 535
536#define EXT4_EXTENT_MAGIC 0xF30A536#define EXT4_EXTENT_MAGIC 0xF30A
537 537
538#define EXT4_EXTENT_FIRST(header) \538#define EXT4_EXTENT_FIRST(header) \
539 ((struct ext4_extent *) (((void *) (header)) + sizeof(struct ext4_extent_header)))539 ((struct ext4_extent *) (((void *) (header)) + sizeof(struct ext4_extent_header)))
540 540
541#define EXT4_EXTENT_FIRST_INDEX(header) \541#define EXT4_EXTENT_FIRST_INDEX(header) \
542 ((struct ext4_extent_index *) (((void *) (header)) + sizeof(struct ext4_extent_header)))542 ((struct ext4_extent_index *) (((void *) (header)) + sizeof(struct ext4_extent_header)))
543 543
544 544
545/* EXT3 HTree directory indexing */545/* EXT3 HTree directory indexing */
546#define EXT2_HTREE_LEGACY 0546#define EXT2_HTREE_LEGACY 0
547#define EXT2_HTREE_HALF_MD4 1547#define EXT2_HTREE_HALF_MD4 1
548#define EXT2_HTREE_TEA 2548#define EXT2_HTREE_TEA 2
549#define EXT2_HTREE_LEGACY_UNSIGNED 3549#define EXT2_HTREE_LEGACY_UNSIGNED 3
550#define EXT2_HTREE_HALF_MD4_UNSIGNED 4550#define EXT2_HTREE_HALF_MD4_UNSIGNED 4
551#define EXT2_HTREE_TEA_UNSIGNED 5551#define EXT2_HTREE_TEA_UNSIGNED 5
552 552
553#define EXT2_HTREE_EOF 0x7FFFFFFF553#define EXT2_HTREE_EOF 0x7FFFFFFF
554 554
555 555
556struct ext4_hash_info {556struct ext4_hash_info {
@@ -578,7 +578,7 @@ static inline uint64_t to_le64(uint64_t n) · 21 unmodified lines
578 578
579static inline uint32_t to_le32(uint32_t n)579static inline uint32_t to_le32(uint32_t n)
580{580{
581 return ((n & 0xff) << 24) |581 return ((n & 0xff) << 24) |
582 ((n & 0xff00) << 8) |582 ((n & 0xff00) << 8) |
583 ((n & 0xff0000) >> 8) |583 ((n & 0xff0000) >> 8) |
584 ((n & 0xff000000) >> 24);584 ((n & 0xff000000) >> 24);
@@ -586,27 +586,27 @@ static inline uint32_t to_le32(uint32_t n) · 1 unmodified line
586 586
587static inline uint16_t to_le16(uint16_t n)587static inline uint16_t to_le16(uint16_t n)
588{588{
589 return ((n & 0xff) << 8) |589 return ((n & 0xff) << 8) |
590 ((n & 0xff00) >> 8);590 ((n & 0xff00) >> 8);
591}591}
592 592
593 593
594#else594#else
595#define to_le64(_n) _n595#define to_le64(_n) _n
596#define to_le32(_n) _n596#define to_le32(_n) _n
597#define to_le16(_n) _n597#define to_le16(_n) _n
598#endif598#endif
599 599
600/****************************Access macros to ext4 structures*****************/600/****************************Access macros to ext4 structures*****************/
601 601
602#define ext4_get32(s, f) to_le32((s)->f)602#define ext4_get32(s, f) to_le32((s)->f)
603#define ext4_get16(s, f) to_le16((s)->f)603#define ext4_get16(s, f) to_le16((s)->f)
604#define ext4_get8(s, f) (s)->f604#define ext4_get8(s, f) (s)->f
605 605
606 606
607#define ext4_set32(s, f, v) do { (s)->f = to_le32(v); }while(0)607#define ext4_set32(s, f, v) do { (s)->f = to_le32(v); }while(0)
608#define ext4_set16(s, f, v) do { (s)->f = to_le16(v); }while(0)608#define ext4_set16(s, f, v) do { (s)->f = to_le16(v); }while(0)
609#define ext4_set8 (s, f, v) do { (s)->f = (v); }while(0)609#define ext4_set8 (s, f, v) do { (s)->f = (v); }while(0)
610 610
611#endif /* EXT4_TYPES_H_ */611#endif /* EXT4_TYPES_H_ */
612 612
readme.txt+4−4
@@ -53,7 +53,7 @@ FEATURE_INCOMPAT (able to mount with unsupported feature): · 52 unmodified lines
53 - DIR_PREALLOC: no53 - DIR_PREALLOC: no
54 - IMAGIC_INODES: no54 - IMAGIC_INODES: no
55 - HAS_JOURNAL: no55 - HAS_JOURNAL: no
56 - EXT_ATTR: no56 - EXT_ATTR: no
57 - RESIZE_INODE: no57 - RESIZE_INODE: no
58 - DIR_INDEX: yes58 - DIR_INDEX: yes
59 59
@@ -67,8 +67,8 @@ FEATURE_RO (able to mount in read only with unsupported feature): · 7 unmodified lines
67 - EXTRA_ISIZE: yes67 - EXTRA_ISIZE: yes
68 68
69Supported filetypes:69Supported filetypes:
70 - FIFO: no70 - FIFO: no
71 - CHARDEV: no71 - CHARDEV: no
72 - DIRECTORY: yes72 - DIRECTORY: yes
73 - BLOCKDEV: no73 - BLOCKDEV: no
74 - FILE: yes74 - FILE: yes
@@ -94,7 +94,7 @@ lwext4 project tree · 19 unmodified lines
94 94
95+toolchain - specific toolchain cmake files95+toolchain - specific toolchain cmake files
96 96
97+ext4.h - lwext4 client library header97+ext4.h - lwext4 client library header
98CMakeLists.txt - CMake config file98CMakeLists.txt - CMake config file
99ext_images.7z - ext2/3/4 100MB images99ext_images.7z - ext2/3/4 100MB images
100Makefile - helper makefile to call cmake100Makefile - helper makefile to call cmake
toolchain/bf518.cmake+7−12
@@ -3,20 +3,15 @@ SET(CMAKE_SYSTEM_NAME Generic) · 2 unmodified lines
3set(CMAKE_SYSTEM_PROCESSOR bf518)3set(CMAKE_SYSTEM_PROCESSOR bf518)
4 4
5# Toolchain settings5# Toolchain settings
6set(CMAKE_C_COMPILER bfin-elf-gcc)6set(CMAKE_C_COMPILER bfin-elf-gcc)
7set(CMAKE_CXX_COMPILER bfin-elf-g++)7set(CMAKE_CXX_COMPILER bfin-elf-g++)
8set(AS bfin-elf--gcc)8set(AS bfin-elf--gcc)
9set(AR bfin-elf-ar)9set(AR bfin-elf-ar)
10set(OBJCOPY bfin-elf-objcopy)10set(OBJCOPY bfin-elf-objcopy)
11set(OBJDUMP bfin-elf-objdump)11set(OBJDUMP bfin-elf-objdump)
12set(SIZE bfin-elf-size)12set(SIZE bfin-elf-size)
13 13
14set(CMAKE_C_FLAGS "-mcpu=bf518 -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")14set(CMAKE_C_FLAGS "-mcpu=bf518 -Os -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
15set(CMAKE_CXX_FLAGS "-mcpu=bf518 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")15set(CMAKE_CXX_FLAGS "-mcpu=bf518 -Os -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
16set(CMAKE_ASM_FLAGS "-mcpu=bf518 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags")16set(CMAKE_ASM_FLAGS "-mcpu=bf518 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags")
17set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mcpu=bf592" CACHE INTERNAL "exe link flags")17set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mcpu=bf592" CACHE INTERNAL "exe link flags")
18
19
20
21
22
toolchain/cortex-m3.cmake+8−8
@@ -3,16 +3,16 @@ SET(CMAKE_SYSTEM_NAME Generic) · 2 unmodified lines
3set(CMAKE_SYSTEM_PROCESSOR cortex-m3)3set(CMAKE_SYSTEM_PROCESSOR cortex-m3)
4 4
5# Toolchain settings5# Toolchain settings
6set(CMAKE_C_COMPILER arm-none-eabi-gcc)6set(CMAKE_C_COMPILER arm-none-eabi-gcc)
7set(CMAKE_CXX_COMPILER arm-none-eabi-g++)7set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
8set(AS arm-none-eabi-as)8set(AS arm-none-eabi-as)
9set(AR arm-none-eabi-ar)9set(AR arm-none-eabi-ar)
10set(OBJCOPY arm-none-eabi-objcopy)10set(OBJCOPY arm-none-eabi-objcopy)
11set(OBJDUMP arm-none-eabi-objdump)11set(OBJDUMP arm-none-eabi-objdump)
12set(SIZE arm-none-eabi-size)12set(SIZE arm-none-eabi-size)
13 13
14set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m3 -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")14set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m3 -Os -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
15set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m3 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")15set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m3 -Os -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
16set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m3" CACHE INTERNAL "asm compiler flags")16set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m3" CACHE INTERNAL "asm compiler flags")
17set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m3" CACHE INTERNAL "exe link flags")17set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m3" CACHE INTERNAL "exe link flags")
18 18
toolchain/cortex-m4.cmake+8−8
@@ -3,16 +3,16 @@ SET(CMAKE_SYSTEM_NAME Generic) · 2 unmodified lines
3set(CMAKE_SYSTEM_PROCESSOR cortex-m4)3set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
4 4
5# Toolchain settings5# Toolchain settings
6set(CMAKE_C_COMPILER arm-none-eabi-gcc)6set(CMAKE_C_COMPILER arm-none-eabi-gcc)
7set(CMAKE_CXX_COMPILER arm-none-eabi-g++)7set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
8set(AS arm-none-eabi-as)8set(AS arm-none-eabi-as)
9set(AR arm-none-eabi-ar)9set(AR arm-none-eabi-ar)
10set(OBJCOPY arm-none-eabi-objcopy)10set(OBJCOPY arm-none-eabi-objcopy)
11set(OBJDUMP arm-none-eabi-objdump)11set(OBJDUMP arm-none-eabi-objdump)
12set(SIZE arm-none-eabi-size)12set(SIZE arm-none-eabi-size)
13 13
14set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m4 -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")14set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m4 -Os -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
15set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m4 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")15set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m4 -Os -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
16set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m4" CACHE INTERNAL "asm compiler flags")16set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m4" CACHE INTERNAL "asm compiler flags")
17set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m4" CACHE INTERNAL "exe link flags")17set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m4" CACHE INTERNAL "exe link flags")
18 18

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t