summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Prakash Jana <engineerarun@gmail.com>2016-09-22 22:43:46 +0530
committerArun Prakash Jana <engineerarun@gmail.com>2016-09-22 22:43:46 +0530
commit0dbde0bfd904fe772e701a43dcaa4a50b66320a8 (patch)
tree315fe5712e79b5309560bc4f0796fa10f47e0375
parent9236948b17f0739c2f614eecc98b270411814900 (diff)
Add dummy help function:wq.
-rw-r--r--calb.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/calb.c b/calb.c
index 469d28a..154c235 100644
--- a/calb.c
+++ b/calb.c
@@ -360,10 +360,15 @@ char *strtolower(char *buf)
return buf;
}
+void usage()
+{
+ printf("calb usage\n");
+}
+
int main(int argc, char **argv)
{
int opt = 0;
- ulong sectorsize = SECTOR_SIZE;
+ long sectorsize = SECTOR_SIZE;
opterr = 0;
@@ -371,13 +376,19 @@ int main(int argc, char **argv)
switch (opt) {
case 'c':
break;
+ case 'h':
+ usage();
+ return 0;
case 's':
- sectorsize = strtoul(optarg, NULL, 0);
- printf("sectorsize: 0x%lx\n", sectorsize);
+ sectorsize = strtol(optarg, NULL, 0);
+ if (sectorsize <= 0) {
+ fprintf(stderr, "sector size must be +ve\n");
+ return 1;
+ }
break;
default:
if (isprint (optopt))
- fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+ fprintf(stderr, "Unknown option `-%c'\n", optopt);
else
fprintf(stderr, "Unknown option\n");
@@ -385,7 +396,12 @@ int main(int argc, char **argv)
}
}
- printf("Non-option args: %d\n", argc - optind);
+ if (argc - optind == 1) {
+ usage();
+ return 1;
+ }
+
+ printf("\n");
if (argc - optind == 2) {
int ret = 0;
@@ -403,8 +419,6 @@ int main(int argc, char **argv)
return 1;
}
- printf("count: %x unit: %s\n", count, units[count]);
-
switch (count) {
case 0:
bytes = convertbyte(argv[optind]);
@@ -440,6 +454,7 @@ int main(int argc, char **argv)
printf("\n\naddress (dec): %llu\naddress (hex): 0x%llx\n\n", bytes, bytes);
+ printf("sector size: 0x%lx\n\n", sectorsize);
lba = bytes / sectorsize;
offset = bytes % sectorsize;
printf("LBA:offset (dec): %llu:%llu\nLBA:offset (hex): 0x%llx:0x%llx\n",