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

Correct VFAT partition is not recognised #37

Open
paaguti opened this issue Mar 26, 2024 · 5 comments
Open

Correct VFAT partition is not recognised #37

paaguti opened this issue Mar 26, 2024 · 5 comments

Comments

@paaguti
Copy link

paaguti commented Mar 26, 2024

I have an ebook reader unbricking image which I transfer to a microSD card.
Using GPARTED I can grow the DOS FAT32 partition to take up all the free space.
Once grown I'm not able to read the partition's information

 paag@840g5  ~/tmp/kobo  sudo fdisk -l /dev/sda
Disk /dev/sda: 7,4 GiB, 7948206080 bytes, 15523840 sectors
Disk model: SD/MMC          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x66e8b073

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1         19456   543744   524289  256M 83 Linux
/dev/sda2        543745  1068033   524289  256M 83 Linux
/dev/sda3       1068034 15523839 14455806  6,9G  b W95 FAT32
paag@840g5  ~/tmp/kobo  sudo fatresize -i /dev/sda3
fatresize 1.1.0 (20201114)
.Error: /dev/sda3 is not valid FAT16/FAT32 partition.
sudo fsck.vfat /dev/sda3             
fsck.fat 4.2 (2021-01-31)
There are differences between boot sector and its backup.
This is mostly harmless. Differences: (offset:original/backup)
  65:00/01
1) Copy original to backup
2) Copy backup to original
3) No action
[123?q]? 1

*** Filesystem was changed ***
The changes have not yet been written, you can still choose to leave the
filesystem unmodified:
1) Write changes
2) Leave filesystem unchanged
[12?q]? 1
/dev/sda3: 84 files, 1444/1803444 clusters
@paaguti
Copy link
Author

paaguti commented Mar 30, 2024

I added the partition name to the error message and this is what I get:

 paag@840g5  ~/Devel/fatresize   master ±  sudo ./fatresize --info /dev/sda3
fatresize 1.0.3 (20240330)
Error: /dev/sda3 is not valid FAT16/FAT32 partition. (ext4)

However, fdisk tells me that /dev/sda3 is a W95 FAT32 partition.

 ✘ paag@840g5  ~/Devel/fatresize   master ±  sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 3,69 GiB, 3965190144 bytes, 7744512 sectors
Disk model: SD/MMC          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6834f926

Device     Boot   Start     End Sectors  Size Id Type
/dev/sda1         19456  543744  524289  256M 83 Linux
/dev/sda2        543745 1068033  524289  256M 83 Linux
/dev/sda3       1068034 7743487 6675454  3,2G  b W95 FAT32

Command (m for help): quit

@paaguti
Copy link
Author

paaguti commented Mar 30, 2024

Problem seems to be in getpartnum()

201	  probe_device(&peddev, devname);
(gdb) n
211	    opts.pnum = get_partnum(devname);
(gdb) n
213	  ped_device_destroy(peddev);
(gdb) print opts
$5 = {fullpath = 0x55555555bbf0 "/dev/sda3", device = 0x0, pnum = 1, size = 0, 
  verbose = 0, progress = 0, info = 1, force_yes = 0}

more precisely, in the way get_partnum is called!

Breakpoint 1, get_partnum (dev=0x55555555bc10 "/dev/sda") at fatresize.c:154

There is no partition number to get there!

@paaguti
Copy link
Author

paaguti commented Mar 30, 2024

A quick fix to allow at least -n <PARTNUM> <dev> attached...
0001-Allow-n-N-DEV.zip

@paaguti
Copy link
Author

paaguti commented Mar 30, 2024

A PoC for alternative way of splitting the cmd line arguments could be:

#!/usr/bin/tcc -run

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char **argv)
{
		char *dev = "/dev/sda3";
		char *p = &dev[strlen(dev) - 1];
		int pnum = -1;

		while (*p && isdigit(*p)) {
				p--;
		}
		p++;
		printf("dev = %s\n",dev);
		printf("p   = %s\n",p);
		printf("strlen(p) = %d\n",strlen(p));
		if ((strlen(p) > 0) && (pnum == -1)) {
				pnum = atoi(p);
				printf("pnum = %d\n",pnum);
		} else if ((strlen(p) > 0) && (pnum != -1)) {
				printf("Don\'t use -n!\n");
		}
		char *realdev = strndup(dev,p-dev);
		printf("realdev = %s\n", realdev);
}

I use tinycc to avoid compiling micro prototypes ;-)

@paaguti
Copy link
Author

paaguti commented Mar 31, 2024

Implemented in pull request 38.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant