/* * create a COW disk image * * Copyright (c) 2003 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "vl.h" void *get_mmap_addr(unsigned long size) { return NULL; } void qemu_free(void *ptr) { free(ptr); } void *qemu_malloc(size_t size) { return malloc(size); } void *qemu_mallocz(size_t size) { void *ptr; ptr = qemu_malloc(size); if (!ptr) return NULL; memset(ptr, 0, size); return ptr; } char *qemu_strdup(const char *str) { char *ptr; ptr = qemu_malloc(strlen(str) + 1); if (!ptr) return NULL; strcpy(ptr, str); return ptr; } void pstrcpy(char *buf, int buf_size, const char *str) { int c; char *q = buf; if (buf_size <= 0) return; for(;;) { c = *str++; if (c == 0 || q >= buf + buf_size - 1) break; *q++ = c; } *q = '\0'; } /* strcat and truncate. */ char *pstrcat(char *buf, int buf_size, const char *s) { int len; len = strlen(buf); if (len < buf_size) pstrcpy(buf + len, buf_size - len, s); return buf; } int strstart(const char *str, const char *val, const char **ptr) { const char *p, *q; p = str; q = val; while (*q != '\0') { if (*p != *q) return 0; p++; q++; } if (ptr) *ptr = p; return 1; } void term_printf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); } void __attribute__((noreturn)) error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "qemu-img: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); exit(1); va_end(ap); } static void format_print(void *opaque, const char *name) { printf(" %s", name); } void help(void) { printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004 Fabrice Bellard\n" "usage: qemu-img command [command options]\n" "QEMU disk image utility\n" "\n" "Command syntax:\n" " create [-e] [-b base_image] [-f fmt] filename [size]\n" " commit [-f fmt] filename\n" " convert [-c] [-e] [-f fmt] filename [-O output_fmt] output_filename\n" " info [-f fmt] filename\n" "\n" "Command parameters:\n" " 'filename' is a disk image filename\n" " 'base_image' is the read-only disk image which is used as base for a copy on\n" " write image; the copy on write image only stores the modified data\n" " 'fmt' is the disk image format. It is guessed automatically in most cases\n" " 'size' is the disk image size in kilobytes. Optional suffixes 'M' (megabyte)\n" " and 'G' (gigabyte) are supported\n" " 'output_filename' is the destination disk image filename\n" " 'output_fmt' is the destination format\n" " '-c' indicates that target image must be compressed (qcow format only)\n" " '-e' indicates that the target image must be encrypted (qcow format only)\n" ); printf("\nSupported format:"); bdrv_iterate_format(format_print, NULL); printf("\n"); exit(1); } #define NB_SUFFIXES 4 static void get_human_readable_size(char *buf, int buf_size, int64_t size) { char suffixes[NB_SUFFIXES] = "KMGT"; int64_t base; int i; if (size <= 999) { snprintf(buf, buf_size, "%lld", size); } else { base = 1024; for(i = 0; i < NB_SUFFIXES; i++) { if (size < (10 * base)) { snprintf(buf, buf_size, "%0.1f%c", (double)size / base, suffixes[i]); break; } else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) { snprintf(buf, buf_size, "%lld%c", (size + (base >> 1)) / base, suffixes[i]); break; } base = base * 1024; } } } #if defined(WIN32) /* XXX: put correct support for win32 */ static int read_password(char *buf, int buf_size) { int c, i; printf("Password: "); fflush(stdout); i = 0; for(;;) { c = getchar(); if (c == '\n') break; if (i < (buf_size - 1)) buf[i++] = c; } buf[i] = '\0'; return 0; } #else #include static struct termios oldtty; static void term_exit(void) { tcsetattr (0, TCSANOW, &oldtty); } static void term_init(void) { struct termios tty; tcgetattr (0, &tty); oldtty = tty; tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON); tty.c_oflag |= OPOST; tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN); tty.c_cflag &= ~(CSIZE|PARENB); tty.c_cflag |= CS8; tty.c_cc[VMIN] = 1; tty.c_cc[VTIME] = 0; tcsetattr (0, TCSANOW, &tty); atexit(term_exit); } int read_password(char *buf, int buf_size)
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *  \brief Application Configuration Header File
 *
 *  This is a header file which is be used to configure some of
 *  the application's compile time options, as an alternative to
 *  specifying the compile time constants supplied through a
 *  makefile or build system.
 *
 *  For information on what each token does, refer to the
 *  \ref Sec_Options section of the application documentation.
 */

