inspector: Sort application names.
[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 Useful targets:
28   make syntax-check    Checks the syntax of the C code.
29   make check           Runs the test suite.
30
31 Enable warnings, and fix any you find:
32   ./configure --enable-gcc-warnings
33
34 Code indentation
35 ----------------------------------------------------------------------
36 Our C source code generally adheres to some basic code-formatting
37 conventions.  The existing code base is not totally consistent on this
38 front, but we do prefer that contributed code be formatted similarly.
39 In short, use spaces-not-TABs for indentation, use 2 spaces for each
40 indentation level, and other than that, follow the K&R style.
41
42 If you use Emacs, add the following to one of one of your start-up files
43 (e.g., ~/.emacs), to help ensure that you get indentation right:
44
45   ;;; In libguestfs, indent with spaces everywhere (not TABs).
46   ;;; Exceptions: Makefile and ChangeLog modes.
47   (add-hook 'find-file-hook
48       '(lambda () (if (and buffer-file-name
49                            (string-match "/libguestfs\\>" (buffer-file-name))
50                            (not (string-equal mode-name "Change Log"))
51                            (not (string-equal mode-name "Makefile")))
52                       (setq indent-tabs-mode nil))))
53
54   ;;; When editing C sources in libguestfs, use this style.
55   (defun libguestfs-c-mode ()
56     "C mode with adjusted defaults for use with libguestfs."
57     (interactive)
58     (c-set-style "K&R")
59     (setq c-indent-level 2)
60     (setq c-basic-offset 2))
61   (add-hook 'c-mode-hook
62             '(lambda () (if (string-match "/libguestfs\\>" (buffer-file-name))
63                             (libguestfs-c-mode))))
64
65 Directories
66 ----------------------------------------------------------------------
67
68 appliance/
69         The qemu appliance, build scripts and so on.
70
71 capitests/
72         Automated tests of the C API.
73
74 contrib/
75         Outside contributions, experimental parts.
76
77 csharp/
78         Experimental C# bindings.
79
80 daemon/
81         The daemon that runs inside the guest and carries out actions.
82
83 examples/
84         The examples.
85
86 fish/
87         Guestfish (the command-line program / shell)
88
89 fuse/
90         FUSE (userspace filesystem) built on top of libguestfs.
91
92 haskell/
93         Haskell bindings.
94
95 hivex/ [removed in 1.0.85]
96        This used to contain the hivex library for reading and
97        writing Windows Registry binary hive files.  This is now
98        available as a separate upstream project.
99
100 images/
101         Some guest images to test against.  These are gzipped to save
102         space.  You have to unzip them before use.
103
104         Also contains some files used by the test suite.
105
106 inspector/
107         Virtual machine image inspector (virt-inspector).
108
109 java/
110         Java bindings.
111
112 m4/
113         M4 macros used by autoconf.
114
115 ocaml/
116         OCaml bindings.
117
118 po/
119         Translations.
120
121 perl/
122         Perl bindings.
123
124 python/
125         Python bindings.
126
127 regressions/
128         Regression tests.
129
130 ruby/
131         Ruby bindings.
132
133 tools/
134         Command line tools like virt-cat, virt-df, virt-edit and more.
135         In versions <= 1.0.73 these were all in separate directories
136         like cat/, df/, edit/, but since then we moved them all into
137         one directory to simplify builds.
138
139 src/
140         Source code to the C library.
141         Also contains the crucial generator program.
142
143 test-tool/
144         Interactive qemu/kernel test tool.
145
146 Debugging
147 ----------------------------------------------------------------------
148
149 It's a good idea to use guestfish to try out new commands.
150
151 Debugging the daemon is a problem because it runs inside a minimal
152 qemu environment.  However you can print messages from the daemon, and
153 they will show up if you use 'guestfish -v'.
154
155 Patches
156 ----------------------------------------------------------------------
157
158 Submit patches to the mailing list:
159 http://www.redhat.com/mailman/listinfo/libguestfs
160 and CC to rjones@redhat.com
161
162 I18N
163 ----------------------------------------------------------------------
164
165 We support i18n (gettext anyhow) in the library.
166
167 However many messages come from the daemon, and we don't translate
168 those at the moment.  One reason is that the appliance generally has
169 all locale files removed from it, because they take up a lot of space.
170 So we'd have to readd some of those, as well as copying our PO files
171 into the appliance.
172
173 Debugging messages are never translated, since they are intended for
174 the programmers.
175
176 Extended printf
177 ----------------------------------------------------------------------
178
179 In the daemon code we have created custom printf formatters %Q and %R,
180 which are used to do shell quoting.
181
182 %Q => Simple shell quoted string.  Any spaces or other shell characters
183       are escaped for you.
184
185 %R => Same as %Q except the string is treated as a path which is prefixed
186       by the sysroot.
187
188 eg.
189
190 asprintf (&cmd, "cat %R", path);
191 ==> "cat /sysroot/some\ path\ with\ spaces"
192
193 Note: Do NOT use these when you are passing parameters to the
194 command{,r,v,rv}() functions.  These parameters do NOT need to be
195 quoted because they are not passed via the shell (instead, straight to
196 exec).  You probably want to use the sysroot_path() function however.