Commit 7775e9ecc264eb3780901a10d786391b5ae955b7

Authored by bellard
1 parent 03d843dd

added do_fcntl()


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@171 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 45 additions and 36 deletions
linux-user/syscall.c
@@ -1103,6 +1103,49 @@ int do_fork(CPUX86State *env, unsigned int flags, unsigned long newsp) @@ -1103,6 +1103,49 @@ int do_fork(CPUX86State *env, unsigned int flags, unsigned long newsp)
1103 1103
1104 #endif 1104 #endif
1105 1105
  1106 +static long do_fcntl(int fd, int cmd, unsigned long arg)
  1107 +{
  1108 + struct flock fl;
  1109 + struct target_flock *target_fl = (void *)arg;
  1110 + long ret;
  1111 +
  1112 + switch(cmd) {
  1113 + case TARGET_F_GETLK:
  1114 + ret = fcntl(fd, cmd, &fl);
  1115 + if (ret == 0) {
  1116 + target_fl->l_type = tswap16(fl.l_type);
  1117 + target_fl->l_whence = tswap16(fl.l_whence);
  1118 + target_fl->l_start = tswapl(fl.l_start);
  1119 + target_fl->l_len = tswapl(fl.l_len);
  1120 + target_fl->l_pid = tswapl(fl.l_pid);
  1121 + }
  1122 + break;
  1123 +
  1124 + case TARGET_F_SETLK:
  1125 + case TARGET_F_SETLKW:
  1126 + fl.l_type = tswap16(target_fl->l_type);
  1127 + fl.l_whence = tswap16(target_fl->l_whence);
  1128 + fl.l_start = tswapl(target_fl->l_start);
  1129 + fl.l_len = tswapl(target_fl->l_len);
  1130 + fl.l_pid = tswapl(target_fl->l_pid);
  1131 + ret = fcntl(fd, cmd, &fl);
  1132 + break;
  1133 +
  1134 + case TARGET_F_GETLK64:
  1135 + case TARGET_F_SETLK64:
  1136 + case TARGET_F_SETLKW64:
  1137 + ret = -1;
  1138 + errno = EINVAL;
  1139 + break;
  1140 +
  1141 + default:
  1142 + ret = fcntl(fd, cmd, arg);
  1143 + break;
  1144 + }
  1145 + return ret;
  1146 +}
  1147 +
  1148 +
1106 #define high2lowuid(x) (x) 1149 #define high2lowuid(x) (x)
1107 #define high2lowgid(x) (x) 1150 #define high2lowgid(x) (x)
1108 #define low2highuid(x) (x) 1151 #define low2highuid(x) (x)
@@ -1343,42 +1386,8 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -1343,42 +1386,8 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
1343 ret = do_ioctl(arg1, arg2, arg3); 1386 ret = do_ioctl(arg1, arg2, arg3);
1344 break; 1387 break;
1345 case TARGET_NR_fcntl: 1388 case TARGET_NR_fcntl:
1346 - {  
1347 - struct flock fl;  
1348 - struct target_flock *target_fl = (void *)arg3;  
1349 -  
1350 - switch(arg2) {  
1351 - case TARGET_F_GETLK:  
1352 - ret = get_errno(fcntl(arg1, arg2, &fl));  
1353 - if (ret == 0) {  
1354 - target_fl->l_type = tswap16(fl.l_type);  
1355 - target_fl->l_whence = tswap16(fl.l_whence);  
1356 - target_fl->l_start = tswapl(fl.l_start);  
1357 - target_fl->l_len = tswapl(fl.l_len);  
1358 - target_fl->l_pid = tswapl(fl.l_pid);  
1359 - }  
1360 - break;  
1361 -  
1362 - case TARGET_F_SETLK:  
1363 - case TARGET_F_SETLKW:  
1364 - fl.l_type = tswap16(target_fl->l_type);  
1365 - fl.l_whence = tswap16(target_fl->l_whence);  
1366 - fl.l_start = tswapl(target_fl->l_start);  
1367 - fl.l_len = tswapl(target_fl->l_len);  
1368 - fl.l_pid = tswapl(target_fl->l_pid);  
1369 - ret = get_errno(fcntl(arg1, arg2, &fl));  
1370 - break;  
1371 -  
1372 - case TARGET_F_GETLK64:  
1373 - case TARGET_F_SETLK64:  
1374 - case TARGET_F_SETLKW64:  
1375 - goto unimplemented;  
1376 - default:  
1377 - ret = get_errno(fcntl(arg1, arg2, arg3));  
1378 - break;  
1379 - } 1389 + ret = get_errno(do_fcntl(arg1, arg2, arg3));
1380 break; 1390 break;
1381 - }  
1382 case TARGET_NR_mpx: 1391 case TARGET_NR_mpx:
1383 goto unimplemented; 1392 goto unimplemented;
1384 case TARGET_NR_setpgid: 1393 case TARGET_NR_setpgid:
@@ -2373,7 +2382,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, @@ -2373,7 +2382,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
2373 ret = get_errno(fcntl(arg1, arg2, &fl)); 2382 ret = get_errno(fcntl(arg1, arg2, &fl));
2374 break; 2383 break;
2375 default: 2384 default:
2376 - ret = get_errno(fcntl(arg1, arg2, arg3)); 2385 + ret = get_errno(do_fcntl(arg1, arg2, arg3));
2377 break; 2386 break;
2378 } 2387 }
2379 break; 2388 break;