#ifndef _APP_CONFIG_H_
#define _APP_CONFIG_H_

	#define ENABLE_DHCP_CLIENT
	#define ENABLE_DHCP_SERVER
	#define ENABLE_TELNET_SERVER
	#define MAX_URI_LENGTH                50

	#define DEVICE_IP_ADDRESS             (uint8_t[]){ 10,   0,   0,   2}
	#define DEVICE_NETMASK                (uint8_t[]){255, 255, 255,   0}
	#define DEVICE_GATEWAY                (uint8_t[]){ 10,   0,   0,   1}
	#define SERVER_MAC_ADDRESS            (uint8_t[]){  1,   0,   1,   0,   1,   0}

	#define UIP_CONF_UDP                  (defined(ENABLE_DHCP_CLIENT) || defined(ENABLE_DHCP_SERVER))
	#define UIP_CONF_BROADCAST            1
	#define UIP_CONF_TCP                  1
	#define UIP_CONF_UDP_CONNS            1
	#define UIP_CONF_MAX_CONNECTIONS      3
	#define UIP_CONF_MAX_LISTENPORTS      5
	#define UIP_CONF_BUFFER_SIZE          1514
	#define UIP_CONF_LL_802154            0
	#define UIP_CONF_LL_80211             0
	#define UIP_CONF_ROUTER               0
	#define UIP_CONF_ICMP6                0
	#define UIP_CONF_ICMP_DEST_UNREACH    1
	#define UIP_URGDATA                   0
	#define UIP_ARCH_CHKSUM               0
	#define UIP_ARCH_ADD32                0
	#define UIP_NEIGHBOR_CONF_ADDRTYPE    0

#endif
= getopt(argc, argv, "f:h"); if (c == -1) break; switch(c) { case 'h': help(); break; case 'f': fmt = optarg; break; } } if (optind >= argc) help(); filename = argv[optind++]; bs = bdrv_new(""); if (!bs) error("Not enough memory"); if (fmt) { drv = bdrv_find_format(fmt); if (!drv) error("Unknown file format '%s'", fmt); } else { drv = NULL; } if (bdrv_open2(bs, filename, 0, drv) < 0) { error("Could not open '%s'", filename); } bdrv_get_format(bs, fmt_name, sizeof(fmt_name)); bdrv_get_geometry(bs, &total_sectors); get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512); allocated_size = get_allocated_file_size(filename); if (allocated_size < 0) error("Could not get file size '%s'", filename); get_human_readable_size(dsize_buf, sizeof(dsize_buf), allocated_size); printf("image: %s\n" "file format: %s\n" "virtual size: %s (%lld bytes)\n" "disk size: %s\n", filename, fmt_name, size_buf, total_sectors * 512, dsize_buf); if (bdrv_is_encrypted(bs)) printf("encrypted: yes\n"); bdrv_delete(bs); return 0; } int main(int argc, char **argv) { const char *cmd; bdrv_init(); if (argc < 2) help(); cmd = argv[1]; optind++; if (!strcmp(cmd, "create")) { img_create(argc, argv); } else if (!strcmp(cmd, "commit")) { img_commit(argc, argv); } else if (!strcmp(cmd, "convert")) { img_convert(argc, argv); } else if (!strcmp(cmd, "info")) { img_info(argc, argv); } else { help(); } return 0; }