Recent

Author Topic: List Pen Drives on Linux Lazarus  (Read 2249 times)

junioraxis

  • Newbie
  • Posts: 2
List Pen Drives on Linux Lazarus
« on: February 02, 2021, 05:42:11 pm »
Would anyone know how I can list the connected flash drives, this on Linux? I researched in the brazilian community  and had no answers.
And would it be possible to know the storage size of this flash drive?

MarkMLl

  • Hero Member
  • *****
  • Posts: 3064
Re: List Pen Drives on Linux Lazarus
« Reply #1 on: February 02, 2021, 07:04:16 pm »
What's a pen drive?

I'm not trying to be funny, but you need to ask yourself: what distinguishes it from any other type of (storage) device?

If your pogrom is guaranteed to be active then you could probably hook hotplug events... I've done that for mouse-type devices and it wasn't difficult, although I don't know what's available pre-packaged.

If it's not guaranteed to be active, then you will probably need to look in the /sys tree, but be warned that parsing that can end up being very hard work.

Alternatively you could run lsblk periodically, or (better) look to see what it's doing. Ditto lsusb.

MarkMLl





Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: List Pen Drives on Linux Lazarus
« Reply #2 on: February 02, 2021, 08:24:54 pm »
Hi!

Code: Bash  [Select][+][-]
  1. cat /sys/kernel/debug/usb/devices
  2.  
gives you a comfortable list of all USB devices (example at bottom).

In the lines prefixed with S: you can see the needed information like:

Code: Text  [Select][+][-]
  1. S:  Manufacturer=TOSHIBA
  2. S:  Product=External USB 3.0
  3. S:  SerialNumber=xxxxxxxxxxxxxxx
  4.  

Here a part of the list:
Code: Text  [Select][+][-]
  1. .....
  2. T:  Bus=03 Lev=01 Prnt=01 Port=03 Cnt=02 Dev#=  3 Spd=1.5  MxCh= 0
  3. D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
  4. P:  Vendor=046d ProdID=c077 Rev=72.00
  5. S:  Manufacturer=Logitech
  6. S:  Product=USB Optical Mouse
  7. C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
  8. I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=usbhid
  9. E:  Ad=81(I) Atr=03(Int.) MxPS=   4 Ivl=10ms
  10. ....
  11.  



Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 3064
Re: List Pen Drives on Linux Lazarus
« Reply #3 on: February 02, 2021, 08:29:37 pm »
Code: Bash  [Select][+][-]
  1. cat /sys/kernel/debug/usb/devices
  2.  

Needs root access (or equivalent capability) on at least some distreaux.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: List Pen Drives on Linux Lazarus
« Reply #4 on: February 02, 2021, 10:01:43 pm »
Code: Bash  [Select][+][-]
  1. cat /sys/kernel/debug/usb/devices
  2.  

Needs root access (or equivalent capability) on at least some distreaux.

MarkMLl

Hi!

You are right .
They call it progress but it is full of disadvantages.

Good old /proc filesystem can be read by everybody.
I forgot about that "progress".

But to show all connected devices you could use

Code: Bash  [Select][+][-]
  1. df -h | grep /dev/sd
  2.  

Now you must know your internal drives.
The rest are external USB devices.

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 3064
Re: List Pen Drives on Linux Lazarus
« Reply #5 on: February 02, 2021, 10:30:15 pm »
But to show all connected devices you could use

Code: Bash  [Select][+][-]
  1. df -h | grep /dev/sd
  2.  

df shows filesystems, not devices. Sorry :-)

lsblk, or very tedious parsing of other parts of /sys (I think it's only /sys/kernel/debug which is unreadable).

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: List Pen Drives on Linux Lazarus
« Reply #6 on: February 02, 2021, 11:06:38 pm »
But to show all connected devices you could use

Code: Bash  [Select][+][-]
  1. df -h | grep /dev/sd
  2.  

df shows filesystems, not devices. Sorry :-)


MarkMLl

df  shows both, the devicess and the filesystem.
Otherwise I could not grep for /dev/sd*

Sorry

MarkMLl

  • Hero Member
  • *****
  • Posts: 3064
Re: List Pen Drives on Linux Lazarus
« Reply #7 on: February 02, 2021, 11:14:25 pm »
df  shows both, the devicess and the filesystem.
Otherwise I could not grep for /dev/sd*

Yes, and it does things like showing multiple entries for a device if it's partitioned, and it won't show a device which has been plugged in but not mounted. It's not the right tool for the job.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: List Pen Drives on Linux Lazarus
« Reply #8 on: February 02, 2021, 11:21:42 pm »
Oh oh oh

A) Perhaps you can distinguish sda1 from sda2. The Linux system anyway is able.
B) In Linux terms everything in /dev is a device. No matter if it is sda, sda1 or sda5
C) Junioraxis aked for connected drives. That's why I used df

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: List Pen Drives on Linux Lazarus
« Reply #9 on: February 02, 2021, 11:57:42 pm »
C) Junioraxis aked for connected drives. That's why I used df

"Connected" doesn't mean "mounted". If a pen-drive is connected (i.e. physically plugged, powered and recognized by the system) but not mounted, df will completely ignore it.

Look at the image: Quite a lot of partitions in the internal disk and a connected thumb-drive; what shows your command? Just the two currently mounted partitions.
« Last Edit: February 03, 2021, 12:06:21 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: List Pen Drives on Linux Lazarus
« Reply #10 on: February 03, 2021, 12:12:45 am »
Hi!

No.

"Connected" is ambiguous.

Does it mean logical connected to the filesystem aka mounted?

Or does it just mean "plugged in" - but not mounted.


Before this peanut discussion goes any further this must be decided.

By junioraxis.

Winni

indigo80

  • New Member
  • *
  • Posts: 41
Re: List Pen Drives on Linux Lazarus
« Reply #11 on: March 24, 2021, 02:27:30 pm »
Would anyone know how I can list the connected flash drives, this on Linux? I researched in the brazilian community  and had no answers.
And would it be possible to know the storage size of this flash drive?
look here
https://github.com/GuvaCode/formatmydrive-pascal
https://github.com/itmitica/laddiso

benohb

  • Full Member
  • ***
  • Posts: 208
Re: List Pen Drives on Linux Lazarus
« Reply #12 on: March 25, 2021, 03:52:42 am »

Code: Pascal  [Select][+][-]
  1. ls /dev/disk/by-id/
You will find all kinds of discs
And the beginning of the name is the type
usb-xxxxxxxxxx
ata-xxxxxxxxxx
wwn-xxxxxxxxxx
It is an Shortcut of the real name of the disk and its partitions

MarkMLl

  • Hero Member
  • *****
  • Posts: 3064
Re: List Pen Drives on Linux Lazarus
« Reply #13 on: March 25, 2021, 09:42:26 am »

Code: Pascal  [Select][+][-]
  1. ls /dev/disk/by-id/
You will find all kinds of discs
And the beginning of the name is the type
usb-xxxxxxxxxx
ata-xxxxxxxxxx
wwn-xxxxxxxxxx
It is an Shortcut of the real name of the disk and its partitions

But that identifies *PARTITIONS*, and OP asked for *DISKS*. What's more he specifically asked for pen drives, and while these are almost always USB-connected there's other types of USB-connected media which he probably wants to exclude.

As several of us have concluded, we can't really arrive at an answer until OP clarifies what he actually wants... and he seems to have wandered off.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018