Jump to content


Photo

Detect cf/usb/hdd/mount


  • Please log in to reply
3 replies to this topic

#1 arnoldl

  • Member
  • 4 posts

0
Neutral

Posted 8 July 2009 - 17:55

hello all,

not a specific pli question, but since there are some good programmers on the pli team....

for a plugin i'm working on (xmltvimport) , i'm looking for a way to detect the best place to store downloaded files (E2) .
so first
- usb
- cf
- harddisk
- mount

but i'm having a hard time to detect these, and see if there writable.
i also noticed that some mountpoints are different between E2 boxes.

so is there a good way to do this??

thanks , arnold

Re: Detect cf/usb/hdd/mount #2 pieterg

  • PLi® Core member
  • 32,766 posts

+245
Excellent

Posted 8 July 2009 - 18:05

you could start by parsing /proc/mounts, and make some assumptions based on what's in there.
Or scan /sys/block entries, which should tell you which device is which (usb/hdd/cf), and combined with /proc/mounts you know where it is mounted.

Re: Detect cf/usb/hdd/mount #3 arnoldl

  • Member
  • 4 posts

0
Neutral

Posted 8 July 2009 - 20:58

hey peterg ,

thanks for the reply.

tried catching the mount output, but still gave me problems.
some autofs mounted devices(usb) are not shown there if i remeber correct (has been a while since i was working on this).

until now i was using :

	path='/tmp'
	 if self.checkPath('/media/cf'):
	  path='/media/cf/'
	 if self.checkPath('/media/usb'):
	   path='/media/usb/'
	 if self.checkPath('/media/hdd'):
	   path='/media/hdd/'
	 print "Downloading : " + sourcefile + " To local path : " + path

def checkPath(self,path):
	 f = os.popen('mount', "r")
	 for l in f.xreadlines():
	   if l.find(path)!=-1:
	    return True
	 return False

this worked for me , with a mounted hdd , but i believe failed on a int. hdd (dm800) and failed with usb.
on this dm800 the output of mount is :
[mail]root@dm800[/mail]:~# mount
/dev/root on / type jffs2 (rw,noatime)
none on /dev type devfs (rw)
proc on /proc type proc (rw,nodiratime)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw)
usbdevfs on /proc/bus/usb type usbfs (rw)
/dev/mtdblock/2 on /boot type jffs2 (ro,noatime)
tmpfs on /var type tmpfs (rw)
tmpfs on /tmp type tmpfs (rw)
/dev/sda1 on /autofs/sda1 type ext3 (rw)
/dev/sdb1 on /autofs/sdb1 type ext3 (rw)
[mail]root@dm800[/mail]:~#

so there is no mount to media/usb or media/hdd...
in this case , how to detect that i can write to usb and/or hdd ??

thanks,


Re: Detect cf/usb/hdd/mount #4 pieterg

  • PLi® Core member
  • 32,766 posts

+245
Excellent

Posted 8 July 2009 - 23:26

I don't think autofs is the way to go. But you'll find corresponding entries in /sys/block which will telll you what kind of device it is.
Or have a look at e2's harddiskmanager, which does a similar job.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users