Skip to content

Commit 1bebbec

Browse files
committed
Merge patch from master to prepare release v2.0.2
1 parent 8483352 commit 1bebbec

File tree

23 files changed

+214
-50
lines changed

23 files changed

+214
-50
lines changed

components/cplusplus/crt.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* File : crt.cpp
3+
* This file is part of Device File System in RT-Thread RTOS
4+
* COPYRIGHT (C) 2008-2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-03-07 Bernard Add copyright header.
23+
*/
24+
125
#include <rtthread.h>
226
#include "crt.h"
327

components/cplusplus/crt.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* File : crt.h
3+
* This file is part of Device File System in RT-Thread RTOS
4+
* COPYRIGHT (C) 2008-2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-03-07 Bernard Add copyright header.
23+
*/
24+
125
#ifndef CRT_H_
226
#define CRT_H_
327

components/cplusplus/crt_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* File : crt_init.c
33
* This file is part of Device File System in RT-Thread RTOS
4-
* COPYRIGHT (C) 2008-2011, RT-Thread Development Team
4+
* COPYRIGHT (C) 2008-2015, RT-Thread Development Team
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by

components/dfs/src/dfs_file.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Date Author Notes
2222
* 2005-02-22 Bernard The first version.
2323
* 2011-12-08 Bernard Merges rename patch from iamcacy.
24+
* 2015-05-27 Bernard Fix the fd clear issue.
2425
*/
2526

2627
#include <dfs.h>
@@ -97,7 +98,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
9798
{
9899
/* clear fd */
99100
rt_free(fd->path);
100-
rt_memset(fd, 0, sizeof(*fd));
101+
fd->path = RT_NULL;
101102

102103
return -DFS_STATUS_ENOSYS;
103104
}
@@ -106,7 +107,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
106107
{
107108
/* clear fd */
108109
rt_free(fd->path);
109-
rt_memset(fd, 0, sizeof(*fd));
110+
fd->path = RT_NULL;
110111

111112
dfs_log(DFS_DEBUG_INFO, ("open failed"));
112113

@@ -143,7 +144,7 @@ int dfs_file_close(struct dfs_fd *fd)
143144
return result;
144145

145146
rt_free(fd->path);
146-
rt_memset(fd, 0, sizeof(struct dfs_fd));
147+
fd->path = RT_NULL;
147148

148149
return result;
149150
}
@@ -165,7 +166,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
165166
return -DFS_STATUS_EINVAL;
166167

167168
fs = fd->fs;
168-
if (fs->ops->ioctl != RT_NULL)
169+
if (fs->ops->ioctl != RT_NULL)
169170
return fs->ops->ioctl(fd, cmd, args);
170171

171172
return -DFS_STATUS_ENOSYS;
@@ -186,11 +187,11 @@ int dfs_file_read(struct dfs_fd *fd, void *buf, rt_size_t len)
186187
struct dfs_filesystem *fs;
187188
int result = 0;
188189

189-
if (fd == RT_NULL)
190+
if (fd == RT_NULL)
190191
return -DFS_STATUS_EINVAL;
191192

192193
fs = (struct dfs_filesystem *)fd->fs;
193-
if (fs->ops->read == RT_NULL)
194+
if (fs->ops->read == RT_NULL)
194195
return -DFS_STATUS_ENOSYS;
195196

196197
if ((result = fs->ops->read(fd, buf, len)) < 0)
@@ -213,7 +214,7 @@ int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, rt_size_t nbytes)
213214
struct dfs_filesystem *fs;
214215

215216
/* parameter check */
216-
if (fd == RT_NULL || fd->type != FT_DIRECTORY)
217+
if (fd == RT_NULL || fd->type != FT_DIRECTORY)
217218
return -DFS_STATUS_EINVAL;
218219

219220
fs = (struct dfs_filesystem *)fd->fs;
@@ -267,7 +268,7 @@ int dfs_file_unlink(const char *path)
267268
result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
268269
}
269270
else
270-
result = fs->ops->unlink(fs, fullpath);
271+
result = fs->ops->unlink(fs, fullpath);
271272
}
272273
else result = -DFS_STATUS_ENOSYS;
273274

@@ -528,7 +529,7 @@ void ls(const char *pathname)
528529

529530
/* build full path for each file */
530531
fullpath = dfs_normalize_path(path, dirent.d_name);
531-
if (fullpath == RT_NULL)
532+
if (fullpath == RT_NULL)
532533
break;
533534

534535
if (dfs_file_stat(fullpath, &stat) == 0)
@@ -555,7 +556,7 @@ void ls(const char *pathname)
555556
{
556557
rt_kprintf("No such directory\n");
557558
}
558-
if (pathname == RT_NULL)
559+
if (pathname == RT_NULL)
559560
rt_free(path);
560561
}
561562
FINSH_FUNCTION_EXPORT(ls, list directory contents);
@@ -632,15 +633,15 @@ static void copyfile(const char *src, const char *dst)
632633
read_bytes = dfs_file_read(&src_fd, block_ptr, BUF_SZ);
633634
if (read_bytes > 0)
634635
{
635-
int length;
636-
636+
int length;
637+
637638
length = dfs_file_write(&fd, block_ptr, read_bytes);
638-
if (length != read_bytes)
639-
{
640-
/* write failed. */
641-
rt_kprintf("Write file data failed, errno=%d\n", length);
642-
break;
643-
}
639+
if (length != read_bytes)
640+
{
641+
/* write failed. */
642+
rt_kprintf("Write file data failed, errno=%d\n", length);
643+
break;
644+
}
644645
}
645646
} while (read_bytes > 0);
646647

