~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc64/solaris/fs.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp