/[qemu]/qemu/block.c
ViewVC logotype

Diff of /qemu/block.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by bellard, Tue Apr 26 21:47:02 2005 UTC revision 1.19 by bellard, Tue Apr 26 21:59:26 2005 UTC
# Line 24  Line 24 
24  #include "vl.h"  #include "vl.h"
25  #include "block_int.h"  #include "block_int.h"
26    
27    #ifdef _BSD
28    #include <sys/types.h>
29    #include <sys/stat.h>
30    #include <sys/ioctl.h>
31    #include <sys/queue.h>
32    #include <sys/disk.h>
33    #endif
34    
35  static BlockDriverState *bdrv_first;  static BlockDriverState *bdrv_first;
36  static BlockDriver *first_drv;  static BlockDriver *first_drv;
37    
# Line 88  static void get_tmp_filename(char *filen Line 96  static void get_tmp_filename(char *filen
96  }  }
97  #endif  #endif
98    
99    /* XXX: force raw format if block or character device ? It would
100       simplify the BSD case */
101  static BlockDriver *find_image_format(const char *filename)  static BlockDriver *find_image_format(const char *filename)
102  {  {
103      int fd, ret, score, score_max;      int fd, ret, score, score_max;
104      BlockDriver *drv1, *drv;      BlockDriver *drv1, *drv;
105      uint8_t buf[1024];      uint8_t *buf;
106        size_t bufsize = 1024;
107    
108      fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);      fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
109      if (fd < 0)      if (fd < 0)
110          return NULL;          return NULL;
111      ret = read(fd, buf, sizeof(buf));  #ifdef DIOCGSECTORSIZE
112        {
113            unsigned int sectorsize = 512;
114            if (!ioctl(fd, DIOCGSECTORSIZE, &sectorsize) &&
115                sectorsize > bufsize)
116                bufsize = sectorsize;
117        }
118    #endif
119        buf = malloc(bufsize);
120        if (!buf)
121            return NULL;
122        ret = read(fd, buf, bufsize);
123      if (ret < 0) {      if (ret < 0) {
124          close(fd);          close(fd);
125            free(buf);
126          return NULL;          return NULL;
127      }      }
128      close(fd);      close(fd);
# Line 113  static BlockDriver *find_image_format(co Line 136  static BlockDriver *find_image_format(co
136              drv = drv1;              drv = drv1;
137          }          }
138      }      }
139        free(buf);
140      return drv;      return drv;
141  }  }
142    
# Line 532  static int raw_open(BlockDriverState *bs Line 556  static int raw_open(BlockDriverState *bs
556              return -1;              return -1;
557          bs->read_only = 1;          bs->read_only = 1;
558      }      }
559      size = lseek(fd, 0, SEEK_END);  #ifdef _BSD
560        {
561            struct stat sb;
562            if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) {
563    #ifdef DIOCGMEDIASIZE
564                if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size))
565    #endif
566                    size = lseek(fd, 0LL, SEEK_END);
567        } else
568    #endif
569        {
570            size = lseek(fd, 0, SEEK_END);
571        }
572  #ifdef _WIN32  #ifdef _WIN32
573      /* On Windows hosts it can happen that we're unable to get file size      /* On Windows hosts it can happen that we're unable to get file size
574         for CD-ROM raw device (it's inherent limitation of the CDFS driver). */         for CD-ROM raw device (it's inherent limitation of the CDFS driver). */

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26