Changeset 3fb0fec in mainline
- Timestamp:
- 2011-07-26T18:29:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7eb0fed8
- Parents:
- efcebe1 (diff), aa865ee (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. - Files:
-
- 16 added
- 3 deleted
- 42 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
refcebe1 r3fb0fec 88 88 @ "tmpfs" TMPFS image 89 89 @ "fat" FAT16 image 90 @ "ext2fs" EXT2 image 90 91 ! RDFMT (choice) 91 92 -
boot/Makefile
refcebe1 r3fb0fec 50 50 $(MKFAT) 1048576 $(DIST_PATH) $@ 51 51 endif 52 ifeq ($(RDFMT),ext2fs) 53 $(MKEXT2) 1048576 $(DIST_PATH) $@ 54 endif 52 55 53 56 build_dist: clean_dist -
boot/Makefile.common
refcebe1 r3fb0fec 56 56 MKTMPFS = $(TOOLS_PATH)/mktmpfs.py 57 57 MKFAT = $(TOOLS_PATH)/mkfat.py 58 MKEXT2 = $(TOOLS_PATH)/mkext2.py 58 59 MKUIMAGE = $(TOOLS_PATH)/mkuimage.py 59 60 … … 82 83 ifeq ($(RDFMT),fat) 83 84 INIT_TASKS += $(USPACE_PATH)/srv/fs/fat/fat 85 endif 86 87 ifeq ($(RDFMT),ext2fs) 88 INIT_TASKS += $(USPACE_PATH)/srv/fs/ext2fs/ext2fs 84 89 endif 85 90 -
kernel/generic/include/lib/elf.h
refcebe1 r3fb0fec 42 42 * current ELF version 43 43 */ 44 #define EV_CURRENT 44 #define EV_CURRENT 1 45 45 46 46 /** 47 47 * ELF types 48 48 */ 49 #define ET_NONE 0/* No type */50 #define ET_REL 1/* Relocatable file */51 #define ET_EXEC 2/* Executable */52 #define ET_DYN 3/* Shared object */53 #define ET_CORE 4/* Core */54 #define ET_LOPROC 0xff00/* Processor specific */55 #define ET_HIPROC 0xffff/* Processor specific */49 #define ET_NONE 0 /* No type */ 50 #define ET_REL 1 /* Relocatable file */ 51 #define ET_EXEC 2 /* Executable */ 52 #define ET_DYN 3 /* Shared object */ 53 #define ET_CORE 4 /* Core */ 54 #define ET_LOPROC 0xff00 /* Processor specific */ 55 #define ET_HIPROC 0xffff /* Processor specific */ 56 56 57 57 /** 58 58 * ELF machine types 59 59 */ 60 #define EM_NO 0/* No machine */61 #define EM_SPARC 2/* SPARC */62 #define EM_386 3/* i386 */63 #define EM_MIPS 8/* MIPS RS3000 */64 #define EM_MIPS_RS3_LE 10/* MIPS RS3000 LE */65 #define EM_PPC 20/* PPC32 */66 #define EM_PPC64 21/* PPC64 */67 #define EM_ARM 40/* ARM */68 #define EM_SPARCV9 43/* SPARC64 */69 #define EM_IA_64 50/* IA-64 */70 #define EM_X86_64 62/* AMD64/EMT64 */60 #define EM_NO 0 /* No machine */ 61 #define EM_SPARC 2 /* SPARC */ 62 #define EM_386 3 /* i386 */ 63 #define EM_MIPS 8 /* MIPS RS3000 */ 64 #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 LE */ 65 #define EM_PPC 20 /* PPC32 */ 66 #define EM_PPC64 21 /* PPC64 */ 67 #define EM_ARM 40 /* ARM */ 68 #define EM_SPARCV9 43 /* SPARC64 */ 69 #define EM_IA_64 50 /* IA-64 */ 70 #define EM_X86_64 62 /* AMD64/EMT64 */ 71 71 72 72 /** 73 73 * ELF identification indexes 74 74 */ 75 #define EI_MAG0 76 #define EI_MAG1 77 #define EI_MAG2 78 #define EI_MAG3 79 #define EI_CLASS 4/* File class */80 #define EI_DATA 5/* Data encoding */81 #define EI_VERSION 6/* File version */82 #define EI_OSABI 83 #define EI_ABIVERSION 84 #define EI_PAD 9/* Start of padding bytes */85 #define EI_NIDENT 16/* ELF identification table size */75 #define EI_MAG0 0 76 #define EI_MAG1 1 77 #define EI_MAG2 2 78 #define EI_MAG3 3 79 #define EI_CLASS 4 /* File class */ 80 #define EI_DATA 5 /* Data encoding */ 81 #define EI_VERSION 6 /* File version */ 82 #define EI_OSABI 7 83 #define EI_ABIVERSION 8 84 #define EI_PAD 9 /* Start of padding bytes */ 85 #define EI_NIDENT 16 /* ELF identification table size */ 86 86 87 87 /** 88 88 * ELF magic number 89 89 */ 90 #define ELFMAG0 91 #define ELFMAG1 92 #define ELFMAG2 93 #define ELFMAG3 90 #define ELFMAG0 0x7f 91 #define ELFMAG1 'E' 92 #define ELFMAG2 'L' 93 #define ELFMAG3 'F' 94 94 95 95 /** 96 96 * ELF file classes 97 97 */ 98 #define ELFCLASSNONE 99 #define ELFCLASS32 100 #define ELFCLASS64 98 #define ELFCLASSNONE 0 99 #define ELFCLASS32 1 100 #define ELFCLASS64 2 101 101 102 102 /** 103 103 * ELF data encoding types 104 104 */ 105 #define ELFDATANONE 0 106 #define ELFDATA2LSB 1 /* Least significant byte first (little endian) */ 107 #define ELFDATA2MSB 2 /* Most signigicant byte first (big endian) */ 108 109 /** 110 * ELF error return codes 111 */ 112 #define EE_OK 0 /* No error */ 113 #define EE_INVALID 1 /* Invalid ELF image */ 114 #define EE_MEMORY 2 /* Cannot allocate address space */ 115 #define EE_INCOMPATIBLE 3 /* ELF image is not compatible with current architecture */ 116 #define EE_UNSUPPORTED 4 /* Non-supported ELF (e.g. dynamic ELFs) */ 117 #define EE_LOADER 5 /* The image is actually a program loader */ 118 #define EE_IRRECOVERABLE 6 105 #define ELFDATANONE 0 106 #define ELFDATA2LSB 1 /* Least significant byte first (little endian) */ 107 #define ELFDATA2MSB 2 /* Most signigicant byte first (big endian) */ 119 108 120 109 /** 121 110 * ELF section types 122 111 */ 123 #define SHT_NULL 124 #define SHT_PROGBITS 125 #define SHT_SYMTAB 126 #define SHT_STRTAB 127 #define SHT_RELA 128 #define SHT_HASH 129 #define SHT_DYNAMIC 130 #define SHT_NOTE 131 #define SHT_NOBITS 132 #define SHT_REL 133 #define SHT_SHLIB 134 #define SHT_DYNSYM 135 #define SHT_LOOS 136 #define SHT_HIOS 137 #define SHT_LOPROC 138 #define SHT_HIPROC 139 #define SHT_LOUSER 140 #define SHT_HIUSER 112 #define SHT_NULL 0 113 #define SHT_PROGBITS 1 114 #define SHT_SYMTAB 2 115 #define SHT_STRTAB 3 116 #define SHT_RELA 4 117 #define SHT_HASH 5 118 #define SHT_DYNAMIC 6 119 #define SHT_NOTE 7 120 #define SHT_NOBITS 8 121 #define SHT_REL 9 122 #define SHT_SHLIB 10 123 #define SHT_DYNSYM 11 124 #define SHT_LOOS 0x60000000 125 #define SHT_HIOS 0x6fffffff 126 #define SHT_LOPROC 0x70000000 127 #define SHT_HIPROC 0x7fffffff 128 #define SHT_LOUSER 0x80000000 129 #define SHT_HIUSER 0xffffffff 141 130 142 131 /** 143 132 * ELF section flags 144 133 */ 145 #define SHF_WRITE 0x1 146 #define SHF_ALLOC 0x2 147 #define SHF_EXECINSTR 0x4 148 #define SHF_TLS 0x400 149 #define SHF_MASKPROC 0xf0000000 134 #define SHF_WRITE 0x1 135 #define SHF_ALLOC 0x2 136 #define SHF_EXECINSTR 0x4 137 #define SHF_TLS 0x400 138 #define SHF_MASKPROC 0xf0000000 139 140 /** Macros for decomposing elf_symbol.st_info into binging and type */ 141 #define ELF_ST_BIND(i) ((i) >> 4) 142 #define ELF_ST_TYPE(i) ((i) & 0x0f) 143 #define ELF_ST_INFO(b, t) (((b) << 4) + ((t) & 0x0f)) 150 144 151 145 /** 152 146 * Symbol binding 153 147 */ 154 #define STB_LOCAL 155 #define STB_GLOBAL 156 #define STB_WEAK 157 #define STB_LOPROC 158 #define STB_HIPROC 148 #define STB_LOCAL 0 149 #define STB_GLOBAL 1 150 #define STB_WEAK 2 151 #define STB_LOPROC 13 152 #define STB_HIPROC 15 159 153 160 154 /** 161 155 * Symbol types 162 156 */ 163 #define STT_NOTYPE 164 #define STT_OBJECT 165 #define STT_FUNC 166 #define STT_SECTION 167 #define STT_FILE 168 #define STT_LOPROC 169 #define STT_HIPROC 157 #define STT_NOTYPE 0 158 #define STT_OBJECT 1 159 #define STT_FUNC 2 160 #define STT_SECTION 3 161 #define STT_FILE 4 162 #define STT_LOPROC 13 163 #define STT_HIPROC 15 170 164 171 165 /** 172 166 * Program segment types 173 167 */ 174 #define PT_NULL 175 #define PT_LOAD 176 #define PT_DYNAMIC 177 #define PT_INTERP 178 #define PT_NOTE 179 #define PT_SHLIB 180 #define PT_PHDR 181 #define PT_LOPROC 182 #define PT_HIPROC 168 #define PT_NULL 0 169 #define PT_LOAD 1 170 #define PT_DYNAMIC 2 171 #define PT_INTERP 3 172 #define PT_NOTE 4 173 #define PT_SHLIB 5 174 #define PT_PHDR 6 175 #define PT_LOPROC 0x70000000 176 #define PT_HIPROC 0x7fffffff 183 177 184 178 /** 185 179 * Program segment attributes. 186 180 */ 187 #define PF_X 188 #define PF_W 189 #define PF_R 181 #define PF_X 1 182 #define PF_W 2 183 #define PF_R 4 190 184 191 185 /** … … 195 189 * ELF object file specifications. They are the only types used 196 190 * in ELF header. 197 *198 191 */ 199 192 typedef uint64_t elf_xword; … … 207 200 * 208 201 * These types are specific for 32-bit format. 209 *210 202 */ 211 203 typedef uint32_t elf32_addr; … … 216 208 * 217 209 * These types are specific for 64-bit format. 218 *219 210 */ 220 211 typedef uint64_t elf64_addr; … … 238 229 elf_half e_shstrndx; 239 230 }; 240 241 231 struct elf64_header { 242 232 uint8_t e_ident[EI_NIDENT]; … … 256 246 }; 257 247 258 /* *248 /* 259 249 * ELF segment header. 260 250 * Segments headers are also known as program headers. … … 270 260 elf_word p_align; 271 261 }; 272 273 262 struct elf64_segment_header { 274 263 elf_word p_type; … … 282 271 }; 283 272 284 /* *273 /* 285 274 * ELF section header 286 275 */ … … 297 286 elf_word sh_entsize; 298 287 }; 299 300 288 struct elf64_section_header { 301 289 elf_word sh_name; … … 311 299 }; 312 300 313 /* *301 /* 314 302 * ELF symbol table entry 315 303 */ … … 322 310 elf_half st_shndx; 323 311 }; 324 325 312 struct elf64_symbol { 326 313 elf_word st_name; … … 332 319 }; 333 320 321 /* 322 * ELF note segment entry 323 */ 324 struct elf32_note { 325 elf_word namesz; 326 elf_word descsz; 327 elf_word type; 328 }; 329 struct elf64_note { 330 elf_xword namesz; 331 elf_xword descsz; 332 elf_xword type; 333 }; 334 334 335 #ifdef __32_BITS__ 335 336 typedef struct elf32_header elf_header_t; … … 337 338 typedef struct elf32_section_header elf_section_header_t; 338 339 typedef struct elf32_symbol elf_symbol_t; 340 typedef struct elf32_note elf_note_t; 339 341 #endif 340 341 342 #ifdef __64_BITS__ 342 343 typedef struct elf64_header elf_header_t; … … 344 345 typedef struct elf64_section_header elf_section_header_t; 345 346 typedef struct elf64_symbol elf_symbol_t; 347 typedef struct elf64_note elf_note_t; 346 348 #endif 347 348 extern const char *elf_error(unsigned int rc);349 349 350 350 /** Interpreter string used to recognize the program loader */ -
kernel/generic/include/mm/as.h
refcebe1 r3fb0fec 307 307 extern mem_backend_t phys_backend; 308 308 309 /**310 * This flags is passed when running the loader, otherwise elf_load()311 * would return with a EE_LOADER error code.312 *313 */314 #define ELD_F_NONE 0315 #define ELD_F_LOADER 1316 317 extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);318 319 309 /* Address space area related syscalls. */ 320 310 extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int); -
kernel/generic/src/lib/elf.c
refcebe1 r3fb0fec 47 47 #include <macros.h> 48 48 #include <arch.h> 49 50 #include <lib/elf_load.h> 49 51 50 52 static const char *error_codes[] = { -
kernel/generic/src/proc/program.c
refcebe1 r3fb0fec 48 48 #include <ipc/ipcrsc.h> 49 49 #include <security/cap.h> 50 #include <lib/elf .h>50 #include <lib/elf_load.h> 51 51 #include <errno.h> 52 52 #include <print.h> -
tools/mkfat.py
refcebe1 r3fb0fec 37 37 import xstruct 38 38 import array 39 40 exclude_names = set(['.svn', '.bzr']) 41 42 def align_up(size, alignment): 43 "Return size aligned up to alignment" 44 45 if (size % alignment == 0): 46 return size 47 48 return ((size // alignment) + 1) * alignment 39 from imgutil import * 49 40 50 41 def subtree_size(root, cluster_size, dirent_size): … … 54 45 files = 2 55 46 56 for name in os.listdir(root): 57 canon = os.path.join(root, name) 58 59 if (os.path.isfile(canon) and (not name in exclude_names)): 60 size += align_up(os.path.getsize(canon), cluster_size) 47 for item in listdir_items(root): 48 if item.is_file: 49 size += align_up(item.size, cluster_size) 61 50 files += 1 62 63 if (os.path.isdir(canon) and (not name in exclude_names)): 64 size += subtree_size(canon, cluster_size, dirent_size) 51 elif item.is_dir: 52 size += subtree_size(item.path, cluster_size, dirent_size) 65 53 files += 1 66 54 … … 72 60 return len(os.listdir(root)) 73 61 74 def write_file( path, outf, cluster_size, data_start, fat, reserved_clusters):62 def write_file(item, outf, cluster_size, data_start, fat, reserved_clusters): 75 63 "Store the contents of a file" 76 64 77 size = os.path.getsize(path)78 65 prev = -1 79 66 first = 0 80 67 81 inf = open(path, "rb") 82 rd = 0; 83 while (rd < size): 68 for data in chunks(item, cluster_size): 84 69 empty_cluster = fat.index(0) 85 70 fat[empty_cluster] = 0xffff … … 92 77 prev = empty_cluster 93 78 94 data = bytes(inf.read(cluster_size));95 79 outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size) 96 80 outf.write(data) 97 rd += len(data) 98 inf.close() 99 100 return first, size 81 82 return first, item.size 101 83 102 84 def write_directory(directory, outf, cluster_size, data_start, fat, reserved_clusters, dirent_size, empty_cluster): … … 303 285 empty_cluster = 0 304 286 305 for name in os.listdir(root): 306 canon = os.path.join(root, name) 307 308 if (os.path.isfile(canon) and (not name in exclude_names)): 309 rv = write_file(canon, outf, cluster_size, data_start, fat, reserved_clusters) 310 directory.append(create_dirent(name, False, rv[0], rv[1])) 311 312 if (os.path.isdir(canon) and (not name in exclude_names)): 313 rv = recursion(False, canon, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster) 314 directory.append(create_dirent(name, True, rv[0], rv[1])) 287 for item in listdir_items(root): 288 if item.is_file: 289 rv = write_file(item, outf, cluster_size, data_start, fat, reserved_clusters) 290 directory.append(create_dirent(item.name, False, rv[0], rv[1])) 291 elif item.is_dir: 292 rv = recursion(False, item.path, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster) 293 directory.append(create_dirent(item.name, True, rv[0], rv[1])) 315 294 316 295 if (head): -
tools/mktmpfs.py
refcebe1 r3fb0fec 35 35 import os 36 36 import xstruct 37 38 exclude_names = set(['.svn', '.bzr']) 37 from imgutil import listdir_items, chunks 39 38 40 39 HEADER = """little: … … 71 70 "Recursive directory walk" 72 71 73 for name in os.listdir(root): 74 canon = os.path.join(root, name) 75 76 if (os.path.isfile(canon) and (not name in exclude_names)): 77 size = os.path.getsize(canon) 78 79 dentry = xstruct.create(DENTRY_FILE % len(name)) 72 for item in listdir_items(root): 73 if item.is_file: 74 dentry = xstruct.create(DENTRY_FILE % len(item.name)) 80 75 dentry.kind = TMPFS_FILE 81 dentry.fname_len = len( name)82 dentry.fname = name.encode('ascii')83 dentry.flen = size76 dentry.fname_len = len(item.name) 77 dentry.fname = item.name.encode('ascii') 78 dentry.flen = item.size 84 79 85 80 outf.write(dentry.pack()) 86 81 87 inf = open(canon, "rb") 88 rd = 0; 89 while (rd < size): 90 data = inf.read(4096); 82 for data in chunks(item, 4096): 91 83 outf.write(data) 92 rd += len(data)93 inf.close()94 84 95 if (os.path.isdir(canon) and (not name in exclude_names)):96 dentry = xstruct.create(DENTRY_DIRECTORY % len( name))85 elif item.is_dir: 86 dentry = xstruct.create(DENTRY_DIRECTORY % len(item.name)) 97 87 dentry.kind = TMPFS_DIRECTORY 98 dentry.fname_len = len( name)99 dentry.fname = name.encode('ascii')88 dentry.fname_len = len(item.name) 89 dentry.fname = item.name.encode('ascii') 100 90 101 91 outf.write(dentry.pack()) 102 92 103 recursion( canon, outf)93 recursion(item.path, outf) 104 94 105 95 dentry = xstruct.create(DENTRY_NONE) -
tools/xstruct.py
refcebe1 r3fb0fec 1 1 # 2 2 # Copyright (c) 2008 Martin Decky 3 # Copyright (c) 2011 Martin Sucha 3 4 # All rights reserved. 4 5 # … … 31 32 32 33 import struct 34 import types 35 36 ranges = { 37 'B': ((int, long), 0x00, 0xff), 38 'H': ((int, long), 0x0000, 0xffff), 39 'L': ((int, long), 0x00000000, 0xffffffff), 40 'Q': ((int, long), 0x0000000000000000, 0xffffffffffffffff), 41 'b': ((int, long), -0x80, 0x7f), 42 'h': ((int, long), -0x8000, 0x7fff), 43 'l': ((int, long), -0x80000000, 0x7fffffff) , 44 'q': ((int, long), -0x8000000000000000, 0x7fffffffffffffff), 45 } 46 47 def check_range(varname, fmt, value): 48 if value == None: 49 raise ValueError('Variable "%s" not set' % varname) 50 if not fmt in ranges: 51 return 52 vartype, varmin, varmax = ranges[fmt] 53 if not isinstance(value, vartype): 54 raise ValueError('Variable "%s" is %s but should be %s' % 55 (varname, str(type(value)), str(vartype))) 56 if value < varmin or value > varmax: 57 raise ValueError('Variable "%s" value %s out of range %s..%s' % 58 (varname, repr(value), repr(varmin), repr(varmax))) 33 59 34 60 class Struct: … … 38 64 def pack(self): 39 65 args = [] 40 for variable in self._args_: 41 if (isinstance(self.__dict__[variable], list)): 42 for item in self.__dict__[variable]: 66 for variable, fmt, length in self._args_: 67 value = self.__dict__[variable] 68 if isinstance(value, list): 69 if length != None and length != len(value): 70 raise ValueError('Variable "%s" length %u does not match %u' % 71 (variable, len(value), length)) 72 for index, item in enumerate(value): 73 check_range(variable + '[' + repr(index) + ']', fmt, item) 43 74 args.append(item) 44 75 else: 45 args.append(self.__dict__[variable])46 76 check_range(variable, fmt, value) 77 args.append(value) 47 78 return struct.pack(self._format_, *args) 79 80 def unpack(self, data): 81 values = struct.unpack(self._format_, data) 82 i = 0 83 for variable, fmt, length in self._args_: 84 self.__dict__[variable] = values[i] 85 i += 1 48 86 49 87 def create(definition): … … 77 115 subtokens = token.split("[") 78 116 117 length = None 79 118 if (len(subtokens) > 1): 80 format += "%d" % int(subtokens[1].split("]")[0]) 119 length = int(subtokens[1].split("]")[0]) 120 format += "%d" % length 81 121 82 122 format += variable 83 123 84 124 inst.__dict__[subtokens[0]] = None 85 args.append( subtokens[0])125 args.append((subtokens[0], variable, length)) 86 126 87 127 variable = None -
uspace/app/bdsh/cmds/modules/cp/cp.c
refcebe1 r3fb0fec 71 71 size_t blen, int vb) 72 72 { 73 int fd1, fd2, bytes = 0;74 off64_t total = 0;73 int fd1, fd2, bytes; 74 off64_t total; 75 75 int64_t copied = 0; 76 76 char *buff = NULL; … … 104 104 } 105 105 106 for (;;) { 107 ssize_t res; 108 size_t written = 0; 109 110 bytes = read(fd1, buff, blen); 111 if (bytes <= 0) 106 while ((bytes = read_all(fd1, buff, blen)) > 0) { 107 if ((bytes = write_all(fd2, buff, bytes)) < 0) 112 108 break; 113 109 copied += bytes; 114 res = bytes;115 do {116 /*117 * Theoretically, it may not be enough to call write()118 * only once. Also the previous read() may have119 * returned less data than requested.120 */121 bytes = write(fd2, buff + written, res);122 if (bytes < 0)123 goto err;124 written += bytes;125 res -= bytes;126 } while (res > 0);127 128 /* TODO: re-insert assert() once this is stand alone,129 * removed as abort() exits the entire shell130 */131 if (res != 0) {132 printf("\n%zd more bytes than actually exist were copied\n", res);133 goto err;134 }135 110 } 136 111 137 112 if (bytes < 0) { 138 err:139 113 printf("\nError copying %s, (%d)\n", src, bytes); 140 114 copied = bytes; -
uspace/app/bdsh/compl.c
refcebe1 r3fb0fec 280 280 281 281 cs->dir = opendir(*cs->path); 282 283 /* Skip directories that we fail to open. */ 284 if (cs->dir == NULL) 285 cs->path++; 282 286 } 283 287 -
uspace/app/bdsh/exec.c
refcebe1 r3fb0fec 52 52 static int try_access(const char *); 53 53 54 const char *search_dir[] = { " app", "srv", NULL };54 const char *search_dir[] = { "/app", "/srv", NULL }; 55 55 56 56 /* work-around for access() */ -
uspace/app/bdsh/input.c
refcebe1 r3fb0fec 170 170 } 171 171 172 rc = run_command( cmd, usr, &new_iostate);172 rc = run_command(actual_cmd, usr, &new_iostate); 173 173 174 174 finit_with_files: -
uspace/app/init/init.c
refcebe1 r3fb0fec 294 294 295 295 #ifdef CONFIG_MOUNT_DATA 296 /* Make sure fat is running. */ 297 if (str_cmp(STRING(RDFMT), "fat") != 0) { 298 srv_start("/srv/fat"); 299 } 296 300 mount_data(); 297 301 #else -
uspace/app/taskdump/elf_core.c
refcebe1 r3fb0fec 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 * Looking at core files produced by Linux, these don't have section headers, 39 39 * only program headers, although objdump shows them as having sections. 40 * Basically at the beginning there should be a note segment (which we 41 * do not write) and one loadable segment per memory area (which we do write). 42 * 43 * The note segment probably contains register state, etc. -- we don't 44 * deal with these yet. Nevertheless you can use these core files with 45 * objdump or gdb. 46 */ 47 40 * Basically at the beginning there should be a note segment followed 41 * by one loadable segment per memory area. 42 * 43 * The note segment contains a series of records with register state, 44 * process info etc. We only write one record NT_PRSTATUS which contains 45 * process/register state (anything which is not register state we fill 46 * with zeroes). 47 */ 48 49 #include <align.h> 50 #include <elf/elf.h> 51 #include <elf/elf_linux.h> 48 52 #include <stdio.h> 49 53 #include <stdlib.h> … … 58 62 #include <udebug.h> 59 63 #include <macros.h> 60 61 #include <elf.h> 62 #include " include/elf_core.h"64 #include <libarch/istate.h> 65 66 #include "elf_core.h" 63 67 64 68 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 65 static int write_all(int, void *, size_t);69 static int align_pos(int, size_t); 66 70 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 67 71 … … 83 87 */ 84 88 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, 85 async_sess_t *sess )89 async_sess_t *sess, istate_t *istate) 86 90 { 87 91 elf_header_t elf_hdr; … … 90 94 elf_word flags; 91 95 elf_segment_header_t *p_hdr; 96 elf_prstatus_t pr_status; 97 elf_note_t note; 98 size_t word_size; 92 99 93 100 int fd; 94 int rc;101 ssize_t rc; 95 102 unsigned int i; 96 103 97 n_ph = n; 98 99 p_hdr = malloc(sizeof(elf_segment_header_t) * n); 104 #ifdef __32_BITS__ 105 word_size = 4; 106 #endif 107 #ifdef __64_BITS__ 108 word_size = 8; 109 #endif 110 memset(&pr_status, 0, sizeof(pr_status)); 111 istate_to_elf_regs(istate, &pr_status.regs); 112 113 n_ph = n + 1; 114 115 p_hdr = malloc(sizeof(elf_segment_header_t) * n_ph); 100 116 if (p_hdr == NULL) { 101 117 printf("Failed allocating memory.\n"); … … 115 131 * ELF header 116 132 * program headers 133 * note segment 117 134 * repeat: 118 135 * (pad for alignment) 119 * segment data136 * core segment 120 137 * end repeat 121 138 */ … … 147 164 foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t); 148 165 149 for (i = 1; i <= n; ++i) { 150 foff = align_foff_up(foff, ainfo[i - 1].start_addr, PAGE_SIZE); 166 memset(&p_hdr[0], 0, sizeof(p_hdr[0])); 167 p_hdr[0].p_type = PT_NOTE; 168 p_hdr[0].p_offset = foff; 169 p_hdr[0].p_vaddr = 0; 170 p_hdr[0].p_paddr = 0; 171 p_hdr[0].p_filesz = sizeof(elf_note_t) 172 + ALIGN_UP((str_size("CORE") + 1), word_size) 173 + ALIGN_UP(sizeof(elf_prstatus_t), word_size); 174 p_hdr[0].p_memsz = 0; 175 p_hdr[0].p_flags = 0; 176 p_hdr[0].p_align = 1; 177 178 foff += p_hdr[0].p_filesz; 179 180 for (i = 0; i < n; ++i) { 181 foff = align_foff_up(foff, ainfo[i].start_addr, PAGE_SIZE); 151 182 152 183 flags = 0; 153 if (ainfo[i - 1].flags & AS_AREA_READ)184 if (ainfo[i].flags & AS_AREA_READ) 154 185 flags |= PF_R; 155 if (ainfo[i - 1].flags & AS_AREA_WRITE)186 if (ainfo[i].flags & AS_AREA_WRITE) 156 187 flags |= PF_W; 157 if (ainfo[i - 1].flags & AS_AREA_EXEC)188 if (ainfo[i].flags & AS_AREA_EXEC) 158 189 flags |= PF_X; 159 190 160 memset(&p_hdr[i - 1], 0, sizeof(p_hdr[i -1]));161 p_hdr[i -1].p_type = PT_LOAD;162 p_hdr[i -1].p_offset = foff;163 p_hdr[i - 1].p_vaddr = ainfo[i - 1].start_addr;164 p_hdr[i -1].p_paddr = 0;165 p_hdr[i - 1].p_filesz = ainfo[i - 1].size;166 p_hdr[i - 1].p_memsz = ainfo[i - 1].size;167 p_hdr[i -1].p_flags = flags;168 p_hdr[i -1].p_align = PAGE_SIZE;169 170 foff += ainfo[i - 1].size;191 memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i + 1])); 192 p_hdr[i + 1].p_type = PT_LOAD; 193 p_hdr[i + 1].p_offset = foff; 194 p_hdr[i + 1].p_vaddr = ainfo[i].start_addr; 195 p_hdr[i + 1].p_paddr = 0; 196 p_hdr[i + 1].p_filesz = ainfo[i].size; 197 p_hdr[i + 1].p_memsz = ainfo[i].size; 198 p_hdr[i + 1].p_flags = flags; 199 p_hdr[i + 1].p_align = PAGE_SIZE; 200 201 foff += ainfo[i].size; 171 202 } 172 203 173 204 rc = write_all(fd, &elf_hdr, sizeof(elf_hdr)); 174 if (rc != EOK) {205 if (rc != sizeof(elf_hdr)) { 175 206 printf("Failed writing ELF header.\n"); 176 207 free(p_hdr); … … 180 211 for (i = 0; i < n_ph; ++i) { 181 212 rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i])); 182 if (rc != EOK) {213 if (rc != sizeof(p_hdr[i])) { 183 214 printf("Failed writing program header.\n"); 184 215 free(p_hdr); … … 187 218 } 188 219 189 for (i = 0; i < n_ph; ++i) { 220 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 221 printf("Failed writing memory data.\n"); 222 free(p_hdr); 223 return EIO; 224 } 225 226 /* 227 * Write note header 228 */ 229 note.namesz = str_size("CORE") + 1; 230 note.descsz = sizeof(elf_prstatus_t); 231 note.type = NT_PRSTATUS; 232 233 rc = write_all(fd, ¬e, sizeof(elf_note_t)); 234 if (rc != sizeof(elf_note_t)) { 235 printf("Failed writing note header.\n"); 236 free(p_hdr); 237 return EIO; 238 } 239 240 rc = write_all(fd, "CORE", note.namesz); 241 if (rc != (ssize_t) note.namesz) { 242 printf("Failed writing note header.\n"); 243 free(p_hdr); 244 return EIO; 245 } 246 247 rc = align_pos(fd, word_size); 248 if (rc != EOK) { 249 printf("Failed writing note header.\n"); 250 free(p_hdr); 251 return EIO; 252 } 253 254 rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t)); 255 if (rc != sizeof(elf_prstatus_t)) { 256 printf("Failed writing register data.\n"); 257 free(p_hdr); 258 return EIO; 259 } 260 261 for (i = 1; i < n_ph; ++i) { 190 262 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 191 263 printf("Failed writing memory data.\n"); … … 193 265 return EIO; 194 266 } 195 if (write_mem_area(fd, &ainfo[i ], sess) != EOK) {267 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) { 196 268 printf("Failed writing memory data.\n"); 197 269 free(p_hdr); … … 210 282 off64_t rva = vaddr % page_size; 211 283 off64_t rfo = foff % page_size; 212 284 213 285 if (rva >= rfo) 214 286 return (foff + (rva - rfo)); 215 287 216 288 return (foff + (page_size + (rva - rfo))); 217 289 } … … 231 303 size_t total; 232 304 uintptr_t addr; 233 int rc;305 ssize_t rc; 234 306 235 307 addr = area->start_addr; … … 245 317 246 318 rc = write_all(fd, buffer, to_copy); 247 if (rc != EOK) {319 if (rc != (ssize_t) to_copy) { 248 320 printf("Failed writing memory contents.\n"); 249 321 return EIO; … … 257 329 } 258 330 259 /** Write until the buffer is written in its entirety. 260 * 261 * This function fails if it cannot write exactly @a len bytes to the file. 262 * 263 * @param fd The file to write to. 264 * @param buf Data, @a len bytes long. 265 * @param len Number of bytes to write. 266 * 267 * @return EOK on error, return value from write() if writing 268 * failed. 269 */ 270 static int write_all(int fd, void *data, size_t len) 331 static int align_pos(int fd, size_t align) 271 332 { 272 int cnt = 0;273 274 do { 275 data += cnt;276 len -= cnt;277 cnt = write(fd, data, len);278 } while (cnt > 0 && (len - cnt) > 0); 279 280 if (cnt < 0)281 return cnt; 282 283 if ( len - cnt >0)284 return EIO;333 off64_t cur_pos; 334 size_t rem, adv; 335 336 cur_pos = lseek(fd, 0, SEEK_CUR); 337 if (cur_pos < 0) 338 return -1; 339 340 rem = cur_pos % align; 341 adv = align - rem; 342 343 cur_pos = lseek(fd, adv, SEEK_CUR); 344 if (cur_pos < 0) 345 return -1; 285 346 286 347 return EOK; 287 348 } 288 349 289 290 350 /** @} 291 351 */ -
uspace/app/taskdump/include/elf_core.h
refcebe1 r3fb0fec 37 37 38 38 #include <async.h> 39 #include <elf/elf_linux.h> 40 #include <libarch/istate.h> 39 41 40 42 extern int elf_core_save(const char *, as_area_info_t *, unsigned int, 41 async_sess_t * );43 async_sess_t *, istate_t *); 42 44 43 45 #endif -
uspace/app/taskdump/include/symtab.h
refcebe1 r3fb0fec 36 36 #define SYMTAB_H_ 37 37 38 #include <elf/elf.h> 38 39 #include <sys/types.h> 39 #include <elf.h>40 40 41 41 typedef struct { -
uspace/app/taskdump/symtab.c
refcebe1 r3fb0fec 36 36 */ 37 37 38 #include <elf/elf.h> 38 39 #include <stdio.h> 39 40 #include <stdlib.h> … … 43 44 #include <fcntl.h> 44 45 45 #include <elf.h>46 46 #include "include/symtab.h" 47 47 … … 50 50 elf_section_header_t *shdr); 51 51 static int chunk_load(int fd, off64_t start, size_t size, void **ptr); 52 static int read_all(int fd, void *buf, size_t len);53 52 54 53 /** Load symbol table from an ELF file. … … 90 89 91 90 rc = read_all(fd, &elf_hdr, sizeof(elf_header_t)); 92 if (rc != EOK) {91 if (rc != sizeof(elf_header_t)) { 93 92 printf("failed reading elf header\n"); 94 93 free(stab); … … 312 311 313 312 rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t)); 314 if (rc != EOK)313 if (rc != sizeof(elf_section_header_t)) 315 314 return EIO; 316 315 … … 331 330 static int chunk_load(int fd, off64_t start, size_t size, void **ptr) 332 331 { 333 int rc; 334 335 rc = lseek(fd, start, SEEK_SET); 336 if (rc == (off64_t) -1) { 332 ssize_t rc; 333 off64_t offs; 334 335 offs = lseek(fd, start, SEEK_SET); 336 if (offs == (off64_t) -1) { 337 337 printf("failed seeking chunk\n"); 338 338 *ptr = NULL; … … 347 347 348 348 rc = read_all(fd, *ptr, size); 349 if (rc != EOK) {349 if (rc != (ssize_t) size) { 350 350 printf("failed reading chunk\n"); 351 351 free(*ptr); … … 357 357 } 358 358 359 /** Read until the buffer is read in its entirety.360 *361 * This function fails if it cannot read exactly @a len bytes from the file.362 *363 * @param fd The file to read from.364 * @param buf Buffer for storing data, @a len bytes long.365 * @param len Number of bytes to read.366 *367 * @return EOK on error, EIO if file is short or return value368 * from read() if reading failed.369 */370 static int read_all(int fd, void *buf, size_t len)371 {372 int cnt = 0;373 374 do {375 buf += cnt;376 len -= cnt;377 cnt = read(fd, buf, len);378 } while (cnt > 0 && (len - cnt) > 0);379 380 if (cnt < 0)381 return cnt;382 383 if (len - cnt > 0)384 return EIO;385 386 return EOK;387 }388 389 359 /** @} 390 360 */ -
uspace/app/taskdump/taskdump.c
refcebe1 r3fb0fec 34 34 35 35 #include <async.h> 36 #include <elf/elf_linux.h> 36 37 #include <stdio.h> 37 38 #include <stdlib.h> … … 72 73 static char *get_app_task_name(void); 73 74 static char *fmt_sym_address(uintptr_t addr); 75 76 static istate_t reg_state; 74 77 75 78 int main(int argc, char *argv[]) … … 293 296 if (write_core_file) { 294 297 printf("Writing core file '%s'\n", core_file_name); 295 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess); 298 299 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess, 300 ®_state); 301 296 302 if (rc != EOK) { 297 303 printf("Failed writing core file.\n"); … … 321 327 pc = istate_get_pc(&istate); 322 328 fp = istate_get_fp(&istate); 329 330 /* Save register state for dumping to core file later. */ 331 reg_state = istate; 323 332 324 333 sym_pc = fmt_sym_address(pc); -
uspace/drv/bus/usb/usbmast/bo_trans.c
refcebe1 r3fb0fec 58 58 * @param tag Command block wrapper tag (automatically compared 59 59 * with answer) 60 * @param cmd Command block 61 * @param cmd_size Command block size in bytes 62 * @param ddir Direction in which data will be transferred 63 * @param dbuf Data send/receive buffer 64 * @param dbuf_size Size of the data buffer 65 * @param xferred_size Number of bytes actually transferred 60 * @param cmd SCSI command 66 61 * 67 62 * @return Error code 68 63 */ 69 static int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, const void *cmd, 70 size_t cmd_size, usb_direction_t ddir, void *dbuf, size_t dbuf_size, 71 size_t *xferred_size) 64 int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, scsi_cmd_t *cmd) 72 65 { 73 66 int rc; 67 int retval = EOK; 74 68 size_t act_size; 75 69 usb_pipe_t *bulk_in_pipe = mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe; 76 70 usb_pipe_t *bulk_out_pipe = mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe; 71 usb_direction_t ddir; 72 void *dbuf; 73 size_t dbuf_size; 74 75 if (cmd->data_out != NULL && cmd->data_in == NULL) { 76 ddir = USB_DIRECTION_OUT; 77 dbuf = (void *)cmd->data_out; 78 dbuf_size = cmd->data_out_size; 79 } else if (cmd->data_out == NULL && cmd->data_in != NULL) { 80 ddir = USB_DIRECTION_IN; 81 dbuf = cmd->data_in; 82 dbuf_size = cmd->data_in_size; 83 } else { 84 assert(false); 85 } 77 86 78 87 /* Prepare CBW - command block wrapper */ 79 88 usb_massstor_cbw_t cbw; 80 89 usb_massstor_cbw_prepare(&cbw, tag, dbuf_size, ddir, mfun->lun, 81 cmd _size, cmd);90 cmd->cdb_size, cmd->cdb); 82 91 83 92 /* Send the CBW. */ 93 MASTLOG("Sending CBW.\n"); 84 94 rc = usb_pipe_write(bulk_out_pipe, &cbw, sizeof(cbw)); 85 95 MASTLOG("CBW '%s' sent: %s.\n", 86 96 usb_debug_str_buffer((uint8_t *) &cbw, sizeof(cbw), 0), 87 97 str_error(rc)); 88 if (rc != EOK) {89 return rc;90 } 91 98 if (rc != EOK) 99 return EIO; 100 101 MASTLOG("Transferring data.\n"); 92 102 if (ddir == USB_DIRECTION_IN) { 93 103 /* Recieve data from the device. */ … … 104 114 } 105 115 106 if (rc != EOK) { 107 /* 108 * XXX If the pipe is stalled, we should clear it 109 * and read CSW. 110 */ 111 return rc; 116 if (rc == ESTALL) { 117 /* Clear stall condition and continue below to read CSW. */ 118 if (ddir == USB_DIRECTION_IN) { 119 usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe, 120 mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe); 121 } else { 122 usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe, 123 mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe); 124 } 125 } else if (rc != EOK) { 126 return EIO; 112 127 } 113 128 … … 115 130 usb_massstor_csw_t csw; 116 131 size_t csw_size; 132 MASTLOG("Reading CSW.\n"); 117 133 rc = usb_pipe_read(bulk_in_pipe, &csw, sizeof(csw), &csw_size); 118 134 MASTLOG("CSW '%s' received (%zu bytes): %s.\n", … … 121 137 if (rc != EOK) { 122 138 MASTLOG("rc != EOK\n"); 123 return rc;139 return EIO; 124 140 } 125 141 126 142 if (csw_size != sizeof(csw)) { 127 143 MASTLOG("csw_size != sizeof(csw)\n"); 128 return E RANGE;144 return EIO; 129 145 } 130 146 131 147 if (csw.dCSWTag != tag) { 132 148 MASTLOG("csw.dCSWTag != tag\n"); 133 return E BADCHECKSUM;149 return EIO; 134 150 } 135 151 … … 137 153 * Determine the actual return value from the CSW. 138 154 */ 139 if (csw.dCSWStatus != 0) { 140 MASTLOG("csw.dCSWStatus != 0\n"); 141 // FIXME: better error code 142 // FIXME: distinguish 0x01 and 0x02 143 return EXDEV; 155 switch (csw.dCSWStatus) { 156 case cbs_passed: 157 cmd->status = CMDS_GOOD; 158 break; 159 case cbs_failed: 160 MASTLOG("Command failed\n"); 161 cmd->status = CMDS_FAILED; 162 break; 163 case cbs_phase_error: 164 MASTLOG("Phase error\n"); 165 retval = EIO; 166 break; 167 default: 168 retval = EIO; 169 break; 144 170 } 145 171 … … 147 173 if (residue > dbuf_size) { 148 174 MASTLOG("residue > dbuf_size\n"); 149 return E RANGE;175 return EIO; 150 176 } 151 177 … … 158 184 */ 159 185 160 if (xferred_size != NULL) 161 *xferred_size = dbuf_size - residue; 162 163 return EOK; 164 } 165 166 /** Perform data-in command. 167 * 168 * @param mfun Mass storage function 169 * @param tag Command block wrapper tag (automatically compared with 170 * answer) 171 * @param cmd CDB (Command Descriptor) 172 * @param cmd_size CDB length in bytes 173 * @param dbuf Data receive buffer 174 * @param dbuf_size Data receive buffer size in bytes 175 * @param proc_size Number of bytes actually processed by device 176 * 177 * @return Error code 178 */ 179 int usb_massstor_data_in(usbmast_fun_t *mfun, uint32_t tag, const void *cmd, 180 size_t cmd_size, void *dbuf, size_t dbuf_size, size_t *proc_size) 181 { 182 return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_IN, 183 dbuf, dbuf_size, proc_size); 184 } 185 186 /** Perform data-out command. 187 * 188 * @param mfun Mass storage function 189 * @param tag Command block wrapper tag (automatically compared with 190 * answer) 191 * @param cmd CDB (Command Descriptor) 192 * @param cmd_size CDB length in bytes 193 * @param data Command data 194 * @param data_size Size of @a data in bytes 195 * @param proc_size Number of bytes actually processed by device 196 * 197 * @return Error code 198 */ 199 int usb_massstor_data_out(usbmast_fun_t *mfun, uint32_t tag, const void *cmd, 200 size_t cmd_size, const void *data, size_t data_size, size_t *proc_size) 201 { 202 return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_OUT, 203 (void *) data, data_size, proc_size); 186 if (ddir == USB_DIRECTION_IN) 187 cmd->rcvd_size = dbuf_size - residue; 188 189 return retval; 204 190 } 205 191 -
uspace/drv/bus/usb/usbmast/bo_trans.h
refcebe1 r3fb0fec 47 47 #define BULK_OUT_EP 1 48 48 49 extern int usb_massstor_data_in(usbmast_fun_t *, uint32_t, const void *, 50 size_t, void *, size_t, size_t *); 51 extern int usb_massstor_data_out(usbmast_fun_t *, uint32_t, const void *, 52 size_t, const void *, size_t, size_t *); 49 typedef enum cmd_status { 50 CMDS_GOOD, 51 CMDS_FAILED 52 } cmd_status_t; 53 54 /** SCSI command. 55 * 56 * Contains (a subset of) the input and output arguments of SCSI 57 * Execute Command procedure call (see SAM-4 chapter 5.1) 58 */ 59 typedef struct { 60 /* 61 * Related to IN fields 62 */ 63 64 /** Command Descriptor Block */ 65 void *cdb; 66 /** CDB size in bytes */ 67 size_t cdb_size; 68 69 /** Outgoing data */ 70 const void *data_out; 71 /** Size of outgoing data in bytes */ 72 size_t data_out_size; 73 74 /* 75 * Related to OUT fields 76 */ 77 78 /** Buffer for incoming data */ 79 void *data_in; 80 /** Size of input buffer in bytes */ 81 size_t data_in_size; 82 83 /** Number of bytes actually received */ 84 size_t rcvd_size; 85 86 /** Status */ 87 cmd_status_t status; 88 } scsi_cmd_t; 89 90 extern int usb_massstor_cmd(usbmast_fun_t *, uint32_t, scsi_cmd_t *); 53 91 extern int usb_massstor_reset(usbmast_dev_t *); 54 92 extern void usb_massstor_reset_recovery(usbmast_dev_t *); -
uspace/drv/bus/usb/usbmast/cmdw.h
refcebe1 r3fb0fec 57 57 } __attribute__((packed)) usb_massstor_csw_t; 58 58 59 enum cmd_block_status { 60 cbs_passed = 0x00, 61 cbs_failed = 0x01, 62 cbs_phase_error = 0x02 63 }; 64 59 65 extern void usb_massstor_cbw_prepare(usb_massstor_cbw_t *, uint32_t, uint32_t, 60 66 usb_direction_t, uint8_t, uint8_t, const uint8_t *); -
uspace/drv/bus/usb/usbmast/scsi_ms.c
refcebe1 r3fb0fec 61 61 } 62 62 63 static void usbmast_dump_sense(scsi_sense_data_t *sense_buf) 64 { 65 unsigned sense_key; 66 67 sense_key = sense_buf->flags_key & 0x0f; 68 printf("Got sense data. Sense key: 0x%x (%s), ASC 0x%02x, " 69 "ASCQ 0x%02x.\n", sense_key, 70 scsi_get_sense_key_str(sense_key), 71 sense_buf->additional_code, 72 sense_buf->additional_cqual); 73 } 74 75 /** Run SCSI command. 76 * 77 * Run command and repeat in case of unit attention. 78 * XXX This is too simplified. 79 */ 80 static int usbmast_run_cmd(usbmast_fun_t *mfun, scsi_cmd_t *cmd) 81 { 82 uint8_t sense_key; 83 scsi_sense_data_t sense_buf; 84 int rc; 85 86 do { 87 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, cmd); 88 if (rc != EOK) { 89 usb_log_error("Inquiry transport failed, device %s: %s.\n", 90 mfun->mdev->ddf_dev->name, str_error(rc)); 91 return rc; 92 } 93 94 if (cmd->status == CMDS_GOOD) 95 return EOK; 96 97 usb_log_error("SCSI command failed, device %s.\n", 98 mfun->mdev->ddf_dev->name); 99 100 rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf)); 101 if (rc != EOK) { 102 usb_log_error("Failed to read sense data.\n"); 103 return EIO; 104 } 105 106 /* Dump sense data to log */ 107 usbmast_dump_sense(&sense_buf); 108 109 /* Get sense key */ 110 sense_key = sense_buf.flags_key & 0x0f; 111 112 if (sense_key == SCSI_SK_UNIT_ATTENTION) { 113 printf("Got unit attention. Re-trying command.\n"); 114 } 115 116 } while (sense_key == SCSI_SK_UNIT_ATTENTION); 117 118 /* Command status is not good, nevertheless transport succeeded. */ 119 return EOK; 120 } 121 63 122 /** Perform SCSI Inquiry command on USB mass storage device. 64 123 * … … 70 129 { 71 130 scsi_std_inquiry_data_t inq_data; 72 s ize_t response_len;131 scsi_cmd_t cmd; 73 132 scsi_cdb_inquiry_t cdb; 74 133 int rc; … … 78 137 cdb.alloc_len = host2uint16_t_be(sizeof(inq_data)); 79 138 80 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 81 sizeof(cdb), &inq_data, sizeof(inq_data), &response_len); 139 memset(&cmd, 0, sizeof(cmd)); 140 cmd.cdb = &cdb; 141 cmd.cdb_size = sizeof(cdb); 142 cmd.data_in = &inq_data; 143 cmd.data_in_size = sizeof(inq_data); 144 145 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 82 146 83 147 if (rc != EOK) { 84 usb_log_error("Inquiry failed, device %s: %s.\n", 85 mfun->mdev->ddf_dev->name, str_error(rc)); 86 return rc; 87 } 88 89 if (response_len < SCSI_STD_INQUIRY_DATA_MIN_SIZE) { 148 usb_log_error("Inquiry transport failed, device %s: %s.\n", 149 mfun->mdev->ddf_dev->name, str_error(rc)); 150 return rc; 151 } 152 153 if (cmd.status != CMDS_GOOD) { 154 usb_log_error("Inquiry command failed, device %s.\n", 155 mfun->mdev->ddf_dev->name); 156 return EIO; 157 } 158 159 if (cmd.rcvd_size < SCSI_STD_INQUIRY_DATA_MIN_SIZE) { 90 160 usb_log_error("SCSI Inquiry response too short (%zu).\n", 91 response_len);161 cmd.rcvd_size); 92 162 return EIO; 93 163 } … … 127 197 int usbmast_request_sense(usbmast_fun_t *mfun, void *buf, size_t size) 128 198 { 199 scsi_cmd_t cmd; 129 200 scsi_cdb_request_sense_t cdb; 130 size_t data_len;131 201 int rc; 132 202 … … 135 205 cdb.alloc_len = min(size, SCSI_SENSE_DATA_MAX_SIZE); 136 206 137 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 138 sizeof(cdb), buf, size, &data_len); 139 140 if (rc != EOK) { 207 memset(&cmd, 0, sizeof(cmd)); 208 cmd.cdb = &cdb; 209 cmd.cdb_size = sizeof(cdb); 210 cmd.data_in = buf; 211 cmd.data_in_size = size; 212 213 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 214 215 if (rc != EOK || cmd.status != CMDS_GOOD) { 141 216 usb_log_error("Request Sense failed, device %s: %s.\n", 142 217 mfun->mdev->ddf_dev->name, str_error(rc)); … … 144 219 } 145 220 146 if ( data_len< SCSI_SENSE_DATA_MIN_SIZE) {221 if (cmd.rcvd_size < SCSI_SENSE_DATA_MIN_SIZE) { 147 222 /* The missing bytes should be considered to be zeroes. */ 148 memset((uint8_t *)buf + data_len, 0,149 SCSI_SENSE_DATA_MIN_SIZE - data_len);223 memset((uint8_t *)buf + cmd.rcvd_size, 0, 224 SCSI_SENSE_DATA_MIN_SIZE - cmd.rcvd_size); 150 225 } 151 226 … … 164 239 uint32_t *block_size) 165 240 { 241 scsi_cmd_t cmd; 166 242 scsi_cdb_read_capacity_10_t cdb; 167 243 scsi_read_capacity_10_data_t data; 168 size_t data_len;169 244 int rc; 170 245 … … 172 247 cdb.op_code = SCSI_CMD_READ_CAPACITY_10; 173 248 174 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 175 sizeof(cdb), &data, sizeof(data), &data_len); 249 memset(&cmd, 0, sizeof(cmd)); 250 cmd.cdb = &cdb; 251 cmd.cdb_size = sizeof(cdb); 252 cmd.data_in = &data; 253 cmd.data_in_size = sizeof(data); 254 255 rc = usbmast_run_cmd(mfun, &cmd); 176 256 177 257 if (rc != EOK) { 178 usb_log_error("Read Capacity (10) failed, device %s: %s.\n", 179 mfun->mdev->ddf_dev->name, str_error(rc)); 180 return rc; 181 } 182 183 if (data_len < sizeof(data)) { 258 usb_log_error("Read Capacity (10) transport failed, device %s: %s.\n", 259 mfun->mdev->ddf_dev->name, str_error(rc)); 260 return rc; 261 } 262 263 if (cmd.status != CMDS_GOOD) { 264 usb_log_error("Read Capacity (10) command failed, device %s.\n", 265 mfun->mdev->ddf_dev->name); 266 return EIO; 267 } 268 269 if (cmd.rcvd_size < sizeof(data)) { 184 270 usb_log_error("SCSI Read Capacity response too short (%zu).\n", 185 data_len);271 cmd.rcvd_size); 186 272 return EIO; 187 273 } … … 203 289 int usbmast_read(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks, void *buf) 204 290 { 205 scsi_cdb_read_12_t cdb; 206 size_t data_len; 207 int rc; 208 209 /* XXX Need softstate to store block size. */ 291 scsi_cmd_t cmd; 292 scsi_cdb_read_10_t cdb; 293 int rc; 210 294 211 295 if (ba > UINT32_MAX) 212 296 return ELIMIT; 213 297 214 if ( (uint64_t)nblocks * mfun->block_size > UINT32_MAX)298 if (nblocks > UINT16_MAX) 215 299 return ELIMIT; 216 300 217 301 memset(&cdb, 0, sizeof(cdb)); 218 cdb.op_code = SCSI_CMD_READ_1 2;302 cdb.op_code = SCSI_CMD_READ_10; 219 303 cdb.lba = host2uint32_t_be(ba); 220 cdb.xfer_len = host2uint32_t_be(nblocks); 221 222 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 223 sizeof(cdb), buf, nblocks * mfun->block_size, &data_len); 304 cdb.xfer_len = host2uint16_t_be(nblocks); 305 306 memset(&cmd, 0, sizeof(cmd)); 307 cmd.cdb = &cdb; 308 cmd.cdb_size = sizeof(cdb); 309 cmd.data_in = buf; 310 cmd.data_in_size = nblocks * mfun->block_size; 311 312 rc = usbmast_run_cmd(mfun, &cmd); 224 313 225 314 if (rc != EOK) { 226 usb_log_error("Read (12) failed, device %s: %s.\n", 227 mfun->mdev->ddf_dev->name, str_error(rc)); 228 return rc; 229 } 230 231 if (data_len < nblocks * mfun->block_size) { 315 usb_log_error("Read (10) transport failed, device %s: %s.\n", 316 mfun->mdev->ddf_dev->name, str_error(rc)); 317 return rc; 318 } 319 320 if (cmd.status != CMDS_GOOD) { 321 usb_log_error("Read (10) command failed, device %s.\n", 322 mfun->mdev->ddf_dev->name); 323 return EIO; 324 } 325 326 if (cmd.rcvd_size < nblocks * mfun->block_size) { 232 327 usb_log_error("SCSI Read response too short (%zu).\n", 233 data_len);328 cmd.rcvd_size); 234 329 return EIO; 235 330 } … … 250 345 const void *data) 251 346 { 252 scsi_c db_write_12_t cdb;253 s ize_t sent_len;347 scsi_cmd_t cmd; 348 scsi_cdb_write_10_t cdb; 254 349 int rc; 255 350 … … 257 352 return ELIMIT; 258 353 259 if ( (uint64_t)nblocks * mfun->block_size > UINT32_MAX)354 if (nblocks > UINT16_MAX) 260 355 return ELIMIT; 261 356 262 357 memset(&cdb, 0, sizeof(cdb)); 263 cdb.op_code = SCSI_CMD_WRITE_1 2;358 cdb.op_code = SCSI_CMD_WRITE_10; 264 359 cdb.lba = host2uint32_t_be(ba); 265 cdb.xfer_len = host2uint32_t_be(nblocks); 266 267 rc = usb_massstor_data_out(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 268 sizeof(cdb), data, nblocks * mfun->block_size, &sent_len); 360 cdb.xfer_len = host2uint16_t_be(nblocks); 361 362 memset(&cmd, 0, sizeof(cmd)); 363 cmd.cdb = &cdb; 364 cmd.cdb_size = sizeof(cdb); 365 cmd.data_out = data; 366 cmd.data_out_size = nblocks * mfun->block_size; 367 368 rc = usbmast_run_cmd(mfun, &cmd); 269 369 270 370 if (rc != EOK) { 271 usb_log_error("Write (1 2)failed, device %s: %s.\n",272 mfun->mdev->ddf_dev->name, str_error(rc)); 273 return rc; 274 } 275 276 if ( sent_len < nblocks * mfun->block_size) {277 usb_log_error(" SCSI Write not all bytes transferred (%zu).\n",278 sent_len);371 usb_log_error("Write (10) transport failed, device %s: %s.\n", 372 mfun->mdev->ddf_dev->name, str_error(rc)); 373 return rc; 374 } 375 376 if (cmd.status != CMDS_GOOD) { 377 usb_log_error("Write (10) command failed, device %s.\n", 378 mfun->mdev->ddf_dev->name); 279 379 return EIO; 280 380 } -
uspace/lib/c/Makefile
refcebe1 r3fb0fec 59 59 -include arch/$(UARCH)/Makefile.inc 60 60 61 EXTRA_CFLAGS += -I../../srv/loader/include62 63 61 GENERIC_SOURCES = \ 64 62 generic/libc.c \ … … 71 69 generic/device/hw_res.c \ 72 70 generic/device/char_dev.c \ 71 generic/elf/elf_load.c \ 73 72 generic/event.c \ 74 73 generic/errno.c \ … … 134 133 generic/dlfcn.c \ 135 134 generic/rtld/rtld.c \ 136 generic/rtld/elf_load.c \137 135 generic/rtld/dynamic.c \ 138 136 generic/rtld/module.c \ -
uspace/lib/c/generic/elf/elf_load.c
refcebe1 r3fb0fec 29 29 */ 30 30 31 /** @addtogroup generic 31 /** @addtogroup generic 32 32 * @{ 33 33 */ … … 49 49 #include <assert.h> 50 50 #include <as.h> 51 #include <elf/elf.h> 51 52 #include <unistd.h> 52 53 #include <fcntl.h> … … 55 56 #include <entry_point.h> 56 57 57 #include "elf.h" 58 #include "elf_load.h" 58 #include <elf/elf_load.h> 59 59 60 60 #define DPRINTF(...) … … 74 74 static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry); 75 75 76 /** Read until the buffer is read in its entirety. */77 static int my_read(int fd, void *buf, size_t len)78 {79 int cnt = 0;80 do {81 buf += cnt;82 len -= cnt;83 cnt = read(fd, buf, len);84 } while ((cnt > 0) && ((len - cnt) > 0));85 86 return cnt;87 }88 89 76 /** Load ELF binary from a file. 90 77 * … … 160 147 int i, rc; 161 148 162 rc = my_read(elf->fd, header, sizeof(elf_header_t));163 if (rc < 0) {149 rc = read_all(elf->fd, header, sizeof(elf_header_t)); 150 if (rc != sizeof(elf_header_t)) { 164 151 DPRINTF("Read error.\n"); 165 152 return EE_INVALID; … … 222 209 + i * sizeof(elf_segment_header_t), SEEK_SET); 223 210 224 rc = my_read(elf->fd, &segment_hdr,211 rc = read_all(elf->fd, &segment_hdr, 225 212 sizeof(elf_segment_header_t)); 226 if (rc < 0) {213 if (rc != sizeof(elf_segment_header_t)) { 227 214 DPRINTF("Read error.\n"); 228 215 return EE_INVALID; … … 244 231 + i * sizeof(elf_section_header_t), SEEK_SET); 245 232 246 rc = my_read(elf->fd, §ion_hdr,233 rc = read_all(elf->fd, §ion_hdr, 247 234 sizeof(elf_section_header_t)); 248 if (rc < 0) {235 if (rc != sizeof(elf_section_header_t)) { 249 236 DPRINTF("Read error.\n"); 250 237 return EE_INVALID; … … 334 321 uintptr_t seg_addr; 335 322 size_t mem_sz; 336 int rc;323 ssize_t rc; 337 324 338 325 bias = elf->bias; … … 412 399 if (now > left) now = left; 413 400 414 rc = my_read(elf->fd, dp, now);415 416 if (rc < 0) {401 rc = read_all(elf->fd, dp, now); 402 403 if (rc != (ssize_t) now) { 417 404 DPRINTF("Read error.\n"); 418 405 return EE_INVALID; -
uspace/lib/c/generic/io/io.c
refcebe1 r3fb0fec 594 594 } 595 595 596 buf+= now;596 data += now; 597 597 stream->buf_head += now; 598 598 buf_free -= now; 599 599 bytes_left -= now; 600 600 total_written += now; 601 stream->buf_state = _bs_write; 601 602 602 603 if (buf_free == 0) { … … 606 607 } 607 608 } 608 609 if (total_written > 0)610 stream->buf_state = _bs_write;611 609 612 610 if (need_flush) -
uspace/lib/c/generic/rtld/module.c
refcebe1 r3fb0fec 35 35 */ 36 36 37 #include <adt/list.h> 38 #include <elf/elf_load.h> 39 #include <fcntl.h> 40 #include <loader/pcb.h> 37 41 #include <stdio.h> 38 42 #include <stdlib.h> 39 43 #include <unistd.h> 40 #include <fcntl.h>41 #include <adt/list.h>42 #include <loader/pcb.h>43 44 44 45 #include <rtld/rtld.h> … … 47 48 #include <rtld/rtld_arch.h> 48 49 #include <rtld/module.h> 49 #include <elf_load.h>50 50 51 51 /** (Eagerly) process all relocation tables in a module. … … 93 93 module_t *module_find(const char *name) 94 94 { 95 link_t *head = &runtime_env->modules_head;96 97 link_t *cur;98 95 module_t *m; 99 96 const char *p, *soname; … … 110 107 111 108 /* Traverse list of all modules. Not extremely fast, but simple */ 112 DPRINTF("head = %p\n", head); 113 for (cur = head->next; cur != head; cur = cur->next) { 109 list_foreach(runtime_env->modules, cur) { 114 110 DPRINTF("cur = %p\n", cur); 115 111 m = list_get_instance(cur, module_t, modules_link); … … 177 173 178 174 /* Insert into the list of loaded modules */ 179 list_append(&m->modules_link, &runtime_env->modules _head);175 list_append(&m->modules_link, &runtime_env->modules); 180 176 181 177 return m; … … 249 245 void modules_process_relocs(module_t *start) 250 246 { 251 link_t *head = &runtime_env->modules_head; 252 253 link_t *cur; 254 module_t *m; 255 256 for (cur = head->next; cur != head; cur = cur->next) { 247 module_t *m; 248 249 list_foreach(runtime_env->modules, cur) { 257 250 m = list_get_instance(cur, module_t, modules_link); 258 251 … … 268 261 void modules_untag(void) 269 262 { 270 link_t *head = &runtime_env->modules_head; 271 272 link_t *cur; 273 module_t *m; 274 275 for (cur = head->next; cur != head; cur = cur->next) { 263 module_t *m; 264 265 list_foreach(runtime_env->modules, cur) { 276 266 m = list_get_instance(cur, module_t, modules_link); 277 267 m->bfs_tag = false; -
uspace/lib/c/generic/rtld/rtld.c
refcebe1 r3fb0fec 44 44 { 45 45 runtime_env = &rt_env_static; 46 list_initialize(&runtime_env->modules _head);46 list_initialize(&runtime_env->modules); 47 47 runtime_env->next_bias = 0x2000000; 48 48 runtime_env->program = NULL; -
uspace/lib/c/generic/rtld/symbol.c
refcebe1 r3fb0fec 38 38 #include <stdlib.h> 39 39 40 #include <elf/elf.h> 40 41 #include <rtld/rtld.h> 41 42 #include <rtld/rtld_debug.h> 42 43 #include <rtld/symbol.h> 43 #include <elf.h>44 44 45 45 /* … … 118 118 module_t *m, *dm; 119 119 elf_symbol_t *sym, *s; 120 li nk_t queue_head;120 list_t queue; 121 121 size_t i; 122 122 … … 132 132 133 133 /* Insert root (the program) into the queue and tag it */ 134 list_initialize(&queue _head);134 list_initialize(&queue); 135 135 start->bfs_tag = true; 136 list_append(&start->queue_link, &queue _head);136 list_append(&start->queue_link, &queue); 137 137 138 138 /* If the symbol is found, it will be stored in 'sym' */ … … 140 140 141 141 /* While queue is not empty */ 142 while (!list_empty(&queue _head)) {142 while (!list_empty(&queue)) { 143 143 /* Pop first element from the queue */ 144 m = list_get_instance( queue_head.next, module_t, queue_link);144 m = list_get_instance(list_first(&queue), module_t, queue_link); 145 145 list_remove(&m->queue_link); 146 146 … … 162 162 if (dm->bfs_tag == false) { 163 163 dm->bfs_tag = true; 164 list_append(&dm->queue_link, &queue _head);164 list_append(&dm->queue_link, &queue); 165 165 } 166 166 } … … 168 168 169 169 /* Empty the queue so that we leave it in a clean state */ 170 while (!list_empty(&queue _head))171 list_remove( queue_head.next);170 while (!list_empty(&queue)) 171 list_remove(list_first(&queue)); 172 172 173 173 if (!sym) { -
uspace/lib/c/generic/vfs/vfs.c
refcebe1 r3fb0fec 417 417 } 418 418 419 /** Read entire buffer. 420 * 421 * In face of short reads this function continues reading until either 422 * the entire buffer is read or no more data is available (at end of file). 423 * 424 * @param fildes File descriptor 425 * @param buf Buffer, @a nbytes bytes long 426 * @param nbytes Number of bytes to read 427 * 428 * @return On success, positive number of bytes read. 429 * On failure, negative error code from read(). 430 */ 431 ssize_t read_all(int fildes, void *buf, size_t nbyte) 432 { 433 ssize_t cnt = 0; 434 size_t nread = 0; 435 uint8_t *bp = (uint8_t *) buf; 436 437 do { 438 bp += cnt; 439 nread += cnt; 440 cnt = read(fildes, bp, nbyte - nread); 441 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 442 443 if (cnt < 0) 444 return cnt; 445 446 return nread + cnt; 447 } 448 449 /** Write entire buffer. 450 * 451 * This function fails if it cannot write exactly @a len bytes to the file. 452 * 453 * @param fildes File descriptor 454 * @param buf Data, @a nbytes bytes long 455 * @param nbytes Number of bytes to write 456 * 457 * @return EOK on error, return value from write() if writing 458 * failed. 459 */ 460 ssize_t write_all(int fildes, const void *buf, size_t nbyte) 461 { 462 ssize_t cnt = 0; 463 ssize_t nwritten = 0; 464 const uint8_t *bp = (uint8_t *) buf; 465 466 do { 467 bp += cnt; 468 nwritten += cnt; 469 cnt = write(fildes, bp, nbyte - nwritten); 470 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 471 472 if (cnt < 0) 473 return cnt; 474 475 if ((ssize_t)nbyte - nwritten - cnt > 0) 476 return EIO; 477 478 return nbyte; 479 } 480 419 481 int fsync(int fildes) 420 482 { -
uspace/lib/c/include/elf/elf_load.h
refcebe1 r3fb0fec 1 1 /* 2 * Copyright (c) 2006 Sergey Bondari 2 3 * Copyright (c) 2008 Jiri Svoboda 3 4 * All rights reserved. … … 38 39 39 40 #include <arch/elf.h> 41 #include <elf/elf.h> 40 42 #include <sys/types.h> 41 43 #include <loader/pcb.h> 42 44 43 #include "elf.h" 45 /** 46 * ELF error return codes 47 */ 48 #define EE_OK 0 /* No error */ 49 #define EE_INVALID 1 /* Invalid ELF image */ 50 #define EE_MEMORY 2 /* Cannot allocate address space */ 51 #define EE_INCOMPATIBLE 3 /* ELF image is not compatible with current architecture */ 52 #define EE_UNSUPPORTED 4 /* Non-supported ELF (e.g. dynamic ELFs) */ 53 #define EE_LOADER 5 /* The image is actually a program loader. */ 54 #define EE_IRRECOVERABLE 6 44 55 45 56 typedef enum { … … 82 93 } elf_ld_t; 83 94 84 int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags, 85 elf_info_t *info);86 void elf_create_pcb(elf_info_t *info, pcb_t *pcb);95 extern const char *elf_error(unsigned int); 96 extern int elf_load_file(const char *, size_t, eld_flags_t, elf_info_t *); 97 extern void elf_create_pcb(elf_info_t *, pcb_t *); 87 98 88 99 #endif -
uspace/lib/c/include/rtld/elf_dyn.h
refcebe1 r3fb0fec 39 39 #include <sys/types.h> 40 40 41 #include <elf .h>41 #include <elf/elf.h> 42 42 #include <libarch/rtld/elf_dyn.h> 43 43 -
uspace/lib/c/include/rtld/rtld.h
refcebe1 r3fb0fec 49 49 50 50 /** List of all loaded modules including rtld and the program */ 51 li nk_t modules_head;51 list_t modules; 52 52 53 53 /** Temporary hack to place each module at different address. */ -
uspace/lib/c/include/rtld/symbol.h
refcebe1 r3fb0fec 36 36 #define LIBC_RTLD_SYMBOL_H_ 37 37 38 #include <elf/elf.h> 38 39 #include <rtld/rtld.h> 39 #include <elf.h>40 40 41 41 elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod); -
uspace/lib/c/include/unistd.h
refcebe1 r3fb0fec 63 63 extern ssize_t read(int, void *, size_t); 64 64 65 extern ssize_t read_all(int, void *, size_t); 66 extern ssize_t write_all(int, const void *, size_t); 67 65 68 extern off64_t lseek(int, off64_t, int); 66 69 extern int ftruncate(int, aoff64_t); -
uspace/lib/scsi/include/scsi/sbc.h
refcebe1 r3fb0fec 56 56 }; 57 57 58 /** SCSI Read (10) command */ 59 typedef struct { 60 /** Operation code (SCSI_CMD_READ_10) */ 61 uint8_t op_code; 62 /** RdProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 63 uint8_t flags; 64 /** Logical block address */ 65 uint32_t lba; 66 /** Reserved, Group Number */ 67 uint8_t group_no; 68 /** Transfer length */ 69 uint16_t xfer_len; 70 /** Control */ 71 uint8_t control; 72 } __attribute__((packed)) scsi_cdb_read_10_t; 73 58 74 /** SCSI Read (12) command */ 59 75 typedef struct { 60 76 /** Operation code (SCSI_CMD_READ_12) */ 61 77 uint8_t op_code; 62 /** RdProtect, DPO, FUA, Reserved, FUA_NV, Reserved*/78 /** RdProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 63 79 uint8_t flags; 64 80 /** Logical block address */ … … 115 131 } scsi_read_capacity_10_data_t; 116 132 133 /** SCSI Write (10) command */ 134 typedef struct { 135 /** Operation code (SCSI_CMD_WRITE_10) */ 136 uint8_t op_code; 137 /** WrProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 138 uint8_t flags; 139 /** Logical block address */ 140 uint32_t lba; 141 /** Reserved, Group Number */ 142 uint8_t group_no; 143 /** Transfer length */ 144 uint16_t xfer_len; 145 /** Control */ 146 uint8_t control; 147 } __attribute__((packed)) scsi_cdb_write_10_t; 148 117 149 /** SCSI Write (12) command */ 118 150 typedef struct { 119 151 /** Operation code (SCSI_CMD_WRITE_12) */ 120 152 uint8_t op_code; 121 /** WrProtect, DPO, FUA, Reserved, FUA_NV, Reserved*/153 /** WrProtect, DPO, FUA, Reserved, FUA_NV, Obsolete */ 122 154 uint8_t flags; 123 155 /** Logical block address */ -
uspace/lib/scsi/include/scsi/spc.h
refcebe1 r3fb0fec 179 179 uint8_t additional_len; 180 180 /** Command-specific Information */ 181 uint 8_t cmd_spec;181 uint32_t cmd_spec; 182 182 /** Additional Sense Code */ 183 183 uint8_t additional_code; … … 205 205 SCSI_SK_ABORTED_COMMAND = 0xb, 206 206 SCSI_SK_VOLUME_OVERFLOW = 0xd, 207 SCSI_SK_MISCOMPARE = 0xe 207 SCSI_SK_MISCOMPARE = 0xe, 208 209 SCSI_SK_LIMIT = 0x10 208 210 }; 209 211 210 212 extern const char *scsi_dev_type_str[SCSI_DEV_LIMIT]; 213 extern const char *scsi_sense_key_str[SCSI_SK_LIMIT]; 214 211 215 extern const char *scsi_get_dev_type_str(unsigned); 216 extern const char *scsi_get_sense_key_str(unsigned); 212 217 213 218 #endif -
uspace/lib/scsi/src/spc.c
refcebe1 r3fb0fec 44 44 }; 45 45 46 const char *scsi_sense_key_str[SCSI_SK_LIMIT] = { 47 [SCSI_SK_NO_SENSE] = "No Sense", 48 [SCSI_SK_RECOVERED_ERROR] = "Recovered Error", 49 [SCSI_SK_NOT_READY] = "Not Ready", 50 [SCSI_SK_MEDIUM_ERROR] = "Medium Error", 51 [SCSI_SK_HARDWARE_ERROR] = "Hardware Error", 52 [SCSI_SK_ILLEGAL_REQUEST] = "Illegal Request", 53 [SCSI_SK_UNIT_ATTENTION] = "Unit Attention", 54 [SCSI_SK_DATA_PROTECT] = "Data Protect", 55 [SCSI_SK_BLANK_CHECK] = "Blank Check", 56 [SCSI_SK_VENDOR_SPECIFIC] = "Vendor-specific", 57 [SCSI_SK_COPY_ABORTED] = "Copy Aborted", 58 [SCSI_SK_ABORTED_COMMAND] = "Aborted Command", 59 [SCSI_SK_VOLUME_OVERFLOW] = "Volume Overflow", 60 [SCSI_SK_MISCOMPARE] = "Miscompare" 61 }; 62 46 63 /** Get peripheral device type string. 47 64 * … … 53 70 { 54 71 if (dev_type >= SCSI_DEV_LIMIT || scsi_dev_type_str[dev_type] == NULL) 55 return " <unknown>";72 return "Unknown"; 56 73 57 74 return scsi_dev_type_str[dev_type]; 58 75 } 76 77 /** Get sense key string. 78 * 79 * Return string description of SCSI sense key. 80 * The returned string is valid indefinitely, the caller should 81 * not attempt to free it. 82 */ 83 const char *scsi_get_sense_key_str(unsigned sense_key) 84 { 85 if (sense_key >= SCSI_SK_LIMIT || scsi_sense_key_str[sense_key] == NULL) 86 return "Unknown"; 87 88 return scsi_sense_key_str[sense_key]; 89 } 90 -
uspace/srv/devman/devman.c
refcebe1 r3fb0fec 270 270 } 271 271 272 ssize_t read_bytes = safe_read(fd, buf, len);272 ssize_t read_bytes = read_all(fd, buf, len); 273 273 if (read_bytes <= 0) { 274 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 274 log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path, 275 read_bytes); 275 276 goto cleanup; 276 277 } … … 421 422 } 422 423 423 insert_fun_node(tree, fun, clone_string(""), NULL);424 insert_fun_node(tree, fun, str_dup(""), NULL); 424 425 match_id_t *id = create_match_id(); 425 id->id = clone_string("root");426 id->id = str_dup("root"); 426 427 id->score = 100; 427 428 add_match_id(&fun->match_ids, id); -
uspace/srv/devman/util.c
refcebe1 r3fb0fec 91 91 } 92 92 93 char *clone_string(const char *s)94 {95 size_t size = str_size(s) + 1;96 char *str;97 98 str = (char *) malloc(size);99 if (str != NULL)100 str_cpy(str, size, s);101 return str;102 }103 104 93 void replace_char(char *str, char orig, char repl) 105 94 { … … 111 100 } 112 101 113 ssize_t safe_read(int fd, void *buffer, size_t size)114 {115 if (size == 0) {116 return 0;117 }118 119 uint8_t *buf_ptr = (uint8_t *) buffer;120 121 size_t total_read = 0;122 while (total_read < size) {123 ssize_t bytes_read = read(fd, buf_ptr, size - total_read);124 if (bytes_read < 0) {125 /* Error. */126 return bytes_read;127 } else if (bytes_read == 0) {128 /* Possibly end of file. */129 break;130 } else {131 /* Read at least something. */132 buf_ptr += bytes_read;133 total_read += bytes_read;134 }135 }136 137 return (ssize_t) total_read;138 }139 140 102 /** @} 141 103 */ -
uspace/srv/devman/util.h
refcebe1 r3fb0fec 44 44 extern size_t get_nonspace_len(const char *); 45 45 extern void free_not_null(const void *); 46 extern char *clone_string(const char *);47 46 extern void replace_char(char *, char, char); 48 49 extern ssize_t safe_read(int, void *, size_t);50 47 51 48 #endif -
uspace/srv/loader/Makefile
refcebe1 r3fb0fec 39 39 LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld 40 40 41 EXTRA_CFLAGS = -Iinclude42 43 41 BINARY = loader 44 42 STATIC_ONLY = y … … 46 44 GENERIC_SOURCES = \ 47 45 main.c \ 48 elf_load.c \49 46 interp.s 50 47 -
uspace/srv/loader/main.c
refcebe1 r3fb0fec 59 59 #include <str.h> 60 60 #include <as.h> 61 #include <elf .h>62 #include <elf _load.h>61 #include <elf/elf.h> 62 #include <elf/elf_load.h> 63 63 64 64 #ifdef CONFIG_RTLD … … 348 348 349 349 /* Initialize list of loaded modules */ 350 list_initialize(&runtime_env->modules _head);351 list_append(&prog_mod.modules_link, &runtime_env->modules _head);350 list_initialize(&runtime_env->modules); 351 list_append(&prog_mod.modules_link, &runtime_env->modules); 352 352 353 353 /* Pointer to program module. Used as root of the module graph. */
Note:
See TracChangeset
for help on using the changeset viewer.