summaryrefslogtreecommitdiffstats
path: root/software/pynsfs.page
blob: 59926994bf2046670791f4a72e92754f234b3777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
format: rst
toc: no
...

=============================================
Python Namespace File System
=============================================

:Author:    Bryan Newbold
:Date:      July 2008
:URL:       http://git.bnewbold.net?p=pynsfs.git;a=summary

.. contents:: 

This is an experimental implementation of a python namespace as a virtual
file system, implemented using the python bindings for fusefs on unix.

At this point only the global namespace of the filesystem instance itself is
accessible, and only limited access is available to that. If anything goes
wrong it can cause a hard lock and system crash; don't leave it running and
don't try to write anything substantial.

The source code can be checked out from the above URL.

Features
---------------
An example session goes like::

    snark# ls /mnt/python/

    snark# python nsfs.py /mnt/python/
    *** init complete
    let's go!

    snark# cd /mnt/python/

    snark# ls -l
    total 6
    -r--r--r--  1 root  wheel  30 Dec 31  1969 DefaultStat
    -r--r--r--  1 root  wheel  33 Dec 31  1969 DefaultStatVfs
    -r--r--r--  1 root  wheel  19 Dec 31  1969 Fuse
    -r--r--r--  1 root  wheel  30 Dec 31  1969 NamespaceFS
    -r--r--r--  1 root  wheel  27 Dec 31  1969 NsfsFile
    -r--r--r--  1 root  wheel  17 Dec 31  1969 StringIO
    drwxr-xr-x  2 root  wheel   0 Dec 31  1969 __builtins__
    -r--r--r--  1 root  wheel   4 Dec 31  1969 __doc__
    -r--r--r--  1 root  wheel   7 Dec 31  1969 __file__
    -r--r--r--  1 root  wheel   8 Dec 31  1969 __name__
    drwxr-xr-x  2 root  wheel   0 Dec 31  1969 _find_fuse_parts
    drwxr-xr-x  2 root  wheel   0 Dec 31  1969 errno
    drwxr-xr-x  2 root  wheel   0 Dec 31  1969 fuse
    -r--r--r--  1 root  wheel  29 Dec 31  1969 main
    drwxr-xr-x  2 root  wheel   0 Dec 31  1969 os
    drwxr-xr-x  2 root  wheel   0 Dec 31  1969 stat
    -r--r--r--  1 root  wheel  24 Dec 31  1969 time

    snark# ls stat/
    ST_ATIME        S_ENFMT         S_IMODE         S_ISDIR         S_IWRITE
    ST_CTIME        S_IEXEC         S_IREAD         S_ISFIFO        S_IWUSR
    ST_DEV          S_IFBLK         S_IRGRP         S_ISGID         S_IXGRP
    ST_GID          S_IFCHR         S_IROTH         S_ISLNK         S_IXOTH
    ST_INO          S_IFDIR         S_IRUSR         S_ISREG         S_IXUSR
    ST_MODE         S_IFIFO         S_IRWXG         S_ISSOCK        __builtins__
    ST_MTIME        S_IFLNK         S_IRWXO         S_ISUID         __doc__
    ST_NLINK        S_IFMT          S_IRWXU         S_ISVTX         __file__
    ST_SIZE         S_IFREG         S_ISBLK         S_IWGRP         __name__
    ST_UID          S_IFSOCK        S_ISCHR         S_IWOTH

    snark# cat time 
    <built-in function time>

    snark# echo " Hello Python" >> os/__name__

    snark# cat os/__name__
    os Hello Python

    snark# rm time

    snark# ls
    DefaultStat             __builtins__            fuse
    DefaultStatVfs          __doc__                 main
    Fuse                    __file__                os
    NamespaceFS             __name__                stat
    NsfsFile                _find_fuse_parts
    StringIO                errno

    snark# ln __nameofos__ os/__name__ 
    ln: __nameofos__: No such file or directory

    snark# ln os/__name__ __nameofos__

    snark# cat __nameofos__ 
    os Hello Python

    snark# cd ..

    snark# umount /mnt/python/

The root directory is the global namespace; modules are available as 
subdirectories and all other objects are accessible as files. Strings can
be appended to; all other "files" are readonly and return their string
representation. "Files" can be deleted; "directories" can not. Hard links to
files are possible.

Requirements
---------------

This was developed and has only been tested on FreeBSD 7.0 with Python 2.5.1 
version 0.2 of the python-fuse bindings. 

* `FUSE Filesystem`__ installed and configured on a compatible operating system
* Recent version of Python__
* `FUSE Python Bindings`__

Once everything is installed and configured, the script can just be run
as root; no installation necessary.

__ http://fuse.sourceforge.net/
__ http://python.org
__ http://fuse.sourceforge.net/wiki/index.php/FusePython

Usage
--------------
Try ``# python nsfs.py -h`` to get a list of general FUSE options. A simple
mount command would look like::

    # python nsfs.py /mnt/python

To unmount::

    # umount /mnt/python

I like to run in foreground, single threaded, with debug info::

    # python nsfs.py -dsf /mnt/python

Really only basic command line tools work because they don't check for many
attributes; try ``echo "blah" >> file``, ``cat file``, ``df -h``, ``ls -l`` etc.

TODO
-----------------------
Functions taking simple arguments (or no arguments) could be implemented as
character devices; ``function_name.doc``, ``function_name.repr``, etc could 
give meta-information.

File of the form ``__thing__`` should be renamed ``.thing``.

New files should be allowed and saved as strings.

CHANGELOG
-----------------------

July 28, 2008
  First implementation