KERNELSUBSUBVER ???

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

KERNELSUBSUBVER ???

Karl Godt
Administrator
In Puppy there are wonderful full of wonders different "standard" variable names for KERNEL VERSION .

A Standard Makefile inside the kernel linux-3.x.x directory uses these :
VERSION = 3
PATCHLEVEL = 7
SUBLEVEL = 0
EXTRAVERSION =
NAME = Terrified Chipmunk

/usr/sbin/filemnt uses code as :
#v423...
KERNELVER="`uname -r`"
if vercmp $KERNELVER ge 3.0;then #111016
 SFSSTR='squashfs, version 4'
 SFSMAJOR=4
else
 KERNELSUBVER=`echo -n "$KERNELVER" | cut -f 3 -d '.' | cut -f 1 -d '-' | cut -f 1 -d '_'` #100831
 KERNELSUBSUBVER=`echo -n "$KERNELVER" | cut -f 4 -d '.' | cut -f 1 -d '-'`
 SFSSTR='squashfs, version 3'
 SFSMAJOR=3
 if [ $KERNELSUBVER -eq 27 ];then
  if [ $KERNELSUBSUBVER -gt 46 ];then #100606
   SFSSTR='squashfs, version 4'
   SFSMAJOR=4
  fi
 fi
 if [ $KERNELSUBVER -gt 28 ];then
  SFSSTR='squashfs, version 4'
  SFSMAJOR=4
 fi
fi

And before using vercmp even more weird names when the kernel became 3.0 I think .

I would like the idea to use the kernel's Makefile naming instead of the Puppy naming -
like so :
KERNEL=`uname -r`

#K_VERSION=`echo "$KERNEL" | awk -F '[_.-]' '{print $1}'`
#K_PATCHLEVEL=`echo "$KERNEL" | awk -F '[_.-]' '{print $2}'`
#K_SUBLEVEL=`echo "$KERNEL" | awk -F '[_.-]' '{print $3}'`
#K_EXTRALEVEL=`echo "$KERNEL" | awk -F '[_.-]' '{print $4}'`

IFS='.-_' read K_VERSION K_PATCHLEVEL K_SUBLEVEL K_EXTRALEVEL K_EXTRANAME<<EOI
`echo "$KERNEL"`
EOI
[ "${K_EXTRALEVEL//[[:digit:]]/}" ] && K_EXTRALEVEL=0

echo $K_VERSION $K_PATCHLEVEL $K_SUBLEVEL $K_EXTRALEVEL $K_EXTRANAME

Any ideas ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KERNELSUBSUBVER ???

01micko
Administrator
Nice.

Ha... that squash version test is a doosie!

SFSSTR=`mksquashfs -version|grep "mksquashfs version"|awk '{print $3}'`
echo ${SFSSTR%%.*}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KERNELSUBSUBVER ???

Karl Godt
Administrator
Yop, that seems to need observed ..
Have compiled all or most filesystems including squashfs.ko into the kernel and dmesg and uname -r output :
bash-3.2# dmesg | grep  squash
[    5.374335] squashfs: version 4.0 (2009/01/31) Phillip Lougher
bash-3.2# uname -r
3.4.9

bash-3.2# mksquashfs4 -version | head -n1
mksquashfs version 4.0 (2009/04/05)


Now how to determine compression mode of a sfs ?

When I run current filemnt with Kernel-2.6.37 on a xz .sfs, I just get the mount error splash info .
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KERNELSUBSUBVER ???

01micko
Administrator
In reply to this post by Karl Godt
Ok, so I wrote the damn thing in C!

I called it "ksub"

build with

gcc -o ksub ksub.c


#include <stdio.h>
#include <string.h>
#define THIS_VERSION "0.1"

char kver[30]; //seen some long extras
int x;
FILE *fp;

static void kernel_version();
static void helpme();
static void kernel_maj();
static void kernel_min();
static void kernel_sub();
static void kernel_extra();
static dotnum(int z);

/*================================help=======================================*/

void helpme()
{
	printf("%s\n","ksub-" THIS_VERSION);
	printf("Usage :\n");
	printf("	-m - shows version level\n");
	printf("	-p - shows patchlevel\n");
	printf("	-s - shows sublevel\n");
	printf("	-n - shows extra name\n\n");
	printf("	Only one argument is accepted\n");
	printf("	No argument the kernel version is printed\n");
}

/*================================dotnum=====================================*/

dotnum(int z)
{
	fp = (FILE *) popen("uname -r", "r"); //kernel version
	fgets(kver,30,fp);
	
	x = 0;
	int i;
	for (i = z; i < strlen(kver); i++)
	{
		if (kver[i] == '.')
		{
			x = i; //get index of decimal point
			break;
		}
	}
	
	return x;
	pclose(fp);
	
}

/*===========================Kernel Version==================================*/

void kernel_version()
{
	fp = (FILE *) popen("uname -r", "r");
	fgets(kver,30,fp);
	pclose(fp);
}

/*===========================Kernel Major====================================*/

void kernel_maj()
{
	fp = (FILE *) popen("uname -r", "r");
	fgets(kver,30,fp);
	
	int i;
	for (i = 0; i < strlen(kver); i++)
	{
		if (kver[i] == '.') //stop at first dot
		{
			char maj = kver[i - 1]; //print what is before first dot
			printf("%c\n",maj);
			return;
		}
	}
	pclose(fp);
}

/*===========================Kernel Minor====================================*/

void kernel_min()
{
	dotnum(0);
	
	fp = (FILE *) popen("uname -r", "r");
	fgets(kver,30,fp);
	
	int k = x + 1;
	int i;
	for (i = k; i < strlen(kver); i++)
	{
		if (kver[i] == '.')
		{
			break;
		}
		else
		{
			char min = kver[i];
			printf("%c",min);
		}
	}
	printf("\n"); //plucking from middle of string, needs carriage return
	pclose(fp);
}

/*===========================Kernel Sub======================================*/

void kernel_sub()
{
	dotnum(2);
	
	fp = (FILE *) popen("uname -r", "r");
	fgets(kver,30,fp);
	
	int k = x + 1;
	int le = 0;
	int i;
	for (i = k; i < strlen(kver); i++)
	{
		if (kver[i] == '.')
		{
			break;
		}
		else if (kver[i] == '-')
		{
			le = 1;
			break;
		}
		else if (kver[i] == '_')
		{
			le = 1;
			break;
		}
		else
		{
			char min = kver[i];
			if ((min != '-')||(min != '_'))
			{
				printf("%c",min);
			} 
			else 
			{
				printf("%c\n",min);
				le = 1;
				break;
			}
		}
	}
	if (le == 1)
	{
		printf("\n"); //needed if not EOF
	}
	pclose(fp);
}

/*===========================Kernel Extra====================================*/

void kernel_extra()
{
	fp = (FILE *) popen("uname -r", "r");
	fgets(kver,30,fp);
	
	int c = 1;
	int i;
	for (i = 2; i < strlen(kver); i++) //no need to scan whole string, eg:3.9
	{
		if (kver[i] == '-')
		{
			c = i;
			break; //get first index
		}
		else if (kver[i] == '_')
		{
			c = i;
			break;
		}
		else
		{
			c = c++;
		}
	}
	if (c == strlen(kver))
	{
		return; //don't print, doesn't exist
	}
	else
	{
		for (i = (c + 1); i < strlen(kver); i++)
		{
			printf("%c",kver[i]); //only print after '-' or '_'
		}
	}	
	pclose(fp);
}

/*================================Main=======================================*/

int main(int argc, char **argv)
{
	kernel_version();
	
	if (argc != 2)
	{
		printf("%s",kver);
		return 0;
	}
	
	if (argc == 2)
	{
		if (strcmp (argv[1], "-h") == 0)
		{
		helpme();
		return 0;
		}
		else if (strcmp (argv[1], "-m") == 0)
		{
		kernel_maj();
		return 0;
		}
		else if (strcmp (argv[1], "-p") == 0)
		{
		kernel_min();
		return 0;
		}
		else if (strcmp (argv[1], "-s") == 0)
		{
		kernel_sub();
		return 0;
		}
		else if (strcmp (argv[1], "-n") == 0)
		{
		kernel_extra();
		return 0;
		}
		else
		{
			printf("invalid argument\n");
			return 1;
		}
	}
}
	

6k stripped binary... a lot of code for crap all really!  --->  --->
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KERNELSUBSUBVER ???

Karl Godt
Administrator
It's kernel-3.x.y-extraname only, but nice !

FWIW :  char kver[30]; //seen some long extras : myself have tried up to 63 or 64 chars inkl the 10 chars of "2.6.32.61""-" or eight of "3.0.101""-" .
The "-" delimiter must be set explicitly in the make menuconfig line.
 



bash-3.2# ./ksub -h
ksub-0.1
Usage :
        -m - shows version level
        -p - shows patchlevel
        -s - shows sublevel
        -n - shows extra name

        Only one argument is accepted
        No argument the kernel version is printed
bash-3.2# ./ksub -m
3
bash-3.2# ./ksub -p
4
bash-3.2# ./ksub -s
9
bash-3.2# ./ksub -n
KRG-iCore2-smp-pae-srv1bash-3.2# 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: KERNELSUBSUBVER ???

01micko
Administrator
Thanks Karl,

I fixed the delimiter.. Ubuntu threw me off.. they do weird stuff there..

Added 2 series support.
Bugfixed the -n (name) option, wasn't working right in Slack so I figured my code was flakey.

Patch

diff -ru a/ksub.c b/ksub.c
--- a/ksub.c	2013-12-09 09:50:14.343360571 +1000
+++ b/ksub.c	2013-12-09 09:50:12.613360660 +1000
@@ -1,9 +1,11 @@
 #include <stdio.h>
 #include <string.h>
-#define THIS_VERSION "0.1"
+#define THIS_VERSION "0.3"
 
 char kver[30]; //seen some long extras
 int x;
+int u = 0;
+int w = 2;
 FILE *fp;
 
 static void kernel_version();
@@ -23,9 +25,11 @@
 	printf("	-m - shows version level\n");
 	printf("	-p - shows patchlevel\n");
 	printf("	-s - shows sublevel\n");
-	printf("	-n - shows extra name\n\n");
+	printf("	-n - shows extra name\n");
+	printf("	-ss - shows sub-sublevel (2 series kernels)\n\n");
 	printf("	Only one argument is accepted\n");
-	printf("	No argument the kernel version is printed\n");
+	printf("	If no argument the kernel version is printed\n");
+	printf("	If extra name or sub-sublevel are undefined program exits with 0 status\n");
 }
 
 /*================================dotnum=====================================*/
@@ -84,11 +88,11 @@
 
 void kernel_min()
 {
-	dotnum(0);
-	
 	fp = (FILE *) popen("uname -r", "r");
 	fgets(kver,30,fp);
 	
+	dotnum(u);
+	
 	int k = x + 1;
 	int i;
 	for (i = k; i < strlen(kver); i++)
@@ -111,11 +115,11 @@
 
 void kernel_sub()
 {
-	dotnum(2);
-	
 	fp = (FILE *) popen("uname -r", "r");
 	fgets(kver,30,fp);
 	
+	dotnum(w);
+	
 	int k = x + 1;
 	int le = 0;
 	int i;
@@ -130,15 +134,10 @@
 			le = 1;
 			break;
 		}
-		else if (kver[i] == '_')
-		{
-			le = 1;
-			break;
-		}
 		else
 		{
 			char min = kver[i];
-			if ((min != '-')||(min != '_'))
+			if (min != '-')
 			{
 				printf("%c",min);
 			} 
@@ -164,34 +163,24 @@
 	fp = (FILE *) popen("uname -r", "r");
 	fgets(kver,30,fp);
 	
-	int c = 1;
 	int i;
-	for (i = 2; i < strlen(kver); i++) //no need to scan whole string, eg:3.9
+	for (i = 0; i < strlen(kver); i++)
 	{
 		if (kver[i] == '-')
 		{
-			c = i;
 			break; //get first index
 		}
-		else if (kver[i] == '_')
-		{
-			c = i;
-			break;
-		}
-		else
-		{
-			c = c++;
-		}
 	}
-	if (c == strlen(kver))
+	
+	if ((i + 1) == strlen(kver))
 	{
 		return; //don't print, doesn't exist
 	}
 	else
 	{
-		for (i = (c + 1); i < strlen(kver); i++)
+		for (i = (i + 1); i < strlen(kver); i++)
 		{
-			printf("%c",kver[i]); //only print after '-' or '_'
+			printf("%c",kver[i]); //only print after '-'
 		}
 	}	
 	pclose(fp);
@@ -219,28 +208,50 @@
 		else if (strcmp (argv[1], "-m") == 0)
 		{
 		kernel_maj();
-		return 0;
 		}
 		else if (strcmp (argv[1], "-p") == 0)
 		{
 		kernel_min();
-		return 0;
 		}
 		else if (strcmp (argv[1], "-s") == 0)
 		{
-		kernel_sub();
-		return 0;
+			/* support for 2 series kernels */
+			
+			if (kver[0] == '2')
+			{
+				u = 2;
+				kernel_min();
+			}
+			else
+			{
+				kernel_sub();
+			}
+		}
+		else if (strcmp (argv[1], "-ss") == 0)
+		{
+			/* support for 2 series kernels */
+			
+			if (kver[0] == '2')
+			{
+				w = 4; 
+				kernel_sub();
+			}
+			else
+			{
+				return 0;
+			}		
 		}
 		else if (strcmp (argv[1], "-n") == 0)
 		{
 		kernel_extra();
-		return 0;
 		}
 		else
 		{
 			printf("invalid argument\n");
 			return 1;
 		}
+		return 0;
 	}
 }



If I ever go live with this app I'll bump the chars to 64 for kver.. then again, seen some long android names too ..
Loading...