@@ -652,7 +653,6 @@ static void copyfile(const char *src, const char *dst)
652653
extern int mkdir(const char *path, mode_t mode);
653654
static void copydir(const char * src, const char * dst)
654655
{
655-
struct dfs_fd fd;
656656
struct dirent dirent;
657657
struct stat stat;
658658
int length;

components/dfs/src/dfs_posix.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,15 @@ off_t lseek(int fd, off_t offset, int whence)
230230
break;
231231

232232
default:
233+
fd_put(d);
233234
rt_set_errno(-DFS_STATUS_EINVAL);
234235

235236
return -1;
236237
}
237238

238239
if (offset < 0)
239240
{
241+
fd_put(d);
240242
rt_set_errno(-DFS_STATUS_EINVAL);
241243

242244
return -1;
@@ -374,6 +376,36 @@ int fstat(int fildes, struct stat *buf)
374376
}
375377
RTM_EXPORT(fstat);
376378

379+
/**
380+
* this function is a POSIX compliant version, which shall request that all data
381+
* for the open file descriptor named by fildes is to be transferred to the storage
382+
* device associated with the file described by fildes.
383+
*
384+
* @param fildes the file description
385+
*
386+
* @return 0 on successful completion. Otherwise, -1 shall be returned and errno
387+
* set to indicate the error.
388+
*/
389+
int fsync(int fildes)
390+
{
391+
int ret;
392+
struct dfs_fd *d;
393+
394+
/* get the fd */
395+
d = fd_get(fildes);
396+
if (d == RT_NULL)
397+
{
398+
rt_set_errno(-DFS_STATUS_EBADF);
399+
return -1;
400+
}
401+
402+
ret = dfs_file_flush(d);
403+
404+
fd_put(d);
405+
return ret;
406+
}
407+
RTM_EXPORT(fsync);
408+
377409
/**
378410
* this function is a POSIX compliant version, which will return the
379411
* information about a mounted file system.
@@ -427,6 +459,7 @@ int mkdir(const char *path, mode_t mode)
427459

428460
if (result < 0)
429461
{
462+
fd_put(d);
430463
fd_put(d);
431464
rt_set_errno(result);
432465

@@ -435,6 +468,7 @@ int mkdir(const char *path, mode_t mode)
435468

436469
dfs_file_close(d);
437470
fd_put(d);
471+
fd_put(d);
438472

439473
return 0;
440474
}

components/drivers/serial/serial.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
279279
serial->config.bufsz);
280280
RT_ASSERT(rx_fifo != RT_NULL);
281281
rx_fifo->buffer = (rt_uint8_t*) (rx_fifo + 1);
282-
rt_memset(rx_fifo->buffer, 0, RT_SERIAL_RB_BUFSZ);
282+
rt_memset(rx_fifo->buffer, 0, serial->config.bufsz);
283283
rx_fifo->put_index = 0;
284284
rx_fifo->get_index = 0;
285285

@@ -302,6 +302,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
302302

303303
tx_dma = (struct rt_serial_tx_dma*) rt_malloc (sizeof(struct rt_serial_tx_dma));
304304
RT_ASSERT(tx_dma != RT_NULL);
305+
tx_dma->activated = RT_FALSE;
305306

306307
rt_data_queue_init(&(tx_dma->data_queue), 8, 4, RT_NULL);
307308
serial->serial_tx = tx_dma;
@@ -519,12 +520,10 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
519520
rt_base_t level;
520521
struct rt_serial_rx_fifo* rx_fifo;
521522

523+
/* interrupt mode receive */
522524
rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx;
523525
RT_ASSERT(rx_fifo != RT_NULL);
524-
525-
/* interrupt mode receive */
526-
RT_ASSERT(serial->parent.open_flag & RT_DEVICE_FLAG_INT_RX);
527-
526+
528527
while (1)
529528
{
530529
ch = serial->ops->getc(serial);

components/drivers/src/completion.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void rt_completion_init(struct rt_completion *completion)
3939
rt_list_init(&completion->suspended_list);
4040
rt_hw_interrupt_enable(level);
4141
}
42+
RTM_EXPORT(rt_completion_init);
4243

4344
rt_err_t rt_completion_wait(struct rt_completion *completion,
4445
rt_int32_t timeout)
@@ -105,6 +106,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
105106

106107
return result;
107108
}
109+
RTM_EXPORT(rt_completion_wait);
108110

109111
void rt_completion_done(struct rt_completion *completion)
110112
{
@@ -139,3 +141,5 @@ void rt_completion_done(struct rt_completion *completion)
139141
rt_hw_interrupt_enable(level);
140142
}
141143
}
144+
RTM_EXPORT(rt_completion_done);
145+

components/finsh/msh.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ int system(const char *command)
253253
{
254254
return msh_exec_module(command, rt_strlen(command));
255255
}
256+
RTM_EXPORT(system);
256257
#endif
257258

258259
static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp)

components/finsh/shell.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ void finsh_set_device(const char *device_name)
123123
rt_device_set_rx_indicate(shell->device, RT_NULL);
124124
}
125125

126+
/* clear line buffer before switch to new device */
127+
memset(shell->line, 0, sizeof(shell->line));
128+
shell->line_curpos = shell->line_position = 0;
129+
126130
shell->device = dev;
127131
rt_device_set_rx_indicate(dev, finsh_rx_ind);
128132
}

components/finsh/shell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
#ifndef FINSH_THREAD_STACK_SIZE
5151
#define FINSH_THREAD_STACK_SIZE 2048
5252
#endif
53+
#ifndef FINSH_CMD_SIZE
5354
#define FINSH_CMD_SIZE 80
55+
#endif
5456

5557
#define FINSH_OPTION_ECHO 0x01
5658
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))

0 commit comments

Comments
 (0)