Changeset 00aece0 in mainline for uspace/app
- Timestamp:
- 2012-02-18T16:47:38Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4449c6c
- Parents:
- bd5f3b7 (diff), f943dd3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 236 added
- 41 edited
- 3 moved
-
bdsh/Makefile (modified) (2 diffs)
-
bdsh/cmds/builtins/batch/batch.c (added)
-
bdsh/cmds/builtins/batch/batch.h (added)
-
bdsh/cmds/builtins/batch/batch_def.h (added)
-
bdsh/cmds/builtins/batch/entry.h (added)
-
bdsh/cmds/builtins/builtins.h (modified) (1 diff)
-
bdsh/cmds/modules/cat/cat.c (modified) (1 diff)
-
bdsh/cmds/modules/cp/cp.c (modified) (7 diffs)
-
bdsh/cmds/modules/help/help.c (modified) (1 diff)
-
bdsh/cmds/modules/mkfile/mkfile.c (modified) (6 diffs)
-
bdsh/cmds/modules/mount/mount.c (modified) (4 diffs)
-
bdsh/cmds/modules/rm/rm.c (modified) (2 diffs)
-
bdsh/compl.c (modified) (6 diffs)
-
bdsh/exec.c (modified) (1 diff)
-
bdsh/input.c (modified) (3 diffs)
-
binutils/Makefile (added)
-
binutils/distclean.sh (added)
-
binutils/intrusive.sh (added)
-
binutils/patch.awk (added)
-
binutils/toolchain.sh (added)
-
cc (added)
-
ccom (added)
-
cpp (added)
-
devctl/devctl.c (modified) (5 diffs)
-
init/init.c (modified) (6 diffs)
-
klog/klog.c (modified) (1 diff)
-
locinfo/locinfo.c (modified) (1 diff)
-
mkbd/main.c (modified) (7 diffs)
-
mkfat/fat.h (modified) (1 diff)
-
mkfat/mkfat.c (modified) (20 diffs)
-
mkmfs/Makefile (moved) (moved from uspace/lib/packet/Makefile ) (1 diff)
-
mkmfs/mkmfs.c (added)
-
netecho/netecho.c (modified) (3 diffs)
-
nettest3/Makefile (added)
-
nettest3/nettest3.c (added)
-
pcc/DATESTAMP (added)
-
pcc/Makefile.in (added)
-
pcc/arch/amd64/code.c (added)
-
pcc/arch/amd64/local.c (added)
-
pcc/arch/amd64/local2.c (added)
-
pcc/arch/amd64/macdefs.h (added)
-
pcc/arch/amd64/order.c (added)
-
pcc/arch/amd64/table.c (added)
-
pcc/arch/arm/code.c (added)
-
pcc/arch/arm/local.c (added)
-
pcc/arch/arm/local2.c (added)
-
pcc/arch/arm/macdefs.h (added)
-
pcc/arch/arm/order.c (added)
-
pcc/arch/arm/table.c (added)
-
pcc/arch/arm32 (added)
-
pcc/arch/hppa/code.c (added)
-
pcc/arch/hppa/local.c (added)
-
pcc/arch/hppa/local2.c (added)
-
pcc/arch/hppa/macdefs.h (added)
-
pcc/arch/hppa/order.c (added)
-
pcc/arch/hppa/table.c (added)
-
pcc/arch/i386/code.c (added)
-
pcc/arch/i386/flocal.c (added)
-
pcc/arch/i386/local.c (added)
-
pcc/arch/i386/local2.c (added)
-
pcc/arch/i386/macdefs.h (added)
-
pcc/arch/i386/order.c (added)
-
pcc/arch/i386/table.c (added)
-
pcc/arch/ia32 (added)
-
pcc/arch/m16c/TODO (added)
-
pcc/arch/m16c/code.c (added)
-
pcc/arch/m16c/local.c (added)
-
pcc/arch/m16c/local2.c (added)
-
pcc/arch/m16c/macdefs.h (added)
-
pcc/arch/m16c/order.c (added)
-
pcc/arch/m16c/table.c (added)
-
pcc/arch/mips/TODO (added)
-
pcc/arch/mips/code.c (added)
-
pcc/arch/mips/local.c (added)
-
pcc/arch/mips/local2.c (added)
-
pcc/arch/mips/macdefs.h (added)
-
pcc/arch/mips/order.c (added)
-
pcc/arch/mips/table.c (added)
-
pcc/arch/mips32 (added)
-
pcc/arch/nova/README (added)
-
pcc/arch/nova/code.c (added)
-
pcc/arch/nova/local.c (added)
-
pcc/arch/nova/local2.c (added)
-
pcc/arch/nova/macdefs.h (added)
-
pcc/arch/nova/order.c (added)
-
pcc/arch/nova/table.c (added)
-
pcc/arch/pdp10/README (added)
-
pcc/arch/pdp10/code.c (added)
-
pcc/arch/pdp10/local.c (added)
-
pcc/arch/pdp10/local2.c (added)
-
pcc/arch/pdp10/macdefs.h (added)
-
pcc/arch/pdp10/order.c (added)
-
pcc/arch/pdp10/table.c (added)
-
pcc/arch/pdp11/code.c (added)
-
pcc/arch/pdp11/local.c (added)
-
pcc/arch/pdp11/local2.c (added)
-
pcc/arch/pdp11/macdefs.h (added)
-
pcc/arch/pdp11/order.c (added)
-
pcc/arch/pdp11/table.c (added)
-
pcc/arch/powerpc/README (added)
-
pcc/arch/powerpc/code.c (added)
-
pcc/arch/powerpc/local.c (added)
-
pcc/arch/powerpc/local2.c (added)
-
pcc/arch/powerpc/macdefs.h (added)
-
pcc/arch/powerpc/order.c (added)
-
pcc/arch/powerpc/table.c (added)
-
pcc/arch/ppc32 (added)
-
pcc/arch/sparc64/code.c (added)
-
pcc/arch/sparc64/local.c (added)
-
pcc/arch/sparc64/local2.c (added)
-
pcc/arch/sparc64/macdefs.h (added)
-
pcc/arch/sparc64/order.c (added)
-
pcc/arch/sparc64/table.c (added)
-
pcc/arch/vax/code.c (added)
-
pcc/arch/vax/local.c (added)
-
pcc/arch/vax/local2.c (added)
-
pcc/arch/vax/macdefs.h (added)
-
pcc/arch/vax/order.c (added)
-
pcc/arch/vax/table.c (added)
-
pcc/cc/Makefile.in (added)
-
pcc/cc/cc/Makefile (moved) (moved from uspace/drv/bus/usb/usbmouse/Makefile ) (2 diffs)
-
pcc/cc/cc/Makefile.in (added)
-
pcc/cc/cc/cc.1 (added)
-
pcc/cc/cc/cc.c (added)
-
pcc/cc/ccom/Makefile (added)
-
pcc/cc/ccom/Makefile.in (added)
-
pcc/cc/ccom/arch/amd64/external.c (added)
-
pcc/cc/ccom/arch/amd64/external.h (added)
-
pcc/cc/ccom/arch/arm32/external.c (added)
-
pcc/cc/ccom/arch/arm32/external.h (added)
-
pcc/cc/ccom/arch/ia32/external.c (added)
-
pcc/cc/ccom/arch/ia32/external.h (added)
-
pcc/cc/ccom/arch/mips32/external.c (added)
-
pcc/cc/ccom/arch/mips32/external.h (added)
-
pcc/cc/ccom/arch/ppc32/external.c (added)
-
pcc/cc/ccom/arch/ppc32/external.h (added)
-
pcc/cc/ccom/builtins.c (added)
-
pcc/cc/ccom/ccom.1 (added)
-
pcc/cc/ccom/cgram.y (added)
-
pcc/cc/ccom/gcc_compat.c (added)
-
pcc/cc/ccom/init.c (added)
-
pcc/cc/ccom/inline.c (added)
-
pcc/cc/ccom/main.c (added)
-
pcc/cc/ccom/mkext/Makefile (added)
-
pcc/cc/ccom/optim.c (added)
-
pcc/cc/ccom/pass1.h (added)
-
pcc/cc/ccom/pftn.c (added)
-
pcc/cc/ccom/scan.l (added)
-
pcc/cc/ccom/softfloat.c (added)
-
pcc/cc/ccom/stabs.c (added)
-
pcc/cc/ccom/symtabs.c (added)
-
pcc/cc/ccom/trees.c (added)
-
pcc/cc/cpp/Makefile (added)
-
pcc/cc/cpp/Makefile.in (added)
-
pcc/cc/cpp/config.h (added)
-
pcc/cc/cpp/cpp.1 (added)
-
pcc/cc/cpp/cpp.c (added)
-
pcc/cc/cpp/cpp.h (added)
-
pcc/cc/cpp/cpy.y (added)
-
pcc/cc/cpp/scanner.l (added)
-
pcc/cc/cpp/tests/res1 (added)
-
pcc/cc/cpp/tests/res10 (added)
-
pcc/cc/cpp/tests/res11 (added)
-
pcc/cc/cpp/tests/res12 (added)
-
pcc/cc/cpp/tests/res13 (added)
-
pcc/cc/cpp/tests/res2 (added)
-
pcc/cc/cpp/tests/res3 (added)
-
pcc/cc/cpp/tests/res4 (added)
-
pcc/cc/cpp/tests/res5 (added)
-
pcc/cc/cpp/tests/res6 (added)
-
pcc/cc/cpp/tests/res7 (added)
-
pcc/cc/cpp/tests/res8 (added)
-
pcc/cc/cpp/tests/res9 (added)
-
pcc/cc/cpp/tests/test1 (added)
-
pcc/cc/cpp/tests/test10 (added)
-
pcc/cc/cpp/tests/test11 (added)
-
pcc/cc/cpp/tests/test12 (added)
-
pcc/cc/cpp/tests/test13 (added)
-
pcc/cc/cpp/tests/test2 (added)
-
pcc/cc/cpp/tests/test3 (added)
-
pcc/cc/cpp/tests/test4 (added)
-
pcc/cc/cpp/tests/test5 (added)
-
pcc/cc/cpp/tests/test6 (added)
-
pcc/cc/cpp/tests/test7 (added)
-
pcc/cc/cpp/tests/test8 (added)
-
pcc/cc/cpp/tests/test9 (added)
-
pcc/cc/cpp/token.c (added)
-
pcc/config.guess (added)
-
pcc/config.h (added)
-
pcc/config.h.in (added)
-
pcc/config.sub (added)
-
pcc/configure (added)
-
pcc/configure.ac (added)
-
pcc/f77/Makefile.in (added)
-
pcc/f77/f77/Makefile.in (added)
-
pcc/f77/f77/f77.1 (added)
-
pcc/f77/f77/f77.c (added)
-
pcc/f77/fcom/Makefile.in (added)
-
pcc/f77/fcom/data.c (added)
-
pcc/f77/fcom/defines.h (added)
-
pcc/f77/fcom/defs.h (added)
-
pcc/f77/fcom/equiv.c (added)
-
pcc/f77/fcom/error.c (added)
-
pcc/f77/fcom/exec.c (added)
-
pcc/f77/fcom/expr.c (added)
-
pcc/f77/fcom/ftypes.h (added)
-
pcc/f77/fcom/gram.dcl (added)
-
pcc/f77/fcom/gram.exec (added)
-
pcc/f77/fcom/gram.expr (added)
-
pcc/f77/fcom/gram.head (added)
-
pcc/f77/fcom/gram.io (added)
-
pcc/f77/fcom/init.c (added)
-
pcc/f77/fcom/intr.c (added)
-
pcc/f77/fcom/io.c (added)
-
pcc/f77/fcom/lex.c (added)
-
pcc/f77/fcom/main.c (added)
-
pcc/f77/fcom/misc.c (added)
-
pcc/f77/fcom/proc.c (added)
-
pcc/f77/fcom/put.c (added)
-
pcc/f77/fcom/putscj.c (added)
-
pcc/f77/fcom/scjdefs.h (added)
-
pcc/f77/fcom/tokens (added)
-
pcc/install-sh (added)
-
pcc/mip/common.c (added)
-
pcc/mip/compat.c (added)
-
pcc/mip/compat.h (added)
-
pcc/mip/config.h (added)
-
pcc/mip/manifest.h (added)
-
pcc/mip/match.c (added)
-
pcc/mip/mkext.c (added)
-
pcc/mip/node.h (added)
-
pcc/mip/optim2.c (added)
-
pcc/mip/pass2.h (added)
-
pcc/mip/reader.c (added)
-
pcc/mip/regs.c (added)
-
pcc/os/bsd/ccconfig.h (added)
-
pcc/os/darwin/ccconfig.h (added)
-
pcc/os/dragonfly/ccconfig.h (added)
-
pcc/os/freebsd/ccconfig.h (added)
-
pcc/os/helenos/ccconfig.h (added)
-
pcc/os/linux/ccconfig.h (added)
-
pcc/os/midnightbsd/ccconfig.h (added)
-
pcc/os/mirbsd/ccconfig.h (added)
-
pcc/os/netbsd/ccconfig.h (added)
-
pcc/os/nextstep/ccconfig.h (added)
-
pcc/os/none/ccconfig.h (added)
-
pcc/os/openbsd/ccconfig.h (added)
-
pcc/os/openbsd/f77config.h (added)
-
pcc/os/sunos/ccconfig.h (added)
-
pcc/os/win32/build.bat (added)
-
pcc/os/win32/build_installer.bat (added)
-
pcc/os/win32/ccconfig.h (added)
-
pcc/os/win32/config.h (added)
-
pcc/os/win32/pcc.iss (added)
-
sportdmp/Makefile (added)
-
sportdmp/sportdmp.c (added)
-
sysinfo/sysinfo.c (modified) (3 diffs)
-
tester/console/console1.c (modified) (3 diffs)
-
tester/mm/common.c (modified) (1 diff)
-
tester/mm/mapping1.c (modified) (2 diffs)
-
tester/print/print2.c (modified) (1 diff)
-
tetris/screen.c (modified) (2 diffs)
-
tetris/shapes.c (modified) (1 diff)
-
tetris/tetris.c (modified) (1 diff)
-
trace/syscalls.c (modified) (1 diff)
-
trace/trace.c (modified) (5 diffs)
-
usbinfo/desctree.c (modified) (2 diffs)
-
usbinfo/dev.c (modified) (2 diffs)
-
usbinfo/dump.c (modified) (4 diffs)
-
usbinfo/hid.c (modified) (3 diffs)
-
usbinfo/info.c (modified) (5 diffs)
-
usbinfo/main.c (modified) (1 diff)
-
usbinfo/usbinfo.h (modified) (2 diffs)
-
vuhid/Makefile (modified) (2 diffs)
-
vuhid/hids/bootkbd.c (modified) (3 diffs)
-
vuhid/hids/logitech_wireless.c (added)
-
vuhid/ifaces.c (modified) (1 diff)
-
vuhid/life.c (moved) (moved from uspace/drv/bus/usb/usbmouse/mouse.h ) (1 diff)
-
vuhid/virthid.h (modified) (2 diffs)
-
websrv/websrv.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/Makefile
rbd5f3b7 r00aece0 31 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a \ 32 32 $(LIBFMTUTIL_PREFIX)/libfmtutil.a 33 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I$(LIBFMTUTIL_PREFIX)\34 -I . -Icmds/ -Icmds/builtins -Icmds/modules33 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) \ 34 -I$(LIBFMTUTIL_PREFIX) -I. -Icmds/ -Icmds/builtins -Icmds/modules 35 35 BINARY = bdsh 36 36 … … 51 51 cmds/modules/unmount/unmount.c \ 52 52 cmds/modules/kcon/kcon.c \ 53 cmds/builtins/batch/batch.c \ 53 54 cmds/builtins/exit/exit.c \ 54 55 cmds/builtins/cd/cd.c \ -
uspace/app/bdsh/cmds/builtins/builtins.h
rbd5f3b7 r00aece0 4 4 #include "config.h" 5 5 6 #include "batch/entry.h" 6 7 #include "cd/entry.h" 7 8 #include "exit/entry.h" 8 9 9 10 builtin_t builtins[] = { 11 #include "batch/batch_def.h" 10 12 #include "cd/cd_def.h" 11 13 #include "exit/exit_def.h" -
uspace/app/bdsh/cmds/modules/cat/cat.c
rbd5f3b7 r00aece0 103 103 { 104 104 console_set_pos(console, 0, console_rows-1); 105 console_set_color(console, COLOR_ BLUE, COLOR_WHITE, 0);105 console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0); 106 106 107 107 printf("ENTER/SPACE/PAGE DOWN - next page, " -
uspace/app/bdsh/cmds/modules/cp/cp.c
rbd5f3b7 r00aece0 33 33 #include <str.h> 34 34 #include <fcntl.h> 35 #include <sys/stat.h> 36 #include <dirent.h> 35 37 #include "config.h" 36 38 #include "util.h" … … 55 57 }; 56 58 59 typedef enum { 60 TYPE_NONE, 61 TYPE_FILE, 62 TYPE_DIR 63 } dentry_type_t; 64 65 static int64_t copy_file(const char *src, const char *dest, 66 size_t blen, int vb); 67 68 /** Get the type of a directory entry. 69 * 70 * @param path Path of the directory entry. 71 * 72 * @return TYPE_DIR if the dentry is a directory. 73 * @return TYPE_FILE if the dentry is a file. 74 * @return TYPE_NONE if the dentry does not exists. 75 */ 76 static dentry_type_t get_type(const char *path) 77 { 78 struct stat s; 79 80 int r = stat(path, &s); 81 82 if (r) 83 return TYPE_NONE; 84 else if (s.is_directory) 85 return TYPE_DIR; 86 else if (s.is_file) 87 return TYPE_FILE; 88 89 return TYPE_NONE; 90 } 91 57 92 static int strtoint(const char *s1) 58 93 { … … 67 102 return (int) t1; 68 103 } 104 105 /** Get the last component of a path. 106 * 107 * e.g. /data/a ---> a 108 * 109 * @param path Pointer to the path. 110 * 111 * @return Pointer to the last component or to the path itself. 112 */ 113 static char *get_last_path_component(char *path) 114 { 115 char *ptr; 116 117 ptr = str_rchr(path, '/'); 118 if (!ptr) 119 return path; 120 else 121 return ptr + 1; 122 } 123 124 /** Merge two paths together. 125 * 126 * e.g. (path1 = /data/dir, path2 = a/b) --> /data/dir/a/b 127 * 128 * @param path1 Path to which path2 will be appended. 129 * @param path1_size Size of the path1 buffer. 130 * @param path2 Path that will be appended to path1. 131 */ 132 static void merge_paths(char *path1, size_t path1_size, char *path2) 133 { 134 const char *delim = "/"; 135 136 str_rtrim(path1, '/'); 137 str_append(path1, path1_size, delim); 138 str_append(path1, path1_size, path2); 139 } 140 141 static int64_t do_copy(const char *src, const char *dest, 142 size_t blen, int vb, int recursive, int force) 143 { 144 int r = -1; 145 char dest_path[PATH_MAX]; 146 char src_path[PATH_MAX]; 147 DIR *dir = NULL; 148 struct dirent *dp; 149 150 dentry_type_t src_type = get_type(src); 151 dentry_type_t dest_type = get_type(dest); 152 153 const size_t src_len = str_size(src); 154 155 if (src_type == TYPE_FILE) { 156 char *src_fname; 157 158 /* Initialize the src_path with the src argument */ 159 str_cpy(src_path, src_len + 1, src); 160 str_rtrim(src_path, '/'); 161 162 /* Get the last component name from the src path */ 163 src_fname = get_last_path_component(src_path); 164 165 /* Initialize dest_path with the dest argument */ 166 str_cpy(dest_path, PATH_MAX, dest); 167 168 if (dest_type == TYPE_DIR) { 169 /* e.g. cp file_name /data */ 170 /* e.g. cp file_name /data/ */ 171 172 /* dest is a directory, 173 * append the src filename to it. 174 */ 175 merge_paths(dest_path, PATH_MAX, src_fname); 176 dest_type = get_type(dest_path); 177 } else if (dest_type == TYPE_NONE) { 178 if (dest_path[str_size(dest_path) - 1] == '/') { 179 /* e.g. cp /textdemo /data/dirnotexists/ */ 180 181 printf("The dest directory %s does not exists", 182 dest_path); 183 goto exit; 184 } 185 } 186 187 if (dest_type == TYPE_DIR) { 188 printf("Cannot overwrite existing directory %s\n", 189 dest_path); 190 goto exit; 191 } else if (dest_type == TYPE_FILE) { 192 /* e.g. cp file_name existing_file */ 193 194 /* dest already exists, if force is set we will 195 * try to remove it. 196 */ 197 if (force) { 198 if (unlink(dest_path)) { 199 printf("Unable to remove %s\n", 200 dest_path); 201 goto exit; 202 } 203 } else { 204 printf("file already exists: %s\n", dest_path); 205 goto exit; 206 } 207 } 208 209 /* call copy_file and exit */ 210 r = (copy_file(src, dest_path, blen, vb) < 0); 211 212 } else if (src_type == TYPE_DIR) { 213 /* e.g. cp -r /x/srcdir /y/destdir/ */ 214 215 if (!recursive) { 216 printf("Cannot copy the %s directory without the " 217 "-r option\n", src); 218 goto exit; 219 } else if (dest_type == TYPE_FILE) { 220 printf("Cannot overwrite a file with a directory\n"); 221 goto exit; 222 } 223 224 char *src_dirname; 225 226 /* Initialize src_path with the content of src */ 227 str_cpy(src_path, src_len + 1, src); 228 str_rtrim(src_path, '/'); 229 230 src_dirname = get_last_path_component(src_path); 231 232 str_cpy(dest_path, PATH_MAX, dest); 233 234 switch (dest_type) { 235 case TYPE_DIR: 236 if (str_cmp(src_dirname, "..") && 237 str_cmp(src_dirname, ".")) { 238 /* The last component of src_path is 239 * not '.' or '..' 240 */ 241 merge_paths(dest_path, PATH_MAX, src_dirname); 242 243 if (mkdir(dest_path, 0) == -1) { 244 printf("Unable to create " 245 "dest directory %s\n", dest_path); 246 goto exit; 247 } 248 } 249 break; 250 default: 251 case TYPE_NONE: 252 /* dest does not exists, this means the user wants 253 * to specify the name of the destination directory 254 * 255 * e.g. cp -r /src /data/new_dir_src 256 */ 257 if (mkdir(dest_path, 0)) { 258 printf("Unable to create " 259 "dest directory %s\n", dest_path); 260 goto exit; 261 } 262 break; 263 } 264 265 dir = opendir(src); 266 if (!dir) { 267 /* Something strange is happening... */ 268 printf("Unable to open src %s directory\n", src); 269 goto exit; 270 } 271 272 /* Copy every single directory entry of src into the 273 * destination directory. 274 */ 275 while ((dp = readdir(dir))) { 276 struct stat src_s; 277 struct stat dest_s; 278 279 char src_dent[PATH_MAX]; 280 char dest_dent[PATH_MAX]; 281 282 str_cpy(src_dent, PATH_MAX, src); 283 merge_paths(src_dent, PATH_MAX, dp->d_name); 284 285 str_cpy(dest_dent, PATH_MAX, dest_path); 286 merge_paths(dest_dent, PATH_MAX, dp->d_name); 287 288 /* Check if we are copying a directory into itself */ 289 stat(src_dent, &src_s); 290 stat(dest_path, &dest_s); 291 292 if (dest_s.index == src_s.index && 293 dest_s.fs_handle == src_s.fs_handle) { 294 printf("Cannot copy a directory " 295 "into itself\n"); 296 goto exit; 297 } 298 299 if (vb) 300 printf("copy %s %s\n", src_dent, dest_dent); 301 302 /* Recursively call do_copy() */ 303 r = do_copy(src_dent, dest_dent, blen, vb, recursive, 304 force); 305 if (r) 306 goto exit; 307 308 } 309 } else 310 printf("Unable to open source file %s\n", src); 311 312 exit: 313 if (dir) 314 closedir(dir); 315 return r; 316 } 317 69 318 70 319 static int64_t copy_file(const char *src, const char *dest, … … 127 376 static char helpfmt[] = 128 377 "Usage: %s [options] <source> <dest>\n" 129 "Options: (* indicates not yet implemented)\n"378 "Options:\n" 130 379 " -h, --help A short option summary\n" 131 380 " -v, --version Print version information and exit\n" 132 "* -V, --verbose Be annoyingly noisy about what's being done\n" 133 "* -f, --force Do not complain when <dest> exists\n" 134 "* -r, --recursive Copy entire directories\n" 135 " -b, --buffer ## Set the read buffer size to ##\n" 136 "Currently, %s is under development, some options may not work.\n"; 381 " -V, --verbose Be annoyingly noisy about what's being done\n" 382 " -f, --force Do not complain when <dest> exists\n" 383 " -r, --recursive Copy entire directories\n" 384 " -b, --buffer ## Set the read buffer size to ##\n"; 137 385 if (level == HELP_SHORT) { 138 386 printf("`%s' copies files and directories\n", cmdname); 139 387 } else { 140 388 help_cmd_cp(HELP_SHORT); 141 printf(helpfmt, cmdname , cmdname);389 printf(helpfmt, cmdname); 142 390 } 143 391 … … 148 396 { 149 397 unsigned int argc, verbose = 0; 150 int buffer = 0; 398 int buffer = 0, recursive = 0; 399 int force = 0; 151 400 int c, opt_ind; 152 401 int64_t ret; … … 167 416 break; 168 417 case 'f': 418 force = 1; 169 419 break; 170 420 case 'r': 421 recursive = 1; 171 422 break; 172 423 case 'b': … … 194 445 } 195 446 196 ret = copy_file(argv[optind], argv[optind + 1], buffer, verbose); 197 198 if (verbose) 199 printf("%" PRId64 " bytes copied\n", ret); 200 201 if (ret >= 0) 447 ret = do_copy(argv[optind], argv[optind + 1], buffer, verbose, 448 recursive, force); 449 450 if (ret == 0) 202 451 return CMD_SUCCESS; 203 452 else -
uspace/app/bdsh/cmds/modules/help/help.c
rbd5f3b7 r00aece0 152 152 "This is but a small glimpse of what you can do with HelenOS. " 153 153 "To learn more please point your browser to the HelenOS User's " 154 "Guide: http://trac.helenos.org/ trac.fcgi/wiki/UsersGuide\n\n",154 "Guide: http://trac.helenos.org/wiki/UsersGuide\n\n", 155 155 ALIGN_LEFT); 156 156 } -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rbd5f3b7 r00aece0 54 54 static struct option const long_options[] = { 55 55 {"size", required_argument, 0, 's'}, 56 {"sparse", no_argument, 0, 'p'}, 56 57 {"help", no_argument, 0, 'h'}, 57 58 {0, 0, 0, 0} … … 69 70 " -h, --help A short option summary\n" 70 71 " -s, --size sz Size of the file\n" 72 " -p, --sparse Create a sparse file\n" 71 73 "\n" 72 74 "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n" … … 115 117 ssize_t file_size; 116 118 ssize_t total_written; 117 ssize_t to_write, rc ;119 ssize_t to_write, rc, rc2 = 0; 118 120 char *file_name; 119 121 void *buffer; 122 bool create_sparse = false; 120 123 121 124 file_size = 0; … … 124 127 125 128 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 126 c = getopt_long(argc, argv, " s:h", long_options, &opt_ind);129 c = getopt_long(argc, argv, "ps:h", long_options, &opt_ind); 127 130 switch (c) { 128 131 case 'h': 129 132 help_cmd_mkfile(HELP_LONG); 130 133 return CMD_SUCCESS; 134 case 'p': 135 create_sparse = true; 136 break; 131 137 case 's': 132 138 file_size = read_size(optarg); … … 154 160 printf("%s: failed to create file %s.\n", cmdname, file_name); 155 161 return CMD_FAILURE; 162 } 163 164 if (create_sparse && file_size > 0) { 165 const char byte = 0x00; 166 167 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) 168 goto exit; 169 170 rc2 = write(fd, &byte, sizeof(char)); 171 goto exit; 156 172 } 157 173 … … 174 190 } 175 191 192 free(buffer); 193 exit: 176 194 rc = close(fd); 177 if (rc != 0) { 195 196 if (rc != 0 || rc2 < 0) { 178 197 printf("%s: Error writing file (%zd).\n", cmdname, rc); 179 198 return CMD_FAILURE; 180 199 } 181 182 free(buffer);183 200 184 201 return CMD_SUCCESS; -
uspace/app/bdsh/cmds/modules/mount/mount.c
rbd5f3b7 r00aece0 27 27 */ 28 28 29 #include <loc.h> 29 30 #include <stdio.h> 30 31 #include <stdlib.h> 31 32 #include <vfs/vfs.h> 33 #include <adt/list.h> 32 34 #include <errno.h> 33 35 #include <getopt.h> 36 #include <inttypes.h> 34 37 #include "config.h" 35 38 #include "util.h" … … 43 46 static struct option const long_options[] = { 44 47 { "help", no_argument, 0, 'h' }, 48 { "instance", required_argument, 0, 'i' }, 45 49 { 0, 0, 0, 0 } 46 50 }; … … 61 65 } 62 66 67 static void print_mtab_list(void) 68 { 69 LIST_INITIALIZE(mtab_list); 70 mtab_ent_t *old_ent = NULL; 71 char *svc_name; 72 int rc; 73 74 get_mtab_list(&mtab_list); 75 76 list_foreach(mtab_list, cur) { 77 mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t, 78 link); 79 80 if (old_ent) 81 free(old_ent); 82 83 old_ent = mtab_ent; 84 85 printf("%s", mtab_ent->fs_name); 86 if (mtab_ent->instance) 87 printf("/%d", mtab_ent->instance); 88 89 printf(" %s", mtab_ent->mp); 90 91 rc = loc_service_get_name(mtab_ent->service_id, &svc_name); 92 if (rc == EOK) { 93 printf(" %s", svc_name); 94 free(svc_name); 95 } else { 96 printf(" (%" PRIun ")", mtab_ent->service_id); 97 } 98 99 if (str_size(mtab_ent->opts) > 0) 100 printf(" (%s)", mtab_ent->opts); 101 102 putchar('\n'); 103 } 104 105 if (old_ent) 106 free(old_ent); 107 } 108 63 109 /* Main entry point for mount, accepts an array of arguments */ 64 110 int cmd_mount(char **argv) … … 68 114 const char *dev = ""; 69 115 int rc, c, opt_ind; 116 unsigned int instance = 0; 117 bool instance_set = false; 118 char **t_argv; 70 119 71 120 argc = cli_count_args(argv); 72 121 73 122 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 74 c = getopt_long(argc, argv, " h", long_options, &opt_ind);123 c = getopt_long(argc, argv, "i:h", long_options, &opt_ind); 75 124 switch (c) { 76 125 case 'h': 77 126 help_cmd_mount(HELP_LONG); 78 127 return CMD_SUCCESS; 128 case 'i': 129 instance = (unsigned int) strtol(optarg, NULL, 10); 130 instance_set = true; 131 break; 79 132 } 80 133 } 81 134 82 if ((argc < 3) || (argc > 5)) { 135 if (instance_set) { 136 argc -= 2; 137 t_argv = &argv[2]; 138 } else 139 t_argv = &argv[0]; 140 141 if ((argc == 2) || (argc > 5)) { 83 142 printf("%s: invalid number of arguments. Try `mount --help'\n", 84 143 cmdname); 85 144 return CMD_FAILURE; 86 145 } 146 if (argc == 1) { 147 print_mtab_list(); 148 return CMD_SUCCESS; 149 } 87 150 if (argc > 3) 88 dev = argv[3];151 dev = t_argv[3]; 89 152 if (argc == 5) 90 mopts = argv[4];153 mopts = t_argv[4]; 91 154 92 rc = mount( argv[1], argv[2], dev, mopts, 0);155 rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance); 93 156 if (rc != EOK) { 94 157 printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n", 95 argv[1], argv[2],argv[3], rc);158 t_argv[1], t_argv[2], t_argv[3], rc); 96 159 return CMD_FAILURE; 97 160 } -
uspace/app/bdsh/cmds/modules/rm/rm.c
rbd5f3b7 r00aece0 95 95 if (NULL != rm->cwd) 96 96 free(rm->cwd); 97 98 return;99 97 } 100 98 … … 129 127 } 130 128 } 129 130 closedir(dirp); 131 131 132 132 return ret; -
uspace/app/bdsh/compl.c
rbd5f3b7 r00aece0 90 90 { 91 91 compl_t *cs = NULL; 92 size_t pref_size;93 92 char *stext = NULL; 94 93 char *prefix = NULL; 95 94 char *dirname = NULL; 95 int retval; 96 97 token_t *tokens = calloc(WORD_MAX, sizeof(token_t)); 98 if (tokens == NULL) { 99 retval = ENOMEM; 100 goto error; 101 } 102 103 size_t pref_size; 96 104 char *rpath_sep; 97 105 static const char *dirlist_arg[] = { ".", NULL }; 98 int retval;99 106 tokenizer_t tok; 100 token_t tokens[WORD_MAX]; 101 int current_token; 107 ssize_t current_token; 102 108 size_t tokens_length; 103 109 104 110 cs = calloc(1, sizeof(compl_t)); 105 111 if (!cs) { … … 107 113 goto error; 108 114 } 109 115 110 116 /* Convert text buffer to string */ 111 117 stext = wstr_to_astr(text); … … 127 133 128 134 /* Find the current token */ 129 for (current_token = 0; current_token < ( int) tokens_length;135 for (current_token = 0; current_token < (ssize_t) tokens_length; 130 136 current_token++) { 131 137 token_t *t = &tokens[current_token]; 132 138 size_t end = t->char_start + t->char_length; 133 /* Check if the caret lies inside the token or immediately 139 140 /* 141 * Check if the caret lies inside the token or immediately 134 142 * after it 135 143 */ … … 138 146 } 139 147 } 140 if (tokens_length == 0) current_token = -1; 141 142 if (current_token >= 0 && tokens[current_token].type != TOKTYPE_SPACE) { 148 149 if (tokens_length == 0) 150 current_token = -1; 151 152 if ((current_token >= 0) && (tokens[current_token].type != TOKTYPE_SPACE)) 143 153 *cstart = tokens[current_token].char_start; 144 } 145 else { 154 else 146 155 *cstart = pos; 147 }148 149 /* Extract the prefix being completed156 157 /* 158 * Extract the prefix being completed 150 159 * XXX: handle strings, etc. 151 160 */ … … 170 179 171 180 /* Skip any whitespace before current token */ 172 int prev_token = current_token - 1;173 if ( prev_token >= 0 && tokens[prev_token].type == TOKTYPE_SPACE) {181 ssize_t prev_token = current_token - 1; 182 if ((prev_token >= 0) && (tokens[prev_token].type == TOKTYPE_SPACE)) 174 183 prev_token--; 175 } 176 184 177 185 /* 178 186 * It is a command if it is the first token or if it immediately 179 187 * follows a pipe token. 180 188 */ 181 if ( prev_token < 0 || tokens[prev_token].type == TOKTYPE_SPACE)189 if ((prev_token < 0) || (tokens[prev_token].type == TOKTYPE_SPACE)) 182 190 cs->is_command = true; 183 191 else … … 254 262 if (cs != NULL) 255 263 free(cs); 264 if (tokens != NULL) 265 free(tokens); 256 266 257 267 return retval; -
uspace/app/bdsh/exec.c
rbd5f3b7 r00aece0 134 134 printf("%s: Failed waiting for command (%s)\n", progname, 135 135 str_error(rc)); 136 return 1; 136 137 } else if (texit != TASK_EXIT_NORMAL) { 137 138 printf("%s: Command failed (unexpectedly terminated)\n", progname); 139 return 1; 138 140 } else if (retval != 0) { 139 141 printf("%s: Command failed (exit code %d)\n", 140 142 progname, retval); 143 return 1; 141 144 } 142 145 -
uspace/app/bdsh/input.c
rbd5f3b7 r00aece0 67 67 int process_input(cliuser_t *usr) 68 68 { 69 char *cmd[WORD_MAX];70 69 token_t *tokens = calloc(WORD_MAX, sizeof(token_t)); 71 70 if (tokens == NULL) 72 71 return ENOMEM; 72 73 char *cmd[WORD_MAX]; 73 74 int rc = 0; 74 75 tokenizer_t tok; … … 78 79 char *redir_to = NULL; 79 80 80 if ( NULL == usr->line) {81 if (usr->line == NULL) { 81 82 free(tokens); 82 83 return CL_EFAIL; … … 195 196 new_iostate.stdout = to; 196 197 } 197 198 198 199 rc = run_command(cmd, usr, &new_iostate); 199 200 -
uspace/app/devctl/devctl.c
rbd5f3b7 r00aece0 37 37 #include <stdio.h> 38 38 #include <stdlib.h> 39 #include <str_error.h> 39 40 #include <sys/typefmt.h> 40 41 … … 43 44 #define MAX_NAME_LENGTH 1024 44 45 45 static int fun_ tree_print(devman_handle_t funh, int lvl)46 static int fun_subtree_print(devman_handle_t funh, int lvl) 46 47 { 47 48 char name[MAX_NAME_LENGTH]; … … 84 85 85 86 for (i = 0; i < count; i++) 86 fun_ tree_print(cfuns[i], lvl + 1);87 fun_subtree_print(cfuns[i], lvl + 1); 87 88 88 89 free(cfuns); … … 90 91 } 91 92 92 int main(int argc, char *argv[])93 static int fun_tree_print(void) 93 94 { 94 95 devman_handle_t root_fun; … … 98 99 if (rc != EOK) { 99 100 printf(NAME ": Error resolving root function.\n"); 101 return EIO; 102 } 103 104 rc = fun_subtree_print(root_fun, 0); 105 if (rc != EOK) 106 return EIO; 107 108 return EOK; 109 } 110 111 static int fun_online(const char *path) 112 { 113 devman_handle_t funh; 114 int rc; 115 116 rc = devman_fun_get_handle(path, &funh, 0); 117 if (rc != EOK) { 118 printf(NAME ": Error resolving device function '%s' (%s)\n", 119 path, str_error(rc)); 120 return rc; 121 } 122 123 rc = devman_fun_online(funh); 124 if (rc != EOK) { 125 printf(NAME ": Failed to online function '%s'.\n", path); 126 return rc; 127 } 128 129 return EOK; 130 } 131 132 static int fun_offline(const char *path) 133 { 134 devman_handle_t funh; 135 int rc; 136 137 rc = devman_fun_get_handle(path, &funh, 0); 138 if (rc != EOK) { 139 printf(NAME ": Error resolving device function '%s' (%s)\n", 140 path, str_error(rc)); 141 return rc; 142 } 143 144 rc = devman_fun_offline(funh); 145 if (rc != EOK) { 146 printf(NAME ": Failed to offline function '%s'.\n", path); 147 return rc; 148 } 149 150 return EOK; 151 } 152 153 static void print_syntax(void) 154 { 155 printf("syntax: devctl [(online|offline) <function>]\n"); 156 } 157 158 int main(int argc, char *argv[]) 159 { 160 int rc; 161 162 if (argc == 1) { 163 rc = fun_tree_print(); 164 if (rc != EOK) 165 return 2; 166 } else if (str_cmp(argv[1], "online") == 0) { 167 if (argc < 3) { 168 printf(NAME ": Argument missing.\n"); 169 print_syntax(); 170 return 1; 171 } 172 173 rc = fun_online(argv[2]); 174 if (rc != EOK) { 175 return 2; 176 } 177 } else if (str_cmp(argv[1], "offline") == 0) { 178 if (argc < 3) { 179 printf(NAME ": Argument missing.\n"); 180 print_syntax(); 181 return 1; 182 } 183 184 rc = fun_offline(argv[2]); 185 if (rc != EOK) { 186 return 2; 187 } 188 } else { 189 printf(NAME ": Invalid argument '%s'.\n", argv[1]); 190 print_syntax(); 100 191 return 1; 101 192 } 102 103 rc = fun_tree_print(root_fun, 0);104 if (rc != EOK)105 return 1;106 193 107 194 return 0; -
uspace/app/init/init.c
rbd5f3b7 r00aece0 121 121 122 122 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts, 123 IPC_FLAG_BLOCKING );123 IPC_FLAG_BLOCKING, 0); 124 124 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype, 125 125 ROOT_DEVICE, rc); … … 138 138 { 139 139 int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "", 140 IPC_FLAG_BLOCKING );140 IPC_FLAG_BLOCKING, 0); 141 141 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT, 142 142 LOCFS_FS_TYPE, NULL, rc); … … 196 196 } 197 197 198 static void console(const char * svc)199 { 200 printf("%s: Spawning %s %s \n", NAME, SRV_CONSOLE,svc);198 static void console(const char *isvc, const char *fbsvc) 199 { 200 printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc); 201 201 202 202 /* Wait for the input service to be ready */ 203 203 service_id_t service_id; 204 int rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING); 205 if (rc != EOK) { 206 printf("%s: Error waiting on %s (%s)\n", NAME, svc, 207 str_error(rc)); 208 return; 209 } 210 211 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, svc, NULL); 212 if (rc != EOK) { 213 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE, 214 svc, str_error(rc)); 204 int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING); 205 if (rc != EOK) { 206 printf("%s: Error waiting on %s (%s)\n", NAME, isvc, 207 str_error(rc)); 208 return; 209 } 210 211 /* Wait for the framebuffer service to be ready */ 212 rc = loc_service_get_id(fbsvc, &service_id, IPC_FLAG_BLOCKING); 213 if (rc != EOK) { 214 printf("%s: Error waiting on %s (%s)\n", NAME, fbsvc, 215 str_error(rc)); 216 return; 217 } 218 219 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, isvc, fbsvc, NULL); 220 if (rc != EOK) { 221 printf("%s: Error spawning %s %s %s (%s)\n", NAME, SRV_CONSOLE, 222 isvc, fbsvc, str_error(rc)); 215 223 } 216 224 } … … 253 261 static bool mount_tmpfs(void) 254 262 { 255 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0 );263 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0); 256 264 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT, 257 265 TMPFS_FS_TYPE, NULL, rc); … … 260 268 static bool mount_data(void) 261 269 { 262 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0 );270 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0, 0); 263 271 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE, 264 272 DATA_DEVICE, rc); … … 294 302 spawn("/srv/obio"); 295 303 srv_start("/srv/cuda_adb"); 296 srv_start("/srv/i8042");297 304 srv_start("/srv/s3c24ser"); 298 305 srv_start("/srv/s3c24ts"); 299 306 307 spawn("/srv/net"); 308 300 309 spawn("/srv/fb"); 301 310 spawn("/srv/input"); 302 console("hid/input" );311 console("hid/input", "hid/fb0"); 303 312 304 313 spawn("/srv/clip"); 314 spawn("/srv/remcons"); 305 315 306 316 /* -
uspace/app/klog/klog.c
rbd5f3b7 r00aece0 205 205 klog_length = size / sizeof(wchar_t); 206 206 207 klog = (wchar_t *) as_get_mappable_page(size); 208 if (klog == NULL) { 209 fprintf(stderr, "%s: Unable to allocate virtual memory area\n", 210 NAME); 211 return ENOMEM; 212 } 213 214 rc = physmem_map((void *) faddr, (void *) klog, pages, 215 AS_AREA_READ | AS_AREA_CACHEABLE); 207 rc = physmem_map((void *) faddr, pages, 208 AS_AREA_READ | AS_AREA_CACHEABLE, (void *) &klog); 216 209 if (rc != EOK) { 217 210 fprintf(stderr, "%s: Unable to map klog\n", NAME); -
uspace/app/locinfo/locinfo.c
rbd5f3b7 r00aece0 89 89 } 90 90 printf("\t%s (%" PRIun ")\n", svc_name, svc_ids[j]); 91 free(svc_name); 91 92 } 92 93 -
uspace/app/mkbd/main.c
rbd5f3b7 r00aece0 48 48 #include <usb/dev/pipes.h> 49 49 #include <async.h> 50 #include <usb/dev.h> 50 51 #include <usb/hid/usages/core.h> 51 52 #include <usb/hid/hidparser.h> … … 69 70 int rc = usb_hid_report_init(*report); 70 71 if (rc != EOK) { 71 usb_hid_ free_report(*report);72 usb_hid_report_deinit(*report); 72 73 *report = NULL; 73 74 return rc; … … 79 80 &report_desc_size); 80 81 if (rc != EOK) { 81 usb_hid_ free_report(*report);82 usb_hid_report_deinit(*report); 82 83 *report = NULL; 83 84 return rc; … … 85 86 86 87 if (report_desc_size == 0) { 87 usb_hid_ free_report(*report);88 usb_hid_report_deinit(*report); 88 89 *report = NULL; 89 90 // TODO: other error code? … … 93 94 uint8_t *desc = (uint8_t *) malloc(report_desc_size); 94 95 if (desc == NULL) { 95 usb_hid_ free_report(*report);96 usb_hid_report_deinit(*report); 96 97 *report = NULL; 97 98 return ENOMEM; … … 103 104 &actual_size); 104 105 if (rc != EOK) { 105 usb_hid_ free_report(*report);106 usb_hid_report_deinit(*report); 106 107 *report = NULL; 107 108 free(desc); … … 110 111 111 112 if (actual_size != report_desc_size) { 112 usb_hid_ free_report(*report);113 usb_hid_report_deinit(*report); 113 114 *report = NULL; 114 115 free(desc); -
uspace/app/mkfat/fat.h
rbd5f3b7 r00aece0 38 38 #define BS_BLOCK 0 39 39 #define BS_SIZE 512 40 #define DIRENT_SIZE 32 40 41 41 #define DIRENT_SIZE 32 42 #define FAT12_CLST_MAX 4085 43 #define FAT16_CLST_MAX 65525 44 45 #define FAT12 12 46 #define FAT16 16 47 #define FAT32 32 48 49 #define FAT_CLUSTER_DOUBLE_SIZE(a) ((a) / 4) 42 50 43 51 typedef struct fat_bs { -
uspace/app/mkfat/mkfat.c
rbd5f3b7 r00aece0 35 35 * @brief Tool for creating new FAT file systems. 36 36 * 37 * Currently we can only create 16-bit FAT.37 * Currently we can create 12/16/32-bit FAT. 38 38 */ 39 39 … … 55 55 #define div_round_up(a, b) (((a) + (b) - 1) / (b)) 56 56 57 /** Predefinedfile-system parameters */57 /** Default file-system parameters */ 58 58 enum { 59 sector_size = 512,60 sectors_per_cluster = 8,61 fat_count = 2,62 reserved_clusters = 2,63 media_descriptor = 0xF8 /**< fixed disk */59 default_sector_size = 512, 60 default_sectors_per_cluster = 4, 61 default_fat_count = 2, 62 default_reserved_clusters = 2, 63 default_media_descriptor = 0xF8 /**< fixed disk */ 64 64 }; 65 65 66 66 /** Configurable file-system parameters */ 67 67 typedef struct fat_cfg { 68 int fat_type; /* FAT12 = 12, FAT16 = 16, FAT32 = 32 */ 69 size_t sector_size; 68 70 uint32_t total_sectors; 69 71 uint16_t root_ent_max; 70 uint16_t addt_res_sectors; 72 uint32_t addt_res_sectors; 73 uint8_t sectors_per_cluster; 74 75 uint16_t reserved_sectors; 76 uint32_t rootdir_sectors; 77 uint32_t fat_sectors; 78 uint32_t total_clusters; 79 uint8_t fat_count; 71 80 } fat_cfg_t; 72 81 73 /** Derived file-system parameters */74 typedef struct fat_params {75 struct fat_cfg cfg;76 uint16_t reserved_sectors;77 uint16_t rootdir_sectors;78 uint32_t fat_sectors;79 uint16_t total_clusters;80 } fat_params_t;81 82 82 static void syntax_print(void); 83 83 84 static int fat_params_compute(struct fat_cfg const *cfg, 85 struct fat_params *par); 86 static int fat_blocks_write(struct fat_params const *par, 87 service_id_t service_id); 88 static void fat_bootsec_create(struct fat_params const *par, struct fat_bs *bs); 84 static int fat_params_compute(struct fat_cfg *cfg); 85 static int fat_blocks_write(struct fat_cfg const *cfg, service_id_t service_id); 86 static void fat_bootsec_create(struct fat_cfg const *cfg, struct fat_bs *bs); 89 87 90 88 int main(int argc, char **argv) 91 89 { 92 struct fat_params par;93 90 struct fat_cfg cfg; 94 91 … … 96 93 char *dev_path; 97 94 service_id_t service_id; 98 size_t block_size;99 95 char *endptr; 100 96 aoff64_t dev_nblocks; 101 97 98 cfg.sector_size = default_sector_size; 99 cfg.sectors_per_cluster = default_sectors_per_cluster; 100 cfg.fat_count = default_fat_count; 102 101 cfg.total_sectors = 0; 103 102 cfg.addt_res_sectors = 0; 104 103 cfg.root_ent_max = 128; 104 cfg.fat_type = FAT16; 105 105 106 106 if (argc < 2) { … … 111 111 112 112 --argc; ++argv; 113 114 113 if (str_cmp(*argv, "--size") == 0) { 115 114 --argc; ++argv; … … 130 129 } 131 130 131 if (str_cmp(*argv, "--type") == 0) { 132 --argc; ++argv; 133 if (*argv == NULL) { 134 printf(NAME ": Error, argument missing.\n"); 135 syntax_print(); 136 return 1; 137 } 138 139 cfg.fat_type = strtol(*argv, &endptr, 10); 140 if (*endptr != '\0') { 141 printf(NAME ": Error, invalid argument.\n"); 142 syntax_print(); 143 return 1; 144 } 145 146 --argc; ++argv; 147 } 148 132 149 if (argc != 1) { 133 150 printf(NAME ": Error, unexpected argument.\n"); … … 137 154 138 155 dev_path = *argv; 156 printf("Device: %s\n", dev_path); 139 157 140 158 rc = loc_service_get_id(dev_path, &service_id, 0); … … 150 168 } 151 169 152 rc = block_get_bsize(service_id, & block_size);170 rc = block_get_bsize(service_id, &cfg.sector_size); 153 171 if (rc != EOK) { 154 172 printf(NAME ": Error determining device block size.\n"); … … 162 180 printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n", 163 181 dev_nblocks); 164 cfg.total_sectors = dev_nblocks; 165 } 166 167 if (block_size != 512) { 168 printf(NAME ": Error. Device block size is not 512 bytes.\n"); 169 return 2; 182 if (!cfg.total_sectors || dev_nblocks < cfg.total_sectors) 183 cfg.total_sectors = dev_nblocks; 170 184 } 171 185 … … 175 189 } 176 190 177 printf(NAME ": Creating FAT filesystem on device %s.\n", dev_path); 178 179 rc = fat_params_compute(&cfg, &par); 191 if (cfg.fat_type != FAT12 && cfg.fat_type != FAT16 && cfg.fat_type != FAT32) { 192 printf(NAME ": Error. Unknown FAT type.\n"); 193 return 2; 194 } 195 196 printf(NAME ": Creating FAT%d filesystem on device %s.\n", cfg.fat_type, dev_path); 197 198 rc = fat_params_compute(&cfg); 180 199 if (rc != EOK) { 181 200 printf(NAME ": Invalid file-system parameters.\n"); … … 183 202 } 184 203 185 rc = fat_blocks_write(& par, service_id);204 rc = fat_blocks_write(&cfg, service_id); 186 205 if (rc != EOK) { 187 206 printf(NAME ": Error writing device.\n"); … … 197 216 static void syntax_print(void) 198 217 { 199 printf("syntax: mkfat [--size < num_blocks>] <device_name>\n");218 printf("syntax: mkfat [--size <sectors>] [--type 12|16|32] <device_name>\n"); 200 219 } 201 220 … … 205 224 * file system params. 206 225 */ 207 static int fat_params_compute(struct fat_cfg const *cfg, struct fat_params *par)226 static int fat_params_compute(struct fat_cfg *cfg) 208 227 { 209 228 uint32_t fat_bytes; … … 211 230 212 231 /* 213 * Make a conservative guess on the FAT size needed for the file 214 * system. The optimum could be potentially smaller since we 215 * do not subtract size of the FAT itself when computing the 216 * size of the data region. 217 */ 218 219 par->reserved_sectors = 1 + cfg->addt_res_sectors; 220 par->rootdir_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE, 221 sector_size); 222 non_data_sectors_lb = par->reserved_sectors + par->rootdir_sectors; 223 224 par->total_clusters = div_round_up(cfg->total_sectors - non_data_sectors_lb, 225 sectors_per_cluster); 226 227 fat_bytes = (par->total_clusters + 2) * 2; 228 par->fat_sectors = div_round_up(fat_bytes, sector_size); 229 230 par->cfg = *cfg; 232 * Make a conservative guess on the FAT size needed for the file 233 * system. The optimum could be potentially smaller since we 234 * do not subtract size of the FAT itself when computing the 235 * size of the data region. 236 */ 237 238 cfg->reserved_sectors = 1 + cfg->addt_res_sectors; 239 if (cfg->fat_type != FAT32) { 240 cfg->rootdir_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE, 241 cfg->sector_size); 242 } else 243 cfg->rootdir_sectors = 0; 244 non_data_sectors_lb = cfg->reserved_sectors + cfg->rootdir_sectors; 245 246 cfg->total_clusters = div_round_up(cfg->total_sectors - non_data_sectors_lb, 247 cfg->sectors_per_cluster); 248 249 if ((cfg->fat_type == FAT12 && cfg->total_clusters > FAT12_CLST_MAX) || 250 (cfg->fat_type == FAT16 && (cfg->total_clusters <= FAT12_CLST_MAX || 251 cfg->total_clusters > FAT16_CLST_MAX)) || 252 (cfg->fat_type == FAT32 && cfg->total_clusters <= FAT16_CLST_MAX)) 253 return ENOSPC; 254 255 fat_bytes = div_round_up((cfg->total_clusters + 2) * 256 FAT_CLUSTER_DOUBLE_SIZE(cfg->fat_type), 2); 257 cfg->fat_sectors = div_round_up(fat_bytes, cfg->sector_size); 231 258 232 259 return EOK; … … 234 261 235 262 /** Create file system with the given parameters. */ 236 static int fat_blocks_write(struct fat_ params const *par, service_id_t service_id)263 static int fat_blocks_write(struct fat_cfg const *cfg, service_id_t service_id) 237 264 { 238 265 aoff64_t addr; … … 243 270 struct fat_bs bs; 244 271 245 fat_bootsec_create( par, &bs);272 fat_bootsec_create(cfg, &bs); 246 273 247 274 rc = block_write_direct(service_id, BS_BLOCK, 1, &bs); … … 251 278 addr = BS_BLOCK + 1; 252 279 253 buffer = calloc( sector_size, 1);280 buffer = calloc(cfg->sector_size, 1); 254 281 if (buffer == NULL) 255 282 return ENOMEM; 283 memset(buffer, 0, cfg->sector_size); 256 284 257 285 /* Reserved sectors */ 258 for (i = 0; i < par->reserved_sectors - 1; ++i) {286 for (i = 0; i < cfg->reserved_sectors - 1; ++i) { 259 287 rc = block_write_direct(service_id, addr, 1, buffer); 260 288 if (rc != EOK) … … 265 293 266 294 /* File allocation tables */ 267 for (i = 0; i < fat_count; ++i) {295 for (i = 0; i < cfg->fat_count; ++i) { 268 296 printf("Writing allocation table %d.\n", i + 1); 269 297 270 for (j = 0; j < par->fat_sectors; ++j) {271 memset(buffer, 0, sector_size);298 for (j = 0; j < cfg->fat_sectors; ++j) { 299 memset(buffer, 0, cfg->sector_size); 272 300 if (j == 0) { 273 buffer[0] = media_descriptor;301 buffer[0] = default_media_descriptor; 274 302 buffer[1] = 0xFF; 275 303 buffer[2] = 0xFF; 276 buffer[3] = 0xFF; 304 if (cfg->fat_type == FAT16) { 305 buffer[3] = 0xFF; 306 } else if (cfg->fat_type == FAT32) { 307 buffer[3] = 0x0F; 308 buffer[4] = 0xFF; 309 buffer[5] = 0xFF; 310 buffer[6] = 0xFF; 311 buffer[7] = 0x0F; 312 buffer[8] = 0xF8; 313 buffer[9] = 0xFF; 314 buffer[10] = 0xFF; 315 buffer[11] = 0x0F; 316 } 277 317 } 278 318 … … 285 325 } 286 326 327 /* Root directory */ 287 328 printf("Writing root directory.\n"); 288 289 memset(buffer, 0, sector_size); 290 291 /* Root directory */ 292 for (i = 0; i < par->rootdir_sectors; ++i) { 293 rc = block_write_direct(service_id, addr, 1, buffer); 294 if (rc != EOK) 295 return EIO; 296 297 ++addr; 329 memset(buffer, 0, cfg->sector_size); 330 if (cfg->fat_type != FAT32) { 331 size_t idx; 332 for (idx = 0; idx < cfg->rootdir_sectors; ++idx) { 333 rc = block_write_direct(service_id, addr, 1, buffer); 334 if (rc != EOK) 335 return EIO; 336 337 ++addr; 338 } 339 } else { 340 for (i = 0; i < cfg->sectors_per_cluster; i++) { 341 rc = block_write_direct(service_id, addr, 1, buffer); 342 if (rc != EOK) 343 return EIO; 344 345 ++addr; 346 } 298 347 } 299 348 … … 304 353 305 354 /** Construct boot sector with the given parameters. */ 306 static void fat_bootsec_create(struct fat_ params const *par, struct fat_bs *bs)355 static void fat_bootsec_create(struct fat_cfg const *cfg, struct fat_bs *bs) 307 356 { 308 357 memset(bs, 0, sizeof(*bs)); … … 315 364 316 365 /* BIOS Parameter Block */ 317 bs->bps = host2uint16_t_le(sector_size); 318 bs->spc = sectors_per_cluster; 319 bs->rscnt = host2uint16_t_le(par->reserved_sectors); 320 bs->fatcnt = fat_count; 321 bs->root_ent_max = host2uint16_t_le(par->cfg.root_ent_max); 322 323 if (par->cfg.total_sectors < 0x10000) 324 bs->totsec16 = host2uint16_t_le(par->cfg.total_sectors); 325 else 326 bs->totsec16 = host2uint16_t_le(0); 327 328 bs->mdesc = media_descriptor; 329 bs->sec_per_fat = host2uint16_t_le(par->fat_sectors); 366 bs->bps = host2uint16_t_le(cfg->sector_size); 367 bs->spc = cfg->sectors_per_cluster; 368 bs->rscnt = host2uint16_t_le(cfg->reserved_sectors); 369 bs->fatcnt = cfg->fat_count; 370 bs->root_ent_max = host2uint16_t_le(cfg->root_ent_max); 371 372 if (cfg->total_sectors < 0x10000) { 373 bs->totsec16 = host2uint16_t_le(cfg->total_sectors); 374 bs->totsec32 = 0; 375 } else { 376 bs->totsec16 = 0; 377 bs->totsec32 = host2uint32_t_le(cfg->total_sectors); 378 } 379 380 bs->mdesc = default_media_descriptor; 330 381 bs->sec_per_track = host2uint16_t_le(63); 382 bs->signature = host2uint16_t_be(0x55AA); 331 383 bs->headcnt = host2uint16_t_le(6); 332 384 bs->hidden_sec = host2uint32_t_le(0); 333 385 334 if (par->cfg.total_sectors >= 0x10000) 335 bs->totsec32 = host2uint32_t_le(par->cfg.total_sectors); 336 else 337 bs->totsec32 = host2uint32_t_le(0); 338 339 /* Extended BPB */ 340 bs->pdn = 0x80; 341 bs->ebs = 0x29; 342 bs->id = host2uint32_t_be(0x12345678); 343 344 memcpy(bs->label, "HELENOS_NEW", 11); 345 memcpy(bs->type, "FAT16 ", 8); 346 bs->signature = host2uint16_t_be(0x55AA); 386 if (cfg->fat_type == FAT32) { 387 bs->sec_per_fat = 0; 388 bs->fat32.sectors_per_fat = host2uint32_t_le(cfg->fat_sectors); 389 390 bs->fat32.pdn = 0x80; 391 bs->fat32.ebs = 0x29; 392 bs->fat32.id = host2uint32_t_be(0x12345678); 393 bs->fat32.root_cluster = 2; 394 395 memcpy(bs->fat32.label, "HELENOS_NEW", 11); 396 memcpy(bs->fat32.type, "FAT32 ", 8); 397 } else { 398 bs->sec_per_fat = host2uint16_t_le(cfg->fat_sectors); 399 bs->pdn = 0x80; 400 bs->ebs = 0x29; 401 bs->id = host2uint32_t_be(0x12345678); 402 403 memcpy(bs->label, "HELENOS_NEW", 11); 404 memcpy(bs->type, "FAT ", 8); 405 } 347 406 } 348 407 -
uspace/app/mkmfs/Makefile
rbd5f3b7 r00aece0 29 29 30 30 USPACE_PREFIX = ../.. 31 EXTRA_CFLAGS = -Iinclude 32 LIBRARY = libpacket 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a 32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBMINIX_PREFIX) 33 BINARY = mkmfs 33 34 34 35 SOURCES = \ 35 generic/packet_server.c36 mkmfs.c 36 37 37 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/netecho/netecho.c
rbd5f3b7 r00aece0 241 241 /* Accept a socket if a stream socket is used */ 242 242 addrlen = sizeof(address_buf); 243 if (verbose) 244 printf("accept()\n"); 243 245 socket_id = accept(listening_id, (void *) address_buf, &addrlen); 244 246 if (socket_id <= 0) { … … 258 260 259 261 /* Receive a message to echo */ 262 if (verbose) 263 printf("recvfrom()\n"); 260 264 rcv_size = recvfrom(socket_id, data, size, 0, address, 261 265 &addrlen); … … 297 301 298 302 /* Answer the request either with the static reply or the original data */ 299 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 300 if (rc != EOK) 301 socket_print_error(stderr, rc, "Socket send: ", "\n"); 303 if (type == SOCK_STREAM) { 304 if (verbose) 305 printf("send()\n"); 306 rc = send(socket_id, reply ? reply : data, reply ? reply_length : length, 0); 307 if (rc != EOK) 308 socket_print_error(stderr, rc, "Socket send: ", "\n"); 309 } else { 310 if (verbose) 311 printf("sendto()\n"); 312 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 313 if (rc != EOK) 314 socket_print_error(stderr, rc, "Socket send: ", "\n"); 315 } 302 316 } 303 317 -
uspace/app/pcc/cc/cc/Makefile
rbd5f3b7 r00aece0 1 1 # 2 # Copyright (c) 2011 Vojtech Horky2 # Copyright (c) 2011 Jiri Zarevucky 3 3 # All rights reserved. 4 4 # … … 28 28 29 29 USPACE_PREFIX = ../../../.. 30 MIPDIR = ../../mip 31 ARCHDIR = ../../arch/$(PLATFORM) 32 OSDIR = ../../os/helenos 33 EXTRA_CFLAGS = -I$(MIPDIR) -I$(ARCHDIR) -I$(OSDIR) -w 34 DEFS = -Dmach_$(PLATFORM) -D__helenos__ 35 BINARY = cc 30 36 31 LIBS = \ 32 $(LIBUSBHID_PREFIX)/libusbhid.a \ 33 $(LIBUSBDEV_PREFIX)/libusbdev.a \ 34 $(LIBUSB_PREFIX)/libusb.a \ 35 $(LIBDRV_PREFIX)/libdrv.a 37 PRE_DEPEND = compat.c 38 EXTRA_CLEAN = compat.c 36 39 37 EXTRA_CFLAGS += \ 38 -I$(LIBUSB_PREFIX)/include \ 39 -I$(LIBUSBDEV_PREFIX)/include \ 40 -I$(LIBUSBHID_PREFIX)/include \ 41 -I$(LIBDRV_PREFIX)/include 42 43 BINARY = usbmouse 40 POSIX_COMPAT = y 44 41 45 42 SOURCES = \ 46 init.c \ 47 main.c \ 48 mouse.c 43 cc.c \ 44 compat.c 49 45 50 46 include $(USPACE_PREFIX)/Makefile.common 47 48 compat.c: $(MIPDIR)/compat.c 49 ln -s -f $^ $@ 50 -
uspace/app/sysinfo/sysinfo.c
rbd5f3b7 r00aece0 51 51 int rc; 52 52 char *ipath; 53 sysinfo_item_ tag_t tag;53 sysinfo_item_val_type_t tag; 54 54 55 55 if (argc != 2) { … … 60 60 ipath = argv[1]; 61 61 62 tag = sysinfo_get_ tag(ipath);62 tag = sysinfo_get_val_type(ipath); 63 63 64 64 /* Silence warning */ … … 75 75 case SYSINFO_VAL_DATA: 76 76 rc = print_item_data(ipath); 77 break; 78 default: 79 printf("Error: Sysinfo item '%s' with unknown value type.\n", 80 ipath); 81 rc = 2; 77 82 break; 78 83 } -
uspace/app/tester/console/console1.c
rbd5f3b7 r00aece0 76 76 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { 77 77 console_flush(console); 78 console_set_color(console, i, COLOR_WHITE,78 console_set_color(console, COLOR_WHITE, i, 79 79 j ? CATTR_BRIGHT : 0); 80 80 printf(" %s ", color_name[i]); … … 89 89 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { 90 90 console_flush(console); 91 console_set_color(console, COLOR_WHITE, i,91 console_set_color(console, i, COLOR_WHITE, 92 92 j ? CATTR_BRIGHT : 0); 93 93 printf(" %s ", color_name[i]); … … 102 102 for (i = 0; i < 255; i += 16) { 103 103 console_flush(console); 104 console_set_rgb_color(console, (255 - i) << 16, i<< 16);104 console_set_rgb_color(console, i << 16, (255 - i) << 16); 105 105 putchar('X'); 106 106 } 107 107 console_flush(console); 108 console_set_color(console, COLOR_ BLACK, COLOR_WHITE, 0);108 console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0); 109 109 putchar('\n'); 110 110 111 111 for (i = 0; i < 255; i += 16) { 112 112 console_flush(console); 113 console_set_rgb_color(console, (255 - i) << 8, i<< 8);113 console_set_rgb_color(console, i << 8, (255 - i) << 8); 114 114 putchar('X'); 115 115 } 116 116 console_flush(console); 117 console_set_color(console, COLOR_ BLACK, COLOR_WHITE, 0);117 console_set_color(console, COLOR_WHITE, COLOR_BLACK, 0); 118 118 putchar('\n'); 119 119 120 120 for (i = 0; i < 255; i += 16) { 121 121 console_flush(console); 122 console_set_rgb_color(console, 255 - i,i);122 console_set_rgb_color(console, i, 255 - i); 123 123 putchar('X'); 124 124 } -
uspace/app/tester/mm/common.c
rbd5f3b7 r00aece0 342 342 link_initialize(&area->link); 343 343 344 /* Map the memory area */345 void *addr = as_get_mappable_page(size);346 if (a ddr == NULL) {344 area->addr = as_area_create((void *) -1, size, 345 AS_AREA_WRITE | AS_AREA_READ); 346 if (area->addr == (void *) -1) { 347 347 free(area); 348 348 check_consistency("map_area (a)"); 349 return NULL;350 }351 352 area->addr = as_area_create(addr, size, AS_AREA_WRITE | AS_AREA_READ);353 if (area->addr == (void *) -1) {354 free(area);355 check_consistency("map_area (b)");356 349 return NULL; 357 350 } -
uspace/app/tester/mm/mapping1.c
rbd5f3b7 r00aece0 35 35 #include "../tester.h" 36 36 37 #define BUFFER1_PAGES 438 #define BUFFER2_PAGES 237 #define BUFFER1_PAGES 4 38 #define BUFFER2_PAGES 2 39 39 40 40 static void *create_as_area(size_t size) 41 41 { 42 void *result = as_get_mappable_page(size);43 42 TPRINTF("Creating AS area...\n"); 44 if (as_area_create(result, size, 45 AS_AREA_READ | AS_AREA_WRITE) != result) { 43 44 void *result = as_area_create((void *) -1, size, 45 AS_AREA_READ | AS_AREA_WRITE); 46 if (result == (void *) -1) 46 47 return NULL; 47 }48 48 49 return result; 49 50 } … … 71 72 int i; 72 73 for (i = 0; i < page_count; i++) { 73 void *page_start = ((char *) area) + PAGE_SIZE * i;74 void *page_start = ((char *) area) + PAGE_SIZE * i; 74 75 int rc = as_get_physical_mapping(page_start, NULL); 75 76 if (rc != expected_rc) { -
uspace/app/tester/print/print2.c
rbd5f3b7 r00aece0 45 45 TPRINTF("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); 46 46 47 TPRINTF("Testing printf(\"%%lld %%3.2lld %%-3.2lld %%2.3lld %%-2.3lld\", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5):\n"); 48 TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); 49 TPRINTF("Real output: [%lld] [%3.2lld] [%-3.2lld] [%2.3lld] [%-2.3lld]\n\n", (long long) -1, (long long) -2, (long long) -3, (long long) -4, (long long) -5); 50 47 51 TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); 48 52 TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); -
uspace/app/tetris/screen.c
rbd5f3b7 r00aece0 95 95 { 96 96 console_flush(console); 97 console_set_rgb_color(console, 0xffffff,98 use_color ? color : 0x000000);97 console_set_rgb_color(console, use_color ? color : 0x000000, 98 0xffffff); 99 99 } 100 100 … … 153 153 return false; 154 154 155 return ( ccap >= CONSOLE_CCAP_RGB);155 return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB); 156 156 } 157 157 -
uspace/app/tetris/shapes.c
rbd5f3b7 r00aece0 69 69 70 70 const struct shape shapes[] = { 71 /* 0 */ { 7, 7, { TL, TC, MR }, 0x ff042d},72 /* 1 */ { 8, 8, { TC, TR, ML }, 0x ff9304},73 /* 2 */ { 9, 11, { ML, MR, BC }, 0x beff04},74 /* 3 */ { 3, 3, { TL, TC, ML }, 0x 63ff04},75 /* 4 */ { 12, 14, { ML, BL, MR }, 0x ce04ff},76 /* 5 */ { 15, 17, { ML, BR, MR }, 0xff 04cf},77 /* 6 */ { 18, 18, { ML, MR, 2 }, 0x 7604ff}, /* sticks out */78 /* 7 */ { 0, 0, { TC, ML, BL }, 0x ff042d},79 /* 8 */ { 1, 1, { TC, MR, BR }, 0x ff9304},80 /* 9 */ { 10, 2, { TC, MR, BC }, 0x beff04},81 /* 10 */ { 11, 9, { TC, ML, MR }, 0x beff04},82 /* 11 */ { 2, 10, { TC, ML, BC }, 0x beff04},83 /* 12 */ { 13, 4, { TC, BC, BR }, 0x ce04ff},84 /* 13 */ { 14, 12, { TR, ML, MR }, 0x ce04ff},85 /* 14 */ { 4, 13, { TL, TC, BC }, 0x ce04ff},86 /* 15 */ { 16, 5, { TR, TC, BC }, 0xff 04cf},87 /* 16 */ { 17, 15, { TL, MR, ML }, 0xff 04cf},88 /* 17 */ { 5, 16, { TC, BC, BL }, 0xff 04cf},89 /* 18 */ { 6, 6, { TC, BC, 2 * B_COLS }, 0x 7604ff} /* sticks out */71 /* 0 */ { 7, 7, { TL, TC, MR }, 0x00aaaa}, 72 /* 1 */ { 8, 8, { TC, TR, ML }, 0x00aa00}, 73 /* 2 */ { 9, 11, { ML, MR, BC }, 0xaa5500}, 74 /* 3 */ { 3, 3, { TL, TC, ML }, 0x0000aa}, 75 /* 4 */ { 12, 14, { ML, BL, MR }, 0xaa00aa}, 76 /* 5 */ { 15, 17, { ML, BR, MR }, 0xffa500}, 77 /* 6 */ { 18, 18, { ML, MR, 2 }, 0xaa0000}, /* sticks out */ 78 /* 7 */ { 0, 0, { TC, ML, BL }, 0x00aaaa}, 79 /* 8 */ { 1, 1, { TC, MR, BR }, 0x00aa00}, 80 /* 9 */ { 10, 2, { TC, MR, BC }, 0xaa5500}, 81 /* 10 */ { 11, 9, { TC, ML, MR }, 0xaa5500}, 82 /* 11 */ { 2, 10, { TC, ML, BC }, 0xaa5500}, 83 /* 12 */ { 13, 4, { TC, BC, BR }, 0xaa00aa}, 84 /* 13 */ { 14, 12, { TR, ML, MR }, 0xaa00aa}, 85 /* 14 */ { 4, 13, { TL, TC, BC }, 0xaa00aa}, 86 /* 15 */ { 16, 5, { TR, TC, BC }, 0xffa500}, 87 /* 16 */ { 17, 15, { TL, MR, ML }, 0xffa500}, 88 /* 17 */ { 5, 16, { TC, BC, BL }, 0xffa500}, 89 /* 18 */ { 6, 6, { TC, BC, 2 * B_COLS }, 0xaa0000} /* sticks out */ 90 90 }; 91 91 -
uspace/app/tetris/tetris.c
rbd5f3b7 r00aece0 291 291 for (j = i + 1; j <= 5; j++) { 292 292 if (keys[i] == keys[j]) 293 errx(1, " duplicate command keys specified.");293 errx(1, "%s", "duplicate command keys specified."); 294 294 } 295 295 -
uspace/app/trace/syscalls.c
rbd5f3b7 r00aece0 72 72 [SYS_PHYSMEM_MAP] = { "physmem_map", 4, V_ERRNO }, 73 73 [SYS_IOSPACE_ENABLE] = { "iospace_enable", 1, V_ERRNO }, 74 [SYS_ REGISTER_IRQ] = { "register_irq", 4, V_ERRNO },75 [SYS_ UNREGISTER_IRQ] = { "unregister_irq", 2, V_ERRNO },74 [SYS_IRQ_REGISTER] = { "irq_register", 4, V_ERRNO }, 75 [SYS_IRQ_UNREGISTER] = { "irq_unregister", 2, V_ERRNO }, 76 76 77 [SYS_SYSINFO_GET_ TAG] = { "sysinfo_get_tag", 2, V_INTEGER },77 [SYS_SYSINFO_GET_VAL_TYPE] = { "sysinfo_get_val_type", 2, V_INTEGER }, 78 78 [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value", 3, V_ERRNO }, 79 79 [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size", 3, V_ERRNO }, -
uspace/app/trace/trace.c
rbd5f3b7 r00aece0 86 86 void thread_trace_start(uintptr_t thread_hash); 87 87 88 static proto_t *proto_console;89 88 static task_id_t task_id; 90 89 static loader_t *task_ldr; … … 624 623 error: 625 624 loader_abort(ldr); 626 free(ldr);627 625 return NULL; 628 626 } … … 659 657 ipcp_init(); 660 658 661 /*662 * User apps now typically have console on phone 3.663 * (Phones 1 and 2 are used by the loader).664 */665 ipcp_connection_set(3, 0, proto_console);666 667 659 rc = get_thread_list(); 668 660 if (rc < 0) { … … 714 706 fibril_mutex_unlock(&state_lock); 715 707 printf("Resume...\n"); 708 break; 709 default: 716 710 break; 717 711 } … … 790 784 791 785 proto_register(SERVICE_VFS, p); 792 793 #if 0794 p = proto_new("console");795 796 o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);797 proto_add_oper(p, VFS_IN_WRITE, o);798 799 resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;800 resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR;801 o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def);802 803 arg_def[0] = V_CHAR;804 o = oper_new("clear", 0, arg_def, V_VOID, 0, resp_def);805 proto_add_oper(p, CONSOLE_CLEAR, o);806 807 arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;808 o = oper_new("goto", 2, arg_def, V_VOID, 0, resp_def);809 proto_add_oper(p, CONSOLE_GOTO, o);810 811 resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER;812 o = oper_new("getsize", 0, arg_def, V_INTEGER, 2, resp_def);813 proto_add_oper(p, CONSOLE_GET_SIZE, o);814 815 arg_def[0] = V_INTEGER;816 o = oper_new("set_style", 1, arg_def, V_VOID, 0, resp_def);817 proto_add_oper(p, CONSOLE_SET_STYLE, o);818 arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER; arg_def[2] = V_INTEGER;819 o = oper_new("set_color", 3, arg_def, V_VOID, 0, resp_def);820 proto_add_oper(p, CONSOLE_SET_COLOR, o);821 arg_def[0] = V_INTEGER; arg_def[1] = V_INTEGER;822 o = oper_new("set_rgb_color", 2, arg_def, V_VOID, 0, resp_def);823 proto_add_oper(p, CONSOLE_SET_RGB_COLOR, o);824 o = oper_new("cursor_visibility", 1, arg_def, V_VOID, 0, resp_def);825 proto_add_oper(p, CONSOLE_CURSOR_VISIBILITY, o);826 827 proto_console = p;828 proto_register(SERVICE_CONSOLE, p);829 #endif830 786 } 831 787 -
uspace/app/usbinfo/desctree.c
rbd5f3b7 r00aece0 50 50 51 51 static void browse_descriptor_tree_internal(usb_dp_parser_t *parser, 52 usb_dp_parser_data_t *data, uint8_t *root, size_t depth,52 usb_dp_parser_data_t *data, const uint8_t *root, size_t depth, 53 53 dump_descriptor_in_tree_t callback, void *arg) 54 54 { … … 57 57 } 58 58 callback(root, depth, arg); 59 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);59 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 60 60 do { 61 61 browse_descriptor_tree_internal(parser, data, child, depth + 1, -
uspace/app/usbinfo/dev.c
rbd5f3b7 r00aece0 34 34 * Representation of queried device. 35 35 */ 36 #include <usb/dev/pipes.h> 36 #include <usb/dev.h> 37 #include <usb/hc.h> 37 38 #include <errno.h> 38 39 #include <str_error.h> … … 52 53 bool transfer_started = false; 53 54 54 rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr); 55 usb_hc_connection_initialize(&dev->hc_conn, hc_handle); 56 57 rc = usb_device_connection_initialize( 58 &dev->wire, &dev->hc_conn, dev_addr); 55 59 if (rc != EOK) { 56 60 fprintf(stderr, -
uspace/app/usbinfo/dump.c
rbd5f3b7 r00aece0 110 110 } 111 111 112 static void dump_tree_descriptor( uint8_t *descriptor, size_t depth)112 static void dump_tree_descriptor(const uint8_t *descriptor, size_t depth) 113 113 { 114 114 if (descriptor == NULL) { 115 115 return; 116 116 } 117 int type = (int) *(descriptor + 1);117 int type = descriptor[1]; 118 118 const char *name = "unknown"; 119 119 switch (type) { … … 136 136 } 137 137 138 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 139 uint8_t *root, size_t depth) 138 static void dump_tree_internal( 139 usb_dp_parser_t *parser, usb_dp_parser_data_t *data, 140 const uint8_t *root, size_t depth) 140 141 { 141 142 if (root == NULL) { … … 143 144 } 144 145 dump_tree_descriptor(root, depth); 145 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);146 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 146 147 do { 147 148 dump_tree_internal(parser, data, child, depth + 1); … … 152 153 static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data) 153 154 { 154 uint8_t *ptr = data->data;155 const uint8_t *ptr = data->data; 155 156 printf("Descriptor tree:\n"); 156 157 dump_tree_internal(parser, data, ptr, 0); -
uspace/app/usbinfo/hid.c
rbd5f3b7 r00aece0 55 55 } descriptor_walk_context_t; 56 56 57 static bool is_descriptor_kind( uint8_t *d, usb_descriptor_type_t t)57 static bool is_descriptor_kind(const uint8_t *d, usb_descriptor_type_t t) 58 58 { 59 59 if (d == NULL) { … … 167 167 168 168 free(raw_report); 169 usb_hid_ free_report(&report);169 usb_hid_report_deinit(&report); 170 170 } 171 171 … … 180 180 * @param arg Custom argument, passed as descriptor_walk_context_t. 181 181 */ 182 static void descriptor_walk_callback( uint8_t *raw_descriptor,182 static void descriptor_walk_callback(const uint8_t *raw_descriptor, 183 183 size_t depth, void *arg) 184 184 { -
uspace/app/usbinfo/info.c
rbd5f3b7 r00aece0 51 51 } 52 52 53 static void dump_match_ids_from_interface( uint8_t *descriptor, size_t depth,54 void *arg)53 static void dump_match_ids_from_interface( 54 const uint8_t *descriptor, size_t depth, void *arg) 55 55 { 56 56 if (depth != 1) { … … 165 165 166 166 167 static void dump_descriptor_tree_callback( uint8_t *descriptor,168 size_t depth, void *arg)167 static void dump_descriptor_tree_callback( 168 const uint8_t *descriptor, size_t depth, void *arg) 169 169 { 170 170 const char *indent = get_indent(depth + 1); … … 246 246 } 247 247 248 static void find_string_indexes_callback( uint8_t *descriptor,249 size_t depth, void *arg)248 static void find_string_indexes_callback( 249 const uint8_t *descriptor, size_t depth, void *arg) 250 250 { 251 251 size_t descriptor_length = descriptor[0]; … … 287 287 void dump_strings(usbinfo_device_t *dev) 288 288 { 289 /* Find used indexes. Devices with more than 64 strings are very rare.*/ 290 uint64_t str_mask = 0; 291 find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0, 292 &str_mask); 293 usb_dp_walk_simple(dev->full_configuration_descriptor, 294 dev->full_configuration_descriptor_size, 295 usb_dp_standard_descriptor_nesting, 296 find_string_indexes_callback, 297 &str_mask); 298 299 if (str_mask == 0) { 300 printf("Device does not support string descriptors.\n"); 301 return; 302 } 303 289 304 /* Get supported languages. */ 290 305 l18_win_locales_t *langs; … … 305 320 } 306 321 printf(".\n"); 307 308 /* Find used indexes. Device with more than 64 strings are very rare.309 */310 uint64_t str_mask = 0;311 find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,312 &str_mask);313 usb_dp_walk_simple(dev->full_configuration_descriptor,314 dev->full_configuration_descriptor_size,315 usb_dp_standard_descriptor_nesting,316 find_string_indexes_callback,317 &str_mask);318 322 319 323 /* Get all strings and dump them. */ -
uspace/app/usbinfo/main.c
rbd5f3b7 r00aece0 44 44 #include <loc.h> 45 45 #include <usb/hc.h> 46 #include <usb/dev.h> 46 47 #include <usb/dev/pipes.h> 47 48 #include "usbinfo.h" -
uspace/app/usbinfo/usbinfo.h
rbd5f3b7 r00aece0 44 44 45 45 typedef struct { 46 usb_hc_connection_t hc_conn; 47 usb_device_connection_t wire; 46 48 usb_pipe_t ctrl_pipe; 47 usb_device_connection_t wire;48 49 usb_standard_device_descriptor_t device_descriptor; 49 50 uint8_t *full_configuration_descriptor; … … 74 75 void destroy_device(usbinfo_device_t *); 75 76 76 typedef void (*dump_descriptor_in_tree_t)( uint8_t *, size_t, void *);77 typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *); 77 78 void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *, 78 79 dump_descriptor_in_tree_t, size_t, void *); -
uspace/app/vuhid/Makefile
rbd5f3b7 r00aece0 47 47 48 48 SOURCES_INTERFACES = \ 49 hids/bootkbd.c 49 hids/bootkbd.c \ 50 hids/logitech_wireless.c 50 51 51 52 SOURCES = \ … … 53 54 device.c \ 54 55 ifaces.c \ 56 life.c \ 55 57 stdreq.c \ 56 58 $(SOURCES_INTERFACES) -
uspace/app/vuhid/hids/bootkbd.c
rbd5f3b7 r00aece0 93 93 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 94 94 }; 95 static size_t in_data_count = sizeof(in_data)/INPUT_SIZE; 96 // FIXME - locking 97 static size_t in_data_position = 0; 98 99 static int on_data_in(vuhid_interface_t *iface, 100 void *buffer, size_t buffer_size, size_t *act_buffer_size) 101 { 102 static size_t last_pos = (size_t) -1; 103 size_t pos = in_data_position; 104 if (pos >= in_data_count) { 105 return EBADCHECKSUM; 106 } 107 108 if (last_pos == pos) { 109 return ENAK; 110 } 111 112 if (buffer_size > INPUT_SIZE) { 113 buffer_size = INPUT_SIZE; 114 } 115 116 if (act_buffer_size != NULL) { 117 *act_buffer_size = buffer_size; 118 } 119 120 memcpy(buffer, in_data + pos * INPUT_SIZE, buffer_size); 121 last_pos = pos; 122 123 return EOK; 124 } 95 static vuhid_interface_life_t boot_life = { 96 .data_in = in_data, 97 .data_in_count = sizeof(in_data)/INPUT_SIZE, 98 .data_in_pos_change_delay = 500, 99 .msg_born = "Boot keyboard comes to life...", 100 .msg_die = "Boot keyboard died." 101 }; 125 102 126 103 static int on_data_out(vuhid_interface_t *iface, … … 141 118 } 142 119 143 144 static void live(vuhid_interface_t *iface)145 {146 async_usleep(1000 * 1000 * 5);147 usb_log_debug("Boot keyboard comes to life...\n");148 while (in_data_position < in_data_count) {149 async_usleep(1000 * 500);150 in_data_position++;151 }152 usb_log_debug("Boot keyboard died.\n");153 }154 155 156 120 vuhid_interface_t vuhid_interface_bootkbd = { 157 121 .id = "boot", … … 164 128 165 129 .in_data_size = INPUT_SIZE, 166 .on_data_in = on_data_in,130 .on_data_in = interface_live_on_data_in, 167 131 168 132 .out_data_size = 1, 169 133 .on_data_out = on_data_out, 170 134 171 .live = live,135 .live = interface_life_live, 172 136 137 .interface_data = &boot_life, 173 138 .vuhid_data = NULL 174 139 }; -
uspace/app/vuhid/ifaces.c
rbd5f3b7 r00aece0 38 38 39 39 extern vuhid_interface_t vuhid_interface_bootkbd; 40 extern vuhid_interface_t vuhid_interface_logitech_wireless_1; 40 41 41 42 vuhid_interface_t *available_hid_interfaces[] = { 42 43 &vuhid_interface_bootkbd, 44 &vuhid_interface_logitech_wireless_1, 43 45 NULL 44 46 }; -
uspace/app/vuhid/life.c
rbd5f3b7 r00aece0 27 27 */ 28 28 29 /** @addtogroup drvusbmouse29 /** @addtogroup usbvirthid 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * Common definitions for USB mouse driver.34 * 35 35 */ 36 #include <errno.h> 37 #include <usb/debug.h> 38 #include "virthid.h" 36 39 37 #ifndef USBMOUSE_MOUSE_H_38 #define USBMOUSE_MOUSE_H_39 40 40 #include <usb/dev/driver.h> 41 #include <usb/dev/pipes.h> 42 #include <time.h> 43 #include <async.h> 41 void interface_life_live(vuhid_interface_t *iface) 42 { 43 vuhid_interface_life_t *data = iface->interface_data; 44 data->data_in_pos = 0; 45 data->data_in_last_pos = (size_t) -1; 46 async_usleep(1000 * 1000 * 5); 47 usb_log_debug("%s\n", data->msg_born); 48 while (data->data_in_pos < data->data_in_count) { 49 async_usleep(1000 * data->data_in_pos_change_delay); 50 // FIXME: proper locking 51 data->data_in_pos++; 52 } 53 usb_log_debug("%s\n", data->msg_die); 54 } 44 55 45 #define POLL_PIPE(dev) \46 ((dev)->pipes[0].pipe)47 56 48 /** Container for USB mouse device. */49 typedef struct {50 /** Generic device container. */51 usb_device_t *dev;52 53 /** Function representing the device. */54 ddf_fun_t *mouse_fun;55 56 /** Polling interval in microseconds. */57 suseconds_t poll_interval_us;58 59 /** Callback session to console (consumer). */60 async_sess_t *console_sess;61 } usb_mouse_t;62 57 63 extern usb_endpoint_description_t poll_endpoint_description; 58 int interface_live_on_data_in(vuhid_interface_t *iface, 59 void *buffer, size_t buffer_size, size_t *act_buffer_size) 60 { 61 vuhid_interface_life_t *life = iface->interface_data; 62 size_t pos = life->data_in_pos; 63 if (pos >= life->data_in_count) { 64 return EBADCHECKSUM; 65 } 64 66 65 extern int usb_mouse_create(usb_device_t *); 66 extern bool usb_mouse_polling_callback(usb_device_t *, uint8_t *, size_t, 67 void *); 68 extern void usb_mouse_polling_ended_callback(usb_device_t *, bool, void *); 67 if (pos == life->data_in_last_pos) { 68 return ENAK; 69 } 69 70 70 #endif 71 if (buffer_size > iface->in_data_size) { 72 buffer_size = iface->in_data_size; 73 } 71 74 72 /** 73 * @} 75 if (act_buffer_size != NULL) { 76 *act_buffer_size = buffer_size; 77 } 78 79 memcpy(buffer, life->data_in + pos * iface->in_data_size, buffer_size); 80 life->data_in_last_pos = pos; 81 82 return EOK; 83 } 84 85 /** @} 74 86 */ -
uspace/app/vuhid/virthid.h
rbd5f3b7 r00aece0 82 82 83 83 typedef struct { 84 /** Buffer with data from device to the host. */ 85 uint8_t *data_in; 86 /** Number of items in @c data_in. 87 * The total size of @c data_in buffer shall be 88 * <code>data_in_count * vuhid_interface_t.in_data_size</code>. 89 */ 90 size_t data_in_count; 91 92 /** Current position in the data buffer. */ 93 size_t data_in_pos; 94 /** Previous position. */ 95 size_t data_in_last_pos; 96 97 /** Delay between transition to "next" input buffer (in ms). */ 98 size_t data_in_pos_change_delay; 99 100 /** Message to print when interface becomes alive. */ 101 const char *msg_born; 102 /** Message to print when interface dies. */ 103 const char *msg_die; 104 } vuhid_interface_life_t; 105 106 typedef struct { 84 107 uint8_t length; 85 108 uint8_t type; … … 94 117 void wait_for_interfaces_death(usbvirt_device_t *); 95 118 119 void interface_life_live(vuhid_interface_t *); 120 int interface_live_on_data_in(vuhid_interface_t *, void *, size_t, size_t *); 121 122 96 123 #endif 97 124 /** -
uspace/app/websrv/websrv.c
rbd5f3b7 r00aece0 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 31 31 */ 32 32 /** 33 * @file (Less-than-skeleton)web server.33 * @file Skeletal web server. 34 34 */ 35 35 36 #include <bool.h> 37 #include <errno.h> 36 38 #include <stdio.h> 39 #include <sys/types.h> 40 #include <sys/stat.h> 41 #include <stdlib.h> 42 #include <fcntl.h> 37 43 38 44 #include <net/in.h> … … 40 46 #include <net/socket.h> 41 47 48 #include <arg_parse.h> 49 #include <macros.h> 42 50 #include <str.h> 43 44 #define PORT_NUMBER 8080 51 #include <str_error.h> 52 53 #define NAME "websrv" 54 55 #define DEFAULT_PORT 8080 56 #define BACKLOG_SIZE 3 57 58 #define WEB_ROOT "/data/web" 45 59 46 60 /** Buffer for receiving the request. */ 47 #define BUFFER_SIZE 1024 48 static char buf[BUFFER_SIZE]; 49 50 /** Response to send to client. */ 51 static const char *response_msg = 61 #define BUFFER_SIZE 1024 62 63 static uint16_t port = DEFAULT_PORT; 64 65 static char rbuf[BUFFER_SIZE]; 66 static size_t rbuf_out; 67 static size_t rbuf_in; 68 69 static char lbuf[BUFFER_SIZE + 1]; 70 static size_t lbuf_used; 71 72 static char fbuf[BUFFER_SIZE]; 73 74 /** Responses to send to client. */ 75 76 static const char *msg_ok = 52 77 "HTTP/1.0 200 OK\r\n" 78 "\r\n"; 79 80 static const char *msg_bad_request = 81 "HTTP/1.0 400 Bad Request\r\n" 53 82 "\r\n" 54 "<h1>Hello from HelenOS!</h1>\r\n"; 83 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 84 "<html><head>\r\n" 85 "<title>400 Bad Request</title>\r\n" 86 "</head>\r\n" 87 "<body>\r\n" 88 "<h1>Bad Request</h1>\r\n" 89 "<p>The requested URL has bad syntax.</p>\r\n" 90 "</body>\r\n" 91 "</html>\r\n"; 92 93 static const char *msg_not_found = 94 "HTTP/1.0 404 Not Found\r\n" 95 "\r\n" 96 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 97 "<html><head>\r\n" 98 "<title>404 Not Found</title>\r\n" 99 "</head>\r\n" 100 "<body>\r\n" 101 "<h1>Not Found</h1>\r\n" 102 "<p>The requested URL was not found on this server.</p>\r\n" 103 "</body>\r\n" 104 "</html>\r\n"; 105 106 static const char *msg_not_implemented = 107 "HTTP/1.0 501 Not Implemented\r\n" 108 "\r\n" 109 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 110 "<html><head>\r\n" 111 "<title>501 Not Implemented</title>\r\n" 112 "</head>\r\n" 113 "<body>\r\n" 114 "<h1>Not Implemented</h1>\r\n" 115 "<p>The requested method is not implemented on this server.</p>\r\n" 116 "</body>\r\n" 117 "</html>\r\n"; 118 119 /** Receive one character (with buffering) */ 120 static int recv_char(int fd, char *c) 121 { 122 if (rbuf_out == rbuf_in) { 123 rbuf_out = 0; 124 rbuf_in = 0; 125 126 ssize_t rc = recv(fd, rbuf, BUFFER_SIZE, 0); 127 if (rc <= 0) { 128 fprintf(stderr, "recv() failed (%zd)\n", rc); 129 return rc; 130 } 131 132 rbuf_in = rc; 133 } 134 135 *c = rbuf[rbuf_out++]; 136 return EOK; 137 } 138 139 /** Receive one line with length limit */ 140 static int recv_line(int fd) 141 { 142 char *bp = lbuf; 143 char c = '\0'; 144 145 while (bp < lbuf + BUFFER_SIZE) { 146 char prev = c; 147 int rc = recv_char(fd, &c); 148 149 if (rc != EOK) 150 return rc; 151 152 *bp++ = c; 153 if ((prev == '\r') && (c == '\n')) 154 break; 155 } 156 157 lbuf_used = bp - lbuf; 158 *bp = '\0'; 159 160 if (bp == lbuf + BUFFER_SIZE) 161 return ELIMIT; 162 163 return EOK; 164 } 165 166 static bool uri_is_valid(char *uri) 167 { 168 if (uri[0] != '/') 169 return false; 170 171 if (uri[1] == '.') 172 return false; 173 174 char *cp = uri + 1; 175 176 while (*cp != '\0') { 177 char c = *cp++; 178 if (c == '/') 179 return false; 180 } 181 182 return true; 183 } 184 185 static int send_response(int conn_sd, const char *msg) 186 { 187 size_t response_size = str_size(msg); 188 189 fprintf(stderr, "Sending response\n"); 190 ssize_t rc = send(conn_sd, (void *) msg, response_size, 0); 191 if (rc < 0) { 192 fprintf(stderr, "send() failed\n"); 193 return rc; 194 } 195 196 return EOK; 197 } 198 199 static int uri_get(const char *uri, int conn_sd) 200 { 201 if (str_cmp(uri, "/") == 0) 202 uri = "/index.htm"; 203 204 char *fname; 205 int rc = asprintf(&fname, "%s%s", WEB_ROOT, uri); 206 if (rc < 0) 207 return ENOMEM; 208 209 int fd = open(fname, O_RDONLY); 210 if (fd < 0) { 211 rc = send_response(conn_sd, msg_not_found); 212 free(fname); 213 return rc; 214 } 215 216 free(fname); 217 218 rc = send_response(conn_sd, msg_ok); 219 if (rc != EOK) 220 return rc; 221 222 while (true) { 223 ssize_t nr = read(fd, fbuf, BUFFER_SIZE); 224 if (nr == 0) 225 break; 226 227 if (nr < 0) { 228 close(fd); 229 return EIO; 230 } 231 232 rc = send(conn_sd, fbuf, nr, 0); 233 if (rc < 0) { 234 fprintf(stderr, "send() failed\n"); 235 close(fd); 236 return rc; 237 } 238 } 239 240 close(fd); 241 242 return EOK; 243 } 244 245 static int req_process(int conn_sd) 246 { 247 int rc = recv_line(conn_sd); 248 if (rc != EOK) { 249 fprintf(stderr, "recv_line() failed\n"); 250 return rc; 251 } 252 253 fprintf(stderr, "Request: %s", lbuf); 254 255 if (str_lcmp(lbuf, "GET ", 4) != 0) { 256 rc = send_response(conn_sd, msg_not_implemented); 257 return rc; 258 } 259 260 char *uri = lbuf + 4; 261 char *end_uri = str_chr(uri, ' '); 262 if (end_uri == NULL) { 263 end_uri = lbuf + lbuf_used - 2; 264 assert(*end_uri == '\r'); 265 } 266 267 *end_uri = '\0'; 268 fprintf(stderr, "Requested URI: %s\n", uri); 269 270 if (!uri_is_valid(uri)) { 271 rc = send_response(conn_sd, msg_bad_request); 272 return rc; 273 } 274 275 return uri_get(uri, conn_sd); 276 } 277 278 static void usage(void) 279 { 280 printf("Skeletal server\n" 281 "\n" 282 "Usage: " NAME " [options]\n" 283 "\n" 284 "Where options are:\n" 285 "-p port_number | --port=port_number\n" 286 "\tListening port (default " STRING(DEFAULT_PORT) ").\n" 287 "\n" 288 "-h | --help\n" 289 "\tShow this application help.\n"); 290 } 291 292 static int parse_option(int argc, char *argv[], int *index) 293 { 294 int value; 295 int rc; 296 297 switch (argv[*index][1]) { 298 case 'h': 299 usage(); 300 exit(0); 301 break; 302 case 'p': 303 rc = arg_parse_int(argc, argv, index, &value, 0); 304 if (rc != EOK) 305 return rc; 306 307 port = (uint16_t) value; 308 break; 309 /* Long options with double dash */ 310 case '-': 311 if (str_lcmp(argv[*index] + 2, "help", 5) == 0) { 312 usage(); 313 exit(0); 314 } else if (str_lcmp(argv[*index] + 2, "port=", 5) == 0) { 315 rc = arg_parse_int(argc, argv, index, &value, 7); 316 if (rc != EOK) 317 return rc; 318 319 port = (uint16_t) value; 320 } else { 321 usage(); 322 return EINVAL; 323 } 324 break; 325 default: 326 usage(); 327 return EINVAL; 328 } 329 330 return EOK; 331 } 55 332 56 333 int main(int argc, char *argv[]) 57 334 { 335 /* Parse command line arguments */ 336 for (int i = 1; i < argc; i++) { 337 if (argv[i][0] == '-') { 338 int rc = parse_option(argc, argv, &i); 339 if (rc != EOK) 340 return rc; 341 } else { 342 usage(); 343 return EINVAL; 344 } 345 } 346 58 347 struct sockaddr_in addr; 59 struct sockaddr_in raddr; 60 61 socklen_t raddr_len; 62 63 int listen_sd, conn_sd; 64 int rc; 65 66 size_t response_size; 67 348 68 349 addr.sin_family = AF_INET; 69 addr.sin_port = htons(PORT_NUMBER); 70 71 rc = inet_pton(AF_INET, "127.0.0.1", (void *) &addr.sin_addr.s_addr); 350 addr.sin_port = htons(port); 351 352 int rc = inet_pton(AF_INET, "127.0.0.1", (void *) 353 &addr.sin_addr.s_addr); 72 354 if (rc != EOK) { 73 printf("Error parsing network address.\n"); 355 fprintf(stderr, "Error parsing network address (%s)\n", 356 str_error(rc)); 74 357 return 1; 75 358 } 76 77 printf("Creating socket.\n");78 79 listen_sd = socket(PF_INET, SOCK_STREAM, 0);359 360 fprintf(stderr, "Creating socket\n"); 361 362 int listen_sd = socket(PF_INET, SOCK_STREAM, 0); 80 363 if (listen_sd < 0) { 81 printf("Error creating listening socket.\n"); 82 return 1; 83 } 84 364 fprintf(stderr, "Error creating listening socket (%s)\n", 365 str_error(listen_sd)); 366 return 2; 367 } 368 85 369 rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr)); 86 370 if (rc != EOK) { 87 printf("Error binding socket.\n"); 88 return 1; 89 } 90 91 rc = listen(listen_sd, 1); 371 fprintf(stderr, "Error binding socket (%s)\n", 372 str_error(rc)); 373 return 3; 374 } 375 376 rc = listen(listen_sd, BACKLOG_SIZE); 92 377 if (rc != EOK) { 93 printf("Error calling listen() (%d).\n", rc); 94 return 1; 95 } 96 97 response_size = str_size(response_msg); 98 99 printf("Listening for connections at port number %u.\n", PORT_NUMBER); 378 fprintf(stderr, "listen() failed (%s)\n", str_error(rc)); 379 return 4; 380 } 381 382 fprintf(stderr, "Listening for connections at port %" PRIu16 "\n", 383 port); 100 384 while (true) { 101 raddr_len = sizeof(raddr); 102 conn_sd = accept(listen_sd, (struct sockaddr *) &raddr, 385 struct sockaddr_in raddr; 386 socklen_t raddr_len = sizeof(raddr); 387 int conn_sd = accept(listen_sd, (struct sockaddr *) &raddr, 103 388 &raddr_len); 104 389 105 390 if (conn_sd < 0) { 106 printf("accept() failed.\n"); 107 return 1; 108 } 109 110 printf("Accepted connection, sd=%d.\n", conn_sd); 111 112 printf("Wait for client request\n"); 113 114 /* Really we should wait for a blank line. */ 115 rc = recv(conn_sd, buf, BUFFER_SIZE, 0); 116 if (rc < 0) { 117 printf("recv() failed\n"); 118 return 1; 119 } 120 121 /* Send a canned response. */ 122 printf("Send response...\n"); 123 rc = send(conn_sd, (void *) response_msg, response_size, 0); 124 if (rc < 0) { 125 printf("send() failed.\n"); 126 return 1; 127 } 128 391 fprintf(stderr, "accept() failed (%s)\n", str_error(rc)); 392 continue; 393 } 394 395 fprintf(stderr, "Connection accepted (sd=%d), " 396 "waiting for request\n", conn_sd); 397 398 rbuf_out = 0; 399 rbuf_in = 0; 400 401 rc = req_process(conn_sd); 402 if (rc != EOK) 403 fprintf(stderr, "Error processing request (%s)\n", 404 str_error(rc)); 405 129 406 rc = closesocket(conn_sd); 130 407 if (rc != EOK) { 131 printf("Error closing connection socket: %d\n", rc); 132 return 1; 133 } 134 135 printf("Closed connection.\n"); 136 } 137 138 /* Not reached. */ 408 fprintf(stderr, "Error closing connection socket (%s)\n", 409 str_error(rc)); 410 closesocket(listen_sd); 411 return 5; 412 } 413 414 fprintf(stderr, "Connection closed\n"); 415 } 416 417 /* Not reached */ 139 418 return 0; 140 419 }
Note:
See TracChangeset
for help on using the changeset viewer.
