Skip to content

Commit d6ef599

Browse files
committed
Implement simple emulation for the FIODTYPE ioctl(2). This
makes dd(1) happy among other things.
1 parent fc868be commit d6ef599

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

bsd-user/bsd-ioctl.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,6 @@ STRUCT_MAX
202202
#undef STRUCT
203203
#undef STRUCT_SPECIAL
204204

205-
206-
struct IOCTLEntry;
207-
208-
typedef abi_long do_ioctl_fn(const struct IOCTLEntry *ie, uint8_t *buf_temp,
209-
int fd, abi_long cmd, abi_long arg);
210-
211-
struct IOCTLEntry {
212-
unsigned int target_cmd;
213-
unsigned int host_cmd;
214-
const char *name;
215-
int access;
216-
do_ioctl_fn *do_ioctl;
217-
const argtype arg_type[5];
218-
};
219-
typedef struct IOCTLEntry IOCTLEntry;
220-
221205
#define MAX_STRUCT_SIZE 4096
222206

223207
#if !defined(__linux__)

bsd-user/bsd-ioctl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,19 @@ static const bitmask_transtbl lflag_tbl[] = {
121121
{ EXTPROC, EXTPROC, HOST_EXTPROC, HOST_EXTPROC},
122122
};
123123

124+
struct IOCTLEntry;
125+
126+
typedef abi_long do_ioctl_fn(const struct IOCTLEntry *ie, uint8_t *buf_temp,
127+
int fd, abi_long cmd, abi_long arg);
128+
129+
struct IOCTLEntry {
130+
unsigned int target_cmd;
131+
unsigned int host_cmd;
132+
const char *name;
133+
int access;
134+
do_ioctl_fn *do_ioctl;
135+
const argtype arg_type[5];
136+
};
137+
typedef struct IOCTLEntry IOCTLEntry;
138+
124139
#endif /* BSD_IOCTL_H */

bsd-user/freebsd/os-ioctl-cmds.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ IOCTL(FIOSETOWN, IOC_W, MK_PTR(TYPE_INT))
5959
IOCTL(FIOGETOWN, IOC_R, MK_PTR(TYPE_INT))
6060
#if !defined(__linux__)
6161
IOCTL(FIODTYPE, IOC_R, MK_PTR(TYPE_INT))
62+
#else
63+
IOCTL_SPECIAL_UNIMPL(FIODTYPE, IOC_R, do_ioctl_FIODTYPE)
64+
#endif
65+
#if !defined(__linux__)
6266
IOCTL(FIOGETLBA, IOC_R, MK_PTR(TYPE_INT))
6367
IOCTL(FIODGNAME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_fiodgname_arg)))
6468
IOCTL(FIONWRITE, IOC_R, MK_PTR(TYPE_INT))

bsd-user/freebsd/os-ioctl-filio.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,33 @@ struct target_fiodgname_arg {
4343
#define TARGET_FIOSEEKDATA TARGET_IOWR('f', 97, off_t)
4444
#define TARGET_FIOSEEKHOLE TARGET_IOWR('f', 98, off_t)
4545

46+
#if defined(__linux__)
47+
static abi_long do_ioctl_FIODTYPE(__unused const IOCTLEntry *ie,
48+
__unused uint8_t *buf_temp,
49+
int fd, __unused abi_long cmd,
50+
abi_long arg)
51+
{
52+
abi_int *argptr;
53+
int target_size = sizeof(abi_int);
54+
struct stat st;
55+
int res = 0;
56+
57+
argptr = lock_user(VERIFY_WRITE, arg, target_size, 0);
58+
if (!argptr) {
59+
return -TARGET_EFAULT;
60+
}
61+
if (fstat(fd, &st) != 0) {
62+
return -TARGET_EBADF;
63+
}
64+
if (S_ISCHR(st.st_mode) && isatty(fd)) {
65+
res = TARGET_D_TTY;
66+
} else if (S_ISBLK(st.st_mode)) {
67+
res = TARGET_D_DISK;
68+
}
69+
*argptr = res;
70+
unlock_user(argptr, arg, target_size);
71+
return 0;
72+
}
73+
#endif
74+
4675
#endif /* BSD_USER_FREEBSD_OS_IOCTL_FILIO_H */

bsd-user/linux/target_os_defs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@ static const typeof(VTIME) HOST_VTIME = VTIME;
446446
#endif /* found in: sys/_termios.h */
447447
#undef VTIME
448448
#define VTIME 17 /* !ICANON */
449+
#if defined(TARGET_D_TTY)
450+
#undef TARGET_D_TTY
451+
#endif /* found in: sys/conf.h */
452+
#define TARGET_D_TTY 0x0004
453+
#if defined(TARGET_D_DISK)
454+
#undef TARGET_D_DISK
455+
#endif /* found in: sys/conf.h */
456+
#define TARGET_D_DISK 0x0002
449457
#if defined(TARGET_E2BIG)
450458
#undef TARGET_E2BIG
451459
#endif /* found in: sys/errno.h */

0 commit comments

Comments
 (0)