ref: 79bc1a343033f4b91363683d1bedb8726bb30385
parent: d69ffabcc83a63783f589fdcb7dfb15728aa12f6
author: gkostka <[email protected]>
date: Sat Nov 21 12:52:55 EST 2015
Style & indentation improvements in ext4 part 2
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -959,9 +959,8 @@
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDONLY,
- EXT4_DE_UNKNOWN,
- &parent_inode, &name_off);
+ r = ext4_generic_open2(&f, path, O_RDONLY, EXT4_DE_UNKNOWN,
+ &parent_inode, &name_off);
if (r != EOK)
goto Finish;
@@ -1044,8 +1043,7 @@
return ENOENT;
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR,
- EXT4_DE_UNKNOWN,
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN,
&parent_inode, &name_off);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
@@ -1101,8 +1099,7 @@
return r;
}
-int ext4_fill_raw_inode(const char *path,
- uint32_t *ret_ino,
+int ext4_fill_raw_inode(const char *path, uint32_t *ret_ino,
struct ext4_inode *inode)
{
int r;
@@ -1116,9 +1113,7 @@
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDONLY,
- EXT4_DE_UNKNOWN,
- NULL, NULL);
+ r = ext4_generic_open2(&f, path, O_RDONLY, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK) {
EXT4_MP_UNLOCK(mp);
return r;
@@ -1135,7 +1130,6 @@
}
memcpy(inode, inode_ref.inode, sizeof(struct ext4_inode));
-
ext4_fs_put_inode_ref(&inode_ref);
EXT4_MP_UNLOCK(mp);
@@ -1174,7 +1168,7 @@
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
- r = ext4_generic_open2(f, path, flags, filetype, 0, 0);
+ r = ext4_generic_open2(f, path, flags, filetype, NULL, NULL);
ext4_block_cache_write_back(mp->fs.bdev, 0);
EXT4_MP_UNLOCK(mp);
return r;
@@ -1245,9 +1239,7 @@
return EPERM;
EXT4_MP_LOCK(f->mp);
-
r = ext4_ftruncate_no_lock(f, size);
-
EXT4_MP_UNLOCK(f->mp);
return r;
}
@@ -1254,7 +1246,7 @@
int ext4_fread(ext4_file *f, void *buf, size_t size, size_t *rcnt)
{
- uint32_t unaligned;
+ uint32_t unalg;
uint32_t iblock_idx;
uint32_t iblock_last;
uint32_t block_size;
@@ -1278,10 +1270,13 @@
EXT4_MP_LOCK(f->mp);
+ struct ext4_fs *const fs = &f->mp->fs;
+ struct ext4_sblock *const sb = &f->mp->fs.sb;
+
if (rcnt)
*rcnt = 0;
- r = ext4_fs_get_inode_ref(&f->mp->fs, f->inode, &ref);
+ r = ext4_fs_get_inode_ref(fs, f->inode, &ref);
if (r != EOK) {
EXT4_MP_UNLOCK(f->mp);
return r;
@@ -1288,33 +1283,30 @@
}
/*Sync file size*/
- f->fsize = ext4_inode_get_size(&f->mp->fs.sb, ref.inode);
+ f->fsize = ext4_inode_get_size(sb, ref.inode);
- block_size = ext4_sb_get_block_size(&f->mp->fs.sb);
+ block_size = ext4_sb_get_block_size(sb);
size = size > (f->fsize - f->fpos) ? (f->fsize - f->fpos) : size;
iblock_idx = (f->fpos) / block_size;
iblock_last = (f->fpos + size) / block_size;
- unaligned = (f->fpos) % block_size;
+ unalg = (f->fpos) % block_size;
/*If the size of symlink is smaller than 60 bytes*/
- if (ext4_inode_is_type(&f->mp->fs.sb, ref.inode, EXT4_INODE_MODE_SOFTLINK)
- && f->fsize < sizeof(ref.inode->blocks)
- && !ext4_inode_get_blocks_count(&f->mp->fs.sb, ref.inode)) {
+ bool softlink;
+ softlink = ext4_inode_is_type(sb, ref.inode, EXT4_INODE_MODE_SOFTLINK);
+ if (softlink && f->fsize < sizeof(ref.inode->blocks)
+ && !ext4_inode_get_blocks_count(sb, ref.inode)) {
+
char *content = (char *)ref.inode->blocks;
if (f->fpos < f->fsize) {
- r = (unaligned + size > f->fsize)
- ?(f->fsize - unaligned)
- :(size);
- memcpy(buf, content + unaligned, r);
+ size_t len = size;
+ if (unalg + size > f->fsize)
+ len = f->fsize - unalg;
+ memcpy(buf, content + unalg, len);
if (rcnt)
- *rcnt = r;
+ *rcnt = len;
- } else {
- r = 0;
- if (rcnt)
- *rcnt = 0;
-
}
r = EOK;
@@ -1321,11 +1313,13 @@
goto Finish;
}
- if (unaligned) {
- uint32_t l = size > (block_size - unaligned) ?
- (block_size - unaligned) : size;
- r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx, &fblock,
- true);
+ if (unalg) {
+ size_t len = size;
+ if (size > (block_size - unalg))
+ len = block_size - unalg;
+
+ r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx,
+ &fblock, true);
if (r != EOK)
goto Finish;
@@ -1335,7 +1329,7 @@
if (r != EOK)
goto Finish;
- memcpy(u8_buf, b.data + unaligned, l);
+ memcpy(u8_buf, b.data + unalg, len);
r = ext4_block_set(f->mp->fs.bdev, &b);
if (r != EOK)
@@ -1342,15 +1336,15 @@
goto Finish;
} else {
/* Yes, we do. */
- memset(u8_buf, 0, l);
+ memset(u8_buf, 0, len);
}
- u8_buf += l;
- size -= l;
- f->fpos += l;
+ u8_buf += len;
+ size -= len;
+ f->fpos += len;
if (rcnt)
- *rcnt += l;
+ *rcnt += len;
iblock_idx++;
}
@@ -1392,8 +1386,8 @@
}
if (size) {
- r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx, &fblock,
- true);
+ r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx,
+ &fblock, true);
if (r != EOK)
goto Finish;
@@ -1421,8 +1415,8 @@
int ext4_fwrite(ext4_file *f, const void *buf, size_t size, size_t *wcnt)
{
- uint32_t unaligned;
- uint32_t iblock_idx;
+ uint32_t unalg;
+ uint32_t iblk_idx;
uint32_t iblock_last;
uint32_t ifile_blocks;
uint32_t block_size;
@@ -1446,10 +1440,13 @@
EXT4_MP_LOCK(f->mp);
+ struct ext4_fs *const fs = &f->mp->fs;
+ struct ext4_sblock *const sb = &f->mp->fs.sb;
+
if (wcnt)
*wcnt = 0;
- r = ext4_fs_get_inode_ref(&f->mp->fs, f->inode, &ref);
+ r = ext4_fs_get_inode_ref(fs, f->inode, &ref);
if (r != EOK) {
EXT4_MP_UNLOCK(f->mp);
return r;
@@ -1456,19 +1453,21 @@
}
/*Sync file size*/
- f->fsize = ext4_inode_get_size(&f->mp->fs.sb, ref.inode);
- block_size = ext4_sb_get_block_size(&f->mp->fs.sb);
+ f->fsize = ext4_inode_get_size(sb, ref.inode);
+ block_size = ext4_sb_get_block_size(sb);
iblock_last = (f->fpos + size) / block_size;
- iblock_idx = (f->fpos) / block_size;
+ iblk_idx = (f->fpos) / block_size;
ifile_blocks = (f->fsize + block_size - 1) / block_size;
- unaligned = (f->fpos) % block_size;
+ unalg = (f->fpos) % block_size;
- if (unaligned) {
- uint32_t l = size > (block_size - unaligned) ?
- (block_size - unaligned) : size;
- r = ext4_fs_init_inode_data_block_index(&ref, iblock_idx, &fblock);
+ if (unalg) {
+ size_t len = size;
+ if (size > (block_size - unalg))
+ len = block_size - unalg;
+
+ r = ext4_fs_init_inode_data_block_index(&ref, iblk_idx, &fblock);
if (r != EOK)
goto Finish;
@@ -1476,7 +1475,7 @@
if (r != EOK)
goto Finish;
- memcpy(b.data + unaligned, u8_buf, l);
+ memcpy(b.data + unalg, u8_buf, len);
b.dirty = true;
r = ext4_block_set(f->mp->fs.bdev, &b);
@@ -1483,14 +1482,14 @@
if (r != EOK)
goto Finish;
- u8_buf += l;
- size -= l;
- f->fpos += l;
+ u8_buf += len;
+ size -= len;
+ f->fpos += len;
if (wcnt)
- *wcnt += l;
+ *wcnt += len;
- iblock_idx++;
+ iblk_idx++;
}
/*Start write back cache mode.*/
@@ -1502,24 +1501,24 @@
fblock_count = 0;
while (size >= block_size) {
- while (iblock_idx < iblock_last) {
- if (iblock_idx < ifile_blocks) {
+ while (iblk_idx < iblock_last) {
+ if (iblk_idx < ifile_blocks) {
r = ext4_fs_init_inode_data_block_index(
- &ref, iblock_idx, &fblock);
+ &ref, iblk_idx, &fblock);
if (r != EOK)
goto Finish;
} else {
rr = ext4_fs_append_inode_block(&ref, &fblock,
- &iblock_idx);
+ &iblk_idx);
if (rr != EOK) {
- /* Unable to append more blocks. But some
- * block might be allocated already.
+ /* Unable to append more blocks. But
+ * some block might be allocated already
* */
break;
}
}
- iblock_idx++;
+ iblk_idx++;
if (!fblock_start) {
fblock_start = fblock;
@@ -1562,13 +1561,13 @@
goto Finish;
if (size) {
- if (iblock_idx < ifile_blocks) {
- r = ext4_fs_init_inode_data_block_index(&ref, iblock_idx,
+ if (iblk_idx < ifile_blocks) {
+ r = ext4_fs_init_inode_data_block_index(&ref, iblk_idx,
&fblock);
if (r != EOK)
goto Finish;
} else {
- r = ext4_fs_append_inode_block(&ref, &fblock, &iblock_idx);
+ r = ext4_fs_append_inode_block(&ref, &fblock, &iblk_idx);
if (r != EOK)
/*Node size sholud be updated.*/
goto out_fsize;
@@ -1629,9 +1628,15 @@
return EINVAL;
}
-uint64_t ext4_ftell(ext4_file *f) { return f->fpos; }
+uint64_t ext4_ftell(ext4_file *f)
+{
+ return f->fpos;
+}
-uint64_t ext4_fsize(ext4_file *f) { return f->fsize; }
+uint64_t ext4_fsize(ext4_file *f)
+{
+ return f->fsize;
+}
int ext4_chmod(const char *path, uint32_t mode)
{
@@ -1926,7 +1931,7 @@
EXT4_MP_LOCK(mp);
ext4_block_cache_write_back(mp->fs.bdev, 1);
- r = ext4_generic_open2(&f, path, O_RDONLY, filetype, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDONLY, filetype, NULL, NULL);
if (r == EOK)
r = ext4_fread(&f, buf, bufsize, rcnt);
else
@@ -1961,8 +1966,7 @@
return EINVAL;
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR,
- EXT4_DE_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK)
goto Finish;
inode = f.inode;
@@ -1972,8 +1976,7 @@
if (r != EOK)
goto Finish;
- r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref,
- &xattr_ref);
+ r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref, &xattr_ref);
if (r != EOK) {
ext4_fs_put_inode_ref(&inode_ref);
goto Finish;
@@ -2010,8 +2013,7 @@
return EINVAL;
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR,
- EXT4_DE_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK)
goto Finish;
inode = f.inode;
@@ -2021,16 +2023,14 @@
if (r != EOK)
goto Finish;
- r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref,
- &xattr_ref);
+ r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref, &xattr_ref);
if (r != EOK) {
ext4_fs_put_inode_ref(&inode_ref);
goto Finish;
}
- r = ext4_fs_get_xattr(&xattr_ref, name_index,
- dissected_name, dissected_len,
- buf, buf_size, data_size);
+ r = ext4_fs_get_xattr(&xattr_ref, name_index, dissected_name,
+ dissected_len, buf, buf_size, data_size);
ext4_fs_put_xattr_ref(&xattr_ref);
ext4_fs_put_inode_ref(&inode_ref);
@@ -2054,21 +2054,17 @@
struct ext4_listxattr_iterator *lxi;
lxi = ref->iter_arg;
if (!lxi->get_required_size) {
- size_t prefix_len;
+ size_t plen;
const char *prefix;
- prefix = ext4_get_xattr_name_prefix(item->name_index,
- &prefix_len);
- if (lxi->ret_size +
- prefix_len + item->name_len + 1 >
- lxi->size) {
-
+ prefix = ext4_get_xattr_name_prefix(item->name_index, &plen);
+ if (lxi->ret_size + plen + item->name_len + 1 > lxi->size) {
lxi->list_too_small = 1;
return EXT4_XATTR_ITERATE_STOP;
}
if (prefix) {
- memcpy(lxi->list_ptr, prefix, prefix_len);
- lxi->list_ptr += prefix_len;
- lxi->ret_size += prefix_len;
+ memcpy(lxi->list_ptr, prefix, plen);
+ lxi->list_ptr += plen;
+ lxi->ret_size += plen;
}
memcpy(lxi->list_ptr, item->name, item->name_len);
lxi->list_ptr[item->name_len] = 0;
@@ -2098,8 +2094,7 @@
lxi.get_required_size = (!size) ? true : false;
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR,
- EXT4_DE_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK)
goto Finish;
inode = f.inode;
@@ -2109,8 +2104,7 @@
if (r != EOK)
goto Finish;
- r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref,
- &xattr_ref);
+ r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref, &xattr_ref);
if (r != EOK) {
ext4_fs_put_inode_ref(&inode_ref);
goto Finish;
@@ -2149,13 +2143,12 @@
return ENOENT;
dissected_name = ext4_extract_xattr_name(name, name_len,
- &name_index, &dissected_len);
+ &name_index, &dissected_len);
if (!dissected_len)
return EINVAL;
EXT4_MP_LOCK(mp);
- r = ext4_generic_open2(&f, path, O_RDWR,
- EXT4_DE_UNKNOWN, 0, 0);
+ r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK)
goto Finish;
inode = f.inode;
@@ -2165,8 +2158,7 @@
if (r != EOK)
goto Finish;
- r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref,
- &xattr_ref);
+ r = ext4_fs_get_xattr_ref(&mp->fs, &inode_ref, &xattr_ref);
if (r != EOK) {
ext4_fs_put_inode_ref(&inode_ref);
goto Finish;
--- a/lwext4/ext4.h
+++ b/lwext4/ext4.h
@@ -311,8 +311,7 @@
* @param ret_ino the inode id of the path
* @param ext4_inode buffer
* @return standard error code*/
-int ext4_fill_raw_inode(const char *path,
- uint32_t *ret_ino,
+int ext4_fill_raw_inode(const char *path, uint32_t *ret_ino,
struct ext4_inode *inode);
/**@brief File truncate function.