Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror Linux lsblk command #1705

Merged
merged 1 commit into from
Mar 19, 2020

Conversation

ahmedkrmn
Copy link
Contributor

Fixes #1699

  • This PR improves the available lsblk command in Embox. It mirrors the linux lsblk command adding the -b, --bytes flags to choose the unit of displaying size.

    lsblk

I tried multiple ways to round the value of size to the nearest integer but they all failed resulting in the error message posted on the issue page. The current behavior is typecasting the float to uint64_t (flooring).

@ahmedkrmn
Copy link
Contributor Author

Travis check was successfully completed on all templates except mips/qemu. This is the error message:

Embox kernel start
	unit: initializing embox.mem.phymem: 
			start=0x894f7000 end=0x90000000 size=112234496
		done
runlevel: init level is 0
	unit: initializing embox.kernel.task.task_resource: done
	unit: initializing embox.mem.static_heap: done
	unit: initializing embox.kernel.task.task_table: done
	unit: initializing embox.kernel.task.kernel_task: done
	unit: initializing embox.profiler.tracing: done
	unit: initializing embox.driver.interrupt.mips_intc: done
	unit: initializing embox.kernel.sched.sched: done
	unit: initializing embox.arch.mips.kernel.exception: done
	unit: initializing embox.arch.mips.kernel.interrupt: done
	unit: initializing embox.driver.clock.mips_clk: done
	unit: initializing embox.kernel.time.timer_handler: done
	unit: initializing embox.kernel.time.kernel_time: done
	test: running embox.test.math.math_test .
	failure at src/tests/math/math_test.c : 45, in function __test_case_at_line_38
		test_assert_true(l == l)
	   case at src/tests/math/math_test.c : 38
		"Test for soft-fp operations"
	
	testing math_test (math/common routines's tests) failed
		1/2 failures
Failed to get into level 1, current level 0

#include <inttypes.h>

#include <drivers/block_dev.h>

const char *convertUnit(uint64_t *size){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use 'static' if it's an internal routine

#include <inttypes.h>

#include <drivers/block_dev.h>

const char *convertUnit(uint64_t *size){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use name conversion from Embox code-style
convertUnit->convert_unit

int main(int argc, char **argv) {
int i;
struct block_dev **bdevs;

bdevs = get_bdev_tab();
assert(bdevs);

bool isBytes = argc > 1 && !(strcmp(argv[1], "-b") && strcmp(argv[1], "--bytes"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name conversion
isBytes->is_bytes

@anton-bondarev
Copy link
Collaborator

@ahmedkrmn Ahmed, thank you. It's look good, but resolve some my comments please

int main(int argc, char **argv) {
int i;
struct block_dev **bdevs;

bdevs = get_bdev_tab();
assert(bdevs);

bool isBytes = argc > 1 && !(strcmp(argv[1], "-b") && strcmp(argv[1], "--bytes"));
Copy link
Member

@alexkalmuk alexkalmuk Feb 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmedkrmn I do not think it's a good idea to have this option at the fixed position. It's much better to analyze the arguments list.

@ahmedkrmn
Copy link
Contributor Author

Thanks @alexkalmuk and @anton-bondarev for the feedback. I will start working on the proposed changes.

@ahmedkrmn
Copy link
Contributor Author

@alexkalmuk, @anton-bondarev
I've applied the coding convention for naming the functions and the variables.
I've also created a separate function to parse the -b and --bytes arguments instead of manually comparing it with the first index.

@ahmedkrmn
Copy link
Contributor Author

The time complexity for the argument vectors parsing function is O(n). It can be implemented in O(logn) if the vector is sorted, but after all, the list of arguments is so small compared to the overhead needed to implement it this way.

return unit;
}

static bool parse_is_bytes(int argc, char **argv){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check Code-style
} else {

static bool parse_is_bytes(int argc, char **argv){
if (argc == 1) return 0;
bool res = 0;
for (size_t i = 1; i < argc; i++)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style
for ( ..) {
,,
}

}

static bool parse_is_bytes(int argc, char **argv){
if (argc == 1) return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-style
if (..) {
..
}

@anton-bondarev
Copy link
Collaborator

The time complexity for the argument vectors parsing function is O(n). It can be implemented in O(logn) if the vector is sorted, but after all, the list of arguments is so small compared to the overhead needed to implement it this way.

Yes, may be. But let start with code-style https://github.com/embox/embox/wiki/Code-Style

@alexkalmuk
Copy link
Member

@ahmedkrmn Can we just use getopt_* functions to parse arguments?

@ahmedkrmn
Copy link
Contributor Author

@ahmedkrmn Can we just use getopt_* functions to parse arguments?

Didn't know that there already exists a function that parses the argument vector.
I need to find where it is implemented to know how to use it. I only could find where it was used but couldn't reach the implementation.

@anton-bondarev
Copy link
Collaborator

@ahmedkrmn Can we just use getopt_* functions to parse arguments?

Didn't know that there already exists a function that parses the argument vector.
I need to find where it is implemented to know how to use it. I only could find where it was used but couldn't reach the implementation.

it's declared in getopt.h It's usual and described in linux man (https://linux.die.net/man/3/getopt_long

@ahmedkrmn
Copy link
Contributor Author

@anton-bondarev and @alexkalmuk
I've used the getopt() function defined in getopt.h as requested.
Can you please re-review this?

@anton-bondarev
Copy link
Collaborator

@ahmedkrmn Thanks
There are a small code-style mistakes, fix it please.

@ahmedkrmn
Copy link
Contributor Author

@anton-bondarev Can you please point them out?
I followed the styling guide here throughout the whole file.

@anton-bondarev
Copy link
Collaborator

@anton-bondarev Can you please point them out?
I followed the styling guide here throughout the whole file.

@ahmedkrmn
I commented these places

In part "Tabs and Brackets" said

We use tabs as the indentation

at least in line 46 using spaces at the start of line

And it's not in our code-style

Please move the variable declarations to the start of the block (to the declaration part)

That is enough for me

@ahmedkrmn
Copy link
Contributor Author

@anton-bondarev Done!

Copy link
Collaborator

@anton-bondarev anton-bondarev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anton-bondarev
Copy link
Collaborator

@ahmedkrmn I've approved it. Please rebase under embox/master and squash commits

Add argv parsing and apply naming convention

Remove unnecessary printf statement

Apply embox code style convention

Remove trailing spaces

Use  for parsing cmd arguments
@ahmedkrmn
Copy link
Contributor Author

@anton-bondarev Done!

@anton-bondarev anton-bondarev merged commit 07d861b into embox:master Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve 'lsblk' command
3 participants