parent
cb6d451564
commit
3237efd089
|
@ -63,6 +63,7 @@ struct dfs_file
|
|||
struct dfs_vnode *vnode; /* file node struct */
|
||||
void *data; /* Specific fd data */
|
||||
};
|
||||
#define DFS_FILE_POS(dfs_file) ((dfs_file)->pos)
|
||||
|
||||
#ifdef RT_USING_SMART
|
||||
struct dfs_mmap2_args
|
||||
|
|
|
@ -282,9 +282,7 @@ int dfs_devfs_ioctl(struct dfs_file *file, int cmd, void *args)
|
|||
{
|
||||
result = device->fops->ioctl(file, cmd, args);
|
||||
}
|
||||
else if (device->ops)
|
||||
#else
|
||||
if (device->ops)
|
||||
else
|
||||
#endif /* RT_USING_POSIX_DEVIO */
|
||||
{
|
||||
result = rt_device_control(device, cmd, args);
|
||||
|
@ -312,9 +310,7 @@ ssize_t dfs_devfs_read(struct dfs_file *file, void *buf, size_t count, off_t *po
|
|||
{
|
||||
result = device->fops->read(file, buf, count, pos);
|
||||
}
|
||||
else if (device->ops)
|
||||
#else
|
||||
if (device->ops)
|
||||
else
|
||||
#endif /* RT_USING_POSIX_DEVIO */
|
||||
{
|
||||
/* read device data */
|
||||
|
@ -344,9 +340,7 @@ ssize_t dfs_devfs_write(struct dfs_file *file, const void *buf, size_t count, of
|
|||
{
|
||||
result = device->fops->write(file, buf, count, pos);
|
||||
}
|
||||
else if (device->ops)
|
||||
#else
|
||||
if (device->ops)
|
||||
else
|
||||
#endif /* RT_USING_POSIX_DEVIO */
|
||||
{
|
||||
/* read device data */
|
||||
|
@ -375,9 +369,7 @@ int dfs_devfs_close(struct dfs_file *file)
|
|||
{
|
||||
result = device->fops->close(file);
|
||||
}
|
||||
else if (device->ops)
|
||||
#else
|
||||
if (device->ops)
|
||||
else
|
||||
#endif /* RT_USING_POSIX_DEVIO */
|
||||
{
|
||||
/* close device handler */
|
||||
|
@ -417,9 +409,7 @@ int dfs_devfs_open(struct dfs_file *file)
|
|||
return RT_EOK;
|
||||
}
|
||||
}
|
||||
else if (device->ops)
|
||||
#else
|
||||
if (device->ops)
|
||||
else
|
||||
#endif /* RT_USING_POSIX_DEVIO */
|
||||
{
|
||||
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
|
||||
|
|
|
@ -101,6 +101,7 @@ struct dfs_file
|
|||
|
||||
void *data;
|
||||
};
|
||||
#define DFS_FILE_POS(dfs_file) ((dfs_file)->fpos)
|
||||
|
||||
/* file is open for reading */
|
||||
#define FMODE_READ 0x1
|
||||
|
|
|
@ -32,12 +32,12 @@
|
|||
#ifdef RT_USING_DEVICE
|
||||
|
||||
#ifdef RT_USING_DEVICE_OPS
|
||||
#define device_init (dev->ops->init)
|
||||
#define device_open (dev->ops->open)
|
||||
#define device_close (dev->ops->close)
|
||||
#define device_read (dev->ops->read)
|
||||
#define device_write (dev->ops->write)
|
||||
#define device_control (dev->ops->control)
|
||||
#define device_init (dev->ops ? dev->ops->init : RT_NULL)
|
||||
#define device_open (dev->ops ? dev->ops->open : RT_NULL)
|
||||
#define device_close (dev->ops ? dev->ops->close : RT_NULL)
|
||||
#define device_read (dev->ops ? dev->ops->read : RT_NULL)
|
||||
#define device_write (dev->ops ? dev->ops->write : RT_NULL)
|
||||
#define device_control (dev->ops ? dev->ops->control : RT_NULL)
|
||||
#else
|
||||
#define device_init (dev->init)
|
||||
#define device_open (dev->open)
|
||||
|
|
|
@ -424,7 +424,7 @@ static int char_dev_fopen(struct dfs_file *fd)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
fd->pos = 0;
|
||||
DFS_FILE_POS(fd) = 0;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
@ -436,15 +436,15 @@ static int char_dev_fread(struct dfs_file *fd, void *buf, size_t count)
|
|||
|
||||
assert(part != RT_NULL);
|
||||
|
||||
if (fd->pos + count > part->fal_part->len)
|
||||
count = part->fal_part->len - fd->pos;
|
||||
if (DFS_FILE_POS(fd) + count > part->fal_part->len)
|
||||
count = part->fal_part->len - DFS_FILE_POS(fd);
|
||||
|
||||
ret = fal_partition_read(part->fal_part, fd->pos, buf, count);
|
||||
ret = fal_partition_read(part->fal_part, DFS_FILE_POS(fd), buf, count);
|
||||
|
||||
if (ret != (int)(count))
|
||||
return 0;
|
||||
|
||||
fd->pos += ret;
|
||||
DFS_FILE_POS(fd) += ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -456,15 +456,15 @@ static int char_dev_fwrite(struct dfs_file *fd, const void *buf, size_t count)
|
|||
|
||||
assert(part != RT_NULL);
|
||||
|
||||
if (fd->pos + count > part->fal_part->len)
|
||||
count = part->fal_part->len - fd->pos;
|
||||
if (DFS_FILE_POS(fd) + count > part->fal_part->len)
|
||||
count = part->fal_part->len - DFS_FILE_POS(fd);
|
||||
|
||||
ret = fal_partition_write(part->fal_part, fd->pos, buf, count);
|
||||
ret = fal_partition_write(part->fal_part, DFS_FILE_POS(fd), buf, count);
|
||||
|
||||
if (ret != (int) count)
|
||||
return 0;
|
||||
|
||||
fd->pos += ret;
|
||||
DFS_FILE_POS(fd) += ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue