Trash Spec Idea

João Valverde backup95 at netcabo.pt
Thu Aug 14 07:42:58 PDT 2008


Andrea Francia wrote:
> 2008/8/13 João Valverde <backup95 at netcabo.pt <mailto:backup95 at netcabo.pt>>
>
>     Hello,
>
>     I was looking into doing a bash command line trash implementation as a
>     beginner's exercise but I quickly realized it would be much
>     hairier than
>     I thought at first.  Besides some inherent complexity from the file
>     system hierarchy and permissions I think the spec has some
>     shortcomings
>     and from browsing the archive I see that they have been discussed
>     here.
>
>
> I created a similar program. A command line interface written in 
> python for the trash can.
> The website is http://code.google.com/p/trash-cli/
>
> May be we can collaborate.

Interesting, thanks. I'll be sure to take a look and contact you if I
can be of use. Unfortunately my knowledge of Python is limited to
skimming some books and code but I've been meaning to dive in sometime.

>  
>
>     Is this feasible? Better than going through mtab right? How else
>     could I
>     find mount points for trash folders? How much can be done
>     automatically
>     when mounting or unmounting volumes? Are there any plans to
>     involve HAL
>     on this? My ignorance starts to show here...
>
>
> The component that knows the informations about the mount points is 
> the kernel.
> There's no need to duplicate these informations in $XDG_DATA_HOME with 
> the risk that those are inaccurate or non synchronized.
>
> The kernel communicates the status of the current mount points with 
> /etc/mtab and (in some systems) with /proc/mounts.
>
> To parse the /etc/mtab (or the /proc/mounts) file you should use 
> getmnt(2) system function that recognizes all the special cases  (like 
> spaces in mount points) that and a reinvented parser may not consider.
>

Your points are all valid. The problem with mtab is that there is a lot
of cruft in there. It's not straightforward to interpret its contents.
Anyway doing this from the shell would require writing a parser using
getmntent(2) as you mentioned. How do we distinguish which filesystems
are "interesting" from the mntent structure without reading every single
one and checking whether a .Trash* folder exists? Do we go by filesystem
type? There are a lot of filesystems out there and it seems futile to
keep track of every single one. One possibility is writing a parser in C
that compares the filesystems in /proc/filesystems (I assume "nodev"
means it's a virtual filesystem?) against /etc/mtab and returns the
mount points that have the correct type. On my system I get

$ cat /proc/filesystems
nodev    sysfs
nodev    rootfs
nodev    bdev
nodev    proc
nodev    cgroup
nodev    cpuset
nodev    debugfs
nodev    securityfs
nodev    sockfs
nodev    pipefs
nodev    anon_inodefs
nodev    futexfs
nodev    tmpfs
nodev    inotifyfs
nodev    devpts
              cramfs
nodev    ramfs
nodev    mqueue
nodev    fuse
              fuseblk
nodev    fusectl
nodev    usbfs
              ext3
nodev    binfmt_misc
              vfat


So in this case the C parser would return the mnt_dir from struct
mnt_ent for every entry in mtab of type "cramfs", "fuseblk", "ext3" and
"vfat". From there the script would check those mount points for Trash
contents. What am I missing?

Regards,

João V.






More information about the xdg mailing list