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