df syntax to handle path with spaces?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

df syntax to handle path with spaces?

#1 Post by Rattlehead »

My android has two hard disks. Accessed from Puppy, their paths are:

/mnt/LG-E430/Internal storage
/mnt/LG-E430/SD card

Both names have spaces. If I want to know how much memory is in each, the usual command

Code: Select all

df /mnt/LG-E430/Internal\ storage/
Produces

Code: Select all

df-FULL: ‘/mnt/LG-E430/Internal’: No such file or directory
df-FULL: ‘storage/’: No such file or directory
I've tried all the usual remedies (double and single quotes, taking the backslash out), with no result. To see the remaining memory in my cellphone I have to do it via the cellphone itself. Internet search hasn't given any result, either. I even tried Gparted, but it doesn't detect the phone's mount point, I guess because it is not really mounted, but uses that smtp (smart media transfer protocol) thing.

Anybody stumbled upon this problem and got the syntax of this command right?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

Are you using an older, pre-Woof-CE Puppy?
Because this can be a bug in 'df' itself (which is just a wrapper script).
Try using 'df-FULL' (or 'busybox df') directly.

And here's the fix for /bin/df:
https://github.com/puppylinux-woof-CE/w ... e1b677c652

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#3 Post by Rattlehead »

Hey SFR,

thank you for the response. Yup, my Puppy is Slacko 5.5. I think that's before Woof-CE Puppy.

df-FULL gave me an error (revising the previous code, it seems df invokes df-FULL anyway, by defect). BUT: using busybox df did the trick.

However, I've found that passing /mnt/LG-E430/Internal storage
or /mnt/LG-E430/SD card as arguments produce both the same output, a single line of results. In other words, the command considers both Android drives as belonging to the same filesystem.

I've also tried the command du -hc to see the memory remaining, but any attempt to use that command in the Android phone shows size=0 for all files, for some reason.

I'd like to have both sizes because of the different purpose the Android drives have:

SD card: to store music, documents, etc
Internal: not to be disturbed, or horrible things will start to happen.

This busybox df is a good advance, although still a bit approximative.

(As an aside: rereading my previous post, I see I got a bit carried away with the acronyms: it's just media transfer protocol (MTP), no smart whatsoever :) )

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#4 Post by amigo »

Use double-quotes:
df "/mnt/LG-E430/Internal storage"

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#5 Post by Karl Godt »

The kernel writes octals into /proc/mounts :

Code: Select all

bash-3.00# mkdir /mnt/"s d b 7"
bash-3.00# mount /dev/sdb7 /mnt/"s d b 7"
bash-3.00# grep '^/dev/sdb7 ' /proc/mounts

Code: Select all

/dev/sdb7 /mnt/s\040d\040b\0407 ext4 rw,relatime,data=ordered 0 0
Use echo -e then :

Code: Select all

~ # df "$(echo -e `grep '^/dev/sdb7 ' /proc/mounts | cut -f2 -d' '`)"

Code: Select all

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sdb7             32403332  23272040   7478608  76% /mnt/s d b 7
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#6 Post by Karl Godt »

For SFR's post : It is usually a VERY GOOD idea to wrap $@ into double quotes !

Just "test" does not like $@ or "$@" .

"$@" means to evaluate the string, and if $@ is "-d /dev/sr0" ..?

Code: Select all

_function1(){
test "$@"
}

_function2(){
test "$*"
}

_function1 "-d" "cabrio"; echo $?
_function2 "-d" "cabrio"; echo $?
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#7 Post by Rattlehead »

@Karl Godt,

My bash knowledge is limited and I cannot say I know what your code does, but I promise I'll keep coming back to this thread and maybe in a couple of decades, at the end of my days, I'll be able to understand everything (my grandson will have to read the text for me, though :) ).

What I did understand: using echo -e to escape the characters.

The application of that command to my problem would be:

Code: Select all

df "$(echo -e /mnt/LG-E430/SD card/)"
However, back to square one, the result such code produces is:

Code: Select all

