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

Diff of /qemu/block.c

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

revision 1.1 by bellard, Mon Jun 30 10:03:06 2003 UTC revision 1.2 by bellard, Mon Jun 30 23:17:31 2003 UTC
# Line 44  Line 44 
44  struct BlockDriverState {  struct BlockDriverState {
45      int fd;      int fd;
46      int64_t total_sectors;      int64_t total_sectors;
47        int read_only;
48  };  };
49    
50  BlockDriverState *bdrv_open(const char *filename)  BlockDriverState *bdrv_open(const char *filename)
# Line 55  BlockDriverState *bdrv_open(const char * Line 56  BlockDriverState *bdrv_open(const char *
56      bs = malloc(sizeof(BlockDriverState));      bs = malloc(sizeof(BlockDriverState));
57      if(!bs)      if(!bs)
58          return NULL;          return NULL;
59        bs->read_only = 0;
60      fd = open(filename, O_RDWR);      fd = open(filename, O_RDWR);
61      if (fd < 0) {      if (fd < 0) {
62          close(fd);          fd = open(filename, O_RDONLY);
63          free(bs);          if (fd < 0) {
64          return NULL;              close(fd);
65                free(bs);
66                return NULL;
67            }
68            bs->read_only = 1;
69      }      }
70      size = lseek64(fd, 0, SEEK_END);      size = lseek64(fd, 0, SEEK_END);
71      bs->total_sectors = size / 512;      bs->total_sectors = size / 512;
# Line 93  int bdrv_write(BlockDriverState *bs, int Line 99  int bdrv_write(BlockDriverState *bs, int
99  {  {
100      int ret;      int ret;
101    
102        if (bs->read_only)
103            return -1;
104    
105      lseek64(bs->fd, sector_num * 512, SEEK_SET);      lseek64(bs->fd, sector_num * 512, SEEK_SET);
106      ret = write(bs->fd, buf, nb_sectors * 512);      ret = write(bs->fd, buf, nb_sectors * 512);
107      if (ret != nb_sectors * 512)      if (ret != nb_sectors * 512)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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