#define FSACL_WRITE 2
#define FSACL_EXEC 1
+#define FSACL_MASK 03777
#define FSACL_RWXMASK 0777
#define FSACL_U(x) (((x) & 0b111) << 6)
#define FSACL_G(x) (((x) & 0b111) << 3)
#define FSACL_o(r, w, x) \
(v__(__fsacl_sel(o, r)) | v__(__fsacl_sel(o, w)) | v__(__fsacl_sel(o, x)))
+#define FSACL_DEFAULT \
+ (FSACL_u(R, W, X) | FSACL_g(R, W, X) | FSACL_o(R, _, X))
+
#define fsacl_test(acl, type) ((acl) & (FSACL_##type))
static inline bool must_inline
typedef unsigned long ptr_t;
typedef unsigned long reg_t;
-typedef unsigned int uid_t;
-typedef unsigned int gid_t;
-
#ifndef CONFIG_ARCH_BITS_64
typedef unsigned long long u64_t;
#else
/* Mount with block-cache-disabled flag */
#define MNT_NC (1 << 1)
+typedef unsigned int mode_t;
+typedef unsigned int nlink_t;
+
struct file_stat
{
- dev_t st_dev;
- ino_t st_ino;
- unsigned int mode;
- dev_t st_rdev;
- off_t st_size;
- size_t st_blksize;
- size_t st_ioblksize;
- size_t st_blocks;
+ dev_t st_dev;
+ ino_t st_ino;
+ mode_t st_mode;
+ nlink_t st_nlink;
+ uid_t st_uid;
+ gid_t st_gid;
+ dev_t st_rdev;
+ off_t st_size;
+ size_t st_blksize;
+ size_t st_blocks;
+
+ unsigned long st_atim;
+ unsigned long st_ctim;
+ unsigned long st_mtim;
+
+ size_t st_ioblksize;
};
#endif /* __LUNAIX_FNCTL_DEFS_H */
typedef int pid_t;
typedef int tid_t;
+typedef int uid_t;
+typedef int gid_t;
typedef __SIZE_TYPE__ size_t;
inode->ops = &devfs_inode_ops;
inode->default_fops = &devfs_file_ops;
- // we set default access right to be 0660.
+ // we set default access right to be 0775.
// TODO need a way to allow this to be changed
- fsapi_inode_setaccess(inode, FSACL_u(R, W, X) | FSACL_g(R, W, X) | FSACL_oX);
+ fsapi_inode_setaccess(inode, FSACL_DEFAULT);
fsapi_inode_setowner(inode, 0, 0);
}
if (!check_allow_execute(current_inode)) {
errno = EACCESS;
+ unlock_dnode(current_level);
goto error;
}
if (!dnode) {
errno = ENOMEM;
+ unlock_dnode(current_level);
goto error;
}
int errno = __ramfs_mknod(mount_point, NULL, RAMF_DIR);
if (!errno) {
- fsapi_inode_setaccess(mount_point->inode, FSACL_aX | FSACL_aR);
+ fsapi_inode_setaccess(mount_point->inode, FSACL_DEFAULT);
}
return errno;
// we set default access right to be 0660.
// TODO need a way to allow this to be changed
- fsapi_inode_setaccess(inode, FSACL_u(R, W, _) | FSACL_g(R, W, _));
+ fsapi_inode_setaccess(inode, FSACL_DEFAULT);
fsapi_inode_setowner(inode, 0, 0);
}
struct v_inode* vino = fds->file->inode;
struct device* fdev = vino->sb->dev;
- *stat = (struct file_stat){.st_ino = vino->id,
- .st_blocks = vino->lb_usage,
- .st_size = vino->fsize,
- .mode = vino->itype,
- .st_ioblksize = PAGE_SIZE,
- .st_blksize = vino->sb->blksize};
+ stat->st_ino = vino->id;
+ stat->st_blocks = vino->lb_usage;
+ stat->st_size = vino->fsize;
+ stat->st_blksize = vino->sb->blksize;
+ stat->st_nlink = vino->link_count;
+ stat->st_uid = vino->uid;
+ stat->st_gid = vino->gid;
+
+ stat->st_ctim = vino->ctime;
+ stat->st_atim = vino->atime;
+ stat->st_mtim = vino->mtime;
+
+ stat->st_mode = (vino->itype << 16) | vino->acl;
+
+ stat->st_ioblksize = PAGE_SIZE;
if (check_device_node(vino)) {
struct device* rdev = resolve_device(vino->data);
{
time_t s = pos->time / 1000;
time_t ms = pos->time % 1000;
- twimap_printf(map, "[%05d.%03d] %s\n", s, ms, pos->content);
+ twimap_printf(map, "[%05d.%03d] %s", s, ms, pos->content);
}
}
return 1;
}
- if ((stat.mode & F_DIR)) {
+ if (((stat.st_mode >> 16) & F_DIR)) {
printf("%s is a directory", argv[i]);
return 1;
}
check(tcgetattr(fd, &term));
- term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE | ECHONL;
+ term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE;
term.c_iflag = ICRNL | IGNBRK;
term.c_oflag = ONLCR | OPOST;
term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
flags = flags | FLAG_CAPS;
base = 16;
goto format_unsigned;
+ case 'o':
+ base = 8;
+ goto format_unsigned;
case 'p':
num = (uintptr_t)va_arg(vargs, void*);
base = 16;
DIR* dir = opendir(path);
if (!dir) {
- return errno;
+ goto done;
}
struct dirent* dent;
+ int i = 0, sz;
+ char bf[100];
while ((dent = readdir(dir))) {
if (dent->d_type == DT_DIR) {
- printf(" %s/\n", dent->d_name);
+ sz = snprintf(bf, 100, "%s/", dent->d_name);
} else if (dent->d_type == DT_SYMLINK) {
- printf(" %s@\n", dent->d_name);
+ sz = snprintf(bf, 100, "%s@", dent->d_name);
} else {
- printf(" %s\n", dent->d_name);
+ sz = snprintf(bf, 100, "%s", dent->d_name);
}
+
+ bf[sz] = 0;
+ printf("%-15s ", bf);
+
+ i++;
+ if ((i % 4) == 0) {
+ printf("\n");
+ }
+ }
+
+ if ((i % 4) != 0) {
+ printf("\n");
}
+done:
int err = errno;
if (err) {
printf("failed: %d\n",err);
}
- closedir(dir);
+ if (dir)
+ closedir(dir);
return err;
}
\ No newline at end of file
close(fd);
- if ((stat.mode & F_DIR)) {
+ if (((stat.st_mode >> 16) & F_DIR)) {
err = rmdir(path);
}
else {
while (1) {
getcwd(pwd, 512);
- printf("[%s]$ ", pwd);
+ printf("%s # ", pwd);
int sz = read(stdin, buf, 511);
if (sz < 0) {
// currently, this shell only support single argument
if (!parse_cmdline(buf, argv)) {
- printf("\n");
- goto cont;
+ continue;
}
// cmd=="exit"
break;
}
- sh_exec((const char**)argv);
- cont:
- printf("\n");
+ sh_exec((const char**)argv);
}
}
printf("File: %s ", argv[1]);
char* ftype = "directory";
- int mode = stat.mode;
+ int mode = stat.st_mode >> 16;
if ((mode & F_DEV)) {
ftype = "mappable (sequential) device";
stat.st_blocks,
stat.st_blksize,
stat.st_ioblksize);
- printf("Inode: %d; ", stat.st_ino);
dev_t* dev;
- if (!(stat.mode & F_DEV)) {
+ if (!(mode & F_DEV)) {
dev = &stat.st_dev;
} else {
dev = &stat.st_rdev;
}
+ printf("Device: %xh:%xh@%d; Inode: %d; Links: %d\n",
+ dev->meta, dev->unique, dev->index,
+ stat.st_ino, stat.st_nlink);
- printf("Device: %xh:%xh@%d;\n", dev->meta, dev->unique, dev->index);
+ printf("Access: 0%o; Uid: %d; Gid: %d\n",
+ stat.st_mode & 0xffff,
+ stat.st_uid,
+ stat.st_gid);
+
+ printf("Access: %lu\n", stat.st_atim);
+ printf("Modify: %lu\n", stat.st_mtim);
+ printf("Create: %lu\n", stat.st_ctim);
close(fd);
return 0;