-
Notifications
You must be signed in to change notification settings - Fork 267
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
Conversation
Travis check was successfully completed on all templates except
|
src/cmds/hardware/lsblk/lsblk.c
Outdated
#include <inttypes.h> | ||
|
||
#include <drivers/block_dev.h> | ||
|
||
const char *convertUnit(uint64_t *size){ |
There was a problem hiding this comment.
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
src/cmds/hardware/lsblk/lsblk.c
Outdated
#include <inttypes.h> | ||
|
||
#include <drivers/block_dev.h> | ||
|
||
const char *convertUnit(uint64_t *size){ |
There was a problem hiding this comment.
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
src/cmds/hardware/lsblk/lsblk.c
Outdated
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")); |
There was a problem hiding this comment.
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
@ahmedkrmn Ahmed, thank you. It's look good, but resolve some my comments please |
src/cmds/hardware/lsblk/lsblk.c
Outdated
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")); |
There was a problem hiding this comment.
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.
Thanks @alexkalmuk and @anton-bondarev for the feedback. I will start working on the proposed changes. |
@alexkalmuk, @anton-bondarev |
The time complexity for the argument vectors parsing function is |
src/cmds/hardware/lsblk/lsblk.c
Outdated
return unit; | ||
} | ||
|
||
static bool parse_is_bytes(int argc, char **argv){ |
There was a problem hiding this comment.
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 {
src/cmds/hardware/lsblk/lsblk.c
Outdated
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++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style
for ( ..) {
,,
}
src/cmds/hardware/lsblk/lsblk.c
Outdated
} | ||
|
||
static bool parse_is_bytes(int argc, char **argv){ | ||
if (argc == 1) return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code-style
if (..) {
..
}
Yes, may be. But let start with code-style https://github.com/embox/embox/wiki/Code-Style |
@ahmedkrmn Can we just use |
Didn't know that there already exists a function that parses the argument vector. |
it's declared in getopt.h It's usual and described in linux man (https://linux.die.net/man/3/getopt_long |
@anton-bondarev and @alexkalmuk |
@ahmedkrmn Thanks |
@anton-bondarev Can you please point them out? |
@ahmedkrmn In part "Tabs and Brackets" said
at least in line 46 using spaces at the start of line And it's not in our code-style
That is enough for me |
@anton-bondarev Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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
47aefe2
to
200c239
Compare
@anton-bondarev Done! |
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.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
touint64_t
(flooring).