Adds an -smbrc option (to obsolete -smb option?) that gives better control of 
start up of private smb server and shares. Largest portion of change is 
moving option lists to separate file.

diff -r -N qemu-0.8.0/opts.h qemu-0.8.0-patched/opts.h
0a1,154
> /*
>  * QEMU System Emulator
>  * 
>  * Copyright (c) 2003-2005 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.
>  */
> 
> #define HAS_ARG     0x0001
> #define HAS_OPT_ARG 0x0002
> 
> enum {
>     QEMU_OPTION_h,
> 
>     QEMU_OPTION_M,
>     QEMU_OPTION_fda,
>     QEMU_OPTION_fdb,
>     QEMU_OPTION_hda,
>     QEMU_OPTION_hdb,
>     QEMU_OPTION_hdc,
>     QEMU_OPTION_hdd,
>     QEMU_OPTION_cdrom,
>     QEMU_OPTION_boot,
>     QEMU_OPTION_snapshot,
>     QEMU_OPTION_m,
>     QEMU_OPTION_nographic,
> #ifdef HAS_AUDIO
>     QEMU_OPTION_audio_help,
>     QEMU_OPTION_soundhw,
> #endif
> 
>     QEMU_OPTION_net,
>     QEMU_OPTION_tftp,
>     QEMU_OPTION_smb,
>     QEMU_OPTION_smbrc,
>     QEMU_OPTION_redir,
> 
>     QEMU_OPTION_kernel,
>     QEMU_OPTION_append,
>     QEMU_OPTION_initrd,
> 
>     QEMU_OPTION_S,
>     QEMU_OPTION_s,
>     QEMU_OPTION_p,
>     QEMU_OPTION_d,
>     QEMU_OPTION_hdachs,
>     QEMU_OPTION_L,
>     QEMU_OPTION_no_code_copy,
>     QEMU_OPTION_k,
>     QEMU_OPTION_localtime,
>     QEMU_OPTION_cirrusvga,
>     QEMU_OPTION_g,
>     QEMU_OPTION_std_vga,
>     QEMU_OPTION_monitor,
>     QEMU_OPTION_serial,
>     QEMU_OPTION_parallel,
>     QEMU_OPTION_loadvm,
>     QEMU_OPTION_full_screen,
>     QEMU_OPTION_pidfile,
>     QEMU_OPTION_no_kqemu,
>     QEMU_OPTION_win2k_hack,
>     QEMU_OPTION_usb,
>     QEMU_OPTION_usbdevice,
>     QEMU_OPTION_smp,
> };
> 
> typedef struct QEMUOption {
>     const char *name;
>     int flags;
>     int index;
> } QEMUOption;
> 
> static const QEMUOption qemu_options[] = {
>     { "h", 0, QEMU_OPTION_h },
> 
>     { "M", HAS_ARG, QEMU_OPTION_M },
>     { "fda", HAS_ARG, QEMU_OPTION_fda },
>     { "fdb", HAS_ARG, QEMU_OPTION_fdb },
>     { "hda", HAS_ARG, QEMU_OPTION_hda },
>     { "hdb", HAS_ARG, QEMU_OPTION_hdb },
>     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
>     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
>     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
>     { "boot", HAS_ARG, QEMU_OPTION_boot },
>     { "snapshot", 0, QEMU_OPTION_snapshot },
>     { "m", HAS_ARG, QEMU_OPTION_m },
>     { "nographic", 0, QEMU_OPTION_nographic },
>     { "k", HAS_ARG, QEMU_OPTION_k },
> #ifdef HAS_AUDIO
>     { "audio-help", 0, QEMU_OPTION_audio_help },
>     { "soundhw", HAS_ARG, QEMU_OPTION_soundhw },
> #endif
> 
>     { "net", HAS_ARG, QEMU_OPTION_net},
> #ifdef CONFIG_SLIRP
>     { "tftp", HAS_ARG, QEMU_OPTION_tftp },
> #ifndef _WIN32
>     { "smb", HAS_ARG, QEMU_OPTION_smb },
>     { "smbrc", HAS_OPT_ARG, QEMU_OPTION_smbrc },
> #endif
>     { "redir", HAS_ARG, QEMU_OPTION_redir },
> #endif
> 
>     { "kernel", HAS_ARG, QEMU_OPTION_kernel },
>     { "append", HAS_ARG, QEMU_OPTION_append },
>     { "initrd", HAS_ARG, QEMU_OPTION_initrd },
> 
>     { "S", 0, QEMU_OPTION_S },
>     { "s", 0, QEMU_OPTION_s },
>     { "p", HAS_ARG, QEMU_OPTION_p },
>     { "d", HAS_ARG, QEMU_OPTION_d },
>     { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
>     { "L", HAS_ARG, QEMU_OPTION_L },
>     { "no-code-copy", 0, QEMU_OPTION_no_code_copy },
> #ifdef USE_KQEMU
>     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
> #endif
> #if defined(TARGET_PPC) || defined(TARGET_SPARC)
>     { "g", 1, QEMU_OPTION_g },
> #endif
>     { "localtime", 0, QEMU_OPTION_localtime },
>     { "std-vga", 0, QEMU_OPTION_std_vga },
>     { "monitor", 1, QEMU_OPTION_monitor },
>     { "serial", 1, QEMU_OPTION_serial },
>     { "parallel", 1, QEMU_OPTION_parallel },
>     { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
>     { "full-screen", 0, QEMU_OPTION_full_screen },
>     { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
>     { "win2k-hack", 0, QEMU_OPTION_win2k_hack },
>     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
>     { "smp", HAS_ARG, QEMU_OPTION_smp },
>     
>     /* temporary options */
>     { "usb", 0, QEMU_OPTION_usb },
>     { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
>     { NULL },
> };
> 
diff -r -N qemu-0.8.0/README.smbrc qemu-0.8.0-patched/README.smbrc
0a1,48
> The -smbrc option permits much greater control over the operation of
> the private smb server by providing for startup and shutdown scripts
> for smb. I use it to access cups printers. In my (in)experience a shut
> down script is not very useful so getting one to run is a little
> awkward. Here are the various forms:
> 
> 	Option			Startup		Shutdown
> 	------			-------		--------
> 	-smbrc			default		<none>
> 	-smbrc :		default		default
> 	-smbrc name1		name1		<none>
> 	-smbrc name1:		name1		default
> 	-smbrc name1:name2	name1		name2
> 	-smbrc :name2		default		name2
> 
> The default scripts are $HOME/.qemu/smb_uprc and $HOME/.qemu/smb_dnrc.
> If the name of a script begins with a slash (/) or a tilde (~) it is
> assumed to be an absolute path name. Otherwise the name is assumed to
> be relative to $HOME/.qemu/ so name1 would become $HOME/.qemu/name1 in
> use.
> 
> Qemu calls the startup script with the name of the temporary directory
> name as argument 1 and the name of the config file as argument 2. The
> shutdown script gets only the temporary directory name. The following
> example startup script recreates the behavior of the -smb option with
> the substitution of the exported directory:
> 
> 
> #! /bin/bash
> cat >$2 <<EOF
> [global]  
>   private dir=$1  
>   smb ports=0  
>   socket address=127.0.0.1  
>   pid directory=$1
>   lock directory=$1  
>   log file=$i/log.smbd  
>   smb passwd file=$1/smbpasswd  
>   security = share  
> [qemu]  
>   path=!!!!!!!!!EXPORT DIRECTORY HERE!!!!!!!!!
>   read only=no  
>   guest ok=yes
> EOF
> 
> 
> Don't forget to make it executable. Enjoy.
> 
diff -r -N qemu-0.8.0/vl.c qemu-0.8.0-patched/vl.c
33a34
> #include <stdlib.h>
85a87,88
> #include "opts.h"
> 
1901c1904,1906
< char smb_dir[1024];
---
> static char  smb_dir[50];
> static char* smb_dnrc = 0;;
> const  char* qemu_opt_home = "$HOME/.qemu/";
1905,1907c1910
<     DIR *d;
<     struct dirent *de;
<     char filename[1024];
---
>     char smb_cmdline[PATH_MAX];
1909,1920c1912,1916
<     /* erase all the files in the directory */
<     d = opendir(smb_dir);
<     for(;;) {
<         de = readdir(d);
<         if (!de)
<             break;
<         if (strcmp(de->d_name, ".") != 0 &&
<             strcmp(de->d_name, "..") != 0) {
<             snprintf(filename, sizeof(filename), "%s/%s", 
<                      smb_dir, de->d_name);
<             unlink(filename);
<         }
---
>     if (smb_dnrc != 0) {
>         snprintf(smb_cmdline,sizeof(smb_cmdline),"%s %s",smb_dnrc,smb_dir);
>         if (system(smb_cmdline) != 0)
>             fprintf(stderr, "qemu: error executing samba stop script '%s'\n", smb_dnrc);
>         free(smb_dnrc);
1922,1923c1918,1919
<     closedir(d);
<     rmdir(smb_dir);
---
>     snprintf(smb_cmdline,sizeof(smb_cmdline),"rm -R %s",smb_dir);
>     system(smb_cmdline);
1927c1923
< void net_slirp_smb(const char *exported_dir)
---
> void net_slirp_smb(const char *exported_dir, const int style)
1929,1930c1925,1926
<     char smb_conf[1024];
<     char smb_cmdline[1024];
---
>     char smb_conf[60];
>     char smb_cmdline[PATH_MAX];
1946,1951c1942,1949
<     f = fopen(smb_conf, "w");
<     if (!f) {
<         fprintf(stderr, "qemu: could not create samba server configuration file '%s'\n", smb_conf);
<         exit(1);
<     }
<     fprintf(f, 
---
>     if (style == QEMU_OPTION_smb) {
>         f = fopen(smb_conf, "w");
>         if (!f) {
>             fprintf(stderr, "qemu: could not create samba server configuration file '%s'\n", smb_conf);
>             exit(1);
>         }
> 
>         fprintf(f, 
1972c1970,2009
<     fclose(f);
---
>         fclose(f);
>     } else {
>         char* cp;
>         char  smb_uprc[PATH_MAX];
>         /* New style using setup and teardown scripts in home directory */
>         /*
>            First parse the option string to extract any script names
>         */
>         strcpy(smb_uprc,qemu_opt_home);
>         if (exported_dir == 0)
>             strcat(smb_uprc,"smb_uprc");
>         else {
>             for (cp = (char*)exported_dir; *cp != '\0' && *cp != ':'; ++cp);
>             if (*cp == ':') {
>                 *cp++ = '\0';
>                 smb_dnrc = (char*)malloc(PATH_MAX);
>                 if (smb_dnrc == 0) {
>                     fprintf(stderr, "qemu: could not allocate samba server memory\n");
>                     exit(1);
>                     }            
>                 strcpy(smb_dnrc,qemu_opt_home);
>                 if (*cp == '\0')
>                     strcat(smb_dnrc,"smb_dnrc");
>                 else if (*cp == '/' || *cp == '~')
>                     strcpy(smb_dnrc,cp);
>                 else
>        	            strcat(smb_dnrc,cp);
>             }
>             if (exported_dir[0] == '\0')
>                 strcat(smb_uprc,"smb_uprc");
>             else if (exported_dir[0] == '/' || exported_dir[0] == '~')
>            	strcpy(smb_uprc,exported_dir);
>             else
>        	        strcat(smb_uprc,exported_dir);
> 	}
>         /* Execute the start up script */
>         snprintf(smb_cmdline, sizeof(smb_cmdline), "%s %s %s",smb_uprc,smb_dir,smb_conf);
>         if (system(smb_cmdline) != 0)
>             fprintf(stderr, "qemu: error executing samba start script '%s'\n", smb_uprc);
>         }
4013a4051,4053
>            "-smbrc [start_rc][:[stop_rc]]\n"
>            "                allow SMB access to files using 'start_rc' and\n"
>            "                'stop_rc' (Obsoletes -smb option?)\n"
4075,4201d4114
< #define HAS_ARG 0x0001
< 
< enum {
<     QEMU_OPTION_h,
< 
<     QEMU_OPTION_M,
<     QEMU_OPTION_fda,
<     QEMU_OPTION_fdb,
<     QEMU_OPTION_hda,
<     QEMU_OPTION_hdb,
<     QEMU_OPTION_hdc,
<     QEMU_OPTION_hdd,
<     QEMU_OPTION_cdrom,
<     QEMU_OPTION_boot,
<     QEMU_OPTION_snapshot,
<     QEMU_OPTION_m,
<     QEMU_OPTION_nographic,
< #ifdef HAS_AUDIO
<     QEMU_OPTION_audio_help,
<     QEMU_OPTION_soundhw,
< #endif
< 
<     QEMU_OPTION_net,
<     QEMU_OPTION_tftp,
<     QEMU_OPTION_smb,
<     QEMU_OPTION_redir,
< 
<     QEMU_OPTION_kernel,
<     QEMU_OPTION_append,
<     QEMU_OPTION_initrd,
< 
<     QEMU_OPTION_S,
<     QEMU_OPTION_s,
<     QEMU_OPTION_p,
<     QEMU_OPTION_d,
<     QEMU_OPTION_hdachs,
<     QEMU_OPTION_L,
<     QEMU_OPTION_no_code_copy,
<     QEMU_OPTION_k,
<     QEMU_OPTION_localtime,
<     QEMU_OPTION_cirrusvga,
<     QEMU_OPTION_g,
<     QEMU_OPTION_std_vga,
<     QEMU_OPTION_monitor,
<     QEMU_OPTION_serial,
<     QEMU_OPTION_parallel,
<     QEMU_OPTION_loadvm,
<     QEMU_OPTION_full_screen,
<     QEMU_OPTION_pidfile,
<     QEMU_OPTION_no_kqemu,
<     QEMU_OPTION_win2k_hack,
<     QEMU_OPTION_usb,
<     QEMU_OPTION_usbdevice,
<     QEMU_OPTION_smp,
< };
< 
< typedef struct QEMUOption {
<     const char *name;
<     int flags;
<     int index;
< } QEMUOption;
< 
< const QEMUOption qemu_options[] = {
<     { "h", 0, QEMU_OPTION_h },
< 
<     { "M", HAS_ARG, QEMU_OPTION_M },
<     { "fda", HAS_ARG, QEMU_OPTION_fda },
<     { "fdb", HAS_ARG, QEMU_OPTION_fdb },
<     { "hda", HAS_ARG, QEMU_OPTION_hda },
<     { "hdb", HAS_ARG, QEMU_OPTION_hdb },
<     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
<     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
<     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
<     { "boot", HAS_ARG, QEMU_OPTION_boot },
<     { "snapshot", 0, QEMU_OPTION_snapshot },
<     { "m", HAS_ARG, QEMU_OPTION_m },
<     { "nographic", 0, QEMU_OPTION_nographic },
<     { "k", HAS_ARG, QEMU_OPTION_k },
< #ifdef HAS_AUDIO
<     { "audio-help", 0, QEMU_OPTION_audio_help },
<     { "soundhw", HAS_ARG, QEMU_OPTION_soundhw },
< #endif
< 
<     { "net", HAS_ARG, QEMU_OPTION_net},
< #ifdef CONFIG_SLIRP
<     { "tftp", HAS_ARG, QEMU_OPTION_tftp },
< #ifndef _WIN32
<     { "smb", HAS_ARG, QEMU_OPTION_smb },
< #endif
<     { "redir", HAS_ARG, QEMU_OPTION_redir },
< #endif
< 
<     { "kernel", HAS_ARG, QEMU_OPTION_kernel },
<     { "append", HAS_ARG, QEMU_OPTION_append },
<     { "initrd", HAS_ARG, QEMU_OPTION_initrd },
< 
<     { "S", 0, QEMU_OPTION_S },
<     { "s", 0, QEMU_OPTION_s },
<     { "p", HAS_ARG, QEMU_OPTION_p },
<     { "d", HAS_ARG, QEMU_OPTION_d },
<     { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
<     { "L", HAS_ARG, QEMU_OPTION_L },
<     { "no-code-copy", 0, QEMU_OPTION_no_code_copy },
< #ifdef USE_KQEMU
<     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
< #endif
< #if defined(TARGET_PPC) || defined(TARGET_SPARC)
<     { "g", 1, QEMU_OPTION_g },
< #endif
<     { "localtime", 0, QEMU_OPTION_localtime },
<     { "std-vga", 0, QEMU_OPTION_std_vga },
<     { "monitor", 1, QEMU_OPTION_monitor },
<     { "serial", 1, QEMU_OPTION_serial },
<     { "parallel", 1, QEMU_OPTION_parallel },
<     { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
<     { "full-screen", 0, QEMU_OPTION_full_screen },
<     { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
<     { "win2k-hack", 0, QEMU_OPTION_win2k_hack },
<     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
<     { "smp", HAS_ARG, QEMU_OPTION_smp },
<     
<     /* temporary options */
<     { "usb", 0, QEMU_OPTION_usb },
<     { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
<     { NULL },
< };
< 
4477a4391
>             optarg = NULL;
4485,4486c4399,4401
<             } else {
<                 optarg = NULL;
---
>             } else if (popt->flags & HAS_OPT_ARG) {
>                 if (optind < argc && argv[optind][0] != '-')
>                     optarg = argv[optind++];
4610c4525,4526
< 		net_slirp_smb(optarg);
---
>             case QEMU_OPTION_smbrc:
> 		net_slirp_smb(optarg,popt->index);
_______________________________________________
Qemu-devel mailing list
Qemu-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Reply via email to