df-FULL: ‘/mnt/LG-E430/SD’: No such file or directory
df-FULL: ‘card/’: No such file or directory
:(

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#8 Post by Karl Godt »

Sorry, I had been in the ash shell configured
with frist use of busybox applets and then path look up .

You may want to look into the file "/proc/mounts" to understand , what I mean .

But ROX-Filer may not like to open /proc if "thumbnails" enabled in it's options ( hangs ) .

So better use

Code: Select all

cat /proc/mounts
in the terminal .



Puppy may not support :blank: as space and tab in it's /bin/mount wrapper script .
mount-FULL -n ${@}
may not work,

Code: Select all

mount-FULL  "${@}"
may be better .

So I wonder how things work now .

I myself had made a workaround for MTPFS as
using two scripts : One that renames /bin/mount , mounts and renames /bin/mount to its name again at the end and one that returns a fake "0" error code :

Code: Select all

#!/bin/ash


. /etc/rc.d/f4puppy5

_pidof go-mtpfs && _exit 3 "go-mtpfs already running -- use umountMTP"


test -L /bin/mount    || _exit 4 "/bin/mount needs to be a link"
test -e /bin/mountBAK || cp -a /bin/mount /bin/mountBAK

test -e /bin/mountMTP.sh || {
echo 'exit 0' >/bin/mountMTP.sh || _exit 41 "Could not create /bin/mountMTP.sh wrapper"
chmod $VERB +x /bin/mountMTP.sh || _exit 42 "Could not set /bin/mountMTP.sh executable"
}

OLD_MOUNT=`realpath /bin/mount`
# REM: Needs here in case of early exit
#      link /bin/mount does
which go-mtpfs >>$OUT || _exit 6 "go-mtpfs not found in PATH"

ln $VERB -sf mountMTP.sh /bin/mount || _exit 5 "Could not create link /bin/mount -> mountMTP.sh"

MOUNT_POINT=/mntf/MTPdev
test -e "$MOUNT_POINT" || mkdir -p "$MOUNT_POINT"

GO_MTPFS_OPS=
go-mtpfs $GO_MTPFS_OPS "$MOUNT_POINT" &

sleep 5

ln $VERB -sf "$OLD_MOUNT" /bin/mount
_pidof go-mtpfs && exit 0 || exit 1

# TODO: Handle GetStorageInfo 10001: SessionNotOpen
#       app. when mtpdevice switches into lower-power-mode
/etc/rc.d/f4puppy5 is a private function collection of mine .

It basically works on the premisse, that /bin/mount got renamed already to something like /bin/mountORIG , and /bin/mount made a link to /bin/mountORIG .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#9 Post by Karl Godt »

The code

test "$@" evaluates as

test -d cabrio

and tests, if the directory "cabrio" exists .


test "$*" does not evaluate,
it just tests if it has content or not .

And test returns 0 if it has any kind of some content, and 1 if not ,
same 0 if directory cabrio exists , and 1 if not .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#10 Post by Rattlehead »

Sorry, I've been staring at your code until my brow bled, and still cannot understand what it does and how does that relate to my problem.

This has started to go off-topic, to become kind of an exercise in humility for me: I feel as if you are on top of the learning curve, making signs to me, and here I am, at the bottom of the valley, catching only weak glimpses :?

A couple of examples:
You may want to look into the file "/proc/mounts" to understand , what I mean .
Yeah, it turns out that's what I happened to do when I read your former post.

Code: Select all

rootfs / rootfs rw,relatime 0 0
/dev/sda1 /initrd/mnt/dev_save ext3 rw,noatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 0 0
/dev/loop1 /initrd/pup_rw ext2 rw,noatime,errors=continue,user_xattr,acl 0 0
/dev/loop0 /initrd/pup_ro2 squashfs ro,noatime 0 0
/dev/loop4 /initrd/pup_ro4 squashfs ro,noatime 0 0
/dev/loop5 /initrd/pup_ro5 squashfs ro,noatime 0 0
/dev/loop6 /initrd/pup_ro6 squashfs ro,noatime 0 0
/dev/loop7 /initrd/pup_ro7 squashfs ro,noatime 0 0
/dev/loop8 /initrd/pup_ro8 squashfs ro,noatime 0 0
unionfs / aufs rw,relatime,si=144e9fb6 0 0
tmpfs /tmp tmpfs rw,relatime,size=741820k 0 0
none /proc proc rw,relatime 0 0
none /dev/pts devpts rw,relatime,gid=2,mode=620 0 0
none /sys sysfs rw,relatime 0 0
shmfs /dev/shm tmpfs rw,relatime,size=234572k 0 0
none /proc/bus/usb usbfs rw,relatime 0 0
/dev/sda2 /mnt/sda2 ext2 rw,relatime,errors=continue,user_xattr,acl 0 0
The only entries I understand are /dev/sda1 and /dev/sda2. I know Linux mounts everything as a loop device, but I don't know what's in each mount point. Again, this does not change the situation that the whole Android device (comprised of two disk drives) gets mounted in a single mount point and is, thus, not accessible individually with df.

As for your workaround script, the first three lines send me right away to kissing the floor. Never used ash, /etc/rc.d for me is like the suburbs, I never go there, somebody might get hurt :), and a command that starts with a _ makes me cringe (I guess it's an ash sofistication).

Maybe I gave a wrong impression of my degree of knowledge by saying that I use go-mtpfs. I use an adapter script called mtpconnect that uses go-mtpfs. Here is the URL, for what is worth: http://www.murga-linux.com/puppy/viewto ... 85f01f23f3

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#11 Post by amigo »

Ummm, I think that mtpconnect will not give you access to the internal storage -only to the real SD card which you can inset and remove.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#12 Post by Karl Godt »

Looks, like you have no Android device mounted as I read your /proc/mounts .


You raun frugal with a couple of additional .sfs files loaded ( loop mounts with the
usual puppy specific mountpoints in /initrd/pup_ro* );
and you run on normal HDD, not USB, since the savefile is not pup_ro1 .
Your savefile mountpoint is pup_rw , on USB pup_rw would be the tmpfs, that would get
copied into pup_ro1 . pup_ro1 is misleading, since the savefile is not read-only, but read-write all the time like on HDD pup_rw is the savefile .

The "none" devices are misleading too, but makes it easier for programs to filter out these pseudo-filesystems .
Otherwise it would be
proc /proc
devpts /dev/pts
sysfs /sys
usbfs /proc/bus/usb

So no mount of android visible like :

Code: Select all

bash-3.2# mountMTP          
mountpoint: /mntf/MTPdev: No such file or directory
/bin/mount:-i -f -t fuse.Locked(DeviceFs(End. -o rw,nosuid,nodev Locked(DeviceFs(End. /mntf/MTPdev
2015/10/30 18:40:44 starting FUSE 70ad1f3 (2013-02-24 20:42:03 +0100)
Here I have added

Code: Select all

echo "$0:$*" >&2
to the fake mount wrapper, so it looks like

Code: Select all

#!/bin/ash
echo "$0:$*" >&2

exit 0
go-mtpfs runs a 'fake' mount using the -f option to test for availability .
If that return not 0 , go-mtpfs refuses to mount, so I had to force this here,
and I do not know the cause anymore :) .

I use an other directory than /mnt/ since bogus fuse mounts had froozen the whole /mnt/ directory with submount like /mnt/sda2 .
I use /mntf/ - f for fuse .
I do not dare to mount fuse directly on a toplevel mountpoint, in fear of freezing the whole / .

cat /proc/mounts :

Code: Select all

Locked(DeviceFs(End. /mntf/MTPdev fuse.Locked(DeviceFs(End. rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0
And so it looks like with sapce :

Code: Select all

Locked(DeviceFs(End. /mntf/MTP\040dev fuse.Locked(DeviceFs(End. rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0
TAB would be \011 and newline \012 . I have not found out yet what writes the /proc/mount file(s) , and what other special charakters would be escaped in the /proc/mount file .


But that is Android 4.x .
Android 2.x mounts as usual .


unmount :

Code: Select all

#!/bin/ash

. /etc/rc.d/f4puppy5

MOUNT_POINT=/mntf/"MTP dev"

mountpoint "$MOUNT_POINT" || _exit 4 "'$MOUNT_POINT' not mounted"

rox -D "$MOUNT_POINT"

sleep 1

fusermount -uz "$MOUNT_POINT"
My fusermount version does nothing except ordering usual /bin/umount to unmount the mountpoint .

It is always a better idea to unmount a mountpoint directory than the device, since a device can be mountet several times on different mountpoint directories .

df :

Code: Select all

bash-3.2# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sdb6             32534404  23944760   6936960  78% /
shmfs                   816352         0    816352   0% /dev/shm
/dev/sdb19           317214768 102448272 198652904  35% /mnt/sdb19
/dev/sda9            236638972  58479992 166138348  27% /mnt/sda9
Locked(DeviceFs(End.  44532824  10006544  34526280  23% /mntf/MTP dev

Code: Select all

bash-3.2# df "/mntf/MTP dev"
df-FULL: `/mntf/MTP': No such file or directory
Filesystem           1K-blocks      Used Available Use% Mounted on
devramfs                     0         0         0   -  /dev
And with RETSTUFF=`$DF "$@"` in /bin/df script :

Code: Select all

bash-3.2# df "/mntf/MTP dev"
/bin/df:/mntf/MTP dev
Filesystem           1K-blocks      Used Available Use% Mounted on
Locked(DeviceFs(End.  44532824  10006544  34526280  23% /mntf/MTP dev
Attachments
Screenshot_2015-10-30-19-10-20.jpg
(27.33 KiB) Downloaded 231 times
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
Rattlehead
Posts: 368
Joined: Thu 11 Sep 2008, 11:40

#13 Post by Rattlehead »

amigo wrote:Ummm, I think that mtpconnect will not give you access to the internal storage -only to the real SD card which you can inset and remove.
Not really, amigo. For the sake of clarity for the poor fellow who comes to this thread in search of Android information, mtpconnect accesses both storage units - and I'll stick to my story - I've created, removed and moved files from the internal storage with no problem (see screenshot-there are two entries, both internal and external storage).
Karl Godt wrote:Looks, like you have no Android device mounted as I read your /proc/mounts .
Yes, sorry, I ran cat /proc/mounts without having the phone connected. My bad. :oops:
Here is the good output, with the Android device in the last line:

Code: Select all

rootfs / rootfs rw,relatime 0 0
/dev/sda1 /initrd/mnt/dev_save ext3 rw,noatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 0 0
/dev/loop1 /initrd/pup_rw ext2 rw,noatime,errors=continue,user_xattr,acl 0 0
/dev/loop0 /initrd/pup_ro2 squashfs ro,noatime 0 0
/dev/loop4 /initrd/pup_ro4 squashfs ro,noatime 0 0
/dev/loop5 /initrd/pup_ro5 squashfs ro,noatime 0 0
/dev/loop6 /initrd/pup_ro6 squashfs ro,noatime 0 0
/dev/loop7 /initrd/pup_ro7 squashfs ro,noatime 0 0
/dev/loop8 /initrd/pup_ro8 squashfs ro,noatime 0 0
unionfs / aufs rw,relatime,si=19998ac2 0 0
tmpfs /tmp tmpfs rw,relatime,size=741820k 0 0
none /proc proc rw,relatime 0 0
none /dev/pts devpts rw,relatime,gid=2,mode=620 0 0
none /sys sysfs rw,relatime 0 0
shmfs /dev/shm tmpfs rw,relatime,size=234568k 0 0
none /proc/bus/usb usbfs rw,relatime 0 0
/dev/sda2 /mnt/sda2 ext2 rw,relatime,errors=continue,user_xattr,acl 0 0
Locked(DeviceFs(LG-E /mnt/LG-E430 fuse.Locked(DeviceFs(LG-E rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0
You made quite a radiography of my system, I didn't know I was giving away so much; it looked like an episode from Colombo, "Oh, and one last thing... you don't have an Android device" :P
I learned a lot about Puppy architecture, so thank you.

And now more on the issue of scatterbrain...

I rerun the df-Full command and it DOES generate different results for Internal storage and SD Card.

Code: Select all

df-FULL -h /mnt/LG-E430/SD\ card/
Filesystem                     Size  Used Avail Use% Mounted on
Locked(DeviceFs(LG-E  1.9G  1.8G  146M  93% /mnt/LG-E430

df-FULL -h /mnt/LG-E430/Internal\ storage/
Filesystem                      Size  Used Avail Use% Mounted on
Locked(DeviceFs(LG-E  1.8G  1.5G  323M  82% /mnt/LG-E430
I don't know how I did it last time, what led me to think it gave the same result for both... Sorry for being misleading...

Now one peculiar thing is that, when I check the same information on free storage in my device, the data on SD Card match (146M available), but in Internal Storage the Android device says 423 M, i.e. 100M more than in the df command. Does anybody know why this difference and what's the correct amount?
Attachments
androidmounts.png
(31.68 KiB) Downloaded 268 times

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#14 Post by Karl Godt »

Your go-mtpfs is like mine :

It mounts only one mountpoint .

Beneath that mountpoint, the two directories (with spaces) are not separate mountpoints .

I tried to mount -o bind /mnt/FUSEMOUNTFOLDER/"Nand Flash" "/mnt/ABC" but that does not work .

df shows apparently the top level of the mount tree instead erroring out ,
and this "/mnt/LG-E430" that does not contain space .


You may want to try

Code: Select all

df /usr
to see what I mean .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

Post Reply