blob: 4885ca6cbc777dc2cf0623650db158cc0a5772a8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: fs.c,v 1.27 2002/02/08 03:57:14 davem Exp $
2 * fs.c: fs related syscall emulation for Solaris
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 *
6 * 1999-08-19 Implemented solaris F_FREESP (truncate)
7 * fcntl, by Jason Rappleye (rappleye@ccr.buffalo.edu)
8 */
9
10#include <linux/types.h>
11#include <linux/sched.h>
12#include <linux/slab.h>
Randy Dunlapa9415642006-01-11 12:17:48 -080013#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/fs.h>
15#include <linux/namei.h>
16#include <linux/mm.h>
17#include <linux/file.h>
18#include <linux/stat.h>
19#include <linux/smp_lock.h>
20#include <linux/limits.h>
21#include <linux/resource.h>
22#include <linux/quotaops.h>
23#include <linux/mount.h>
24#include <linux/vfs.h>
25
26#include <asm/uaccess.h>
27#include <asm/string.h>
28#include <asm/ptrace.h>
29
30#include "conv.h"
31
32#define R3_VERSION 1
33#define R4_VERSION 2
34
35typedef struct {
36 s32 tv_sec;
37 s32 tv_nsec;
38} timestruct_t;
39
40struct sol_stat {
41 u32 st_dev;
42 s32 st_pad1[3]; /* network id */
43 u32 st_ino;
44 u32 st_mode;
45 u32 st_nlink;
46 u32 st_uid;
47 u32 st_gid;
48 u32 st_rdev;
49 s32 st_pad2[2];
50 s32 st_size;
51 s32 st_pad3; /* st_size, off_t expansion */
52 timestruct_t st_atime;
53 timestruct_t st_mtime;
54 timestruct_t st_ctime;
55 s32 st_blksize;
56 s32 st_blocks;
57 char st_fstype[16];
58 s32 st_pad4[8]; /* expansion area */
59};
60
61struct sol_stat64 {
62 u32 st_dev;
63 s32 st_pad1[3]; /* network id */
64 u64 st_ino;
65 u32 st_mode;
66 u32 st_nlink;
67 u32 st_uid;
68 u32 st_gid;
69 u32 st_rdev;
70 s32 st_pad2[2];
71 s64 st_size;
72 timestruct_t st_atime;
73 timestruct_t st_mtime;
74 timestruct_t st_ctime;
75 s64 st_blksize;
76 s32 st_blocks;
77 char st_fstype[16];
78 s32 st_pad4[4]; /* expansion area */
79};
80
81#define UFSMAGIC (((unsigned)'u'<<24)||((unsigned)'f'<<16)||((unsigned)'s'<<8))
82
83static inline int putstat(struct sol_stat __user *ubuf, struct kstat *kbuf)
84{
85 if (kbuf->size > MAX_NON_LFS ||
86 !sysv_valid_dev(kbuf->dev) ||
87 !sysv_valid_dev(kbuf->rdev))
88 return -EOVERFLOW;
89 if (put_user (sysv_encode_dev(kbuf->dev), &ubuf->st_dev) ||
90 __put_user (kbuf->ino, &ubuf->st_ino) ||
91 __put_user (kbuf->mode, &ubuf->st_mode) ||
92 __put_user (kbuf->nlink, &ubuf->st_nlink) ||
93 __put_user (kbuf->uid, &ubuf->st_uid) ||
94 __put_user (kbuf->gid, &ubuf->st_gid) ||
95 __put_user (sysv_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
96 __put_user (kbuf->size, &ubuf->st_size) ||
97 __put_user (kbuf->atime.tv_sec, &ubuf->st_atime.tv_sec) ||
98 __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime.tv_nsec) ||
99 __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime.tv_sec) ||
100 __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime.tv_nsec) ||
101 __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime.tv_sec) ||
102 __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime.tv_nsec) ||
103 __put_user (kbuf->blksize, &ubuf->st_blksize) ||
104 __put_user (kbuf->blocks, &ubuf->st_blocks) ||
105 __put_user (UFSMAGIC, (unsigned __user *)ubuf->st_fstype))
106 return -EFAULT;
107 return 0;
108}
109
110static inline int putstat64(struct sol_stat64 __user *ubuf, struct kstat *kbuf)
111{
112 if (!sysv_valid_dev(kbuf->dev) || !sysv_valid_dev(kbuf->rdev))
113 return -EOVERFLOW;
114 if (put_user (sysv_encode_dev(kbuf->dev), &ubuf->st_dev) ||
115 __put_user (kbuf->ino, &ubuf->st_ino) ||
116 __put_user (kbuf->mode, &ubuf->st_mode) ||
117 __put_user (kbuf->nlink, &ubuf->st_nlink) ||
118 __put_user (kbuf->uid, &ubuf->st_uid) ||
119 __put_user (kbuf->gid, &ubuf->st_gid) ||
120 __put_user (sysv_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
121 __put_user (kbuf->size, &ubuf->st_size) ||
122 __put_user (kbuf->atime.tv_sec, &ubuf->st_atime.tv_sec) ||
123 __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime.tv_nsec) ||
124 __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime.tv_sec) ||
125 __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime.tv_nsec) ||
126 __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime.tv_sec) ||
127 __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime.tv_nsec) ||
128 __put_user (kbuf->blksize, &ubuf->st_blksize) ||
129 __put_user (kbuf->blocks, &ubuf->st_blocks) ||
130 __put_user (UFSMAGIC, (unsigned __user *)ubuf->st_fstype))
131 return -EFAULT;
132 return 0;
133}
134
135asmlinkage int solaris_stat(u32 filename, u32 statbuf)
136{
137 struct kstat s;
138 int ret = vfs_stat(A(filename), &s);
139 if (!ret)
140 return putstat(A(statbuf), &s);
141 return ret;
142}
143
144asmlinkage int solaris_xstat(int vers, u32 filename, u32 statbuf)
145{
146 /* Solaris doesn't bother with looking at vers, so we do neither */
147 return solaris_stat(filename, statbuf);
148}
149
150asmlinkage int solaris_stat64(u32 filename, u32 statbuf)
151{
152 struct kstat s;
153 int ret = vfs_stat(A(filename), &s);
154 if (!ret)
155 return putstat64(A(statbuf), &s);
156 return ret;
157}
158
159asmlinkage int solaris_lstat(u32 filename, u32 statbuf)
160{
161 struct kstat s;
162 int ret = vfs_lstat(A(filename), &s);
163 if (!ret)
164 return putstat(A(statbuf), &s);
165 return ret;
166}
167
168asmlinkage int solaris_lxstat(int vers, u32 filename, u32 statbuf)
169{
170 return solaris_lstat(filename, statbuf);
171}
172
173asmlinkage int solaris_lstat64(u32 filename, u32 statbuf)
174{
175 struct kstat s;
176 int ret = vfs_lstat(A(filename), &s);
177 if (!ret)
178 return putstat64(A(statbuf), &s);
179 return ret;
180}
181
182asmlinkage int solaris_fstat(unsigned int fd, u32 statbuf)
183{
184 struct kstat s;
185 int ret = vfs_fstat(fd, &s);
186 if (!ret)
187 return putstat(A(statbuf), &s);
188 return ret;
189}
190
191asmlinkage int solaris_fxstat(int vers, u32 fd, u32 statbuf)
192{
193 return solaris_fstat(fd, statbuf);
194}
195
196asmlinkage int solaris_fstat64(unsigned int fd, u32 statbuf)
197{
198 struct kstat s;
199 int ret = vfs_fstat(fd, &s);
200 if (!ret)
201 return putstat64(A(statbuf), &s);
202 return ret;
203}
204
205asmlinkage int solaris_mknod(u32 path, u32 mode, s32 dev)
206{
207 int (*sys_mknod)(const char __user *,int,unsigned) =
208 (int (*)(const char __user *,int,unsigned))SYS(mknod);
209 int major = sysv_major(dev);
210 int minor = sysv_minor(dev);
211
212 /* minor is guaranteed to be OK for MKDEV, major might be not */
213 if (major > 0xfff)
214 return -EINVAL;
215 return sys_mknod(A(path), mode, new_encode_dev(MKDEV(major,minor)));
216}
217
218asmlinkage int solaris_xmknod(int vers, u32 path, u32 mode, s32 dev)
219{
220 return solaris_mknod(path, mode, dev);
221}
222
223asmlinkage int solaris_getdents64(unsigned int fd, void __user *dirent, unsigned int count)
224{
225 int (*sys_getdents)(unsigned int, void __user *, unsigned int) =
226 (int (*)(unsigned int, void __user *, unsigned int))SYS(getdents);
227
228 return sys_getdents(fd, dirent, count);
229}
230
231/* This statfs thingie probably will go in the near future, but... */
232
233struct sol_statfs {
234 short f_type;
235 s32 f_bsize;
236 s32 f_frsize;
237 s32 f_blocks;
238 s32 f_bfree;
239 u32 f_files;
240 u32 f_ffree;
241 char f_fname[6];
242 char f_fpack[6];
243};
244
245asmlinkage int solaris_statfs(u32 path, u32 buf, int len, int fstype)
246{
247 int ret;
248 struct statfs s;
249 mm_segment_t old_fs = get_fs();
250 int (*sys_statfs)(const char __user *,struct statfs __user *) =
251 (int (*)(const char __user *,struct statfs __user *))SYS(statfs);
252 struct sol_statfs __user *ss = A(buf);
253
254 if (len != sizeof(struct sol_statfs)) return -EINVAL;
255 if (!fstype) {
256 /* FIXME: mixing userland and kernel pointers */
257 set_fs (KERNEL_DS);
258 ret = sys_statfs(A(path), &s);
259 set_fs (old_fs);
260 if (!ret) {
261 if (put_user (s.f_type, &ss->f_type) ||
262 __put_user (s.f_bsize, &ss->f_bsize) ||
263 __put_user (0, &ss->f_frsize) ||
264 __put_user (s.f_blocks, &ss->f_blocks) ||
265 __put_user (s.f_bfree, &ss->f_bfree) ||
266 __put_user (s.f_files, &ss->f_files) ||
267 __put_user (s.f_ffree, &ss->f_ffree) ||
268 __clear_user (&ss->f_fname, 12))
269 return -EFAULT;
270 }
271 return ret;
272 }
273/* Linux can't stat unmounted filesystems so we
274 * simply lie and claim 100MB of 1GB is free. Sorry.
275 */
276 if (put_user (fstype, &ss->f_type) ||
277 __put_user (1024, &ss->f_bsize) ||
278 __put_user (0, &ss->f_frsize) ||
279 __put_user (1024*1024, &ss->f_blocks) ||
280 __put_user (100*1024, &ss->f_bfree) ||
281 __put_user (60000, &ss->f_files) ||
282 __put_user (50000, &ss->f_ffree) ||
283 __clear_user (&ss->f_fname, 12))
284 return -EFAULT;
285 return 0;
286}
287
288asmlinkage int solaris_fstatfs(u32 fd, u32 buf, int len, int fstype)
289{
290 int ret;
291 struct statfs s;
292 mm_segment_t old_fs = get_fs();
293 int (*sys_fstatfs)(unsigned,struct statfs __user *) =
294 (int (*)(unsigned,struct statfs __user *))SYS(fstatfs);
295 struct sol_statfs __user *ss = A(buf);
296
297 if (len != sizeof(struct sol_statfs)) return -EINVAL;
298 if (!fstype) {
299 set_fs (KERNEL_DS);
300 ret = sys_fstatfs(fd, &s);
301 set_fs (old_fs);
302 if (!ret) {
303 if (put_user (s.f_type, &ss->f_type) ||
304 __put_user (s.f_bsize, &ss->f_bsize) ||
305 __put_user (0, &ss->f_frsize) ||
306 __put_user (s.f_blocks, &ss->f_blocks) ||
307 __put_user (s.f_bfree, &ss->f_bfree) ||
308 __put_user (s.f_files, &ss->f_files) ||
309 __put_user (s.f_ffree, &ss->f_ffree) ||
310 __clear_user (&ss->f_fname, 12))
311 return -EFAULT;
312 }
313 return ret;
314 }
315 /* Otherwise fstatfs is the same as statfs */
316 return solaris_statfs(0, buf, len, fstype);
317}
318
319struct sol_statvfs {
320 u32 f_bsize;
321 u32 f_frsize;
322 u32 f_blocks;
323 u32 f_bfree;
324 u32 f_bavail;
325 u32 f_files;
326 u32 f_ffree;
327 u32 f_favail;
328 u32 f_fsid;
329 char f_basetype[16];
330 u32 f_flag;
331 u32 f_namemax;
332 char f_fstr[32];
333 u32 f_filler[16];
334};
335
336struct sol_statvfs64 {
337 u32 f_bsize;
338 u32 f_frsize;
339 u64 f_blocks;
340 u64 f_bfree;
341 u64 f_bavail;
342 u64 f_files;
343 u64 f_ffree;
344 u64 f_favail;
345 u32 f_fsid;
346 char f_basetype[16];
347 u32 f_flag;
348 u32 f_namemax;
349 char f_fstr[32];
350 u32 f_filler[16];
351};
352
353static int report_statvfs(struct vfsmount *mnt, struct inode *inode, u32 buf)
354{
355 struct kstatfs s;
356 int error;
357 struct sol_statvfs __user *ss = A(buf);
358
359 error = vfs_statfs(mnt->mnt_sb, &s);
360 if (!error) {
361 const char *p = mnt->mnt_sb->s_type->name;
362 int i = 0;
363 int j = strlen (p);
364
365 if (j > 15) j = 15;
366 if (IS_RDONLY(inode)) i = 1;
367 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
368 if (!sysv_valid_dev(inode->i_sb->s_dev))
369 return -EOVERFLOW;
370 if (put_user (s.f_bsize, &ss->f_bsize) ||
371 __put_user (0, &ss->f_frsize) ||
372 __put_user (s.f_blocks, &ss->f_blocks) ||
373 __put_user (s.f_bfree, &ss->f_bfree) ||
374 __put_user (s.f_bavail, &ss->f_bavail) ||
375 __put_user (s.f_files, &ss->f_files) ||
376 __put_user (s.f_ffree, &ss->f_ffree) ||
377 __put_user (s.f_ffree, &ss->f_favail) ||
378 __put_user (sysv_encode_dev(inode->i_sb->s_dev), &ss->f_fsid) ||
379 __copy_to_user (ss->f_basetype,p,j) ||
380 __put_user (0, (char __user *)&ss->f_basetype[j]) ||
381 __put_user (s.f_namelen, &ss->f_namemax) ||
382 __put_user (i, &ss->f_flag) ||
383 __clear_user (&ss->f_fstr, 32))
384 return -EFAULT;
385 }
386 return error;
387}
388
389static int report_statvfs64(struct vfsmount *mnt, struct inode *inode, u32 buf)
390{
391 struct kstatfs s;
392 int error;
393 struct sol_statvfs64 __user *ss = A(buf);
394
395 error = vfs_statfs(mnt->mnt_sb, &s);
396 if (!error) {
397 const char *p = mnt->mnt_sb->s_type->name;
398 int i = 0;
399 int j = strlen (p);
400
401 if (j > 15) j = 15;
402 if (IS_RDONLY(inode)) i = 1;
403 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
404 if (!sysv_valid_dev(inode->i_sb->s_dev))
405 return -EOVERFLOW;
406 if (put_user (s.f_bsize, &ss->f_bsize) ||
407 __put_user (0, &ss->f_frsize) ||
408 __put_user (s.f_blocks, &ss->f_blocks) ||
409 __put_user (s.f_bfree, &ss->f_bfree) ||
410 __put_user (s.f_bavail, &ss->f_bavail) ||
411 __put_user (s.f_files, &ss->f_files) ||
412 __put_user (s.f_ffree, &ss->f_ffree) ||
413 __put_user (s.f_ffree, &ss->f_favail) ||
414 __put_user (sysv_encode_dev(inode->i_sb->s_dev), &ss->f_fsid) ||
415 __copy_to_user (ss->f_basetype,p,j) ||
416 __put_user (0, (char __user *)&ss->f_basetype[j]) ||
417 __put_user (s.f_namelen, &ss->f_namemax) ||
418 __put_user (i, &ss->f_flag) ||
419 __clear_user (&ss->f_fstr, 32))
420 return -EFAULT;
421 }
422 return error;
423}
424
425asmlinkage int solaris_statvfs(u32 path, u32 buf)
426{
427 struct nameidata nd;
428 int error;
429
430 error = user_path_walk(A(path),&nd);
431 if (!error) {
432 struct inode * inode = nd.dentry->d_inode;
433 error = report_statvfs(nd.mnt, inode, buf);
434 path_release(&nd);
435 }
436 return error;
437}
438
439asmlinkage int solaris_fstatvfs(unsigned int fd, u32 buf)
440{
441 struct file * file;
442 int error;
443
444 error = -EBADF;
445 file = fget(fd);
446 if (file) {
447 error = report_statvfs(file->f_vfsmnt, file->f_dentry->d_inode, buf);
448 fput(file);
449 }
450
451 return error;
452}
453
454asmlinkage int solaris_statvfs64(u32 path, u32 buf)
455{
456 struct nameidata nd;
457 int error;
458
459 lock_kernel();
460 error = user_path_walk(A(path), &nd);
461 if (!error) {
462 struct inode * inode = nd.dentry->d_inode;
463 error = report_statvfs64(nd.mnt, inode, buf);
464 path_release(&nd);
465 }
466 unlock_kernel();
467 return error;
468}
469
470asmlinkage int solaris_fstatvfs64(unsigned int fd, u32 buf)
471{
472 struct file * file;
473 int error;
474
475 error = -EBADF;
476 file = fget(fd);
477 if (file) {
478 lock_kernel();
479 error = report_statvfs64(file->f_vfsmnt, file->f_dentry->d_inode, buf);
480 unlock_kernel();
481 fput(file);
482 }
483 return error;
484}
485
486extern asmlinkage long sparc32_open(const char * filename, int flags, int mode);
487
488asmlinkage int solaris_open(u32 fname, int flags, u32 mode)
489{
490 const char *filename = (const char *)(long)fname;
491 int fl = flags & 0xf;
492
493 /* Translate flags first. */
494 if (flags & 0x2000) fl |= O_LARGEFILE;
495 if (flags & 0x8050) fl |= O_SYNC;
496 if (flags & 0x80) fl |= O_NONBLOCK;
497 if (flags & 0x100) fl |= O_CREAT;
498 if (flags & 0x200) fl |= O_TRUNC;
499 if (flags & 0x400) fl |= O_EXCL;
500 if (flags & 0x800) fl |= O_NOCTTY;
501 flags = fl;
502
503 return sparc32_open(filename, flags, mode);
504}
505
506#define SOL_F_SETLK 6
507#define SOL_F_SETLKW 7
508#define SOL_F_FREESP 11
509#define SOL_F_ISSTREAM 13
510#define SOL_F_GETLK 14
511#define SOL_F_PRIV 15
512#define SOL_F_NPRIV 16
513#define SOL_F_QUOTACTL 17
514#define SOL_F_BLOCKS 18
515#define SOL_F_BLKSIZE 19
516#define SOL_F_GETOWN 23
517#define SOL_F_SETOWN 24
518
519struct sol_flock {
520 short l_type;
521 short l_whence;
522 u32 l_start;
523 u32 l_len;
524 s32 l_sysid;
525 s32 l_pid;
526 s32 l_pad[4];
527};
528
529asmlinkage int solaris_fcntl(unsigned fd, unsigned cmd, u32 arg)
530{
531 int (*sys_fcntl)(unsigned,unsigned,unsigned long) =
532 (int (*)(unsigned,unsigned,unsigned long))SYS(fcntl);
533 int ret, flags;
534
535 switch (cmd) {
536 case F_DUPFD:
537 case F_GETFD:
538 case F_SETFD: return sys_fcntl(fd, cmd, (unsigned long)arg);
539 case F_GETFL:
540 flags = sys_fcntl(fd, cmd, 0);
541 ret = flags & 0xf;
542 if (flags & O_SYNC) ret |= 0x8050;
543 if (flags & O_NONBLOCK) ret |= 0x80;
544 return ret;
545 case F_SETFL:
546 flags = arg & 0xf;
547 if (arg & 0x8050) flags |= O_SYNC;
548 if (arg & 0x80) flags |= O_NONBLOCK;
549 return sys_fcntl(fd, cmd, (long)flags);
550 case SOL_F_GETLK:
551 case SOL_F_SETLK:
552 case SOL_F_SETLKW:
553 {
554 struct flock f;
555 struct sol_flock __user *p = A(arg);
556 mm_segment_t old_fs = get_fs();
557
558 switch (cmd) {
559 case SOL_F_GETLK: cmd = F_GETLK; break;
560 case SOL_F_SETLK: cmd = F_SETLK; break;
561 case SOL_F_SETLKW: cmd = F_SETLKW; break;
562 }
563
564 if (get_user (f.l_type, &p->l_type) ||
565 __get_user (f.l_whence, &p->l_whence) ||
566 __get_user (f.l_start, &p->l_start) ||
567 __get_user (f.l_len, &p->l_len) ||
568 __get_user (f.l_pid, &p->l_sysid))
569 return -EFAULT;
570
571 set_fs(KERNEL_DS);
572 ret = sys_fcntl(fd, cmd, (unsigned long)&f);
573 set_fs(old_fs);
574
575 if (__put_user (f.l_type, &p->l_type) ||
576 __put_user (f.l_whence, &p->l_whence) ||
577 __put_user (f.l_start, &p->l_start) ||
578 __put_user (f.l_len, &p->l_len) ||
579 __put_user (f.l_pid, &p->l_pid) ||
580 __put_user (0, &p->l_sysid))
581 return -EFAULT;
582
583 return ret;
584 }
585 case SOL_F_FREESP:
586 {
587 int length;
588 int (*sys_newftruncate)(unsigned int, unsigned long)=
589 (int (*)(unsigned int, unsigned long))SYS(ftruncate);
590
591 if (get_user(length, &((struct sol_flock __user *)A(arg))->l_start))
592 return -EFAULT;
593
594 return sys_newftruncate(fd, length);
595 }
596 };
597 return -EINVAL;
598}
599
600asmlinkage int solaris_ulimit(int cmd, int val)
601{
602 switch (cmd) {
603 case 1: /* UL_GETFSIZE - in 512B chunks */
604 return current->signal->rlim[RLIMIT_FSIZE].rlim_cur >> 9;
605 case 2: /* UL_SETFSIZE */
606 if ((unsigned long)val > (LONG_MAX>>9)) return -ERANGE;
607 val <<= 9;
608 task_lock(current->group_leader);
609 if (val > current->signal->rlim[RLIMIT_FSIZE].rlim_max) {
610 if (!capable(CAP_SYS_RESOURCE)) {
611 task_unlock(current->group_leader);
612 return -EPERM;
613 }
614 current->signal->rlim[RLIMIT_FSIZE].rlim_max = val;
615 }
616 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = val;
617 task_unlock(current->group_leader);
618 return 0;
619 case 3: /* UL_GMEMLIM */
620 return current->signal->rlim[RLIMIT_DATA].rlim_cur;
621 case 4: /* UL_GDESLIM */
622 return NR_OPEN;
623 }
624 return -EINVAL;
625}
626
627/* At least at the time I'm writing this, Linux doesn't have ACLs, so we
628 just fake this */
629asmlinkage int solaris_acl(u32 filename, int cmd, int nentries, u32 aclbufp)
630{
631 return -ENOSYS;
632}
633
634asmlinkage int solaris_facl(unsigned int fd, int cmd, int nentries, u32 aclbufp)
635{
636 return -ENOSYS;
637}
638
639asmlinkage int solaris_pread(unsigned int fd, char __user *buf, u32 count, u32 pos)
640{
641 ssize_t (*sys_pread64)(unsigned int, char __user *, size_t, loff_t) =
642 (ssize_t (*)(unsigned int, char __user *, size_t, loff_t))SYS(pread64);
643
644 return sys_pread64(fd, buf, count, (loff_t)pos);
645}
646
647asmlinkage int solaris_pwrite(unsigned int fd, char __user *buf, u32 count, u32 pos)
648{
649 ssize_t (*sys_pwrite64)(unsigned int, char __user *, size_t, loff_t) =
650 (ssize_t (*)(unsigned int, char __user *, size_t, loff_t))SYS(pwrite64);
651
652 return sys_pwrite64(fd, buf, count, (loff_t)pos);
653}
654
655/* POSIX.1 names */
656#define _PC_LINK_MAX 1
657#define _PC_MAX_CANON 2
658#define _PC_MAX_INPUT 3
659#define _PC_NAME_MAX 4
660#define _PC_PATH_MAX 5
661#define _PC_PIPE_BUF 6
662#define _PC_NO_TRUNC 7
663#define _PC_VDISABLE 8
664#define _PC_CHOWN_RESTRICTED 9
665/* POSIX.4 names */
666#define _PC_ASYNC_IO 10
667#define _PC_PRIO_IO 11
668#define _PC_SYNC_IO 12
669#define _PC_LAST 12
670
671/* This is not a real and complete implementation yet, just to keep
672 * the easy Solaris binaries happy.
673 */
674asmlinkage int solaris_fpathconf(int fd, int name)
675{
676 int ret;
677
678 switch(name) {
679 case _PC_LINK_MAX:
680 ret = LINK_MAX;
681 break;
682 case _PC_MAX_CANON:
683 ret = MAX_CANON;
684 break;
685 case _PC_MAX_INPUT:
686 ret = MAX_INPUT;
687 break;
688 case _PC_NAME_MAX:
689 ret = NAME_MAX;
690 break;
691 case _PC_PATH_MAX:
692 ret = PATH_MAX;
693 break;
694 case _PC_PIPE_BUF:
695 ret = PIPE_BUF;
696 break;
697 case _PC_CHOWN_RESTRICTED:
698 ret = 1;
699 break;
700 case _PC_NO_TRUNC:
701 case _PC_VDISABLE:
702 ret = 0;
703 break;
704 default:
705 ret = -EINVAL;
706 break;
707 }
708 return ret;
709}
710
711asmlinkage int solaris_pathconf(u32 path, int name)
712{
713 return solaris_fpathconf(0, name);
714}
715
716/* solaris_llseek returns long long - quite difficult */
717asmlinkage long solaris_llseek(struct pt_regs *regs, u32 off_hi, u32 off_lo, int whence)
718{
719 int (*sys_llseek)(unsigned int, unsigned long, unsigned long, loff_t __user *, unsigned int) =
720 (int (*)(unsigned int, unsigned long, unsigned long, loff_t __user *, unsigned int))SYS(_llseek);
721 int ret;
722 mm_segment_t old_fs = get_fs();
723 loff_t retval;
724
725 set_fs(KERNEL_DS);
726 ret = sys_llseek((unsigned int)regs->u_regs[UREG_I0], off_hi, off_lo, &retval, whence);
727 set_fs(old_fs);
728 if (ret < 0) return ret;
729 regs->u_regs[UREG_I1] = (u32)retval;
730 return (retval >> 32);
731}
732
733/* Have to mask out all but lower 3 bits */
734asmlinkage int solaris_access(u32 filename, long mode)
735{
736 int (*sys_access)(const char __user *, int) =
737 (int (*)(const char __user *, int))SYS(access);
738
739 return sys_access(A(filename), mode & 7);
740}