generator.ml: use new "Pathname" designation
[libguestfs.git] / HACKING
1 PLEASE LOOK AT THE TOP OF EACH FILE BEFORE EDITING TO SEE WHETHER IT
2 IS AUTOMATICALLY GENERATED OR NOT.
3
4 Adding a new action
5 ----------------------------------------------------------------------
6
7 All action functions are generated automatically, so there are only
8 two files you need to edit:
9
10 (1) src/generator.ml: Add your new action, parameters, description,
11 etc. to the big list called 'functions' at the top of this file.
12
13 (2) Edit/create a C file in daemon/ subdirectory which implements your
14 'do_action' function.  Take a look at one of the numerous examples
15 there.
16
17 Formatting
18 ----------------------------------------------------------------------
19
20 Try to use GNU / Emacs default formatting, following the convention
21 used elsewhere in the source.
22
23 Please make sure that the code compiles without warnings.
24
25 Please test any changes.
26
27 Code indentation
28 ----------------------------------------------------------------------
29 Our C source code generally adheres to some basic code-formatting
30 conventions.  The existing code base is not totally consistent on this
31 front, but we do prefer that contributed code be formatted similarly.
32 In short, use spaces-not-TABs for indentation, use 2 spaces for each
33 indentation level, and other than that, follow the K&R style.
34
35 If you use Emacs, add the following to one of one of your start-up files
36 (e.g., ~/.emacs), to help ensure that you get indentation right:
37
38   ;;; In libguestfs, indent with spaces everywhere (not TABs).
39   ;;; Exceptions: Makefile and ChangeLog modes.
40   (add-hook 'find-file-hook
41       '(lambda () (if (and buffer-file-name
42                            (string-match "/libguestfs\\>" (buffer-file-name))
43                            (not (string-equal mode-name "Change Log"))
44                            (not (string-equal mode-name "Makefile")))
45                       (setq indent-tabs-mode nil))))
46
47   ;;; When editing C sources in libguestfs, use this style.
48   (defun libguestfs-c-mode ()
49     "C mode with adjusted defaults for use with libguestfs."
50     (interactive)
51     (c-set-style "K&R")
52     (setq c-indent-level 2)
53     (setq c-basic-offset 2))
54   (add-hook 'c-mode-hook
55             '(lambda () (if (string-match "/libguestfs\\>" (buffer-file-name))
56                             (libguestfs-c-mode))))
57
58 Directories
59 ----------------------------------------------------------------------
60
61 appliance/
62         The qemu appliance, build scripts and so on.
63
64 cat/
65         The virt-cat tool.
66
67 capitests/
68         Automated tests of the C API.
69
70 contrib/
71         Outside contributions, experimental parts.
72
73 daemon/
74         The daemon that runs inside the guest and carries out actions.
75
76 df/
77         The virt-df tool.
78
79 examples/
80         The examples.
81
82 fish/
83         Guestfish (the command-line program / shell)
84
85 haskell/
86         Haskell bindings.
87
88 images/
89         Some guest images to test against.  These are gzipped to save
90         space.  You have to unzip them before use.
91
92         Also contains some files used by the test suite.
93
94 inspector/
95         Virtual machine image inspector (virt-inspector).
96
97 java/
98         Java bindings.
99
100 m4/
101         M4 macros used by autoconf.
102
103 ocaml/
104         OCaml bindings.
105
106 po/
107         Translations.
108
109 perl/
110         Perl bindings.
111
112 python/
113         Python bindings.
114
115 regressions/
116         Regression tests.
117
118 ruby/
119         Ruby bindings.
120
121 src/
122         Source code to the C library.
123         Also contains the crucial generator program.
124
125 test-tool/
126         Interactive qemu/kernel test tool.
127
128 v2v/
129         Xen to KVM (V2V) conversion tool.
130
131 Debugging
132 ----------------------------------------------------------------------
133
134 It's a good idea to use guestfish to try out new commands.
135
136 Debugging the daemon is a problem because it runs inside a minimal
137 qemu environment.  However you can print messages from the daemon, and
138 they will show up if you use 'guestfish -v'.
139
140 Patches
141 ----------------------------------------------------------------------
142
143 Submit patches to the mailing list:
144 http://www.redhat.com/mailman/listinfo/libguestfs
145 and CC to rjones@redhat.com
146
147 I18N
148 ----------------------------------------------------------------------
149
150 We support i18n (gettext anyhow) in the library.
151
152 However many messages come from the daemon, and we don't translate
153 those at the moment.  One reason is that the appliance generally has
154 all locale files removed from it, because they take up a lot of space.
155 So we'd have to readd some of those, as well as copying our PO files
156 into the appliance.
157
158 Debugging messages are never translated, since they are intended for
159 the programmers.
160
161 Extended printf
162 ----------------------------------------------------------------------
163
164 In the daemon code we have created custom printf formatters %Q and %R,
165 which are used to do shell quoting.
166
167 %Q => Simple shell quoted string.  Any spaces or other shell characters
168       are escaped for you.
169
170 %R => Same as %Q except the string is treated as a path which is prefixed
171       by the sysroot.
172
173 eg.
174
175 asprintf (&cmd, "cat %R", path);
176 ==> "cat /sysroot/some\ path\ with\ spaces"
177
178 Note: Do NOT use these when you are passing parameters to the
179 command{,r,v,rv}() functions.  These parameters do NOT need to be
180 quoted because they are not passed via the shell (instead, straight to
181 exec).  You probably want to use the sysroot_path() function however.