From 7e0d45cb1f23228ed95d358f4398e713e421c98d Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 15 Nov 2008 19:18:32 +0000 Subject: semaphore not being initialized; wrong offset used git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1245 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/drivers/loop.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'nuttx/drivers/loop.c') diff --git a/nuttx/drivers/loop.c b/nuttx/drivers/loop.c index 7719bd994..c1a160be0 100644 --- a/nuttx/drivers/loop.c +++ b/nuttx/drivers/loop.c @@ -211,13 +211,13 @@ static ssize_t loop_read(FAR struct inode *inode, unsigned char *buffer, if (start_sector + nsectors > dev->nsectors) { - dbg("Seek failed for offset=%d: %d\n", (int)offset, errno); + dbg("Read past end of file\n"); return -EIO; } /* Calculate the offset to read the sectors and seek to the position */ - offset = start_sector * dev->sectsize + offset; + offset = start_sector * dev->sectsize + dev->offset; ret = lseek(dev->fd, offset, SEEK_SET); if (ret == (off_t)-1) { @@ -264,7 +264,7 @@ static ssize_t loop_write(FAR struct inode *inode, const unsigned char *buffer, /* Calculate the offset to write the sectors and seek to the position */ - offset = start_sector * dev->sectsize + offset; + offset = start_sector * dev->sectsize + dev->offset; ret = lseek(dev->fd, offset, SEEK_SET); if (ret == (off_t)-1) { @@ -373,8 +373,9 @@ int losetup(const char *devname, const char *filename, uint16 sectsize, return -ENOMEM; } - /* Initialize the geometry */ + /* Initialize the loop device structure. */ + sem_init(&dev->sem, 0, 1); dev->nsectors = (sb.st_size - offset) / sectsize; dev->sectsize = sectsize; dev->offset = offset; -- cgit v1.2.3