[Klug-general] Memory Stick

Wayne browns.postbox at gmail.com
Mon Nov 17 09:54:45 UTC 2008


Hi Rich,

I'm not sure of the exact problem from your description but I suspect a
couple of possibilities. 
[edit] sorry for the length of this mail, it started short and has
grown rather! [/edit]

Firstly I should point out that, to descend into a directory you need
execute permissions, so to make a directory navigate-able you need at
least r-x or octal 5 permissions, assuming you want to write you need
rwx or octal 7. so, knowing that you can see setting 666 would make the
directories un-enterable except for root (it seems)

I've done an example for you in a terminal session that shows this well:

------------------------------------------------------------------------
wayne at coolblue ~ $ mkdir testdir
wayne at coolblue ~ $ ls -ld testdir
drwxr-xr-x 2 wayne wayne 4096 2008-11-17 09:08 testdir
wayne at coolblue ~ $ cd testdir
wayne at coolblue ~/testdir $ touch myfile
wayne at coolblue ~/testdir $ ls
myfile
wayne at coolblue ~/testdir $ rm myfile
wayne at coolblue ~/testdir $ cd ..
wayne at coolblue ~ $ chmod 666 testdir
wayne at coolblue ~ $ cd testdir
bash: cd: testdir: Permission denied
wayne at coolblue ~ $ ls -ld testdir
drw-rw-rw- 2 wayne wayne 4096 2008-11-17 09:08 testdir
wayne at coolblue ~ $ su
Password:
coolblue wayne # cd testdir
coolblue testdir # ls
coolblue testdir # touch myfile
coolblue testdir # ls -l
total 0
-rw-r--r-- 1 root root 0 2008-11-17 09:10 myfile
coolblue testdir # cd ..
coolblue wayne # ls -l testdir
total 0
-rw-r--r-- 1 root root 0 2008-11-17 09:10 myfile
coolblue wayne # exit
exit
wayne at coolblue ~ $ ls -l testdir
ls: cannot access testdir/myfile: Permission denied
total 0
-????????? ? ? ? ?                ? myfile
wayne at coolblue ~ $
wayne at coolblue ~ $ chmod 755 testdir/
wayne at coolblue ~ $ ls -l testdir
total 0
-rw-r--r-- 1 root root 0 2008-11-17 09:10 myfile
wayne at coolblue ~ $

------------------------------------------------------------------------------------------

You can see above how a file can appear with loads of ???? 's because
it's un-readable as a user since the directory has no x bit set.
Knowing this you can also see you recursively setting file permissions
on files / folders can be dangerous to ones' health!

The problems on both sticks are related, one is formatted vfat whilst
the other is ext2:
Dealing with the vfat stick first, what could be happening is the
default permissions set at mount time by the kernel is making it
un-writable by a user yet root can write to it. I believe this is
because of the way vfat is handled on *nix systems since vfat has no
concept of file owner/group/other permissions.

look at the session below, I have a memory card that's formatted with
vfat, it shows how only root can write to it by default (I've trimmed
the output of the mount command:
---------------------------------------------------------------------
wayne at coolblue ~ $mount 
/dev/hda1 on / type ext3 (rw) 
/dev/sdb1 on /media/DSC_LABEL type vfat
(rw,nosuid,nodev,uhelper=hal,uid=1000,utf8) 

wayne at coolblue ~ $ ls -ld /media/ drwxr-xr-x 4 root root 4096
2008-11-17 08:49 /media/ 
wayne at coolblue ~ $ cd /media/
wayne at coolblue /media $ touch myfile touch: cannot touch `myfile':
Permission denied 
wayne at coolblue /media $ su Password:
coolblue media # touch myfile
coolblue media # ls
DSC_LABEL  myfile  usbhd
coolblue media # rm myfile
coolblue media # exit
exit
--------------------------------------------------------------------

This behaviour is not good for most users since we want to plug a stick
in and write to it, luckily we can control this in a number of ways to
make it seamless. 

I'm using Gentoo here so your distro may vary, but basically I can
control how a device is mounted in the /etc/fstab file.
I have to point out there are also issues with device naming of usb
devices, again this is controllable with udev, short explanation: if
you don't control it, plugging in different sticks in a different order
will result in the underlying device name changing /dev/sdb1, /dev/sdc1
etc dependant on order plugged in. you can write 'rules' that will
prevent this happening, a search on udev rules will explain more.

Adding this line to my /etc/fstab file makes the media mount on
insertion, with default permissions of 777 :
/dev/sdb1               /media/camera   vfat auto,user,sync,umask=000 0
0

make sure you have created the mount point like /media/camera
Its worth reading about 'umask' to get an explanation of how it affects
this and all file / directory creation.
Changing auto to noauto means it will require you to type
'mount /media/camera' or 'mount /dev/sdb1' to make the device available.

The problems with the ext2 formatted one is similar in that its
permissions related, hopefully the above is
a/ useful
b/ helps fix it!

Best wishes,
Wayne.

On Sun, 16 Nov 2008 23:59:15 +0100 (GMT+01:00)
"rich-ayres at tiscali.co.uk" <rich-ayres at tiscali.co.uk> wrote:

> Hi Its Me Again
>  ( groans all round). I have somehow managed to convert two 1Gig 
> memory sticks into Read Only Filing system devices. Both appear on
> the desktop and can be opened one appears to be empty while the other 
> contains lots of files which appear to contain garbage. I have
> mounted both from the command line as su and tried chmod
> 0666 /media/disk to try to make it read/write and also tried
> rm /media/* to try to  clear it. mount with -o remount,rw also
> failed. Also reformatting failed as device is read only.  Perhaps
> someone could tell me what I did wrong I did use cfdisk on one to put
> ext2 fs on it. but the problem seemed to happen after I moved some
> files into folders and deleted the rest, but was not apparent until
> the nxt time I used the stick. If I've trashed them permanently it is
> nota great loss but it would be nice to know why it happened.
>  regards R.   
> 



More information about the Kent mailing list