parent
1b8654b98e
commit
7c2353a622
@ -63,6 +63,7 @@ struct dfs_file
|
|||||||
struct dfs_vnode *vnode; /* file node struct */
|
struct dfs_vnode *vnode; /* file node struct */
|
||||||
void *data; /* Specific fd data */
|
void *data; /* Specific fd data */
|
||||||
};
|
};
|
||||||
|
#define DFS_FILE_POS(dfs_file) ((dfs_file)->pos)
|
||||||
|
|
||||||
#ifdef RT_USING_SMART
|
#ifdef RT_USING_SMART
|
||||||
struct dfs_mmap2_args
|
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);
|
result = device->fops->ioctl(file, cmd, args);
|
||||||
}
|
}
|
||||||
else if (device->ops)
|
else
|
||||||
#else
|
|
||||||
if (device->ops)
|
|
||||||
#endif /* RT_USING_POSIX_DEVIO */
|
#endif /* RT_USING_POSIX_DEVIO */
|
||||||
{
|
{
|
||||||
result = rt_device_control(device, cmd, args);
|
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);
|
result = device->fops->read(file, buf, count, pos);
|
||||||
}
|
}
|
||||||
else if (device->ops)
|
else
|
||||||
#else
|
|
||||||
if (device->ops)
|
|
||||||
#endif /* RT_USING_POSIX_DEVIO */
|
#endif /* RT_USING_POSIX_DEVIO */
|
||||||
{
|
{
|
||||||
/* read device data */
|
/* 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);
|
result = device->fops->write(file, buf, count, pos);
|
||||||
}
|
}
|
||||||
else if (device->ops)
|
else
|
||||||
#else
|
|
||||||
if (device->ops)
|
|
||||||
#endif /* RT_USING_POSIX_DEVIO */
|
#endif /* RT_USING_POSIX_DEVIO */
|
||||||
{
|
{
|
||||||
/* read device data */
|
/* read device data */
|
||||||
@ -375,9 +369,7 @@ int dfs_devfs_close(struct dfs_file *file)
|
|||||||
{
|
{
|
||||||
result = device->fops->close(file);
|
result = device->fops->close(file);
|
||||||
}
|
}
|
||||||
else if (device->ops)
|
else
|
||||||
#else
|
|
||||||
if (device->ops)
|
|
||||||
#endif /* RT_USING_POSIX_DEVIO */
|
#endif /* RT_USING_POSIX_DEVIO */
|
||||||
{
|
{
|
||||||
/* close device handler */
|
/* close device handler */
|
||||||
@ -417,9 +409,7 @@ int dfs_devfs_open(struct dfs_file *file)
|
|||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (device->ops)
|
else
|
||||||
#else
|
|
||||||
if (device->ops)
|
|
||||||
#endif /* RT_USING_POSIX_DEVIO */
|
#endif /* RT_USING_POSIX_DEVIO */
|
||||||
{
|
{
|
||||||
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
|
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
|
||||||
|
@ -101,6 +101,7 @@ struct dfs_file
|
|||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
#define DFS_FILE_POS(dfs_file) ((dfs_file)->fpos)
|
||||||
|
|
||||||
/* file is open for reading */
|
/* file is open for reading */
|
||||||
#define FMODE_READ 0x1
|
#define FMODE_READ 0x1
|
||||||
|
@ -32,12 +32,12 @@
|
|||||||
#ifdef RT_USING_DEVICE
|
#ifdef RT_USING_DEVICE
|
||||||
|
|
||||||
#ifdef RT_USING_DEVICE_OPS
|
#ifdef RT_USING_DEVICE_OPS
|
||||||
#define device_init (dev->ops->init)
|
#define device_init (dev->ops ? dev->ops->init : RT_NULL)
|
||||||
#define device_open (dev->ops->open)
|
#define device_open (dev->ops ? dev->ops->open : RT_NULL)
|
||||||
#define device_close (dev->ops->close)
|
#define device_close (dev->ops ? dev->ops->close : RT_NULL)
|
||||||
#define device_read (dev->ops->read)
|
#define device_read (dev->ops ? dev->ops->read : RT_NULL)
|
||||||
#define device_write (dev->ops->write)
|
#define device_write (dev->ops ? dev->ops->write : RT_NULL)
|
||||||
#define device_control (dev->ops->control)
|
#define device_control (dev->ops ? dev->ops->control : RT_NULL)
|
||||||
#else
|
#else
|
||||||
#define device_init (dev->init)
|
#define device_init (dev->init)
|
||||||
#define device_open (dev->open)
|
#define device_open (dev->open)
|
||||||
|
@ -424,7 +424,7 @@ static int char_dev_fopen(struct dfs_file *fd)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fd->pos = 0;
|
DFS_FILE_POS(fd) = 0;
|
||||||
|
|
||||||
return RT_EOK;
|
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);
|
assert(part != RT_NULL);
|
||||||
|
|
||||||
if (fd->pos + count > part->fal_part->len)
|
if (DFS_FILE_POS(fd) + count > part->fal_part->len)
|
||||||
count = part->fal_part->len - fd->pos;
|
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))
|
if (ret != (int)(count))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fd->pos += ret;
|
DFS_FILE_POS(fd) += ret;
|
||||||
|
|
||||||
return 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);
|
assert(part != RT_NULL);
|
||||||
|
|
||||||
if (fd->pos + count > part->fal_part->len)
|
if (DFS_FILE_POS(fd) + count > part->fal_part->len)
|
||||||
count = part->fal_part->len - fd->pos;
|
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)
|
if (ret != (int) count)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fd->pos += ret;
|
DFS_FILE_POS(fd) += ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user